tor-browser

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

test_autofill_prefix_fallback.js (2494B)


      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 // This tests autofill prefix fallback in case multiple origins have the same
      6 // exact frecency.
      7 // We should prefer https, or in case of other prefixes just sort by descending
      8 // id.
      9 
     10 add_task(async function () {
     11  registerCleanupFunction(async () => {
     12    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
     13    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
     14  });
     15  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
     16  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
     17 
     18  let host = "example.com";
     19  let prefixes = ["https://", "https://www.", "http://", "http://www."];
     20  for (let prefix of prefixes) {
     21    await PlacesUtils.bookmarks.insert({
     22      url: `${prefix}${host}`,
     23      parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     24    });
     25  }
     26  await checkOriginsOrder(host, prefixes);
     27 
     28  // The https://www version should be filled because it's https and the www
     29  // version has been added later so it has an higher id.
     30  let context = createContext("ex", { isPrivate: false });
     31  await check_results({
     32    context,
     33    autofilled: `${host}/`,
     34    completed: `https://www.${host}/`,
     35    matches: [
     36      makeVisitResult(context, {
     37        uri: `https://www.${host}/`,
     38        title: UrlbarTestUtils.trimURL(`https://www.${host}`),
     39        heuristic: true,
     40      }),
     41      makeBookmarkResult(context, {
     42        uri: `https://${host}/`,
     43        title: host,
     44      }),
     45    ],
     46  });
     47 
     48  // Remove and reinsert bookmarks in another order.
     49  await PlacesUtils.bookmarks.eraseEverything();
     50  await PlacesUtils.history.clear();
     51  prefixes = ["https://www.", "http://", "https://", "http://www."];
     52  for (let prefix of prefixes) {
     53    await PlacesUtils.bookmarks.insert({
     54      url: `${prefix}${host}`,
     55      parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     56    });
     57  }
     58  await checkOriginsOrder(host, prefixes);
     59 
     60  await check_results({
     61    context,
     62    autofilled: `${host}/`,
     63    completed: `https://${host}/`,
     64    matches: [
     65      makeVisitResult(context, {
     66        uri: `https://${host}/`,
     67        title: UrlbarTestUtils.trimURL(`https://${host}`),
     68        heuristic: true,
     69      }),
     70      makeBookmarkResult(context, {
     71        uri: `https://www.${host}/`,
     72        title: `www.${host}`,
     73      }),
     74    ],
     75  });
     76 });