tor-browser

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

browser_jsterm_completion_case_sensitivity.js (3983B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests that code completion works properly in regards to case sensitivity.
      5 
      6 "use strict";
      7 
      8 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html><p>test case-sensitivity completion.
      9  <script>
     10    fooBar = Object.create(null, Object.getOwnPropertyDescriptors({
     11      Foo: 1,
     12      test: 2,
     13      Test: 3,
     14      TEST: 4,
     15    }));
     16    FooBar = true;
     17  </script>`;
     18 
     19 add_task(async function () {
     20  const hud = await openNewTabAndConsole(TEST_URI);
     21  const { jsterm } = hud;
     22  const { autocompletePopup } = jsterm;
     23 
     24  const checkInput = (expected, assertionInfo) =>
     25    checkInputValueAndCursorPosition(hud, expected, assertionInfo);
     26 
     27  info("Check that lowercased input is case-insensitive");
     28  await setInputValueForAutocompletion(hud, "foob");
     29 
     30  ok(
     31    hasExactPopupLabels(autocompletePopup, ["fooBar", "FooBar"]),
     32    "popup has expected item, in expected order"
     33  );
     34 
     35  checkInputCompletionValue(hud, "ar", "completeNode has expected value");
     36 
     37  info("Check that filtering the autocomplete cache is also case insensitive");
     38  let onAutoCompleteUpdated = jsterm.once("autocomplete-updated");
     39  // Send "a" to make the input "fooba"
     40  EventUtils.sendString("a");
     41  await onAutoCompleteUpdated;
     42 
     43  checkInput("fooba|");
     44  ok(
     45    hasExactPopupLabels(autocompletePopup, ["fooBar", "FooBar"]),
     46    "popup cache filtering is also case-insensitive"
     47  );
     48  checkInputCompletionValue(hud, "r", "completeNode has expected value");
     49 
     50  info(
     51    "Check that accepting the completion value will change the input casing"
     52  );
     53  let onPopupClose = autocompletePopup.once("popup-closed");
     54  EventUtils.synthesizeKey("KEY_Tab");
     55  await onPopupClose;
     56  checkInput("fooBar|", "The input was completed with the correct casing");
     57  checkInputCompletionValue(hud, "", "completeNode is empty");
     58 
     59  info("Check that the popup is displayed with only 1 matching item");
     60  onAutoCompleteUpdated = jsterm.once("autocomplete-updated");
     61  EventUtils.sendString(".f");
     62  await onAutoCompleteUpdated;
     63  ok(autocompletePopup.isOpen, "autocomplete popup is open");
     64 
     65  // Here we want to match "Foo", and since the completion text will only be "oo", we want
     66  // to display the popup so the user knows that we are matching "Foo" and not "foo".
     67  checkInput("fooBar.f|");
     68  ok(true, "The popup was opened even if there's 1 item matching");
     69  ok(
     70    hasExactPopupLabels(autocompletePopup, ["Foo"]),
     71    "popup has expected item"
     72  );
     73  checkInputCompletionValue(hud, "oo", "completeNode has expected value");
     74 
     75  onPopupClose = autocompletePopup.once("popup-closed");
     76  EventUtils.synthesizeKey("KEY_Tab");
     77  await onPopupClose;
     78  checkInput("fooBar.Foo|", "The input was completed with the correct casing");
     79  checkInputCompletionValue(hud, "", "completeNode is empty");
     80 
     81  info("Check that Javascript keywords are displayed first");
     82  await setInputValueForAutocompletion(hud, "func");
     83 
     84  ok(
     85    hasExactPopupLabels(autocompletePopup, ["function", "Function"]),
     86    "popup has expected item"
     87  );
     88  checkInputCompletionValue(hud, "tion", "completeNode has expected value");
     89 
     90  onPopupClose = autocompletePopup.once("popup-closed");
     91  EventUtils.synthesizeKey("KEY_Tab");
     92  await onPopupClose;
     93  checkInput("function|", "The input was completed as expected");
     94  checkInputCompletionValue(hud, "", "completeNode is empty");
     95 
     96  info("Check that filtering the cache works like on the server");
     97  await setInputValueForAutocompletion(hud, "fooBar.");
     98  ok(
     99    hasExactPopupLabels(autocompletePopup, ["test", "Foo", "Test", "TEST"]),
    100    "popup has expected items"
    101  );
    102 
    103  onAutoCompleteUpdated = jsterm.once("autocomplete-updated");
    104  EventUtils.sendString("T");
    105  await onAutoCompleteUpdated;
    106  ok(
    107    hasExactPopupLabels(autocompletePopup, ["Test", "TEST"]),
    108    "popup was filtered case-sensitively, as expected"
    109  );
    110 
    111  info("Close autocomplete popup");
    112  await closeAutocompletePopup(hud);
    113 });