tor-browser

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

browser_rules_completion-on-empty.js (2057B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests the suggest completion popup behavior of CSS property field.
      7 
      8 const TEST_URI = "<h1 style='color: lime'>Header</h1>";
      9 
     10 add_task(async function () {
     11  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     12  const { inspector, view } = await openRuleView();
     13 
     14  info("Selecting the test node");
     15  await selectNode("h1", inspector);
     16 
     17  const prop = getTextProperty(view, 0, { color: "lime" });
     18 
     19  info("Test with css property value field");
     20  await testCompletion(view, prop.editor.valueSpan, true);
     21 
     22  info("Test with css property name field");
     23  await testCompletion(view, prop.editor.nameSpan, false);
     24 });
     25 
     26 async function testCompletion(view, target, isExpectedOpenPopup) {
     27  const editor = await focusEditableField(view, target);
     28 
     29  info(
     30    "Check the suggest completion popup visibility after clearing the field"
     31  );
     32 
     33  const onChanged = view.once("ruleview-changed");
     34  const popupEvent = isExpectedOpenPopup ? "popup-opened" : "popup-closed";
     35  const onPopupEvent =
     36    editor.popup.isOpen === isExpectedOpenPopup
     37      ? Promise.resolve()
     38      : once(view.popup, popupEvent);
     39  EventUtils.synthesizeKey("VK_BACK_SPACE", {}, view.styleWindow);
     40 
     41  // Flush the debounce to update the preview text.
     42  view.debounce.flush();
     43 
     44  await Promise.all([onChanged, onPopupEvent]);
     45  is(
     46    editor.popup.isOpen,
     47    isExpectedOpenPopup,
     48    "The popup visibility is correct"
     49  );
     50 
     51  if (editor.popup.isOpen) {
     52    info("Close the suggest completion popup");
     53    const onPopupClosed = once(view.popup, "popup-closed");
     54    EventUtils.synthesizeKey("VK_ESCAPE", {}, view.styleWindow);
     55    await onPopupClosed;
     56    ok(true, "popup was closed");
     57 
     58    info("And hit Escape again to cancel the change");
     59    const onRuleViewChanged = view.once("ruleview-changed");
     60    EventUtils.synthesizeKey("VK_ESCAPE", {}, view.styleWindow);
     61    await onRuleViewChanged;
     62    ok(true, "Got ruleview-changed event");
     63  }
     64 }