tor-browser

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

browser_disable_author_style_oop.js (2728B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function getColor(aSpawnTarget) {
      7  return SpecialPowers.spawn(aSpawnTarget, [], function () {
      8    return content.document.defaultView.getComputedStyle(
      9      content.document.querySelector("p")
     10    ).color;
     11  });
     12 }
     13 
     14 async function insertIFrame() {
     15  let bc = gBrowser.selectedBrowser.browsingContext;
     16  let len = bc.children.length;
     17 
     18  const kURL =
     19    WEB_ROOT.replace("example.com", "example.net") + "page_style.html";
     20  await SpecialPowers.spawn(gBrowser.selectedBrowser, [kURL], function (url) {
     21    return new Promise(function (resolve) {
     22      let e = content.document.createElement("iframe");
     23      e.src = url;
     24      e.onload = () => resolve();
     25      content.document.body.append(e);
     26    });
     27  });
     28 
     29  // Wait for the new frame to get a pres shell and be styled.
     30  await BrowserTestUtils.waitForCondition(async function () {
     31    return (
     32      bc.children.length == len + 1 && (await getColor(bc.children[len])) != ""
     33    );
     34  });
     35 }
     36 
     37 // Test that inserting an iframe with a URL that is loaded OOP with Fission
     38 // enabled correctly matches the tab's author style disabled state.
     39 add_task(async function test_disable_style() {
     40  let tab = await BrowserTestUtils.openNewForegroundTab(
     41    gBrowser,
     42    WEB_ROOT + "page_style.html",
     43    /* waitForLoad = */ true
     44  );
     45 
     46  let bc = gBrowser.selectedBrowser.browsingContext;
     47 
     48  await insertIFrame();
     49 
     50  is(
     51    await getColor(bc),
     52    "rgb(0, 0, 255)",
     53    "parent color before disabling style"
     54  );
     55  is(
     56    await getColor(bc.children[0]),
     57    "rgb(0, 0, 255)",
     58    "first child color before disabling style"
     59  );
     60 
     61  gPageStyleMenu.disableStyle();
     62 
     63  is(await getColor(bc), "rgb(0, 0, 0)", "parent color after disabling style");
     64  is(
     65    await getColor(bc.children[0]),
     66    "rgb(0, 0, 0)",
     67    "first child color after disabling style"
     68  );
     69 
     70  await insertIFrame();
     71 
     72  is(
     73    await getColor(bc.children[1]),
     74    "rgb(0, 0, 0)",
     75    "second child color after disabling style"
     76  );
     77 
     78  await BrowserTestUtils.reloadTab(tab, {
     79    includeSubFrames: true,
     80  });
     81 
     82  // Check the menu:
     83  let { menupopup } = document.getElementById("pageStyleMenu");
     84  gPageStyleMenu.fillPopup(menupopup);
     85  Assert.equal(
     86    menupopup.querySelector("menuitem[checked]").dataset.l10nId,
     87    "menu-view-page-style-no-style",
     88    "No style menu should be checked."
     89  );
     90 
     91  // check the page content still has a disabled author style:
     92  Assert.ok(
     93    await SpecialPowers.spawn(
     94      tab.linkedBrowser,
     95      [],
     96      () => content.docShell.docViewer.authorStyleDisabled
     97    ),
     98    "Author style should still be disabled."
     99  );
    100 
    101  BrowserTestUtils.removeTab(tab);
    102 });