tor-browser

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

browser_rules_completion-new-property_04.js (2624B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that a new property editor supports the following flow:
      7 // - type first character of property name
      8 // - select an autocomplete suggestion !!with a mouse click!!
      9 // - press RETURN to move to the property value
     10 // - blur the input to commit
     11 
     12 const TEST_URI =
     13  "<style>.title {color: red;}</style>" + "<h1 class=title>Header</h1>";
     14 
     15 add_task(async function () {
     16  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     17  const { inspector, view } = await openRuleView();
     18 
     19  info("Selecting the test node");
     20  await selectNode("h1", inspector);
     21 
     22  info("Focusing the new property editable field");
     23  const ruleEditor = getRuleViewRuleEditor(view, 1);
     24  let editor = await focusNewRuleViewProperty(ruleEditor);
     25 
     26  info('Sending "background" to the editable field.');
     27  for (const key of "background") {
     28    const onSuggest = editor.once("after-suggest");
     29    EventUtils.synthesizeKey(key, {}, view.styleWindow);
     30    await onSuggest;
     31  }
     32 
     33  const itemIndex = 4;
     34  const bgcItem = editor.popup.getItemAtIndex(itemIndex);
     35  is(
     36    bgcItem.label,
     37    "background-color",
     38    "Check the expected completion element is background-color."
     39  );
     40  editor.popup.selectItemAtIndex(itemIndex);
     41 
     42  info("Select the background-color suggestion with a mouse click.");
     43  const onSuggest = editor.once("after-suggest");
     44  const node = editor.popup.elements.get(bgcItem);
     45  EventUtils.synthesizeMouseAtCenter(node, {}, node.ownerGlobal);
     46 
     47  await onSuggest;
     48  is(editor.input.value, "background-color", "Correct value is autocompleted");
     49 
     50  info("Press RETURN to move the focus to a property value editor.");
     51  let onModifications = view.once("ruleview-changed");
     52  EventUtils.synthesizeKey("VK_RETURN", {}, view.styleWindow);
     53 
     54  await onModifications;
     55 
     56  // Getting the new value editor after focus
     57  editor = inplaceEditor(view.styleDocument.activeElement);
     58  const textProp = ruleEditor.rule.textProps[1];
     59 
     60  is(ruleEditor.rule.textProps.length, 2, "Created a new text property.");
     61  is(ruleEditor.propertyList.children.length, 2, "Created a property editor.");
     62  is(
     63    editor,
     64    inplaceEditor(textProp.editor.valueSpan),
     65    "Editing the value span now."
     66  );
     67 
     68  info("Entering a value and blurring the field to expect a rule change");
     69  onModifications = view.once("ruleview-changed");
     70 
     71  EventUtils.sendString("#F00");
     72  EventUtils.synthesizeKey("VK_RETURN", {}, view.styleWindow);
     73 
     74  await onModifications;
     75 
     76  is(textProp.value, "#F00", "Text prop should have been changed.");
     77 });