michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Test bug 393678 to make sure matches against the url, title, tags are only michael@0: * made on word boundaries instead of in the middle of words. michael@0: * michael@0: * Make sure we don't try matching one after a CamelCase because the upper-case michael@0: * isn't really a word boundary. (bug 429498) michael@0: * michael@0: * Bug 429531 provides switching between "must match on word boundary" and "can michael@0: * match," so leverage "must match" pref for checking word boundary logic and michael@0: * make sure "can match" matches anywhere. michael@0: */ michael@0: michael@0: let katakana = ["\u30a8", "\u30c9"]; // E, Do michael@0: let ideograph = ["\u4efb", "\u5929", "\u5802"]; // Nin Ten Do michael@0: michael@0: // Define some shared uris and titles (each page needs its own uri) michael@0: let kURIs = [ michael@0: "http://matchme/", michael@0: "http://dontmatchme/", michael@0: "http://title/1", michael@0: "http://title/2", michael@0: "http://tag/1", michael@0: "http://tag/2", michael@0: "http://crazytitle/", michael@0: "http://katakana/", michael@0: "http://ideograph/", michael@0: "http://camel/pleaseMatchMe/", michael@0: ]; michael@0: let kTitles = [ michael@0: "title1", michael@0: "matchme2", michael@0: "dontmatchme3", michael@0: "!@#$%^&*()_+{}|:<>?word", michael@0: katakana.join(""), michael@0: ideograph.join(""), michael@0: ]; michael@0: michael@0: // Boundaries on the url michael@0: addPageBook(0, 0); michael@0: addPageBook(1, 0); michael@0: // Boundaries on the title michael@0: addPageBook(2, 1); michael@0: addPageBook(3, 2); michael@0: // Boundaries on the tag michael@0: addPageBook(4, 0, 0, [1]); michael@0: addPageBook(5, 0, 0, [2]); michael@0: // Lots of word boundaries before a word michael@0: addPageBook(6, 3); michael@0: // Katakana michael@0: addPageBook(7, 4); michael@0: // Ideograph michael@0: addPageBook(8, 5); michael@0: // CamelCase michael@0: addPageBook(9, 0); michael@0: michael@0: // Provide for each test: description; search terms; array of gPages indices of michael@0: // pages that should match; optional function to be run before the test michael@0: let gTests = [ michael@0: // Tests after this one will match only on word boundaries michael@0: ["0: Match 'match' at the beginning or after / or on a CamelCase", michael@0: "match", [0,2,4,9], michael@0: function() setBehavior(2)], michael@0: ["1: Match 'dont' at the beginning or after /", michael@0: "dont", [1,3,5]], michael@0: ["2: Match '2' after the slash and after a word (in tags too)", michael@0: "2", [2,3,4,5]], michael@0: ["3: Match 't' at the beginning or after /", michael@0: "t", [0,1,2,3,4,5,9]], michael@0: ["4: Match 'word' after many consecutive word boundaries", michael@0: "word", [6]], michael@0: ["5: Match a word boundary '/' for everything", michael@0: "/", [0,1,2,3,4,5,6,7,8,9]], michael@0: ["6: Match word boundaries '()_+' that are among word boundaries", michael@0: "()_+", [6]], michael@0: michael@0: ["7: Katakana characters form a string, so match the beginning", michael@0: katakana[0], [7]], michael@0: /*["8: Middle of a katakana word shouldn't be matched", michael@0: katakana[1], []],*/ michael@0: michael@0: ["9: Ideographs are treated as words so 'nin' is one word", michael@0: ideograph[0], [8]], michael@0: ["10: Ideographs are treated as words so 'ten' is another word", michael@0: ideograph[1], [8]], michael@0: ["11: Ideographs are treated as words so 'do' is yet another", michael@0: ideograph[2], [8]], michael@0: michael@0: ["12: Extra negative assert that we don't match in the middle", michael@0: "ch", []], michael@0: ["13: Don't match one character after a camel-case word boundary (bug 429498)", michael@0: "atch", []], michael@0: michael@0: // Tests after this one will match against word boundaries and anywhere michael@0: ["14: Match on word boundaries as well as anywhere (bug 429531)", michael@0: "tch", [0,1,2,3,4,5,9], michael@0: function() setBehavior(1)], michael@0: ]; michael@0: michael@0: function setBehavior(aType) { michael@0: prefs.setIntPref("browser.urlbar.matchBehavior", aType); michael@0: }