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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:cc5b486d72c0
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/. */
4
5 /**
6 * Test for bug 392143 that puts keyword results into the autocomplete. Makes
7 * sure that multiple parameter queries get spaces converted to +, + converted
8 * to %2B, non-ascii become escaped, and pages in history that match the
9 * keyword uses the page's title.
10 *
11 * Also test for bug 249468 by making sure multiple keyword bookmarks with the
12 * same keyword appear in the list.
13 */
14
15 // Details for the keyword bookmark
16 let keyBase = "http://abc/?search=";
17 let keyKey = "key";
18
19 // A second keyword bookmark with the same keyword
20 let otherBase = "http://xyz/?foo=";
21
22 let unescaped = "ユニコード";
23 let pageInHistory = "ThisPageIsInHistory";
24
25 // Define some shared uris and titles (each page needs its own uri)
26 let kURIs = [
27 keyBase + "%s",
28 keyBase + "term",
29 keyBase + "multi+word",
30 keyBase + "blocking%2B",
31 keyBase + unescaped,
32 keyBase + pageInHistory,
33 keyBase,
34 otherBase + "%s",
35 keyBase + "twoKey",
36 otherBase + "twoKey"
37 ];
38 let kTitles = [
39 "Generic page title",
40 "Keyword title",
41 ];
42
43 // Add the keyword bookmark
44 addPageBook(0, 0, 1, [], keyKey);
45 // Add in the "fake pages" for keyword searches
46 gPages[1] = [1,1];
47 gPages[2] = [2,1];
48 gPages[3] = [3,1];
49 gPages[4] = [4,1];
50 // Add a page into history
51 addPageBook(5, 0);
52 gPages[6] = [6,1];
53
54 // Provide for each test: description; search terms; array of gPages indices of
55 // pages that should match; optional function to be run before the test
56 let gTests = [
57 ["0: Plain keyword query",
58 keyKey + " term", [1]],
59 ["1: Multi-word keyword query",
60 keyKey + " multi word", [2]],
61 ["2: Keyword query with +",
62 keyKey + " blocking+", [3]],
63 ["3: Unescaped term in query",
64 keyKey + " " + unescaped, [4]],
65 ["4: Keyword that happens to match a page",
66 keyKey + " " + pageInHistory, [5]],
67 ["5: Keyword without query (without space)",
68 keyKey, [6]],
69 ["6: Keyword without query (with space)",
70 keyKey + " ", [6]],
71
72 // This adds a second keyword so anything after this will match 2 keywords
73 ["7: Two keywords matched",
74 keyKey + " twoKey", [8,9],
75 function() {
76 // Add the keyword search as well as search results
77 addPageBook(7, 0, 1, [], keyKey);
78 gPages[8] = [8,1];
79 gPages[9] = [9,1];
80 }]
81 ];

mercurial