tor-browser

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

test_richsuggestions.js (2195B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Tests that rich suggestion results results are shown without
      6 * rich data if richSuggestions are disabled.
      7 */
      8 
      9 const SUGGEST_ENABLED_PREF = "browser.search.suggest.enabled";
     10 const RICH_SUGGESTIONS_PREF = "browser.urlbar.richSuggestions.featureGate";
     11 const QUICKACTIONS_URLBAR_PREF = "quickactions.enabled";
     12 
     13 add_setup(async function () {
     14  let engine = await addTestTailSuggestionsEngine(defaultRichSuggestionsFn);
     15  // Install the test engine.
     16  let oldDefaultEngine = await Services.search.getDefault();
     17  registerCleanupFunction(async () => {
     18    Services.search.setDefault(
     19      oldDefaultEngine,
     20      Ci.nsISearchService.CHANGE_REASON_UNKNOWN
     21    );
     22    Services.prefs.clearUserPref(RICH_SUGGESTIONS_PREF);
     23    Services.prefs.clearUserPref(SUGGEST_ENABLED_PREF);
     24    UrlbarPrefs.clear(QUICKACTIONS_URLBAR_PREF);
     25  });
     26  Services.search.setDefault(engine, Ci.nsISearchService.CHANGE_REASON_UNKNOWN);
     27  Services.prefs.setBoolPref(RICH_SUGGESTIONS_PREF, true);
     28  Services.prefs.setBoolPref(SUGGEST_ENABLED_PREF, true);
     29  UrlbarPrefs.set(QUICKACTIONS_URLBAR_PREF, false);
     30 });
     31 
     32 /**
     33 * Test that suggestions with rich data are still shown
     34 */
     35 add_task(async function test_richsuggestions_disabled() {
     36  Services.prefs.setBoolPref(RICH_SUGGESTIONS_PREF, false);
     37 
     38  const query = "what time is it in t";
     39  let context = createContext(query, { isPrivate: false });
     40 
     41  await check_results({
     42    context,
     43    matches: [
     44      makeSearchResult(context, {
     45        engineName: TAIL_SUGGESTIONS_ENGINE_NAME,
     46        heuristic: true,
     47      }),
     48      makeSearchResult(context, {
     49        engineName: TAIL_SUGGESTIONS_ENGINE_NAME,
     50        suggestion: query + "oronto",
     51      }),
     52      makeSearchResult(context, {
     53        engineName: TAIL_SUGGESTIONS_ENGINE_NAME,
     54        suggestion: query + "unisia",
     55      }),
     56      makeSearchResult(context, {
     57        engineName: TAIL_SUGGESTIONS_ENGINE_NAME,
     58        suggestion: query + "acoma",
     59      }),
     60      makeSearchResult(context, {
     61        engineName: TAIL_SUGGESTIONS_ENGINE_NAME,
     62        suggestion: query + "aipei",
     63      }),
     64    ],
     65  });
     66 });