summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_about_urls.js
blob: 277ddb8ee1dd0b84a799b247cc89635f884a013e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const { AboutPagesUtils } = ChromeUtils.importESModule(
  "resource://gre/modules/AboutPagesUtils.sys.mjs"
);

testEngine_setup();

// "about:ab" should match "about:about"
add_task(async function aboutAb() {
  let context = createContext("about:ab", { isPrivate: false });
  await check_results({
    context,
    autofilled: "about:about",
    completed: "about:about",
    matches: [
      makeVisitResult(context, {
        uri: "about:about",
        title: "about:about",
        heuristic: true,
      }),
    ],
  });
});

// "about:Ab" should match "about:about"
add_task(async function aboutAb() {
  let context = createContext("about:Ab", { isPrivate: false });
  await check_results({
    context,
    autofilled: "about:About",
    completed: "about:about",
    matches: [
      makeVisitResult(context, {
        uri: "about:about",
        title: "about:about",
        heuristic: true,
      }),
    ],
  });
});

// "about:about" should match "about:about"
add_task(async function aboutAbout() {
  let context = createContext("about:about", { isPrivate: false });
  await check_results({
    context,
    autofilled: "about:about",
    completed: "about:about",
    matches: [
      makeVisitResult(context, {
        uri: "about:about",
        title: "about:about",
        heuristic: true,
      }),
    ],
  });
});

// "about:a" should complete to "about:about" and also match "about:addons"
add_task(async function aboutAboutAndAboutAddons() {
  let context = createContext("about:a", { isPrivate: false });
  await check_results({
    context,
    search: "about:a",
    autofilled: "about:about",
    completed: "about:about",
    matches: [
      makeVisitResult(context, {
        uri: "about:about",
        title: "about:about",
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: "about:addons",
        title: "about:addons",
        tags: null,
        providerName: "AboutPages",
      }),
    ],
  });
});

// "about:" by itself matches a list of about: pages and nothing else
add_task(async function aboutColonMatchesOnlyAboutPages() {
  // We generate 9 about: page results because there are 10 results total,
  // and the first result is the heuristic result.
  function getFirst9AboutPages() {
    const aboutPageNames = AboutPagesUtils.visibleAboutUrls.slice(0, 9);
    const aboutPageResults = aboutPageNames.map(aboutPageName => {
      return makeVisitResult(context, {
        uri: aboutPageName,
        title: aboutPageName,
        tags: null,
        providerName: "AboutPages",
      });
    });
    return aboutPageResults;
  }

  let context = createContext("about:", { isPrivate: false });
  await check_results({
    context,
    search: "about:",
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        providerName: "HeuristicFallback",
        heuristic: true,
      }),
      ...getFirst9AboutPages(),
    ],
  });
});

// Results for about: pages do not match webpage titles from the user's history
add_task(async function aboutResultsDoNotMatchTitlesInHistory() {
  await PlacesTestUtils.addVisits([
    {
      uri: Services.io.newURI("http://example.com/guide/config/"),
      title: "Guide to config in Firefox",
    },
  ]);

  let context = createContext("about:config", { isPrivate: false });
  await check_results({
    context,
    search: "about:config",
    matches: [
      makeVisitResult(context, {
        uri: "about:config",
        title: "about:config",
        heuristic: true,
        providerName: "Autofill",
      }),
    ],
  });
});

// Tests that about: pages are shown after general results.
add_task(async function after_general() {
  await PlacesTestUtils.addVisits([
    {
      uri: Services.io.newURI("http://example.com/guide/aboutaddons/"),
      title: "Guide to about:addons in Firefox",
    },
  ]);

  let context = createContext("about:a", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeVisitResult(context, {
        uri: "about:about",
        title: "about:about",
        heuristic: true,
        providerName: "Autofill",
      }),
      makeVisitResult(context, {
        uri: "http://example.com/guide/aboutaddons/",
        title: "Guide to about:addons in Firefox",
      }),
      makeVisitResult(context, {
        uri: "about:addons",
        title: "about:addons",
        tags: null,
        providerName: "AboutPages",
      }),
    ],
  });
  await cleanupPlaces();
});