summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unifiedcomplete/test_keyword_search_actions.js
blob: 61d98f72d6a62e05a656e3974a8823b829f20156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Test for bug 392143 that puts keyword results into the autocomplete. Makes
 * sure that multiple parameter queries get spaces converted to +, + converted
 * to %2B, non-ascii become escaped, and pages in history that match the
 * keyword uses the page's title.
 *
 * Also test for bug 249468 by making sure multiple keyword bookmarks with the
 * same keyword appear in the list.
 */

add_task(function* test_keyword_search() {
  let uri1 = NetUtil.newURI("http://abc/?search=%s");
  let uri2 = NetUtil.newURI("http://abc/?search=ThisPageIsInHistory");
  let uri3 = NetUtil.newURI("http://abc/?search=%s&raw=%S");
  let uri4 = NetUtil.newURI("http://abc/?search=%s&raw=%S&mozcharset=ISO-8859-1");
  yield PlacesTestUtils.addVisits([{ uri: uri1 },
                                   { uri: uri2 },
                                   { uri: uri3 }]);
  yield addBookmark({ uri: uri1, title: "Keyword", keyword: "key"});
  yield addBookmark({ uri: uri1, title: "Post", keyword: "post", postData: "post_search=%s"});
  yield addBookmark({ uri: uri3, title: "Encoded", keyword: "encoded"});
  yield addBookmark({ uri: uri4, title: "Charset", keyword: "charset"});
  yield addBookmark({ uri: uri2, title: "Noparam", keyword: "noparam"});
  yield addBookmark({ uri: uri2, title: "Noparam-Post", keyword: "post_noparam", postData: "noparam=1"});

  do_print("Plain keyword query");
  yield check_autocomplete({
    search: "key term",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=term", input: "key term"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Plain keyword UC");
  yield check_autocomplete({
    search: "key TERM",
    matches: [ { uri: NetUtil.newURI("http://abc/?search=TERM"),
                 title: "abc", style: ["keyword", "heuristic"] } ]
  });

  do_print("Multi-word keyword query");
  yield check_autocomplete({
    search: "key multi word",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=multi%20word", input: "key multi word"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Keyword query with +");
  yield check_autocomplete({
    search: "key blocking+",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=blocking%2B", input: "key blocking+"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Unescaped term in query");
  // ... but note that UnifiedComplete calls encodeURIComponent() on the query
  // string when it builds the URL, so the expected result will have the
  // ユニコード substring encoded in the URL.
  yield check_autocomplete({
    search: "key ユニコード",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=" + encodeURIComponent("ユニコード"), input: "key ユニコード"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Keyword that happens to match a page");
  yield check_autocomplete({
    search: "key ThisPageIsInHistory",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=ThisPageIsInHistory", input: "key ThisPageIsInHistory"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Keyword without query (without space)");
  yield check_autocomplete({
    search: "key",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=", input: "key"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Keyword without query (with space)");
  yield check_autocomplete({
    search: "key ",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=", input: "key "}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("POST Keyword");
  yield check_autocomplete({
    search: "post foo",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=foo", input: "post foo", postData: "post_search=foo"}),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Bug 420328: no-param keyword with a param");
  yield check_autocomplete({
    search: "noparam foo",
    searchParam: "enable-actions",
    matches: [ makeSearchMatch("noparam foo", { heuristic: true }) ]
  });
  yield check_autocomplete({
    search: "post_noparam foo",
    searchParam: "enable-actions",
    matches: [ makeSearchMatch("post_noparam foo", { heuristic: true }) ]
  });

  do_print("escaping with default UTF-8 charset");
  yield check_autocomplete({
    search: "encoded foé",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=fo%C3%A9&raw=foé", input: "encoded foé" }),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("escaping with forced ISO-8859-1 charset");
  yield check_autocomplete({
    search: "charset foé",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=fo%E9&raw=foé", input: "charset foé" }),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Bug 359809: escaping +, / and @ with default UTF-8 charset");
  yield check_autocomplete({
    search: "encoded +/@",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=%2B%2F%40&raw=+/@", input: "encoded +/@" }),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  do_print("Bug 359809: escaping +, / and @ with forced ISO-8859-1 charset");
  yield check_autocomplete({
    search: "charset +/@",
    searchParam: "enable-actions",
    matches: [ { uri: makeActionURI("keyword", {url: "http://abc/?search=%2B%2F%40&raw=+/@", input: "charset +/@" }),
                 title: "abc", style: [ "action", "keyword", "heuristic" ] } ]
  });

  yield cleanup();
});