tor-browser

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

browser_rules_edit-property-remove_03.js (2805B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests removing a property by clearing the property name and pressing shift
      7 // and tab keys, and checks if the focus is moved to the appropriate editable
      8 // field.
      9 
     10 const TEST_URI = `
     11  <style type='text/css'>
     12  #testid {
     13    background-color: #00F;
     14    color: #00F;
     15  }
     16  </style>
     17  <div id='testid'>Styled Node</div>
     18 `;
     19 
     20 add_task(async function () {
     21  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     22  const { inspector, view } = await openRuleView();
     23  await selectNode("#testid", inspector);
     24 
     25  info("Getting the second property in the rule");
     26  const rule = getRuleViewRuleEditor(view, 1).rule;
     27  let prop = rule.textProps[1];
     28 
     29  info("Clearing the property value and pressing shift-tab");
     30  let editor = await focusEditableField(view, prop.editor.valueSpan);
     31  const onValueDone = view.once("ruleview-changed");
     32  editor.input.value = "";
     33  EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }, view.styleWindow);
     34  await onValueDone;
     35 
     36  let newValue = await getRulePropertyValue(0, 0, "color");
     37  is(newValue, "", "color should have been unset.");
     38  is(
     39    prop.editor.valueSpan.textContent,
     40    "",
     41    "'' property value is correctly set."
     42  );
     43 
     44  info("Pressing shift-tab again to focus the previous property value");
     45  const onValueFocused = view.once("ruleview-changed");
     46  EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }, view.styleWindow);
     47  await onValueFocused;
     48 
     49  info("Getting the first property in the rule");
     50  prop = rule.textProps[0];
     51 
     52  editor = inplaceEditor(view.styleDocument.activeElement);
     53  is(
     54    inplaceEditor(prop.editor.valueSpan),
     55    editor,
     56    "Focus should have moved to the previous property value"
     57  );
     58 
     59  info("Pressing shift-tab again to focus the property name");
     60  const onNameFocused = view.once("ruleview-changed");
     61  EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }, view.styleWindow);
     62  await onNameFocused;
     63 
     64  info("Removing the name and pressing shift-tab to focus the selector");
     65  const onNameDeleted = view.once("ruleview-changed");
     66  EventUtils.synthesizeKey("VK_DELETE", {}, view.styleWindow);
     67  EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }, view.styleWindow);
     68  await onNameDeleted;
     69 
     70  newValue = await getRulePropertyValue(0, 0, "background-color");
     71  is(newValue, "", "background-color should have been unset.");
     72 
     73  editor = inplaceEditor(view.styleDocument.activeElement);
     74  is(
     75    inplaceEditor(rule.editor.selectorText),
     76    editor,
     77    "Focus should have moved to the selector text."
     78  );
     79  is(rule.textProps.length, 0, "All properties should have been removed.");
     80  ok(
     81    !rule.editor.propertyList.hasChildNodes(),
     82    "Should not have any properties."
     83  );
     84 });