Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
5 /**
6 * Test bug 393678 to make sure matches against the url, title, tags are only
7 * made on word boundaries instead of in the middle of words.
8 *
9 * Make sure we don't try matching one after a CamelCase because the upper-case
10 * isn't really a word boundary. (bug 429498)
11 *
12 * Bug 429531 provides switching between "must match on word boundary" and "can
13 * match," so leverage "must match" pref for checking word boundary logic and
14 * make sure "can match" matches anywhere.
15 */
17 let katakana = ["\u30a8", "\u30c9"]; // E, Do
18 let ideograph = ["\u4efb", "\u5929", "\u5802"]; // Nin Ten Do
20 // Define some shared uris and titles (each page needs its own uri)
21 let kURIs = [
22 "http://matchme/",
23 "http://dontmatchme/",
24 "http://title/1",
25 "http://title/2",
26 "http://tag/1",
27 "http://tag/2",
28 "http://crazytitle/",
29 "http://katakana/",
30 "http://ideograph/",
31 "http://camel/pleaseMatchMe/",
32 ];
33 let kTitles = [
34 "title1",
35 "matchme2",
36 "dontmatchme3",
37 "!@#$%^&*()_+{}|:<>?word",
38 katakana.join(""),
39 ideograph.join(""),
40 ];
42 // Boundaries on the url
43 addPageBook(0, 0);
44 addPageBook(1, 0);
45 // Boundaries on the title
46 addPageBook(2, 1);
47 addPageBook(3, 2);
48 // Boundaries on the tag
49 addPageBook(4, 0, 0, [1]);
50 addPageBook(5, 0, 0, [2]);
51 // Lots of word boundaries before a word
52 addPageBook(6, 3);
53 // Katakana
54 addPageBook(7, 4);
55 // Ideograph
56 addPageBook(8, 5);
57 // CamelCase
58 addPageBook(9, 0);
60 // Provide for each test: description; search terms; array of gPages indices of
61 // pages that should match; optional function to be run before the test
62 let gTests = [
63 // Tests after this one will match only on word boundaries
64 ["0: Match 'match' at the beginning or after / or on a CamelCase",
65 "match", [0,2,4,9],
66 function() setBehavior(2)],
67 ["1: Match 'dont' at the beginning or after /",
68 "dont", [1,3,5]],
69 ["2: Match '2' after the slash and after a word (in tags too)",
70 "2", [2,3,4,5]],
71 ["3: Match 't' at the beginning or after /",
72 "t", [0,1,2,3,4,5,9]],
73 ["4: Match 'word' after many consecutive word boundaries",
74 "word", [6]],
75 ["5: Match a word boundary '/' for everything",
76 "/", [0,1,2,3,4,5,6,7,8,9]],
77 ["6: Match word boundaries '()_+' that are among word boundaries",
78 "()_+", [6]],
80 ["7: Katakana characters form a string, so match the beginning",
81 katakana[0], [7]],
82 /*["8: Middle of a katakana word shouldn't be matched",
83 katakana[1], []],*/
85 ["9: Ideographs are treated as words so 'nin' is one word",
86 ideograph[0], [8]],
87 ["10: Ideographs are treated as words so 'ten' is another word",
88 ideograph[1], [8]],
89 ["11: Ideographs are treated as words so 'do' is yet another",
90 ideograph[2], [8]],
92 ["12: Extra negative assert that we don't match in the middle",
93 "ch", []],
94 ["13: Don't match one character after a camel-case word boundary (bug 429498)",
95 "atch", []],
97 // Tests after this one will match against word boundaries and anywhere
98 ["14: Match on word boundaries as well as anywhere (bug 429531)",
99 "tch", [0,1,2,3,4,5,9],
100 function() setBehavior(1)],
101 ];
103 function setBehavior(aType) {
104 prefs.setIntPref("browser.urlbar.matchBehavior", aType);
105 }