async function waitForFileToDownload(browser, url) {
  const downloadPage = await browser.newPage();
  // Note: navigating to this page only works in headful chrome.
  await downloadPage.goto('chrome://downloads/');

  // Wait for our download to show up in the list by matching on its url.
  const jsHandle = await downloadPage.waitForFunction(downloadUrl => {
    const manager = document.querySelector('downloads-manager');
    const downloads = manager.items_.length;
    const lastDownload = manager.items_[0];
    if (downloads && lastDownload.url === downloadUrl &&
        lastDownload.state === 'COMPLETE') {
      return manager.items_[0];
    }
  }, {polling: 100}, url);

  const fileMeta = await jsHandle.jsonValue();

  await downloadPage.close();

  return fileMeta;
}
@param {!Browser} browser
@param {string} url The URL of the download file to wait for.
@returns {!Promise<!Object>} Metadata about the latest file in Download Manager.