toolkit/components/places/tests/autocomplete/test_word_boundary_search.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial