tor-browser

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

browser_dom_iframe_picker.js (2263B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Check that the DOM panel works as expected when a specific frame is selected in the
      7 // iframe picker.
      8 
      9 const TEST_URL = `https://example.com/document-builder.sjs?html=
     10  <h1>top_level</h1>
     11  <iframe src="https://example.org/document-builder.sjs?html=in_iframe"></iframe>`;
     12 
     13 add_task(async function () {
     14  const { panel } = await addTestTab(TEST_URL);
     15  const toolbox = panel._toolbox;
     16 
     17  info("Wait until the iframe picker button is visible");
     18  await waitFor(() => toolbox.doc.getElementById("command-button-frames"));
     19 
     20  info("Check `document` property when no specific frame is focused");
     21  let documentPropertyValue = getDocumentPropertyValue(panel);
     22 
     23  ok(
     24    documentPropertyValue.startsWith("HTMLDocument https://example.com"),
     25    `Got expected "document" value (${documentPropertyValue})`
     26  );
     27 
     28  info(
     29    "Select the frame in the iframe picker and check that the document property is updated"
     30  );
     31  // Wait for the DOM panel to refresh.
     32  const store = getReduxStoreFromPanel(panel);
     33  let onPropertiesFetched = waitForDispatch(store, "FETCH_PROPERTIES");
     34 
     35  const exampleOrgFrame = toolbox.doc.querySelector(
     36    "#toolbox-frame-menu .menuitem:last-child .command"
     37  );
     38 
     39  exampleOrgFrame.click();
     40  await onPropertiesFetched;
     41 
     42  documentPropertyValue = getDocumentPropertyValue(panel);
     43  ok(
     44    documentPropertyValue.startsWith("HTMLDocument https://example.org"),
     45    `Got expected "document" value (${documentPropertyValue})`
     46  );
     47 
     48  info(
     49    "Select the top-level frame and check that the document property is updated"
     50  );
     51  onPropertiesFetched = waitForDispatch(store, "FETCH_PROPERTIES");
     52 
     53  const exampleComFrame = toolbox.doc.querySelector(
     54    "#toolbox-frame-menu .menuitem:first-child .command"
     55  );
     56  exampleComFrame.click();
     57  await onPropertiesFetched;
     58 
     59  documentPropertyValue = getDocumentPropertyValue(panel);
     60  ok(
     61    documentPropertyValue.startsWith("HTMLDocument https://example.com"),
     62    `Got expected "document" value (${documentPropertyValue})`
     63  );
     64 });
     65 
     66 function getDocumentPropertyValue(panel) {
     67  return getRowByLabel(panel, "document").querySelector("td.treeValueCell")
     68    .textContent;
     69 }