Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/autocomplete/autocomplete_match.h" | 7 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 8 #include "chrome/browser/autocomplete/keyword_provider.h" | 8 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(KeywordProviderTest, Edit) { | 83 TEST_F(KeywordProviderTest, Edit) { |
| 84 test_data<string16> edit_cases[] = { | 84 test_data<string16> edit_cases[] = { |
| 85 // Searching for a nonexistent prefix should give nothing. | 85 // Searching for a nonexistent prefix should give nothing. |
| 86 {ASCIIToUTF16("Not Found"), 0, {}}, | 86 {ASCIIToUTF16("Not Found"), 0, {}}, |
| 87 {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, | 87 {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, |
| 88 | 88 |
| 89 // Check that tokenization only collapses whitespace between first tokens, | 89 // Check that tokenization only collapses whitespace between first tokens, |
| 90 // no-query-input cases have a space appended, and action is not escaped. | 90 // no-query-input cases have a space appended, and action is not escaped. |
| 91 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("z foo")}}, | |
| 92 {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("z ")}}, | 91 {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("z ")}}, |
| 93 {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("z ")}}, | 92 {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("z ")}}, |
| 94 {ASCIIToUTF16("z a b c++"), 1, {ASCIIToUTF16("z a b c++")}}, | 93 |
| 94 // Check that exact, substituting keywords with a verbatim search term | |
| 95 // don't generate a result. (These are handled by SearchProvider.) | |
| 96 {ASCIIToUTF16("z foo"), 0, {}}, | |
| 97 {ASCIIToUTF16("z a b c++"), 0, {}}, | |
| 95 | 98 |
| 96 // Matches should be limited to three, and sorted in quality order, not | 99 // Matches should be limited to three, and sorted in quality order, not |
| 97 // alphabetical. | 100 // alphabetical. |
| 98 {ASCIIToUTF16("aaa"), 2, {ASCIIToUTF16("aaaa "), | 101 {ASCIIToUTF16("aaa"), 2, {ASCIIToUTF16("aaaa "), |
| 99 ASCIIToUTF16("aaaaa ")}}, | 102 ASCIIToUTF16("aaaaa ")}}, |
| 100 {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("aa 1 2 3"), | 103 {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("aa 1 2 3"), |
| 101 ASCIIToUTF16("ab 1 2 3"), | 104 ASCIIToUTF16("ab 1 2 3"), |
| 102 ASCIIToUTF16("aaaa 1 2 3")}}, | 105 ASCIIToUTF16("aaaa 1 2 3")}}, |
| 103 {ASCIIToUTF16("www.a"), 3, {ASCIIToUTF16("aa "), | 106 {ASCIIToUTF16("www.a"), 3, {ASCIIToUTF16("aa "), |
| 104 ASCIIToUTF16("ab "), | 107 ASCIIToUTF16("ab "), |
| 105 ASCIIToUTF16("aaaa ")}}, | 108 ASCIIToUTF16("aaaa ")}}, |
| 106 // Exact matches should prevent returning inexact matches. | 109 // Exact matches should prevent returning inexact matches. |
|
msw
2013/01/31 00:38:16
nit: add a comment about the verbatim match suppre
Mark P
2013/01/31 23:09:27
Done.
| |
| 107 {ASCIIToUTF16("aaaa foo"), 1, {ASCIIToUTF16("aaaa foo")}}, | 110 {ASCIIToUTF16("aaaa foo"), 0, {}}, |
| 108 {ASCIIToUTF16("www.aaaa foo"), 1, {ASCIIToUTF16("aaaa foo")}}, | 111 {ASCIIToUTF16("www.aaaa foo"), 0, {}}, |
| 109 | 112 |
| 110 // Clean up keyword input properly. "http" and "https" are the only | 113 // Clean up keyword input properly. "http" and "https" are the only |
| 111 // allowed schemes. | 114 // allowed schemes. |
| 112 {ASCIIToUTF16("www"), 1, {ASCIIToUTF16("www ")}}, | 115 {ASCIIToUTF16("www"), 1, {ASCIIToUTF16("www ")}}, |
| 113 {ASCIIToUTF16("www."), 0, {}}, | 116 {ASCIIToUTF16("www."), 0, {}}, |
| 114 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("www w"), | 117 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("www w"), |
| 115 ASCIIToUTF16("weasel w")}}, | 118 ASCIIToUTF16("weasel w")}}, |
| 116 {ASCIIToUTF16("http://www"), 1, {ASCIIToUTF16("www ")}}, | 119 {ASCIIToUTF16("http://www"), 1, {ASCIIToUTF16("www ")}}, |
| 117 {ASCIIToUTF16("http://www."), 0, {}}, | 120 {ASCIIToUTF16("http://www."), 0, {}}, |
| 118 {ASCIIToUTF16("ftp: blah"), 0, {}}, | 121 {ASCIIToUTF16("ftp: blah"), 0, {}}, |
| 119 {ASCIIToUTF16("mailto:z"), 0, {}}, | 122 {ASCIIToUTF16("mailto:z"), 0, {}}, |
| 120 {ASCIIToUTF16("ftp://z"), 0, {}}, | 123 {ASCIIToUTF16("ftp://z"), 0, {}}, |
| 121 {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}}, | 124 {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}}, |
| 122 }; | 125 }; |
| 123 | 126 |
| 124 RunTest<string16>(edit_cases, arraysize(edit_cases), | 127 RunTest<string16>(edit_cases, arraysize(edit_cases), |
| 125 &AutocompleteMatch::fill_into_edit); | 128 &AutocompleteMatch::fill_into_edit); |
| 126 } | 129 } |
| 127 | 130 |
| 128 TEST_F(KeywordProviderTest, URL) { | 131 TEST_F(KeywordProviderTest, URL) { |
| 129 test_data<GURL> url_cases[] = { | 132 test_data<GURL> url_cases[] = { |
| 130 // No query input -> empty destination URL. | 133 // No query input -> empty destination URL. |
| 131 {ASCIIToUTF16("z"), 1, {GURL()}}, | 134 {ASCIIToUTF16("z"), 1, {GURL()}}, |
| 132 {ASCIIToUTF16("z \t"), 1, {GURL()}}, | 135 {ASCIIToUTF16("z \t"), 1, {GURL()}}, |
| 133 | 136 |
| 134 // Check that tokenization only collapses whitespace between first tokens | 137 // Check that tokenization only collapses whitespace between first tokens |
| 135 // and query input, but not rest of URL, is escaped. | 138 // and query input, but not rest of URL, is escaped. |
| 136 {ASCIIToUTF16("z a b c++"), 1, {GURL("a+++b+++c%2B%2B=z")}}, | 139 {ASCIIToUTF16("w bar +baz"), 2, {GURL(" +%2B?=bar+%2Bbazfoo "), |
| 137 {ASCIIToUTF16("www.www www"), 1, {GURL(" +%2B?=wwwfoo ")}}, | 140 GURL("bar+%2Bbaz=z")}}, |
| 138 | 141 |
| 139 // Substitution should work with various locations of the "%s". | 142 // Substitution should work with various locations of the "%s". |
| 140 {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), | 143 {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), |
| 141 GURL("1a2b")}}, | 144 GURL("1a2b")}}, |
| 142 {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"), | 145 {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"), |
| 143 GURL("bogus URL 1+2+3"), | 146 GURL("bogus URL 1+2+3"), |
| 144 GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, | 147 GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, |
| 145 {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "), | 148 {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "), |
| 146 GURL("weaselwweasel")}}, | 149 GURL("weaselwweasel")}}, |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 RunTest<GURL>(url_cases, arraysize(url_cases), | 152 RunTest<GURL>(url_cases, arraysize(url_cases), |
| 150 &AutocompleteMatch::destination_url); | 153 &AutocompleteMatch::destination_url); |
| 151 } | 154 } |
| 152 | 155 |
| 153 TEST_F(KeywordProviderTest, Contents) { | 156 TEST_F(KeywordProviderTest, Contents) { |
| 154 test_data<string16> contents_cases[] = { | 157 test_data<string16> contents_cases[] = { |
| 155 // No query input -> substitute "<enter query>" into contents. | 158 // No query input -> substitute "<enter query>" into contents. |
| 156 {ASCIIToUTF16("z"), 1, | 159 {ASCIIToUTF16("z"), 1, |
| 157 {ASCIIToUTF16("Search z for <enter query>")}}, | 160 {ASCIIToUTF16("Search z for <enter query>")}}, |
| 158 {ASCIIToUTF16("z \t"), 1, | 161 {ASCIIToUTF16("z \t"), 1, |
| 159 {ASCIIToUTF16("Search z for <enter query>")}}, | 162 {ASCIIToUTF16("Search z for <enter query>")}}, |
| 160 | 163 |
| 161 // Check that tokenization only collapses whitespace between first tokens | 164 // Exact keyword matches with remaining text should return nothing. |
| 162 // and contents are not escaped or unescaped. | 165 {ASCIIToUTF16("www.www www"), 0, {}}, |
| 163 {ASCIIToUTF16("z a b c++"), 1, | 166 {ASCIIToUTF16("z a b c++"), 0, {}}, |
| 164 {ASCIIToUTF16("Search z for a b c++")}}, | 167 |
| 165 {ASCIIToUTF16("www.www www"), 1, {ASCIIToUTF16("Search www for www")}}, | 168 // Exact keyword matches with remaining text when the keyword is an |
| 169 // extension keyword should return something. This is tested in | |
| 170 // chrome/browser/extensions/api/omnibox/omnibox_apitest.cc's | |
| 171 // in OmniboxApiTest's Basic test. | |
| 166 | 172 |
| 167 // Substitution should work with various locations of the "%s". | 173 // Substitution should work with various locations of the "%s". |
| 168 {ASCIIToUTF16("aaa"), 2, | 174 {ASCIIToUTF16("aaa"), 2, |
| 169 {ASCIIToUTF16("Search aaaa for <enter query>"), | 175 {ASCIIToUTF16("Search aaaa for <enter query>"), |
| 170 ASCIIToUTF16("Search aaaaa for <enter query>")}}, | 176 ASCIIToUTF16("Search aaaaa for <enter query>")}}, |
| 171 {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("Search aa for 1 2 3"), | |
| 172 ASCIIToUTF16("Search ab for 1 2 3"), | |
| 173 ASCIIToUTF16("Search aaaa for 1 2 3")}}, | |
| 174 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("Search www for w"), | 177 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("Search www for w"), |
| 175 ASCIIToUTF16("Search weasel for w")}}, | 178 ASCIIToUTF16("Search weasel for w")}}, |
| 179 // Also, check that tokenization only collapses whitespace between first | |
| 180 // tokens and contents are not escaped or unescaped. | |
| 181 {ASCIIToUTF16("a 1 2+ 3"), 3, {ASCIIToUTF16("Search aa for 1 2+ 3"), | |
|
msw
2013/01/31 00:38:16
optional nit: wrap this and the case above like th
Mark P
2013/01/31 23:09:27
Done.
| |
| 182 ASCIIToUTF16("Search ab for 1 2+ 3"), | |
| 183 ASCIIToUTF16("Search aaaa for 1 2+ 3")}}, | |
| 176 }; | 184 }; |
| 177 | 185 |
| 178 RunTest<string16>(contents_cases, arraysize(contents_cases), | 186 RunTest<string16>(contents_cases, arraysize(contents_cases), |
| 179 &AutocompleteMatch::contents); | 187 &AutocompleteMatch::contents); |
| 180 } | 188 } |
| 181 | 189 |
| 182 TEST_F(KeywordProviderTest, DISABLED_Description) { | 190 TEST_F(KeywordProviderTest, DISABLED_Description) { |
| 183 test_data<string16> description_cases[] = { | 191 test_data<string16> description_cases[] = { |
| 184 // Whole keyword should be returned for both exact and inexact matches. | 192 // Whole keyword should be returned for both exact and inexact matches. |
| 185 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("(Keyword: z)")}}, | 193 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("(Keyword: z)")}}, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 } | 225 } |
| 218 | 226 |
| 219 TEST_F(KeywordProviderTest, GetKeywordForInput) { | 227 TEST_F(KeywordProviderTest, GetKeywordForInput) { |
| 220 EXPECT_EQ(ASCIIToUTF16("aa"), | 228 EXPECT_EQ(ASCIIToUTF16("aa"), |
| 221 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); | 229 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); |
| 222 EXPECT_EQ(string16(), | 230 EXPECT_EQ(string16(), |
| 223 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); | 231 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); |
| 224 EXPECT_EQ(string16(), | 232 EXPECT_EQ(string16(), |
| 225 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); | 233 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); |
| 226 } | 234 } |
| OLD | NEW |