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

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

Issue 353223002: Omnibox: Fix URL-What-You-Typed Allowed-To-Be-Default-Match Issues (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix crashes on about: schemes Created 6 years, 5 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/history_quick_provider.h" 5 #include "chrome/browser/autocomplete/history_quick_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Runs an autocomplete query on |text| and checks to see that the returned 151 // Runs an autocomplete query on |text| and checks to see that the returned
152 // results' destination URLs match those provided. |expected_urls| does not 152 // results' destination URLs match those provided. |expected_urls| does not
153 // need to be in sorted order. 153 // need to be in sorted order.
154 void RunTest(const base::string16 text, 154 void RunTest(const base::string16 text,
155 bool prevent_inline_autocomplete, 155 bool prevent_inline_autocomplete,
156 std::vector<std::string> expected_urls, 156 std::vector<std::string> expected_urls,
157 bool can_inline_top_result, 157 bool can_inline_top_result,
158 base::string16 expected_fill_into_edit, 158 base::string16 expected_fill_into_edit,
159 base::string16 autocompletion); 159 base::string16 autocompletion);
160 160
161 // As above, simply with a cursor position specified.
162 void RunTestWithCursor(const base::string16 text,
163 const size_t cursor_position,
164 bool prevent_inline_autocomplete,
165 std::vector<std::string> expected_urls,
166 bool can_inline_top_result,
167 base::string16 expected_fill_into_edit,
168 base::string16 autocompletion);
169
161 history::HistoryBackend* history_backend() { 170 history::HistoryBackend* history_backend() {
162 return history_service_->history_backend_; 171 return history_service_->history_backend_;
163 } 172 }
164 173
165 base::MessageLoopForUI message_loop_; 174 base::MessageLoopForUI message_loop_;
166 content::TestBrowserThread ui_thread_; 175 content::TestBrowserThread ui_thread_;
167 content::TestBrowserThread file_thread_; 176 content::TestBrowserThread file_thread_;
168 177
169 scoped_ptr<TestingProfile> profile_; 178 scoped_ptr<TestingProfile> profile_;
170 HistoryService* history_service_; 179 HistoryService* history_service_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 iter != matched_urls.end(); ++iter) 263 iter != matched_urls.end(); ++iter)
255 matches_.insert(iter->destination_url.spec()); 264 matches_.insert(iter->destination_url.spec());
256 } 265 }
257 266
258 void HistoryQuickProviderTest::SetShouldContain::operator()( 267 void HistoryQuickProviderTest::SetShouldContain::operator()(
259 const std::string& expected) { 268 const std::string& expected) {
260 EXPECT_EQ(1U, matches_.erase(expected)) 269 EXPECT_EQ(1U, matches_.erase(expected))
261 << "Results did not contain '" << expected << "' but should have."; 270 << "Results did not contain '" << expected << "' but should have.";
262 } 271 }
263 272
273 void HistoryQuickProviderTest::RunTest(
274 const base::string16 text,
275 bool prevent_inline_autocomplete,
276 std::vector<std::string> expected_urls,
277 bool can_inline_top_result,
278 base::string16 expected_fill_into_edit,
279 base::string16 expected_autocompletion) {
280 RunTestWithCursor(text, base::string16::npos, prevent_inline_autocomplete,
281 expected_urls, can_inline_top_result,
282 expected_fill_into_edit, expected_autocompletion);
283 }
264 284
265 void HistoryQuickProviderTest::RunTest(const base::string16 text, 285 void HistoryQuickProviderTest::RunTestWithCursor(
266 bool prevent_inline_autocomplete, 286 const base::string16 text,
267 std::vector<std::string> expected_urls, 287 const size_t cursor_position,
268 bool can_inline_top_result, 288 bool prevent_inline_autocomplete,
269 base::string16 expected_fill_into_edit, 289 std::vector<std::string> expected_urls,
270 base::string16 expected_autocompletion) { 290 bool can_inline_top_result,
291 base::string16 expected_fill_into_edit,
292 base::string16 expected_autocompletion) {
271 SCOPED_TRACE(text); // Minimal hint to query being run. 293 SCOPED_TRACE(text); // Minimal hint to query being run.
272 base::MessageLoop::current()->RunUntilIdle(); 294 base::MessageLoop::current()->RunUntilIdle();
273 AutocompleteInput input(text, base::string16::npos, base::string16(), 295 AutocompleteInput input(text, cursor_position, base::string16(),
274 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, 296 GURL(), metrics::OmniboxEventProto::INVALID_SPEC,
275 prevent_inline_autocomplete, false, true, true, 297 prevent_inline_autocomplete, false, true, true,
276 ChromeAutocompleteSchemeClassifier(profile_.get())); 298 ChromeAutocompleteSchemeClassifier(profile_.get()));
277 provider_->Start(input, false); 299 provider_->Start(input, false);
278 EXPECT_TRUE(provider_->done()); 300 EXPECT_TRUE(provider_->done());
279 301
280 ac_matches_ = provider_->matches(); 302 ac_matches_ = provider_->matches();
281 303
282 // We should have gotten back at most AutocompleteProvider::kMaxMatches. 304 // We should have gotten back at most AutocompleteProvider::kMaxMatches.
283 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 305 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 343 }
322 344
323 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 345 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
324 std::vector<std::string> expected_urls; 346 std::vector<std::string> expected_urls;
325 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 347 expected_urls.push_back("http://slashdot.org/favorite_page.html");
326 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, 348 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
327 ASCIIToUTF16("slashdot.org/favorite_page.html"), 349 ASCIIToUTF16("slashdot.org/favorite_page.html"),
328 ASCIIToUTF16(".org/favorite_page.html")); 350 ASCIIToUTF16(".org/favorite_page.html"));
329 } 351 }
330 352
353 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) {
354 std::vector<std::string> expected_urls;
355 expected_urls.push_back("http://slashdot.org/favorite_page.html");
356 // With cursor after "slash", we should retrieve the desired result but it
357 // should not be allowed to be the default match.
358 RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false,
359 expected_urls, false,
360 ASCIIToUTF16("slashdot.org/favorite_page.html"),
361 base::string16());
362 // If the cursor is in the middle of a valid URL suggestion, it should be
363 // allowed to be the default match. The inline completion will be empty
364 // though as no completion is necessary.
365 RunTestWithCursor(ASCIIToUTF16("slashdot.org/favorite_page.html"), 5, false,
366 expected_urls, true,
367 ASCIIToUTF16("slashdot.org/favorite_page.html"),
368 base::string16());
369 }
370
331 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { 371 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) {
332 std::vector<std::string> expected_urls; 372 std::vector<std::string> expected_urls;
333 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); 373 expected_urls.push_back("http://popularsitewithpathonly.com/moo");
334 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false, 374 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false,
335 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); 375 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16());
336 } 376 }
337 377
338 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { 378 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) {
339 std::vector<std::string> expected_urls; 379 std::vector<std::string> expected_urls;
340 expected_urls.push_back( 380 expected_urls.push_back(
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 780
741 TEST_F(HQPOrderingTest, TEAMatch) { 781 TEST_F(HQPOrderingTest, TEAMatch) {
742 std::vector<std::string> expected_urls; 782 std::vector<std::string> expected_urls;
743 expected_urls.push_back("http://www.teamliquid.net/"); 783 expected_urls.push_back("http://www.teamliquid.net/");
744 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 784 expected_urls.push_back("http://www.teamliquid.net/tlpd");
745 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 785 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
746 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 786 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
747 ASCIIToUTF16("www.teamliquid.net"), 787 ASCIIToUTF16("www.teamliquid.net"),
748 ASCIIToUTF16("mliquid.net")); 788 ASCIIToUTF16("mliquid.net"));
749 } 789 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | chrome/browser/autocomplete/search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698