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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/autocomplete/test_word_boundary_search.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * Test bug 393678 to make sure matches against the url, title, tags are only
    1.10 + * made on word boundaries instead of in the middle of words.
    1.11 + *
    1.12 + * Make sure we don't try matching one after a CamelCase because the upper-case
    1.13 + * isn't really a word boundary. (bug 429498)
    1.14 + *
    1.15 + * Bug 429531 provides switching between "must match on word boundary" and "can
    1.16 + * match," so leverage "must match" pref for checking word boundary logic and
    1.17 + * make sure "can match" matches anywhere.
    1.18 + */
    1.19 +
    1.20 +let katakana = ["\u30a8", "\u30c9"]; // E, Do
    1.21 +let ideograph = ["\u4efb", "\u5929", "\u5802"]; // Nin Ten Do
    1.22 +
    1.23 +// Define some shared uris and titles (each page needs its own uri)
    1.24 +let kURIs = [
    1.25 +  "http://matchme/",
    1.26 +  "http://dontmatchme/",
    1.27 +  "http://title/1",
    1.28 +  "http://title/2",
    1.29 +  "http://tag/1",
    1.30 +  "http://tag/2",
    1.31 +  "http://crazytitle/",
    1.32 +  "http://katakana/",
    1.33 +  "http://ideograph/",
    1.34 +  "http://camel/pleaseMatchMe/",
    1.35 +];
    1.36 +let kTitles = [
    1.37 +  "title1",
    1.38 +  "matchme2",
    1.39 +  "dontmatchme3",
    1.40 +  "!@#$%^&*()_+{}|:<>?word",
    1.41 +  katakana.join(""),
    1.42 +  ideograph.join(""),
    1.43 +];
    1.44 +
    1.45 +// Boundaries on the url
    1.46 +addPageBook(0, 0);
    1.47 +addPageBook(1, 0);
    1.48 +// Boundaries on the title
    1.49 +addPageBook(2, 1);
    1.50 +addPageBook(3, 2);
    1.51 +// Boundaries on the tag
    1.52 +addPageBook(4, 0, 0, [1]);
    1.53 +addPageBook(5, 0, 0, [2]);
    1.54 +// Lots of word boundaries before a word
    1.55 +addPageBook(6, 3);
    1.56 +// Katakana
    1.57 +addPageBook(7, 4);
    1.58 +// Ideograph
    1.59 +addPageBook(8, 5);
    1.60 +// CamelCase
    1.61 +addPageBook(9, 0);
    1.62 +
    1.63 +// Provide for each test: description; search terms; array of gPages indices of
    1.64 +// pages that should match; optional function to be run before the test
    1.65 +let gTests = [
    1.66 +  // Tests after this one will match only on word boundaries
    1.67 +  ["0: Match 'match' at the beginning or after / or on a CamelCase",
    1.68 +   "match", [0,2,4,9],
    1.69 +   function() setBehavior(2)],
    1.70 +  ["1: Match 'dont' at the beginning or after /",
    1.71 +   "dont", [1,3,5]],
    1.72 +  ["2: Match '2' after the slash and after a word (in tags too)",
    1.73 +   "2", [2,3,4,5]],
    1.74 +  ["3: Match 't' at the beginning or after /",
    1.75 +   "t", [0,1,2,3,4,5,9]],
    1.76 +  ["4: Match 'word' after many consecutive word boundaries",
    1.77 +   "word", [6]],
    1.78 +  ["5: Match a word boundary '/' for everything",
    1.79 +   "/", [0,1,2,3,4,5,6,7,8,9]],
    1.80 +  ["6: Match word boundaries '()_+' that are among word boundaries",
    1.81 +   "()_+", [6]],
    1.82 +
    1.83 +  ["7: Katakana characters form a string, so match the beginning",
    1.84 +   katakana[0], [7]],
    1.85 +  /*["8: Middle of a katakana word shouldn't be matched",
    1.86 +   katakana[1], []],*/
    1.87 +
    1.88 +  ["9: Ideographs are treated as words so 'nin' is one word",
    1.89 +   ideograph[0], [8]],
    1.90 +  ["10: Ideographs are treated as words so 'ten' is another word",
    1.91 +   ideograph[1], [8]],
    1.92 +  ["11: Ideographs are treated as words so 'do' is yet another",
    1.93 +   ideograph[2], [8]],
    1.94 +
    1.95 +  ["12: Extra negative assert that we don't match in the middle",
    1.96 +   "ch", []],
    1.97 +  ["13: Don't match one character after a camel-case word boundary (bug 429498)",
    1.98 +   "atch", []],
    1.99 +
   1.100 +  // Tests after this one will match against word boundaries and anywhere
   1.101 +  ["14: Match on word boundaries as well as anywhere (bug 429531)",
   1.102 +   "tch", [0,1,2,3,4,5,9],
   1.103 +   function() setBehavior(1)],
   1.104 +];
   1.105 +
   1.106 +function setBehavior(aType) {
   1.107 +  prefs.setIntPref("browser.urlbar.matchBehavior", aType);
   1.108 +}

mercurial