tor-browser

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

browser_inspector_iframe-picker-bfcache-navigation.js (4034B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 // Test that using the iframe picker usage + bfcache navigations don't break the toolbox
      8 
      9 const IFRAME_URL = `https://example.com/document-builder.sjs?html=<meta charset=utf8><div id=in-iframe>frame</div>`;
     10 
     11 const URL =
     12  "https://example.com/document-builder.sjs?html=" +
     13  `<meta charset=utf8><iframe src='${IFRAME_URL}'></iframe><div id=top>top</div>`;
     14 
     15 add_task(async function () {
     16  await pushPref("devtools.command-button-frames.enabled", true);
     17 
     18  // Don't show the third panel to limit the logs and activity.
     19  await pushPref("devtools.inspector.three-pane-enabled", false);
     20  await pushPref("devtools.inspector.activeSidebar", "ruleview");
     21 
     22  const { inspector, toolbox } = await openInspectorForURL(URL);
     23 
     24  info("Verify we are on the top level document");
     25  await assertMarkupViewAsTree(
     26    `
     27    body
     28      iframe!ignore-children
     29      div id="top"`,
     30    "body",
     31    inspector
     32  );
     33 
     34  info("Navigate to a different page to put the current page in the bfcache");
     35  let onMarkupLoaded = getOnInspectorReadyAfterNavigation(inspector);
     36  await navigateTo(
     37    "https://example.org/document-builder.sjs?html=<meta charset=utf8>example.org page"
     38  );
     39  await onMarkupLoaded;
     40 
     41  info("Navigate back to the example.com page");
     42  onMarkupLoaded = getOnInspectorReadyAfterNavigation(inspector);
     43  gBrowser.goBack();
     44  await onMarkupLoaded;
     45 
     46  // Verify that the frame map button is empty at the moment.
     47  const btn = toolbox.doc.getElementById("command-button-frames");
     48  ok(!btn.firstChild, "The frame list button doesn't have any children");
     49 
     50  // Open frame menu and wait till it's available on the screen.
     51  const frameMenu = toolbox.doc.getElementById("toolbox-frame-menu");
     52  info("Wait for the frame to be populated before opening the tooltip");
     53  await waitUntil(() => frameMenu.childNodes.length == 2);
     54  const panel = toolbox.doc.getElementById("command-button-frames-panel");
     55  btn.click();
     56  ok(panel, "popup panel has created.");
     57  await waitUntil(() => panel.classList.contains("tooltip-visible"));
     58 
     59  // Verify that the menu is populated.
     60  const menuList = toolbox.doc.getElementById("toolbox-frame-menu");
     61  const frames = Array.from(menuList.querySelectorAll(".command")).sort(
     62    (a, b) => a.textContent < b.textContent
     63  );
     64  is(frames.length, 2, "We have both frames in the menu");
     65  const [topLevelFrameItem, iframeItem] = frames;
     66 
     67  is(
     68    topLevelFrameItem.querySelector(".label").textContent,
     69    URL,
     70    "Got top-level document in the list"
     71  );
     72  is(
     73    iframeItem.querySelector(".label").textContent,
     74    IFRAME_URL,
     75    "Got iframe document in the list"
     76  );
     77 
     78  info("Select the iframe in the iframe picker");
     79  const newRoot = inspector.once("new-root");
     80  iframeItem.click();
     81  await newRoot;
     82 
     83  info("Check that the markup view was updated");
     84  await assertMarkupViewAsTree(
     85    `
     86    body
     87      div id="in-iframe"`,
     88    "body",
     89    inspector
     90  );
     91 
     92  info("Go forward (to example.org page)");
     93  onMarkupLoaded = getOnInspectorReadyAfterNavigation(inspector);
     94  gBrowser.goForward();
     95  await onMarkupLoaded;
     96 
     97  info("And go back again to example.com page");
     98  onMarkupLoaded = getOnInspectorReadyAfterNavigation(inspector);
     99  gBrowser.goBack();
    100  await onMarkupLoaded;
    101 
    102  info("Check that the document markup is displayed as expected");
    103  await assertMarkupViewAsTree(
    104    `
    105    body
    106      iframe!ignore-children
    107      div id="top"`,
    108    "body",
    109    inspector
    110  );
    111 });
    112 
    113 function getOnInspectorReadyAfterNavigation(inspector) {
    114  return Promise.all([
    115    inspector.once("reloaded"),
    116    // the inspector is initializing the accessibility front in onTargetAvailable, so we
    117    // need to wait for the target to be processed, otherwise we may end up with pending
    118    // promises failures.
    119    inspector.toolbox.commands.targetCommand.once("processed-available-target"),
    120  ]);
    121 }