toolkit/components/places/tests/autocomplete/test_keyword_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_keyword_search.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     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 for bug 392143 that puts keyword results into the autocomplete. Makes
    1.10 + * sure that multiple parameter queries get spaces converted to +, + converted
    1.11 + * to %2B, non-ascii become escaped, and pages in history that match the
    1.12 + * keyword uses the page's title.
    1.13 + *
    1.14 + * Also test for bug 249468 by making sure multiple keyword bookmarks with the
    1.15 + * same keyword appear in the list.
    1.16 + */
    1.17 +
    1.18 +// Details for the keyword bookmark
    1.19 +let keyBase = "http://abc/?search=";
    1.20 +let keyKey = "key";
    1.21 +
    1.22 +// A second keyword bookmark with the same keyword
    1.23 +let otherBase = "http://xyz/?foo=";
    1.24 +
    1.25 +let unescaped = "ユニコード";
    1.26 +let pageInHistory = "ThisPageIsInHistory";
    1.27 +
    1.28 +// Define some shared uris and titles (each page needs its own uri)
    1.29 +let kURIs = [
    1.30 +  keyBase + "%s",
    1.31 +  keyBase + "term",
    1.32 +  keyBase + "multi+word",
    1.33 +  keyBase + "blocking%2B",
    1.34 +  keyBase + unescaped,
    1.35 +  keyBase + pageInHistory,
    1.36 +  keyBase,
    1.37 +  otherBase + "%s",
    1.38 +  keyBase + "twoKey",
    1.39 +  otherBase + "twoKey"
    1.40 +];
    1.41 +let kTitles = [
    1.42 +  "Generic page title",
    1.43 +  "Keyword title",
    1.44 +];
    1.45 +
    1.46 +// Add the keyword bookmark
    1.47 +addPageBook(0, 0, 1, [], keyKey);
    1.48 +// Add in the "fake pages" for keyword searches
    1.49 +gPages[1] = [1,1];
    1.50 +gPages[2] = [2,1];
    1.51 +gPages[3] = [3,1];
    1.52 +gPages[4] = [4,1];
    1.53 +// Add a page into history
    1.54 +addPageBook(5, 0);
    1.55 +gPages[6] = [6,1];
    1.56 +
    1.57 +// Provide for each test: description; search terms; array of gPages indices of
    1.58 +// pages that should match; optional function to be run before the test
    1.59 +let gTests = [
    1.60 +  ["0: Plain keyword query",
    1.61 +   keyKey + " term", [1]],
    1.62 +  ["1: Multi-word keyword query",
    1.63 +   keyKey + " multi word", [2]],
    1.64 +  ["2: Keyword query with +",
    1.65 +   keyKey + " blocking+", [3]],
    1.66 +  ["3: Unescaped term in query",
    1.67 +   keyKey + " " + unescaped, [4]],
    1.68 +  ["4: Keyword that happens to match a page",
    1.69 +   keyKey + " " + pageInHistory, [5]],
    1.70 +  ["5: Keyword without query (without space)",
    1.71 +   keyKey, [6]],
    1.72 +  ["6: Keyword without query (with space)",
    1.73 +   keyKey + " ", [6]],
    1.74 +
    1.75 +  // This adds a second keyword so anything after this will match 2 keywords
    1.76 +  ["7: Two keywords matched",
    1.77 +   keyKey + " twoKey", [8,9],
    1.78 +   function() {
    1.79 +     // Add the keyword search as well as search results
    1.80 +     addPageBook(7, 0, 1, [], keyKey);
    1.81 +     gPages[8] = [8,1];
    1.82 +     gPages[9] = [9,1];
    1.83 +   }]
    1.84 +];

mercurial