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
|
/* 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 bug 393678 to make sure matches against the url, title, tags are only
* made on word boundaries instead of in the middle of words.
*
* Make sure we don't try matching one after a CamelCase because the upper-case
* isn't really a word boundary. (bug 429498)
*
* Bug 429531 provides switching between "must match on word boundary" and "can
* match," so leverage "must match" pref for checking word boundary logic and
* make sure "can match" matches anywhere.
*/
var katakana = ["\u30a8", "\u30c9"]; // E, Do
var ideograph = ["\u4efb", "\u5929", "\u5802"]; // Nin Ten Do
add_task(function* test_escape() {
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", false);
let uri1 = NetUtil.newURI("http://matchme/");
let uri2 = NetUtil.newURI("http://dontmatchme/");
let uri3 = NetUtil.newURI("http://title/1");
let uri4 = NetUtil.newURI("http://title/2");
let uri5 = NetUtil.newURI("http://tag/1");
let uri6 = NetUtil.newURI("http://tag/2");
let uri7 = NetUtil.newURI("http://crazytitle/");
let uri8 = NetUtil.newURI("http://katakana/");
let uri9 = NetUtil.newURI("http://ideograph/");
let uri10 = NetUtil.newURI("http://camel/pleaseMatchMe/");
yield PlacesTestUtils.addVisits([
{ uri: uri1, title: "title1" },
{ uri: uri2, title: "title1" },
{ uri: uri3, title: "matchme2" },
{ uri: uri4, title: "dontmatchme3" },
{ uri: uri5, title: "title1" },
{ uri: uri6, title: "title1" },
{ uri: uri7, title: "!@#$%^&*()_+{}|:<>?word" },
{ uri: uri8, title: katakana.join("") },
{ uri: uri9, title: ideograph.join("") },
{ uri: uri10, title: "title1" }
]);
yield addBookmark( { uri: uri5, title: "title1", tags: [ "matchme2" ] } );
yield addBookmark( { uri: uri6, title: "title1", tags: [ "dontmatchme3" ] } );
// match only on word boundaries
Services.prefs.setIntPref("browser.urlbar.matchBehavior", 2);
do_print("Match 'match' at the beginning or after / or on a CamelCase");
yield check_autocomplete({
search: "match",
matches: [ { uri: uri1, title: "title1" },
{ uri: uri3, title: "matchme2" },
{ uri: uri5, title: "title1", tags: [ "matchme2" ], style: [ "bookmark-tag" ] },
{ uri: uri10, title: "title1" } ]
});
do_print("Match 'dont' at the beginning or after /");
yield check_autocomplete({
search: "dont",
matches: [ { uri: uri2, title: "title1" },
{ uri: uri4, title: "dontmatchme3" },
{ uri: uri6, title: "title1", tags: [ "dontmatchme3" ], style: [ "bookmark-tag" ] } ]
});
do_print("Match 'match' at the beginning or after / or on a CamelCase");
yield check_autocomplete({
search: "2",
matches: [ { uri: uri3, title: "matchme2" },
{ uri: uri4, title: "dontmatchme3" },
{ uri: uri5, title: "title1", tags: [ "matchme2" ], style: [ "bookmark-tag" ] },
{ uri: uri6, title: "title1", tags: [ "dontmatchme3" ], style: [ "bookmark-tag" ] } ]
});
do_print("Match 't' at the beginning or after /");
yield check_autocomplete({
search: "t",
matches: [ { uri: uri1, title: "title1" },
{ uri: uri2, title: "title1" },
{ uri: uri3, title: "matchme2" },
{ uri: uri4, title: "dontmatchme3" },
{ uri: uri5, title: "title1", tags: [ "matchme2" ], style: [ "bookmark-tag" ] },
{ uri: uri6, title: "title1", tags: [ "dontmatchme3" ], style: [ "bookmark-tag" ] },
{ uri: uri10, title: "title1" } ]
});
do_print("Match 'word' after many consecutive word boundaries");
yield check_autocomplete({
search: "word",
matches: [ { uri: uri7, title: "!@#$%^&*()_+{}|:<>?word" } ]
});
do_print("Match a word boundary '/' for everything");
yield check_autocomplete({
search: "/",
matches: [ { uri: uri1, title: "title1" },
{ uri: uri2, title: "title1" },
{ uri: uri3, title: "matchme2" },
{ uri: uri4, title: "dontmatchme3" },
{ uri: uri5, title: "title1", tags: [ "matchme2" ], style: [ "bookmark-tag" ] },
{ uri: uri6, title: "title1", tags: [ "dontmatchme3" ], style: [ "bookmark-tag" ] },
{ uri: uri7, title: "!@#$%^&*()_+{}|:<>?word" },
{ uri: uri8, title: katakana.join("") },
{ uri: uri9, title: ideograph.join("") },
{ uri: uri10, title: "title1" } ]
});
do_print("Match word boundaries '()_+' that are among word boundaries");
yield check_autocomplete({
search: "()_+",
matches: [ { uri: uri7, title: "!@#$%^&*()_+{}|:<>?word" } ]
});
do_print("Katakana characters form a string, so match the beginning");
yield check_autocomplete({
search: katakana[0],
matches: [ { uri: uri8, title: katakana.join("") } ]
});
/*
do_print("Middle of a katakana word shouldn't be matched");
yield check_autocomplete({
search: katakana[1],
matches: [ ]
});
*/
do_print("Ideographs are treated as words so 'nin' is one word");
yield check_autocomplete({
search: ideograph[0],
matches: [ { uri: uri9, title: ideograph.join("") } ]
});
do_print("Ideographs are treated as words so 'ten' is another word");
yield check_autocomplete({
search: ideograph[1],
matches: [ { uri: uri9, title: ideograph.join("") } ]
});
do_print("Ideographs are treated as words so 'do' is yet another word");
yield check_autocomplete({
search: ideograph[2],
matches: [ { uri: uri9, title: ideograph.join("") } ]
});
do_print("Extra negative assert that we don't match in the middle");
yield check_autocomplete({
search: "ch",
matches: [ ]
});
do_print("Don't match one character after a camel-case word boundary (bug 429498)");
yield check_autocomplete({
search: "atch",
matches: [ ]
});
// match against word boundaries and anywhere
Services.prefs.setIntPref("browser.urlbar.matchBehavior", 1);
yield check_autocomplete({
search: "tch",
matches: [ { uri: uri1, title: "title1" },
{ uri: uri2, title: "title1" },
{ uri: uri3, title: "matchme2" },
{ uri: uri4, title: "dontmatchme3" },
{ uri: uri5, title: "title1", tags: [ "matchme2" ], style: [ "bookmark-tag" ] },
{ uri: uri6, title: "title1", tags: [ "dontmatchme3" ], style: [ "bookmark-tag" ] },
{ uri: uri10, title: "title1" } ]
});
yield cleanup();
});
|