tor-browser

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

test_autofill_functional.js (4783B)


      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 file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Functional tests for inline autocomplete
      6 
      7 add_setup(async function () {
      8  registerCleanupFunction(async () => {
      9    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
     10    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
     11  });
     12 
     13  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
     14  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
     15 });
     16 
     17 add_task(async function test_urls_order() {
     18  info("Add urls, check for correct order");
     19  let places = [
     20    { uri: Services.io.newURI("http://visit1.mozilla.org") },
     21    { uri: Services.io.newURI("http://visit2.mozilla.org") },
     22  ];
     23  await PlacesTestUtils.addVisits(places);
     24  let context = createContext("vis", { isPrivate: false });
     25  await check_results({
     26    context,
     27    autofilled: "visit2.mozilla.org/",
     28    completed: "http://visit2.mozilla.org/",
     29    matches: [
     30      makeVisitResult(context, {
     31        uri: "http://visit2.mozilla.org/",
     32        title: "test visit for http://visit2.mozilla.org/",
     33        heuristic: true,
     34      }),
     35      makeVisitResult(context, {
     36        uri: "http://visit1.mozilla.org/",
     37        title: "test visit for http://visit1.mozilla.org/",
     38      }),
     39    ],
     40  });
     41  await cleanupPlaces();
     42 });
     43 
     44 add_task(async function test_bookmark_first() {
     45  info("With a bookmark and history, the query result should be the bookmark");
     46  await PlacesTestUtils.addBookmarkWithDetails({
     47    uri: Services.io.newURI("http://bookmark1.mozilla.org/"),
     48  });
     49  await PlacesTestUtils.addVisits(
     50    Services.io.newURI("http://bookmark1.mozilla.org/foo")
     51  );
     52  let context = createContext("bookmark", { isPrivate: false });
     53  await check_results({
     54    context,
     55    autofilled: "bookmark1.mozilla.org/",
     56    completed: "http://bookmark1.mozilla.org/",
     57    matches: [
     58      makeVisitResult(context, {
     59        uri: "http://bookmark1.mozilla.org/",
     60        title: "A bookmark",
     61        heuristic: true,
     62      }),
     63      makeVisitResult(context, {
     64        uri: "http://bookmark1.mozilla.org/foo",
     65        title: "test visit for http://bookmark1.mozilla.org/foo",
     66      }),
     67    ],
     68  });
     69  await cleanupPlaces();
     70 });
     71 
     72 add_task(async function test_complete_querystring() {
     73  info("Check to make sure we autocomplete after ?");
     74  await PlacesTestUtils.addVisits(
     75    Services.io.newURI("http://smokey.mozilla.org/foo?bacon=delicious")
     76  );
     77  let context = createContext("smokey.mozilla.org/foo?", { isPrivate: false });
     78  await check_results({
     79    context,
     80    autofilled: "smokey.mozilla.org/foo?bacon=delicious",
     81    completed: "http://smokey.mozilla.org/foo?bacon=delicious",
     82    matches: [
     83      makeVisitResult(context, {
     84        uri: "http://smokey.mozilla.org/foo?bacon=delicious",
     85        title: "test visit for http://smokey.mozilla.org/foo?bacon=delicious",
     86        heuristic: true,
     87      }),
     88    ],
     89  });
     90  await cleanupPlaces();
     91 });
     92 
     93 add_task(async function test_complete_fragment() {
     94  info("Check to make sure we autocomplete after #");
     95  await PlacesTestUtils.addVisits(
     96    Services.io.newURI("http://smokey.mozilla.org/foo?bacon=delicious#bar")
     97  );
     98  let context = createContext("smokey.mozilla.org/foo?bacon=delicious#bar", {
     99    isPrivate: false,
    100  });
    101  await check_results({
    102    context,
    103    autofilled: "smokey.mozilla.org/foo?bacon=delicious#bar",
    104    completed: "http://smokey.mozilla.org/foo?bacon=delicious#bar",
    105    matches: [
    106      makeVisitResult(context, {
    107        uri: "http://smokey.mozilla.org/foo?bacon=delicious#bar",
    108        title:
    109          "test visit for http://smokey.mozilla.org/foo?bacon=delicious#bar",
    110        heuristic: true,
    111      }),
    112    ],
    113  });
    114  await cleanupPlaces();
    115 });
    116 
    117 add_task(async function test_prefix_autofill() {
    118  await PlacesTestUtils.addVisits({
    119    uri: Services.io.newURI("http://mozilla.org/test/"),
    120  });
    121  await PlacesTestUtils.addVisits({
    122    uri: Services.io.newURI("http://moz.org/test/"),
    123  });
    124 
    125  info("Should still autofill after a search is cancelled immediately");
    126  let context = createContext("mozi", { isPrivate: false });
    127  await check_results({
    128    context,
    129    incompleteSearch: "moz",
    130    autofilled: "mozilla.org/",
    131    completed: "http://mozilla.org/",
    132    matches: [
    133      makeVisitResult(context, {
    134        uri: "http://mozilla.org/",
    135        title: UrlbarTestUtils.trimURL("http://mozilla.org"),
    136        heuristic: true,
    137      }),
    138      makeVisitResult(context, {
    139        uri: "http://mozilla.org/test/",
    140        title: "test visit for http://mozilla.org/test/",
    141        providerName: "UrlbarProviderPlaces",
    142      }),
    143    ],
    144  });
    145 
    146  await cleanupPlaces();
    147 });