Commit d38f51bc authored by Julian Descottes's avatar Julian Descottes Committed by jdescottes@mozilla.com
Browse files

Bug 1966826 - [devtools] Pass waitForLoad=false to navigateTo from...

Bug 1966826 - [devtools] Pass waitForLoad=false to navigateTo from DebugTargetInfo r=devtools-reviewers,ochameau

Differential Revision: https://phabricator.services.mozilla.com/D250788
parent 9606c22d
Loading
Loading
Loading
Loading
+44 −11
Original line number Diff line number Diff line
@@ -6,20 +6,40 @@
const ORIGINAL_URL = "https://example.com/document-builder.sjs?html=page1";
const OTHER_URL = "https://example.org/document-builder.sjs?html=page2";

async function waitForUrl(url, toolbox, browserTab, win) {
/**
 * Starts waiting for the next URL change. Waits both for the URL to be updated
 * in the UI, but also for the navigation to done in the toolbox and all
 * requests to be settled.
 *
 * @param {string} url
 * @param {object} toolbox
 * @param {Tab} browserTab
 * @param {Window} win
 * @return {Function}
 *     Returns an async function that you can await to wait for the URL update
 *     to be fully processed.
 */
async function startWaitingForUrl(url, toolbox, browserTab, win) {
  const { onDomCompleteResource } =
    await waitForNextTopLevelDomCompleteResource(toolbox.commands);

  return Promise.all([
    waitUntil(
  return async function () {
    info("Wait for URL");
    await waitUntil(
      () =>
        toolbox.target.url === url &&
        browserTab.linkedBrowser.currentURI.spec === url
    ),
    onDomCompleteResource,
    toolbox.commands.client.waitForRequestsToSettle(),
    waitForAboutDebuggingRequests(win.AboutDebugging.store),
  ]);
    );

    info("Wait for dom complete");
    await onDomCompleteResource;

    info("Wait for toolbox requests to settle");
    await toolbox.commands.client.waitForRequestsToSettle();

    info("Wait for about debugging requests to settle");
    await waitForAboutDebuggingRequests(win.AboutDebugging.store);
  };
}

// Test that ensures the remote page can go forward and back via UI buttons
@@ -43,21 +63,34 @@ add_task(async function () {
  info("Navigating to another URL");
  let onTargetSwitched = toolbox.commands.targetCommand.once("switched-target");
  const urlInput = devtoolsDocument.querySelector(".devtools-textinput");
  let onURLReady = await startWaitingForUrl(
    OTHER_URL,
    toolbox,
    browserTab,
    window
  );
  await synthesizeUrlKeyInput(devToolsToolbox, urlInput, OTHER_URL);
  await waitForUrl(OTHER_URL, toolbox, browserTab, window);
  await onURLReady();
  await onTargetSwitched;

  info("Clicking back button");
  onTargetSwitched = toolbox.commands.targetCommand.once("switched-target");
  onURLReady = await startWaitingForUrl(
    ORIGINAL_URL,
    toolbox,
    browserTab,
    window
  );
  devtoolsDocument.querySelector(".qa-back-button").click();
  await waitForUrl(ORIGINAL_URL, toolbox, browserTab, window);
  await onURLReady();
  await onTargetSwitched;

  info("Clicking the forward button");
  onTargetSwitched = toolbox.commands.targetCommand.once("switched-target");
  onURLReady = await startWaitingForUrl(OTHER_URL, toolbox, browserTab, window);
  devtoolsDocument.querySelector(".qa-forward-button").click();
  await waitForUrl(OTHER_URL, toolbox, browserTab, window);
  await onTargetSwitched;
  await onURLReady();

  ok(true, "Clicking back and forward works!");
});
+7 −1
Original line number Diff line number Diff line
@@ -184,7 +184,13 @@ class DebugTargetInfo extends PureComponent {
      console.error(ex);
    }

    this.props.toolbox.commands.targetCommand.navigateTo(url);
    // Do not waitForLoad as we don't wait navigateTo to resolve anyway.
    // Bug 1968023: navigateTo is flaky and sometimes never catches the
    // STATE_STOP notification necessary for waitForLoad=true.
    this.props.toolbox.commands.targetCommand.navigateTo(
      url,
      false /* waitForLoad */
    );
  }

  shallRenderConnection() {