tor-browser

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

browser_rules_user-agent-styles-uneditable.js (1821B)


      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 user agent styles are never editable via
      7 // the UI
      8 
      9 const TEST_URI = `
     10  <blockquote type=cite>
     11   <pre _moz_quote=true>
     12     inspect <a href='foo' style='color:orange'>user agent</a> styles
     13   </pre>
     14  </blockquote>
     15 `;
     16 
     17 var PREF_UA_STYLES = "devtools.inspector.showUserAgentStyles";
     18 
     19 add_task(async function () {
     20  info("Starting the test with the pref set to true before toolbox is opened");
     21  Services.prefs.setBoolPref(PREF_UA_STYLES, true);
     22 
     23  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     24  const { inspector, view } = await openRuleView();
     25 
     26  await userAgentStylesUneditable(inspector, view);
     27 
     28  info("Resetting " + PREF_UA_STYLES);
     29  Services.prefs.clearUserPref(PREF_UA_STYLES);
     30 });
     31 
     32 async function userAgentStylesUneditable(inspector, view) {
     33  info("Making sure that UI is not editable for user agent styles");
     34 
     35  await selectNode("a", inspector);
     36  const uaRules = view._elementStyle.rules.filter(
     37    rule => !rule.editor.isEditable
     38  );
     39 
     40  for (const rule of uaRules) {
     41    ok(
     42      rule.editor.element.hasAttribute("uneditable"),
     43      "UA rules have uneditable attribute"
     44    );
     45 
     46    const firstProp = rule.textProps.filter(p => !p.invisible)[0];
     47 
     48    ok(!firstProp.editor.nameSpan._editable, "nameSpan is not editable");
     49    ok(!firstProp.editor.valueSpan._editable, "valueSpan is not editable");
     50    ok(!rule.editor.closeBrace._editable, "closeBrace is not editable");
     51 
     52    const colorswatch = rule.editor.element.querySelector(
     53      ".inspector-colorswatch"
     54    );
     55    if (colorswatch) {
     56      ok(
     57        !view.tooltips.getTooltip("colorPicker").swatches.has(colorswatch),
     58        "The swatch is not editable"
     59      );
     60    }
     61  }
     62 }