summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unifiedcomplete/test_avoid_middle_complete.js
blob: 54fc343cac0b8430d31a1cff63cec1b05470bc81 (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
177
178
179
/* 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/. */

add_task(function* test_prefix_space_noautofill() {
  yield PlacesTestUtils.addVisits({
    uri: NetUtil.newURI("http://moz.org/test/"),
    transition: TRANSITION_TYPED
  });

  do_print("Should not try to autoFill if search string contains a space");
  yield check_autocomplete({
    search: " mo",
    autofilled: " mo",
    completed: " mo"
  });

  yield cleanup();
});

add_task(function* test_trailing_space_noautofill() {
  yield PlacesTestUtils.addVisits({
    uri: NetUtil.newURI("http://moz.org/test/"),
    transition: TRANSITION_TYPED
  });

  do_print("Should not try to autoFill if search string contains a space");
  yield check_autocomplete({
    search: "mo ",
    autofilled: "mo ",
    completed: "mo "
  });

  yield cleanup();
});

add_task(function* test_searchEngine_autofill() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
  Services.search.addEngineWithDetails("CakeSearch", "", "", "",
                                       "GET", "http://cake.search/");
  let engine = Services.search.getEngineByName("CakeSearch");
  engine.addParam("q", "{searchTerms}", null);
  do_register_cleanup(() => Services.search.removeEngine(engine));

  do_print("Should autoFill search engine if search string does not contains a space");
  yield check_autocomplete({
    search: "ca",
    autofilled: "cake.search",
    completed: "http://cake.search"
  });

  yield cleanup();
});

add_task(function* test_searchEngine_prefix_space_noautofill() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
  Services.search.addEngineWithDetails("CupcakeSearch", "", "", "",
                                       "GET", "http://cupcake.search/");
  let engine = Services.search.getEngineByName("CupcakeSearch");
  engine.addParam("q", "{searchTerms}", null);
  do_register_cleanup(() => Services.search.removeEngine(engine));

  do_print("Should not try to autoFill search engine if search string contains a space");
  yield check_autocomplete({
    search: " cu",
    autofilled: " cu",
    completed: " cu"
  });

  yield cleanup();
});

add_task(function* test_searchEngine_trailing_space_noautofill() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
  Services.search.addEngineWithDetails("BaconSearch", "", "", "",
                                       "GET", "http://bacon.search/");
  let engine = Services.search.getEngineByName("BaconSearch");
  engine.addParam("q", "{searchTerms}", null);
  do_register_cleanup(() => Services.search.removeEngine(engine));

  do_print("Should not try to autoFill search engine if search string contains a space");
  yield check_autocomplete({
    search: "ba ",
    autofilled: "ba ",
    completed: "ba "
  });

  yield cleanup();
});

add_task(function* test_searchEngine_www_noautofill() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
  Services.search.addEngineWithDetails("HamSearch", "", "", "",
                                       "GET", "http://ham.search/");
  let engine = Services.search.getEngineByName("HamSearch");
  engine.addParam("q", "{searchTerms}", null);
  do_register_cleanup(() => Services.search.removeEngine(engine));

  do_print("Should not autoFill search engine if search string contains www. but engine doesn't");
  yield check_autocomplete({
    search: "www.ham",
    autofilled: "www.ham",
    completed: "www.ham"
  });

  yield cleanup();
});

add_task(function* test_searchEngine_different_scheme_noautofill() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
  Services.search.addEngineWithDetails("PieSearch", "", "", "",
                                       "GET", "https://pie.search/");
  let engine = Services.search.getEngineByName("PieSearch");
  engine.addParam("q", "{searchTerms}", null);
  do_register_cleanup(() => Services.search.removeEngine(engine));

  do_print("Should not autoFill search engine if search string has a different scheme.");
  yield check_autocomplete({
    search: "http://pie",
    autofilled: "http://pie",
    completed: "http://pie"
  });

  yield cleanup();
});

add_task(function* test_searchEngine_matching_prefix_autofill() {
  Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
  Services.search.addEngineWithDetails("BeanSearch", "", "", "",
                                       "GET", "http://www.bean.search/");
  let engine = Services.search.getEngineByName("BeanSearch");
  engine.addParam("q", "{searchTerms}", null);
  do_register_cleanup(() => Services.search.removeEngine(engine));


  do_print("Should autoFill search engine if search string has matching prefix.");
  yield check_autocomplete({
    search: "http://www.be",
    autofilled: "http://www.bean.search",
    completed: "http://www.bean.search"
  })

  do_print("Should autoFill search engine if search string has www prefix.");
  yield check_autocomplete({
    search: "www.be",
    autofilled: "www.bean.search",
    completed: "http://www.bean.search"
  });

  do_print("Should autoFill search engine if search string has matching scheme.");
  yield check_autocomplete({
    search: "http://be",
    autofilled: "http://bean.search",
    completed: "http://www.bean.search"
  });

  yield cleanup();
});

add_task(function* test_prefix_autofill() {
  yield PlacesTestUtils.addVisits({
    uri: NetUtil.newURI("http://mozilla.org/test/"),
    transition: TRANSITION_TYPED
  });
  yield PlacesTestUtils.addVisits({
    uri: NetUtil.newURI("http://moz.org/test/"),
    transition: TRANSITION_TYPED
  });

  do_print("Should not try to autoFill in-the-middle if a search is canceled immediately");
  yield check_autocomplete({
    incompleteSearch: "moz",
    search: "mozi",
    autofilled: "mozilla.org/",
    completed: "mozilla.org/"
  });

  yield cleanup();
});