tor-browser

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

browser_inplace-editor_autoclose_parentheses.js (2179B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* import-globals-from helper_inplace_editor.js */
      4 
      5 "use strict";
      6 
      7 const AutocompletePopup = require("resource://devtools/client/shared/autocomplete-popup.js");
      8 const {
      9  InplaceEditor,
     10 } = require("resource://devtools/client/shared/inplace-editor.js");
     11 loadHelperScript("helper_inplace_editor.js");
     12 
     13 // Test the inplace-editor closes parentheses automatically.
     14 
     15 // format :
     16 //  [
     17 //    what key to press,
     18 //    expected input box value after keypress,
     19 //    selected suggestion index (-1 if popup is hidden),
     20 //    number of suggestions in the popup (0 if popup is hidden),
     21 //  ]
     22 const testData = [
     23  ["u", "u", -1, 0],
     24  ["r", "ur", -1, 0],
     25  ["l", "url", -1, 0],
     26  ["(", "url()", -1, 0],
     27  ["v", "url(v)", -1, 0],
     28  ["a", "url(va)", -1, 0],
     29  ["r", "url(var)", -1, 0],
     30  ["(", "url(var())", -1, 0],
     31  ["-", "url(var(-))", -1, 0],
     32  ["-", "url(var(--))", -1, 0],
     33  ["a", "url(var(--a))", -1, 0],
     34  [")", "url(var(--a))", -1, 0],
     35  [")", "url(var(--a))", -1, 0],
     36 ];
     37 
     38 add_task(async function () {
     39  await addTab(
     40    "data:text/html;charset=utf-8," + "inplace editor parentheses autoclose"
     41  );
     42  const { host, doc } = await createHost();
     43 
     44  const popup = new AutocompletePopup(doc, { autoSelect: true });
     45  await new Promise(resolve => {
     46    createInplaceEditorAndClick(
     47      {
     48        start: runPropertyAutocompletionTest,
     49        contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE,
     50        property: {
     51          name: "background-image",
     52        },
     53        cssProperties: {
     54          // No need to test autocompletion here, return an empty array.
     55          getNames: () => [],
     56          getValues: () => [],
     57        },
     58        cssVariables: new Map(),
     59        done: resolve,
     60        popup,
     61      },
     62      doc
     63    );
     64  });
     65 
     66  popup.destroy();
     67  host.destroy();
     68  gBrowser.removeCurrentTab();
     69 });
     70 
     71 const runPropertyAutocompletionTest = async function (editor) {
     72  info("Starting to test for css property completion");
     73  for (const data of testData) {
     74    await testCompletion(data, editor);
     75  }
     76  EventUtils.synthesizeKey("VK_RETURN", {}, editor.input.defaultView);
     77 };