tor-browser

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

test_multi_word_search.js (3927B)


      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 401869 to allow multiple words separated by spaces to match in
      7 * the page title, page url, or bookmark title to be considered a match. All
      8 * terms must match but not all terms need to be in the title, etc.
      9 *
     10 * Test bug 424216 by making sure bookmark titles are always shown if one is
     11 * available. Also bug 425056 makes sure matches aren't found partially in the
     12 * page title and partially in the bookmark.
     13 */
     14 
     15 testEngine_setup();
     16 
     17 add_task(async function test_match_beginning() {
     18  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
     19  registerCleanupFunction(() => {
     20    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
     21  });
     22 
     23  let uri1 = Services.io.newURI("http://a.b.c/d-e_f/h/t/p");
     24  let uri2 = Services.io.newURI("http://d.e.f/g-h_i/h/t/p");
     25  let uri3 = Services.io.newURI("http://g.h.i/j-k_l/h/t/p");
     26  let uri4 = Services.io.newURI("http://j.k.l/m-n_o/h/t/p");
     27  await PlacesTestUtils.addBookmarkWithDetails({
     28    uri: uri3,
     29    title: "f(o)o b<a>r",
     30  });
     31  await PlacesTestUtils.addBookmarkWithDetails({
     32    uri: uri4,
     33    title: "b(a)r b<a>z",
     34  });
     35  await PlacesTestUtils.addVisits([
     36    { uri: uri4, title: "f(o)o b<a>r" },
     37    { uri: uri3, title: "f(o)o b<a>r" },
     38    { uri: uri2, title: "b(a)r b<a>z" },
     39    { uri: uri1, title: "f(o)o b<a>r" },
     40  ]);
     41 
     42  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();
     43 
     44  info("Match 2 terms all in url");
     45  let context = createContext("c d", { isPrivate: false });
     46  await check_results({
     47    context,
     48    matches: [
     49      makeSearchResult(context, {
     50        engineName: SUGGESTIONS_ENGINE_NAME,
     51        heuristic: true,
     52      }),
     53      makeVisitResult(context, { uri: uri1.spec, title: "f(o)o b<a>r" }),
     54    ],
     55  });
     56 
     57  info("Match 1 term in url and 1 term in title");
     58  context = createContext("b e", { isPrivate: false });
     59  await check_results({
     60    context,
     61    matches: [
     62      makeSearchResult(context, {
     63        engineName: SUGGESTIONS_ENGINE_NAME,
     64        heuristic: true,
     65      }),
     66      makeVisitResult(context, { uri: uri1.spec, title: "f(o)o b<a>r" }),
     67      makeVisitResult(context, { uri: uri2.spec, title: "b(a)r b<a>z" }),
     68    ],
     69  });
     70 
     71  info("Match 3 terms all in title; display bookmark title if matched");
     72  context = createContext("b a z", { isPrivate: false });
     73  await check_results({
     74    context,
     75    matches: [
     76      makeSearchResult(context, {
     77        engineName: SUGGESTIONS_ENGINE_NAME,
     78        heuristic: true,
     79      }),
     80      makeBookmarkResult(context, { uri: uri4.spec, title: "b(a)r b<a>z" }),
     81      makeVisitResult(context, { uri: uri2.spec, title: "b(a)r b<a>z" }),
     82    ],
     83  });
     84 
     85  info(
     86    "Match 2 terms in url and 1 in title; make sure bookmark title is used for search"
     87  );
     88  context = createContext("k f t", { isPrivate: false });
     89  await check_results({
     90    context,
     91    matches: [
     92      makeSearchResult(context, {
     93        engineName: SUGGESTIONS_ENGINE_NAME,
     94        heuristic: true,
     95      }),
     96      makeBookmarkResult(context, { uri: uri3.spec, title: "f(o)o b<a>r" }),
     97    ],
     98  });
     99 
    100  info("Match 3 terms in url and 1 in title");
    101  context = createContext("d i g z", { isPrivate: false });
    102  await check_results({
    103    context,
    104    matches: [
    105      makeSearchResult(context, {
    106        engineName: SUGGESTIONS_ENGINE_NAME,
    107        heuristic: true,
    108      }),
    109      makeVisitResult(context, { uri: uri2.spec, title: "b(a)r b<a>z" }),
    110    ],
    111  });
    112 
    113  info("Match nothing");
    114  context = createContext("m o z i", { isPrivate: false });
    115  await check_results({
    116    context,
    117    matches: [
    118      makeSearchResult(context, {
    119        engineName: SUGGESTIONS_ENGINE_NAME,
    120        heuristic: true,
    121      }),
    122    ],
    123  });
    124 
    125  await cleanupPlaces();
    126 });