tor-browser

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

browser_styleeditor_add_stylesheet.js (1143B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that a newly-added style sheet shows up in the style editor.
      6 
      7 const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html";
      8 
      9 add_task(async function () {
     10  const { ui } = await openStyleEditorForURL(TESTCASE_URI);
     11 
     12  is(ui.editors.length, 2, "Two sheets present after load.");
     13 
     14  // We have to wait for the length to change, because we might still
     15  // be seeing events from the initial open.
     16  const added = new Promise(resolve => {
     17    const handler = () => {
     18      if (ui.editors.length === 3) {
     19        ui.off("editor-added", handler);
     20        resolve();
     21      }
     22    };
     23    ui.on("editor-added", handler);
     24  });
     25 
     26  info("Adding a style sheet");
     27  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
     28    const document = content.document;
     29    const style = document.createElement("style");
     30    style.appendChild(document.createTextNode("div { background: #f06; }"));
     31    document.head.appendChild(style);
     32  });
     33  await added;
     34 
     35  is(ui.editors.length, 3, "Three sheets present after new style sheet");
     36 });