tor-browser

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

test_autofill_search_engine_aliases.js (2653B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Tests autofilling search engine token ("@") aliases.
      6 
      7 "use strict";
      8 
      9 const TEST_ENGINE_NAME = "test autofill aliases";
     10 const TEST_ENGINE_ALIAS = "@autofilltest";
     11 
     12 add_setup(async () => {
     13  // Add an engine with an "@" alias.
     14  await SearchTestUtils.installSearchExtension({
     15    name: TEST_ENGINE_NAME,
     16    keyword: TEST_ENGINE_ALIAS,
     17  });
     18 });
     19 
     20 // Searching for @autofi should autofill to @autofilltest.
     21 add_task(async function basic() {
     22  // Add a history visit that should normally match but for the fact that the
     23  // search uses an @ alias.  When an @ alias is autofilled, there should be no
     24  // other matches except the autofill heuristic match.
     25  await PlacesTestUtils.addVisits({
     26    uri: "http://example.com/",
     27    title: TEST_ENGINE_ALIAS,
     28  });
     29 
     30  let search = TEST_ENGINE_ALIAS.substr(
     31    0,
     32    Math.round(TEST_ENGINE_ALIAS.length / 2)
     33  );
     34  let autofilledValue = TEST_ENGINE_ALIAS + " ";
     35  let context = createContext(search, { isPrivate: false });
     36  await check_results({
     37    context,
     38    autofilled: autofilledValue,
     39    matches: [
     40      makeSearchResult(context, {
     41        engineName: TEST_ENGINE_NAME,
     42        alias: TEST_ENGINE_ALIAS,
     43        query: "",
     44        providesSearchMode: true,
     45        heuristic: false,
     46        providerName: "UrlbarProviderTokenAliasEngines",
     47      }),
     48    ],
     49  });
     50  await cleanupPlaces();
     51 });
     52 
     53 // Searching for @AUTOFI should autofill to @AUTOFIlltest, preserving the case
     54 // in the search string.
     55 add_task(async function preserveCase() {
     56  // Add a history visit that should normally match but for the fact that the
     57  // search uses an @ alias.  When an @ alias is autofilled, there should be no
     58  // other matches except the autofill heuristic match.
     59  await PlacesTestUtils.addVisits({
     60    uri: "http://example.com/",
     61    title: TEST_ENGINE_ALIAS,
     62  });
     63 
     64  let search = TEST_ENGINE_ALIAS.toUpperCase().substr(
     65    0,
     66    Math.round(TEST_ENGINE_ALIAS.length / 2)
     67  );
     68  let alias = search + TEST_ENGINE_ALIAS.substr(search.length);
     69 
     70  let autofilledValue = alias + " ";
     71  let context = createContext(search, { isPrivate: false });
     72  await check_results({
     73    context,
     74    autofilled: autofilledValue,
     75    matches: [
     76      makeSearchResult(context, {
     77        engineName: TEST_ENGINE_NAME,
     78        alias,
     79        query: "",
     80        providesSearchMode: true,
     81        heuristic: false,
     82        providerName: "UrlbarProviderTokenAliasEngines",
     83      }),
     84    ],
     85  });
     86  await cleanupPlaces();
     87 });