tor-browser

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

browser_rules_edit-selector_09.js (3305B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests that editing a selector to an unmatched rule does set up the correct
      7 // property on the rule, and that settings property in said rule does not
      8 // lead to overriding properties from matched rules.
      9 // Test that having a rule with both matched and unmatched selectors does work
     10 // correctly.
     11 
     12 const TEST_URI = `
     13  <style type="text/css">
     14    #testid {
     15      color: black;
     16    }
     17    .testclass {
     18      background-color: white;
     19    }
     20  </style>
     21  <div id="testid">Styled Node</div>
     22  <span class="testclass">This is a span</span>
     23 `;
     24 
     25 add_task(async function () {
     26  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     27  const { inspector, view } = await openRuleView();
     28 
     29  await selectNode("#testid", inspector);
     30  await testEditSelector(view, "span");
     31  await testAddImportantProperty(view);
     32  await testAddMatchedRule(view, "span, div");
     33 });
     34 
     35 async function testEditSelector(view, name) {
     36  info("Test editing existing selector fields");
     37 
     38  const ruleEditor = getRuleViewRuleEditor(view, 1);
     39 
     40  info("Focusing an existing selector name in the rule-view");
     41  const editor = await focusEditableField(view, ruleEditor.selectorText);
     42 
     43  is(
     44    inplaceEditor(ruleEditor.selectorText),
     45    editor,
     46    "The selector editor got focused"
     47  );
     48 
     49  info("Entering a new selector name and committing");
     50  editor.input.value = name;
     51 
     52  info("Waiting for rule view to update");
     53  const onRuleViewChanged = once(view, "ruleview-changed");
     54 
     55  info("Entering the commit key");
     56  EventUtils.synthesizeKey("KEY_Enter");
     57  await onRuleViewChanged;
     58 
     59  ok(getRuleViewRule(view, name), "Rule with " + name + " selector exists.");
     60  ok(
     61    getRuleViewRuleEditor(view, 1).element.getAttribute("unmatched"),
     62    "Rule with " + name + " does not match the current element."
     63  );
     64 }
     65 
     66 async function testAddImportantProperty(view) {
     67  info("Test creating a new property with !important");
     68  const textProp = await addProperty(view, 1, "color", "red !important");
     69 
     70  is(textProp.value, "red", "Text prop should have been changed.");
     71  is(textProp.priority, "important", 'Text prop has an "important" priority.');
     72  ok(!textProp.overridden, "Property should not be overridden");
     73 
     74  const prop = getTextProperty(view, 1, { color: "black" });
     75  ok(
     76    !prop.overridden,
     77    "Existing property on matched rule should not be overridden"
     78  );
     79 }
     80 
     81 async function testAddMatchedRule(view, name) {
     82  info("Test adding a matching selector");
     83 
     84  const ruleEditor = getRuleViewRuleEditor(view, 1);
     85 
     86  info("Focusing an existing selector name in the rule-view");
     87  const editor = await focusEditableField(view, ruleEditor.selectorText);
     88 
     89  is(
     90    inplaceEditor(ruleEditor.selectorText),
     91    editor,
     92    "The selector editor got focused"
     93  );
     94 
     95  info("Entering a new selector name and committing");
     96  editor.input.value = name;
     97 
     98  info("Waiting for rule view to update");
     99  const onRuleViewChanged = once(view, "ruleview-changed");
    100 
    101  info("Entering the commit key");
    102  EventUtils.synthesizeKey("KEY_Enter");
    103  await onRuleViewChanged;
    104 
    105  is(
    106    getRuleViewRuleEditor(view, 1).element.getAttribute("unmatched"),
    107    "false",
    108    "Rule with " + name + " does match the current element."
    109  );
    110 }