tor-browser

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

browser_rules_authored_override.js (1829B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test for as-authored styles.
      7 
      8 add_task(async function () {
      9  const gradientText1 = "(orange, blue);";
     10  const gradientText2 = "(pink, teal);";
     11  const html = `
     12    <style type="text/css">
     13      #testid {
     14        background-image: linear-gradient${gradientText1};
     15        background-image: -ms-linear-gradient${gradientText2};
     16        background-image: linear-gradient${gradientText2};
     17      }
     18    </style>
     19    <div id="testid" class="testclass">Styled Node</div>`;
     20  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(html));
     21 
     22  const { inspector, view } = await openRuleView();
     23  await selectNode("#testid", inspector);
     24 
     25  const elementStyle = view._elementStyle;
     26  const rule = elementStyle.rules[1];
     27 
     28  for (let i = 0; i < 3; ++i) {
     29    const prop = rule.textProps[i];
     30    is(prop.name, "background-image", "check the property name");
     31    // Initially only the first property is overridden.
     32    is(prop.overridden, i === 0, `check overridden for property #${i}`);
     33    // and the second one should be invalid
     34    is(prop.editor.isValid(), i !== 1, `check validity for property #${i}`);
     35  }
     36 
     37  await togglePropStatus(view, rule.textProps[2]);
     38 
     39  for (let i = 0; i < 3; ++i) {
     40    const prop = rule.textProps[i];
     41 
     42    // Now the last property shouldn't be enabled anymore
     43    is(prop.enabled, i !== 2, `post-change check enabled for ${i}`);
     44 
     45    // and as a result, the first property should be active, so no properties are overridden
     46    is(prop.overridden, false, `post-change check not overridden for ${i}`);
     47 
     48    // and the second property should still be invalid
     49    is(
     50      prop.editor.isValid(),
     51      i !== 1,
     52      "post-change check validity for property #" + i
     53    );
     54  }
     55 });