tor-browser

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

test_about_urls.js (5099B)


      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 "use strict";
      6 
      7 const { AboutPagesUtils } = ChromeUtils.importESModule(
      8  "resource://gre/modules/AboutPagesUtils.sys.mjs"
      9 );
     10 
     11 testEngine_setup();
     12 
     13 // "about:ab" should match "about:about"
     14 add_task(async function aboutAb() {
     15  let context = createContext("about:ab", { isPrivate: false });
     16  await check_results({
     17    context,
     18    autofilled: "about:about",
     19    completed: "about:about",
     20    matches: [
     21      makeVisitResult(context, {
     22        uri: "about:about",
     23        title: "about:about",
     24        heuristic: true,
     25      }),
     26    ],
     27  });
     28 });
     29 
     30 // "about:Ab" should match "about:about"
     31 add_task(async function aboutAb() {
     32  let context = createContext("about:Ab", { isPrivate: false });
     33  await check_results({
     34    context,
     35    autofilled: "about:About",
     36    completed: "about:about",
     37    matches: [
     38      makeVisitResult(context, {
     39        uri: "about:about",
     40        title: "about:about",
     41        heuristic: true,
     42      }),
     43    ],
     44  });
     45 });
     46 
     47 // "about:about" should match "about:about"
     48 add_task(async function aboutAbout() {
     49  let context = createContext("about:about", { isPrivate: false });
     50  await check_results({
     51    context,
     52    autofilled: "about:about",
     53    completed: "about:about",
     54    matches: [
     55      makeVisitResult(context, {
     56        uri: "about:about",
     57        title: "about:about",
     58        heuristic: true,
     59      }),
     60    ],
     61  });
     62 });
     63 
     64 // "about:a" should complete to "about:about" and also match "about:addons"
     65 add_task(async function aboutAboutAndAboutAddons() {
     66  let context = createContext("about:a", { isPrivate: false });
     67  await check_results({
     68    context,
     69    search: "about:a",
     70    autofilled: "about:about",
     71    completed: "about:about",
     72    matches: [
     73      makeVisitResult(context, {
     74        uri: "about:about",
     75        title: "about:about",
     76        heuristic: true,
     77      }),
     78      makeVisitResult(context, {
     79        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
     80        uri: "about:addons",
     81        title: "about:addons",
     82        iconUri: "page-icon:about:addons",
     83        tags: null,
     84        providerName: "UrlbarProviderAboutPages",
     85      }),
     86    ],
     87  });
     88 });
     89 
     90 // "about:" by itself matches a list of about: pages and nothing else
     91 add_task(async function aboutColonMatchesOnlyAboutPages() {
     92  // We generate 9 about: page results because there are 10 results total,
     93  // and the first result is the heuristic result.
     94  function getFirst9AboutPages() {
     95    const aboutPageNames = AboutPagesUtils.visibleAboutUrls.slice(0, 9);
     96    const aboutPageResults = aboutPageNames.map(aboutPageName => {
     97      return makeVisitResult(context, {
     98        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
     99        uri: aboutPageName,
    100        title: aboutPageName,
    101        iconUri: "page-icon:" + aboutPageName,
    102        tags: null,
    103        providerName: "UrlbarProviderAboutPages",
    104      });
    105    });
    106    return aboutPageResults;
    107  }
    108 
    109  let context = createContext("about:", { isPrivate: false });
    110  await check_results({
    111    context,
    112    search: "about:",
    113    matches: [
    114      makeSearchResult(context, {
    115        engineName: SUGGESTIONS_ENGINE_NAME,
    116        providerName: "UrlbarProviderHeuristicFallback",
    117        heuristic: true,
    118      }),
    119      ...getFirst9AboutPages(),
    120    ],
    121  });
    122 });
    123 
    124 // Results for about: pages do not match webpage titles from the user's history
    125 add_task(async function aboutResultsDoNotMatchTitlesInHistory() {
    126  await PlacesTestUtils.addVisits([
    127    {
    128      uri: Services.io.newURI("http://example.com/guide/config/"),
    129      title: "Guide to config in Firefox",
    130    },
    131  ]);
    132 
    133  let context = createContext("about:config", { isPrivate: false });
    134  await check_results({
    135    context,
    136    search: "about:config",
    137    matches: [
    138      makeVisitResult(context, {
    139        uri: "about:config",
    140        title: "about:config",
    141        heuristic: true,
    142        providerName: "UrlbarProviderAutofill",
    143      }),
    144    ],
    145  });
    146 });
    147 
    148 // Tests that about: pages are shown after general results.
    149 add_task(async function after_general() {
    150  await PlacesTestUtils.addVisits([
    151    {
    152      uri: Services.io.newURI("http://example.com/guide/aboutaddons/"),
    153      title: "Guide to about:addons in Firefox",
    154    },
    155  ]);
    156 
    157  let context = createContext("about:a", { isPrivate: false });
    158  await check_results({
    159    context,
    160    matches: [
    161      makeVisitResult(context, {
    162        uri: "about:about",
    163        title: "about:about",
    164        heuristic: true,
    165        providerName: "UrlbarProviderAutofill",
    166      }),
    167      makeVisitResult(context, {
    168        uri: "http://example.com/guide/aboutaddons/",
    169        title: "Guide to about:addons in Firefox",
    170      }),
    171      makeVisitResult(context, {
    172        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
    173        uri: "about:addons",
    174        title: "about:addons",
    175        iconUri: "page-icon:about:addons",
    176        tags: null,
    177        providerName: "UrlbarProviderAboutPages",
    178      }),
    179    ],
    180  });
    181  await cleanupPlaces();
    182 });