tor-browser

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

browser_rules_edit-property_04.js (2450B)


      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 a disabled property remains disabled when the escaping out of
      7 // the property editor.
      8 
      9 const TEST_URI = `
     10  <style type='text/css'>
     11  #testid {
     12    background-color: blue;
     13  }
     14  </style>
     15  <div id='testid'>Styled Node</div>
     16 `;
     17 
     18 add_task(async function () {
     19  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     20  const { inspector, view } = await openRuleView();
     21  await selectNode("#testid", inspector);
     22 
     23  const prop = getTextProperty(view, 1, { "background-color": "blue" });
     24 
     25  info("Disabling a property");
     26  await togglePropStatus(view, prop);
     27 
     28  const newValue = await getRulePropertyValue(0, 0, "background-color");
     29  is(newValue, "", "background-color should have been unset.");
     30 
     31  await testEditDisableProperty(view, prop, "name", "VK_ESCAPE");
     32  await testEditDisableProperty(view, prop, "value", "VK_ESCAPE");
     33  await testEditDisableProperty(view, prop, "value", "VK_TAB");
     34  await testEditDisableProperty(view, prop, "value", "VK_RETURN");
     35 });
     36 
     37 async function testEditDisableProperty(view, prop, fieldType, commitKey) {
     38  const field =
     39    fieldType === "name" ? prop.editor.nameSpan : prop.editor.valueSpan;
     40 
     41  const editor = await focusEditableField(view, field);
     42 
     43  ok(
     44    !prop.editor.element.classList.contains("ruleview-overridden"),
     45    "property is not overridden."
     46  );
     47  is(
     48    prop.editor.enable.style.visibility,
     49    "hidden",
     50    "property enable checkbox is hidden."
     51  );
     52 
     53  let newValue = await getRulePropertyValue(0, 0, "background-color");
     54  is(newValue, "", "background-color should remain unset.");
     55 
     56  let onChangeDone;
     57  if (fieldType === "value") {
     58    onChangeDone = view.once("ruleview-changed");
     59  }
     60 
     61  const onBlur = once(editor.input, "blur");
     62  EventUtils.synthesizeKey(commitKey, {}, view.styleWindow);
     63  await onBlur;
     64  await onChangeDone;
     65 
     66  ok(!prop.enabled, "property is disabled.");
     67  ok(
     68    prop.editor.element.classList.contains("ruleview-overridden"),
     69    "property is overridden."
     70  );
     71  is(
     72    prop.editor.enable.style.visibility,
     73    "visible",
     74    "property enable checkbox is visible."
     75  );
     76  ok(
     77    !prop.editor.enable.getAttribute("checked"),
     78    "property enable checkbox is not checked."
     79  );
     80 
     81  newValue = await getRulePropertyValue(0, 0, "background-color");
     82  is(newValue, "", "background-color should remain unset.");
     83 }