summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_match_javascript.js
blob: adb1236a68053bf00c7ef276f41fc60ac916f119 (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
/* 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/. */

/**
 * Test for bug 417798 to make sure javascript: URIs don't show up unless the
 * user searches for javascript: explicitly.
 */

testEngine_setup();

add_task(async function test_javascript_match() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", false);
  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
  Services.prefs.setBoolPref("browser.urlbar.suggest.engines", false);
  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
  registerCleanupFunction(() => {
    Services.prefs.clearUserPref("browser.urlbar.autoFill.searchEngines");
    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
    Services.prefs.clearUserPref("browser.urlbar.suggest.engines");
    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
  });

  let uri1 = Services.io.newURI("http://abc/def");
  let uri2 = Services.io.newURI("javascript:5");
  await PlacesTestUtils.addBookmarkWithDetails({
    uri: uri2,
    title: "Title with javascript:",
  });
  await PlacesTestUtils.addVisits([
    { uri: uri1, title: "Title with javascript:" },
  ]);

  info("Match non-javascript: with plain search");
  let context = createContext("a", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: uri1.spec,
        title: "Title with javascript:",
      }),
    ],
  });

  info("Match non-javascript: with 'javascript'");
  context = createContext("javascript", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: uri1.spec,
        title: "Title with javascript:",
      }),
    ],
  });

  info("Match non-javascript with 'javascript:'");
  context = createContext("javascript:", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: uri1.spec,
        title: "Title with javascript:",
      }),
    ],
  });

  info("Match nothing with '5 javascript:'");
  context = createContext("5 javascript:", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
    ],
  });

  info("Match non-javascript: with 'a javascript:'");
  context = createContext("a javascript:", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeSearchResult(context, {
        engineName: SUGGESTIONS_ENGINE_NAME,
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: uri1.spec,
        title: "Title with javascript:",
      }),
    ],
  });

  info("Match non-javascript: and javascript: with 'javascript: a'");
  context = createContext("javascript: a", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeVisitResult(context, {
        uri: "javascript: a",
        title: "javascript: a",
        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
        heuristic: true,
      }),
      makeVisitResult(context, {
        uri: uri1.spec,
        title: "Title with javascript:",
      }),
      makeBookmarkResult(context, {
        uri: uri2.spec,
        iconUri: "chrome://global/skin/icons/defaultFavicon.svg",
        title: "Title with javascript:",
      }),
    ],
  });

  info("Match javascript: with 'javascript: 5'");
  context = createContext("javascript: 5", { isPrivate: false });
  await check_results({
    context,
    matches: [
      makeVisitResult(context, {
        uri: "javascript: 5",
        title: "javascript: 5",
        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
        heuristic: true,
      }),
      makeBookmarkResult(context, {
        uri: uri2.spec,
        iconUri: "chrome://global/skin/icons/defaultFavicon.svg",
        title: "Title with javascript:",
      }),
    ],
  });

  await cleanupPlaces();
});