tor-browser

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

test_local_suggest_prefs.js (3328B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
      2 * vim:set ts=2 sw=2 sts=2 et:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 // Test for following preferences related to local suggest.
      8 // * browser.urlbar.suggest.bookmark
      9 // * browser.urlbar.suggest.history
     10 // * browser.urlbar.suggest.openpage
     11 
     12 testEngine_setup();
     13 
     14 add_setup(async () => {
     15  Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
     16  Services.prefs.setBoolPref("browser.urlbar.suggest.engines", false);
     17  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
     18 
     19  const uri = Services.io.newURI("http://example.com/");
     20 
     21  await PlacesTestUtils.addVisits([{ uri, title: "example" }]);
     22  await PlacesUtils.bookmarks.insert({
     23    url: uri,
     24    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
     25  });
     26  await addOpenPages(uri);
     27 
     28  registerCleanupFunction(async () => {
     29    Services.prefs.clearUserPref("browser.urlbar.autoFill");
     30    Services.prefs.clearUserPref("browser.urlbar.suggest.engines");
     31    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
     32 
     33    Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark");
     34    Services.prefs.clearUserPref("browser.urlbar.suggest.history");
     35    Services.prefs.clearUserPref("browser.urlbar.suggest.openpage");
     36    await cleanupPlaces();
     37  });
     38 });
     39 
     40 add_task(async function test_prefs() {
     41  const testData = [
     42    {
     43      bookmark: true,
     44      history: true,
     45      openpage: true,
     46    },
     47    {
     48      bookmark: false,
     49      history: true,
     50      openpage: true,
     51    },
     52    {
     53      bookmark: true,
     54      history: false,
     55      openpage: true,
     56    },
     57    {
     58      bookmark: true,
     59      history: true,
     60      openpage: false,
     61    },
     62    {
     63      bookmark: false,
     64      history: false,
     65      openpage: true,
     66    },
     67    {
     68      bookmark: false,
     69      history: true,
     70      openpage: false,
     71    },
     72    {
     73      bookmark: true,
     74      history: false,
     75      openpage: false,
     76    },
     77    {
     78      bookmark: false,
     79      history: false,
     80      openpage: false,
     81    },
     82  ];
     83 
     84  for (const { bookmark, history, openpage } of testData) {
     85    Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", bookmark);
     86    Services.prefs.setBoolPref("browser.urlbar.suggest.history", history);
     87    Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", openpage);
     88 
     89    info(`Test bookmark:${bookmark} history:${history} openpage:${openpage}`);
     90 
     91    const context = createContext("e", { isPrivate: false });
     92    const matches = [];
     93 
     94    matches.push(
     95      makeSearchResult(context, {
     96        engineName: SUGGESTIONS_ENGINE_NAME,
     97        heuristic: true,
     98      })
     99    );
    100 
    101    if (openpage) {
    102      matches.push(
    103        makeTabSwitchResult(context, {
    104          uri: "http://example.com/",
    105          title: "example",
    106        })
    107      );
    108    } else if (bookmark) {
    109      matches.push(
    110        makeBookmarkResult(context, {
    111          uri: "http://example.com/",
    112          title: "example",
    113        })
    114      );
    115    } else if (history) {
    116      matches.push(
    117        makeVisitResult(context, {
    118          uri: "http://example.com/",
    119          title: "example",
    120        })
    121      );
    122    }
    123 
    124    await check_results({ context, matches });
    125  }
    126 });