tor-browser

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

browser_boxmodel_update-in-iframes.js (3028B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the box model view for elements within iframes also updates when they
      7 // change
      8 
      9 add_task(async function () {
     10  const tab = await addTab(URL_ROOT + "doc_boxmodel_iframe1.html");
     11  const browser = tab.linkedBrowser;
     12  const { inspector, boxmodel } = await openLayoutView();
     13 
     14  await testResizingInIframe(inspector, boxmodel, browser);
     15  await testReflowsAfterIframeDeletion(inspector, boxmodel, browser);
     16 });
     17 
     18 async function testResizingInIframe(inspector, boxmodel, browser) {
     19  info("Test that resizing an element in an iframe updates its box model");
     20 
     21  info("Selecting the nested test node");
     22  await selectNodeInFrames(["iframe", "iframe", "div"], inspector);
     23 
     24  info("Checking that the box model view shows the right value");
     25  const sizeElt = boxmodel.document.querySelector(".boxmodel-size > span");
     26  is(sizeElt.textContent, "400\u00D7200");
     27 
     28  info("Listening for box model view changes and modifying its size");
     29  const onUpdated = waitForUpdate(inspector);
     30  await setStyleInNestedIframe(browser, "div", "width", "200px");
     31  await onUpdated;
     32  ok(true, "Box model view got updated");
     33 
     34  info("Checking that the box model view shows the right value after update");
     35  is(sizeElt.textContent, "200\u00D7200");
     36 }
     37 
     38 async function testReflowsAfterIframeDeletion(inspector, boxmodel, browser) {
     39  info(
     40    "Test reflows are still sent to the box model view after deleting an " +
     41      "iframe"
     42  );
     43 
     44  info("Deleting the iframe2");
     45  const onInspectorUpdated = inspector.once("inspector-updated");
     46  await removeNestedIframe(browser);
     47  await onInspectorUpdated;
     48 
     49  info("Selecting the test node in iframe1");
     50  await selectNodeInFrames(["iframe", "p"], inspector);
     51 
     52  info("Checking that the box model view shows the right value");
     53  const sizeElt = boxmodel.document.querySelector(".boxmodel-size > span");
     54  is(sizeElt.textContent, "100\u00D7100");
     55 
     56  info("Listening for box model view changes and modifying its size");
     57  const onUpdated = waitForUpdate(inspector);
     58  await setStyleInIframe(browser, "p", "width", "200px");
     59  await onUpdated;
     60  ok(true, "Box model view got updated");
     61 
     62  info("Checking that the box model view shows the right value after update");
     63  is(sizeElt.textContent, "200\u00D7100");
     64 }
     65 
     66 async function setStyleInIframe(browser, selector, propertyName, value) {
     67  const context = await getBrowsingContextInFrames(browser, ["iframe"]);
     68  return setStyle(context, selector, propertyName, value);
     69 }
     70 
     71 async function setStyleInNestedIframe(browser, selector, propertyName, value) {
     72  const context = await getBrowsingContextInFrames(browser, [
     73    "iframe",
     74    "iframe",
     75  ]);
     76  return setStyle(context, selector, propertyName, value);
     77 }
     78 
     79 async function removeNestedIframe(browser) {
     80  const context = await getBrowsingContextInFrames(browser, ["iframe"]);
     81  await SpecialPowers.spawn(context, [], () =>
     82    content.document.querySelector("iframe").remove()
     83  );
     84 }