tor-browser

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

browser_styleeditor_transition_rule.js (1326B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html";
      7 
      8 const NEW_RULE = "body { background-color: purple; }";
      9 
     10 add_task(async function () {
     11  const { ui } = await openStyleEditorForURL(TESTCASE_URI);
     12 
     13  is(ui.editors.length, 2, "correct number of editors");
     14 
     15  const editor = ui.editors[0];
     16  await openEditor(editor);
     17 
     18  // Set text twice in a row
     19  const styleChanges = listenForStyleChange(editor);
     20 
     21  editor.sourceEditor.setText(NEW_RULE);
     22  editor.sourceEditor.setText(NEW_RULE + " ");
     23 
     24  await styleChanges;
     25 
     26  const rules = await SpecialPowers.spawn(
     27    gBrowser.selectedBrowser,
     28    [0],
     29    async function (index) {
     30      const sheet = content.document.styleSheets[index];
     31      return [...sheet.cssRules].map(rule => rule.cssText);
     32    }
     33  );
     34 
     35  // Test that we removed the transition rule, but kept the rule we added
     36  is(rules.length, 1, "only one rule in stylesheet");
     37  is(rules[0], NEW_RULE, "stylesheet only contains rule we added");
     38 });
     39 
     40 /* Helpers */
     41 
     42 function openEditor(editor) {
     43  const link = editor.summary.querySelector(".stylesheet-name");
     44  link.click();
     45 
     46  return editor.getSourceEditor();
     47 }
     48 
     49 function listenForStyleChange(editor) {
     50  return editor.once("style-applied");
     51 }