tor-browser

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

test_empty_search.js (6150B)


      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 /**
      6 * Test for bug 426864 that makes sure searching a space only shows typed pages
      7 * from history.
      8 */
      9 
     10 testEngine_setup();
     11 
     12 add_task(async function test_empty_search() {
     13  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
     14  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
     15  registerCleanupFunction(() => {
     16    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
     17    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
     18  });
     19 
     20  let uri1 = Services.io.newURI("http://t.foo/1");
     21  let uri2 = Services.io.newURI("http://t.foo/2");
     22  let uri3 = Services.io.newURI("http://t.foo/3");
     23  let uri4 = Services.io.newURI("http://t.foo/4");
     24  let uri5 = Services.io.newURI("http://t.foo/5");
     25  let uri6 = Services.io.newURI("http://t.foo/6");
     26  let uri7 = Services.io.newURI("http://t.foo/7");
     27 
     28  await PlacesTestUtils.addBookmarkWithDetails({ uri: uri6, title: "title" });
     29  await PlacesTestUtils.addBookmarkWithDetails({ uri: uri5, title: "title" });
     30  await PlacesTestUtils.addBookmarkWithDetails({ uri: uri4, title: "title" });
     31  await PlacesTestUtils.addBookmarkWithDetails({ uri: uri2, title: "title" });
     32 
     33  await PlacesTestUtils.addVisits([
     34    {
     35      uri: uri7,
     36      title: "title",
     37    },
     38    {
     39      uri: uri6,
     40      title: "title",
     41    },
     42    {
     43      uri: uri4,
     44      title: "title",
     45    },
     46    { uri: uri3, title: "title" },
     47    {
     48      uri: uri2,
     49      title: "title",
     50    },
     51    { uri: uri1, title: "title" },
     52  ]);
     53 
     54  await addOpenPages(uri7, 1);
     55 
     56  // Now remove page 6 from history, so it is an unvisited bookmark.
     57  await PlacesUtils.history.remove(uri6);
     58 
     59  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();
     60 
     61  // With the changes above, the sites have the same frecency:
     62  // Group 1: http://t.foo/6, http://t.foo/5, http://t.foo/4, http://t.foo/2
     63  // Group 2: http://t.foo/7, http://t.foo/3, http://t.foo/1
     64 
     65  // With the changes above, the sites in descending order of frecency are:
     66  // uri2
     67  // uri4
     68  // uri5
     69  // uri6
     70  // uri1
     71  // uri3
     72  // uri7
     73 
     74  info("Match everything");
     75  let context = createContext("foo", { isPrivate: false });
     76  await check_results({
     77    context,
     78    matches: [
     79      makeSearchResult(context, {
     80        engineName: SUGGESTIONS_ENGINE_NAME,
     81        heuristic: true,
     82      }),
     83      makeBookmarkResult(context, {
     84        uri: uri2.spec,
     85        title: "title",
     86      }),
     87      makeBookmarkResult(context, {
     88        uri: uri4.spec,
     89        title: "title",
     90      }),
     91      makeBookmarkResult(context, {
     92        uri: uri5.spec,
     93        title: "title",
     94      }),
     95      makeBookmarkResult(context, {
     96        uri: uri6.spec,
     97        title: "title",
     98      }),
     99      makeVisitResult(context, { uri: uri1.spec, title: "title" }),
    100      makeVisitResult(context, { uri: uri3.spec, title: "title" }),
    101      makeTabSwitchResult(context, { uri: uri7.spec, title: "title" }),
    102    ],
    103  });
    104 
    105  info("Match only history");
    106  context = createContext(`foo ${UrlbarTokenizer.RESTRICT.HISTORY}`, {
    107    isPrivate: false,
    108  });
    109  await check_results({
    110    context,
    111    matches: [
    112      makeSearchResult(context, {
    113        engineName: SUGGESTIONS_ENGINE_NAME,
    114        heuristic: true,
    115      }),
    116      makeVisitResult(context, { uri: uri2.spec, title: "title" }),
    117      makeVisitResult(context, { uri: uri4.spec, title: "title" }),
    118      makeVisitResult(context, { uri: uri1.spec, title: "title" }),
    119      makeVisitResult(context, { uri: uri3.spec, title: "title" }),
    120      makeVisitResult(context, { uri: uri7.spec, title: "title" }),
    121    ],
    122  });
    123 
    124  info("Drop-down empty search matches history sorted by frecency desc");
    125  context = createContext(" ", { isPrivate: false });
    126  await check_results({
    127    context,
    128    matches: [
    129      makeSearchResult(context, {
    130        engineName: SUGGESTIONS_ENGINE_NAME,
    131        // query is made explict so makeSearchResult doesn't trim it.
    132        query: " ",
    133        heuristic: true,
    134      }),
    135      makeVisitResult(context, { uri: uri2.spec, title: "title" }),
    136      makeVisitResult(context, { uri: uri4.spec, title: "title" }),
    137      makeVisitResult(context, { uri: uri1.spec, title: "title" }),
    138      makeVisitResult(context, { uri: uri3.spec, title: "title" }),
    139      makeVisitResult(context, { uri: uri7.spec, title: "title" }),
    140    ],
    141  });
    142 
    143  info("Empty search matches only bookmarks when history is disabled");
    144  Services.prefs.setBoolPref("browser.urlbar.suggest.history", false);
    145  Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
    146  context = createContext(" ", { isPrivate: false });
    147  await check_results({
    148    context,
    149    matches: [
    150      makeSearchResult(context, {
    151        engineName: SUGGESTIONS_ENGINE_NAME,
    152        // query is made explict so makeSearchResult doesn't trim it.
    153        query: " ",
    154        heuristic: true,
    155      }),
    156      makeBookmarkResult(context, {
    157        uri: uri2.spec,
    158        title: "title",
    159      }),
    160      makeBookmarkResult(context, {
    161        uri: uri4.spec,
    162        title: "title",
    163      }),
    164      makeBookmarkResult(context, {
    165        uri: uri5.spec,
    166        title: "title",
    167      }),
    168      makeBookmarkResult(context, {
    169        uri: uri6.spec,
    170        title: "title",
    171      }),
    172    ],
    173  });
    174 
    175  info(
    176    "Empty search matches only open tabs when bookmarks and history are disabled"
    177  );
    178  Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false);
    179  context = createContext(" ", { isPrivate: false });
    180  await check_results({
    181    context,
    182    matches: [
    183      makeSearchResult(context, {
    184        engineName: SUGGESTIONS_ENGINE_NAME,
    185        // query is made explict so makeSearchResult doesn't trim it.
    186        query: " ",
    187        heuristic: true,
    188      }),
    189      makeTabSwitchResult(context, { uri: uri7.spec, title: "title" }),
    190    ],
    191  });
    192 
    193  Services.prefs.clearUserPref("browser.urlbar.suggest.history");
    194  Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark");
    195 
    196  await cleanupPlaces();
    197 });