tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_markup_update-on-navigtion.js (1883B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that markup view handles page navigation correctly.
      6 
      7 const URL_1 = URL_ROOT_SSL + "doc_markup_update-on-navigtion_1.html";
      8 const URL_2 = URL_ROOT_SSL + "doc_markup_update-on-navigtion_2.html";
      9 
     10 add_task(async function () {
     11  const { inspector, toolbox } = await openInspectorForURL(URL_1);
     12 
     13  assertMarkupViewIsLoaded();
     14  await selectNode("#one", inspector);
     15 
     16  const { resourceCommand } = toolbox.commands;
     17  const { onResource: willNavigate } =
     18    await resourceCommand.waitForNextResource(
     19      resourceCommand.TYPES.DOCUMENT_EVENT,
     20      {
     21        ignoreExistingResources: true,
     22        predicate(resource) {
     23          return resource.name == "will-navigate";
     24        },
     25      }
     26    );
     27 
     28  // We should not await on navigateTo here, because the test will assert the
     29  // various phases of the inspector during the navigation.
     30  const onNavigated = navigateTo(URL_2);
     31 
     32  info("Waiting for will-navigate");
     33  await willNavigate;
     34 
     35  info("Navigation to page 2 has started, the inspector should be empty");
     36  assertMarkupViewIsEmpty();
     37 
     38  info("Waiting for new-root");
     39  await inspector.once("new-root");
     40 
     41  info("Navigation to page 2 was done, the inspector should be back up");
     42  assertMarkupViewIsLoaded();
     43 
     44  await onNavigated;
     45  await selectNode("#two", inspector);
     46 
     47  function assertMarkupViewIsLoaded() {
     48    const markupViewBox = inspector.panelDoc.getElementById("markup-box");
     49    is(markupViewBox.childNodes.length, 1, "The markup-view is loaded");
     50  }
     51 
     52  function assertMarkupViewIsEmpty() {
     53    const markupViewFrame = inspector.panelDoc
     54      .getElementById("markup-box")
     55      .querySelector(`iframe`)
     56      .contentDocument.getElementById("root");
     57    is(markupViewFrame.childNodes.length, 0, "The markup-view is unloaded");
     58  }
     59 });