Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_input_unittest.cc

Issue 12623029: Upstreaming mechanism to add query refinement to omnibox searches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed ChromeOS. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/autocomplete/autocomplete_input.h" 5 #include "chrome/browser/autocomplete/autocomplete_input.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 { ASCIIToUTF16("filesystem:http:foo"), AutocompleteInput::URL }, 115 { ASCIIToUTF16("filesystem:http:foo"), AutocompleteInput::URL },
116 { ASCIIToUTF16("filesystem:file://"), AutocompleteInput::URL }, 116 { ASCIIToUTF16("filesystem:file://"), AutocompleteInput::URL },
117 { ASCIIToUTF16("filesystem:http"), AutocompleteInput::URL }, 117 { ASCIIToUTF16("filesystem:http"), AutocompleteInput::URL },
118 { ASCIIToUTF16("filesystem:"), AutocompleteInput::URL }, 118 { ASCIIToUTF16("filesystem:"), AutocompleteInput::URL },
119 { ASCIIToUTF16("ftp:"), AutocompleteInput::URL }, 119 { ASCIIToUTF16("ftp:"), AutocompleteInput::URL },
120 }; 120 };
121 121
122 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 122 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
123 SCOPED_TRACE(input_cases[i].input); 123 SCOPED_TRACE(input_cases[i].input);
124 AutocompleteInput input(input_cases[i].input, string16::npos, string16(), 124 AutocompleteInput input(input_cases[i].input, string16::npos, string16(),
125 true, false, true, AutocompleteInput::ALL_MATCHES); 125 GURL(), true, false, true,
126 AutocompleteInput::ALL_MATCHES);
126 EXPECT_EQ(input_cases[i].type, input.type()); 127 EXPECT_EQ(input_cases[i].type, input.type());
127 } 128 }
128 } 129 }
129 130
130 TEST(AutocompleteInputTest, InputTypeWithDesiredTLD) { 131 TEST(AutocompleteInputTest, InputTypeWithDesiredTLD) {
131 struct test_data { 132 struct test_data {
132 const string16 input; 133 const string16 input;
133 const AutocompleteInput::Type type; 134 const AutocompleteInput::Type type;
134 const std::string spec; // Unused if not a URL. 135 const std::string spec; // Unused if not a URL.
135 } input_cases[] = { 136 } input_cases[] = {
136 { ASCIIToUTF16("401k"), AutocompleteInput::URL, 137 { ASCIIToUTF16("401k"), AutocompleteInput::URL,
137 std::string("http://www.401k.com/") }, 138 std::string("http://www.401k.com/") },
138 { ASCIIToUTF16("999999999999999"), AutocompleteInput::URL, 139 { ASCIIToUTF16("999999999999999"), AutocompleteInput::URL,
139 std::string("http://www.999999999999999.com/") }, 140 std::string("http://www.999999999999999.com/") },
140 { ASCIIToUTF16("x@y"), AutocompleteInput::URL, 141 { ASCIIToUTF16("x@y"), AutocompleteInput::URL,
141 std::string("http://x@www.y.com/") }, 142 std::string("http://x@www.y.com/") },
142 { ASCIIToUTF16("y/z z"), AutocompleteInput::URL, 143 { ASCIIToUTF16("y/z z"), AutocompleteInput::URL,
143 std::string("http://www.y.com/z%20z") }, 144 std::string("http://www.y.com/z%20z") },
144 { ASCIIToUTF16("abc.com"), AutocompleteInput::URL, 145 { ASCIIToUTF16("abc.com"), AutocompleteInput::URL,
145 std::string("http://abc.com/") }, 146 std::string("http://abc.com/") },
146 { ASCIIToUTF16("foo bar"), AutocompleteInput::QUERY, std::string() }, 147 { ASCIIToUTF16("foo bar"), AutocompleteInput::QUERY, std::string() },
147 }; 148 };
148 149
149 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
150 SCOPED_TRACE(input_cases[i].input); 151 SCOPED_TRACE(input_cases[i].input);
151 AutocompleteInput input(input_cases[i].input, string16::npos, 152 AutocompleteInput input(input_cases[i].input, string16::npos,
152 ASCIIToUTF16("com"), true, false, true, 153 ASCIIToUTF16("com"), GURL(), true, false, true,
153 AutocompleteInput::ALL_MATCHES); 154 AutocompleteInput::ALL_MATCHES);
154 EXPECT_EQ(input_cases[i].type, input.type()); 155 EXPECT_EQ(input_cases[i].type, input.type());
155 if (input_cases[i].type == AutocompleteInput::URL) 156 if (input_cases[i].type == AutocompleteInput::URL)
156 EXPECT_EQ(input_cases[i].spec, input.canonicalized_url().spec()); 157 EXPECT_EQ(input_cases[i].spec, input.canonicalized_url().spec());
157 } 158 }
158 } 159 }
159 160
160 // This tests for a regression where certain input in the omnibox caused us to 161 // This tests for a regression where certain input in the omnibox caused us to
161 // crash. As long as the test completes without crashing, we're fine. 162 // crash. As long as the test completes without crashing, we're fine.
162 TEST(AutocompleteInputTest, InputCrash) { 163 TEST(AutocompleteInputTest, InputCrash) {
163 AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16::npos, string16(), 164 AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16::npos, string16(),
164 true, false, true, AutocompleteInput::ALL_MATCHES); 165 GURL(), true, false, true,
166 AutocompleteInput::ALL_MATCHES);
165 } 167 }
166 168
167 TEST(AutocompleteInputTest, ParseForEmphasizeComponent) { 169 TEST(AutocompleteInputTest, ParseForEmphasizeComponent) {
168 using url_parse::Component; 170 using url_parse::Component;
169 Component kInvalidComponent(0, -1); 171 Component kInvalidComponent(0, -1);
170 struct test_data { 172 struct test_data {
171 const string16 input; 173 const string16 input;
172 const Component scheme; 174 const Component scheme;
173 const Component host; 175 const Component host;
174 } input_cases[] = { 176 } input_cases[] = {
(...skipping 21 matching lines...) Expand all
196 Component(12, 11), kInvalidComponent } 198 Component(12, 11), kInvalidComponent }
197 }; 199 };
198 200
199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 201 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
200 SCOPED_TRACE(input_cases[i].input); 202 SCOPED_TRACE(input_cases[i].input);
201 Component scheme, host; 203 Component scheme, host;
202 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, 204 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input,
203 &scheme, 205 &scheme,
204 &host); 206 &host);
205 AutocompleteInput input(input_cases[i].input, string16::npos, string16(), 207 AutocompleteInput input(input_cases[i].input, string16::npos, string16(),
206 true, false, true, AutocompleteInput::ALL_MATCHES); 208 GURL(), true, false, true,
209 AutocompleteInput::ALL_MATCHES);
207 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); 210 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin);
208 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); 211 EXPECT_EQ(input_cases[i].scheme.len, scheme.len);
209 EXPECT_EQ(input_cases[i].host.begin, host.begin); 212 EXPECT_EQ(input_cases[i].host.begin, host.begin);
210 EXPECT_EQ(input_cases[i].host.len, host.len); 213 EXPECT_EQ(input_cases[i].host.len, host.len);
211 } 214 }
212 } 215 }
213 216
214 TEST(AutocompleteInputTest, InputTypeWithCursorPosition) { 217 TEST(AutocompleteInputTest, InputTypeWithCursorPosition) {
215 struct test_data { 218 struct test_data {
216 const string16 input; 219 const string16 input;
(...skipping 16 matching lines...) Expand all
233 { ASCIIToUTF16("?foo bar"), 2, ASCIIToUTF16("foo bar"), 1 }, 236 { ASCIIToUTF16("?foo bar"), 2, ASCIIToUTF16("foo bar"), 1 },
234 { ASCIIToUTF16(" ?foo bar"), 4, ASCIIToUTF16("foo bar"), 1 }, 237 { ASCIIToUTF16(" ?foo bar"), 4, ASCIIToUTF16("foo bar"), 1 },
235 { ASCIIToUTF16("? foo bar"), 4, ASCIIToUTF16("foo bar"), 1 }, 238 { ASCIIToUTF16("? foo bar"), 4, ASCIIToUTF16("foo bar"), 1 },
236 { ASCIIToUTF16(" ? foo bar"), 6, ASCIIToUTF16("foo bar"), 1 }, 239 { ASCIIToUTF16(" ? foo bar"), 6, ASCIIToUTF16("foo bar"), 1 },
237 }; 240 };
238 241
239 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 242 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
240 SCOPED_TRACE(input_cases[i].input); 243 SCOPED_TRACE(input_cases[i].input);
241 AutocompleteInput input(input_cases[i].input, 244 AutocompleteInput input(input_cases[i].input,
242 input_cases[i].cursor_position, 245 input_cases[i].cursor_position,
243 string16(), true, false, true, 246 string16(), GURL(), true, false, true,
244 AutocompleteInput::ALL_MATCHES); 247 AutocompleteInput::ALL_MATCHES);
245 EXPECT_EQ(input_cases[i].normalized_input, input.text()); 248 EXPECT_EQ(input_cases[i].normalized_input, input.text());
246 EXPECT_EQ(input_cases[i].normalized_cursor_position, 249 EXPECT_EQ(input_cases[i].normalized_cursor_position,
247 input.cursor_position()); 250 input.cursor_position());
248 } 251 }
249 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698