tor-browser

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

browser_rules_edit-property-commit.js (2442B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test original value is correctly displayed when ESCaping out of the
      7 // inplace editor in the style inspector.
      8 
      9 const TEST_URI = `
     10  <style type='text/css'>
     11  #testid {
     12    color: #00F;
     13  }
     14  </style>
     15  <div id='testid'>Styled Node</div>
     16 `;
     17 
     18 // Test data format
     19 // {
     20 //  value: what char sequence to type,
     21 //  commitKey: what key to type to "commit" the change,
     22 //  modifiers: commitKey modifiers,
     23 //  expected: what value is expected as a result
     24 // }
     25 const testData = [
     26  {
     27    value: "red",
     28    commitKey: "VK_ESCAPE",
     29    modifiers: {},
     30    expected: "#00F",
     31  },
     32  {
     33    value: "red",
     34    commitKey: "VK_RETURN",
     35    modifiers: {},
     36    expected: "red",
     37  },
     38  {
     39    value: "invalid",
     40    commitKey: "VK_RETURN",
     41    modifiers: {},
     42    expected: "invalid",
     43  },
     44  {
     45    value: "blue",
     46    commitKey: "VK_TAB",
     47    modifiers: { shiftKey: true },
     48    expected: "blue",
     49  },
     50 ];
     51 
     52 add_task(async function () {
     53  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     54  const { inspector, view } = await openRuleView();
     55  await selectNode("#testid", inspector);
     56 
     57  for (const data of testData) {
     58    await runTestData(view, data);
     59  }
     60 });
     61 
     62 async function runTestData(view, { value, commitKey, modifiers, expected }) {
     63  const idRuleEditor = getRuleViewRuleEditor(view, 1);
     64  const propEditor = idRuleEditor.rule.textProps[0].editor;
     65 
     66  info("Focusing the inplace editor field");
     67 
     68  const editor = await focusEditableField(view, propEditor.valueSpan);
     69  is(
     70    inplaceEditor(propEditor.valueSpan),
     71    editor,
     72    "Focused editor should be the value span."
     73  );
     74 
     75  info("Entering test data " + value);
     76  let onRuleViewChanged = view.once("ruleview-changed");
     77  EventUtils.sendString(value, view.styleWindow);
     78  view.debounce.flush();
     79  await onRuleViewChanged;
     80 
     81  info("Entering the commit key " + commitKey + " " + modifiers);
     82  onRuleViewChanged = view.once("ruleview-changed");
     83  const onBlur = once(editor.input, "blur");
     84  EventUtils.synthesizeKey(commitKey, modifiers);
     85  await onBlur;
     86  await onRuleViewChanged;
     87 
     88  if (commitKey === "VK_ESCAPE") {
     89    is(
     90      propEditor.valueSpan.textContent,
     91      expected,
     92      "Value is as expected: " + expected
     93    );
     94  } else {
     95    is(
     96      propEditor.valueSpan.textContent,
     97      expected,
     98      "Value is as expected: " + expected
     99    );
    100  }
    101 }