| 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 "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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Runs an autocomplete query on |text| and checks to see that the returned | 145 // Runs an autocomplete query on |text| and checks to see that the returned |
| 146 // results' destination URLs match those provided. |expected_urls| does not | 146 // results' destination URLs match those provided. |expected_urls| does not |
| 147 // need to be in sorted order. | 147 // need to be in sorted order. |
| 148 void RunTest(const base::string16 text, | 148 void RunTest(const base::string16 text, |
| 149 bool prevent_inline_autocomplete, | 149 bool prevent_inline_autocomplete, |
| 150 std::vector<std::string> expected_urls, | 150 std::vector<std::string> expected_urls, |
| 151 bool can_inline_top_result, | 151 bool can_inline_top_result, |
| 152 base::string16 expected_fill_into_edit, | 152 base::string16 expected_fill_into_edit, |
| 153 base::string16 autocompletion); | 153 base::string16 autocompletion); |
| 154 | 154 |
| 155 // As above, simply with a cursor position specified. |
| 156 void RunTestWithCursor(const base::string16 text, |
| 157 const size_t cursor_position, |
| 158 bool prevent_inline_autocomplete, |
| 159 std::vector<std::string> expected_urls, |
| 160 bool can_inline_top_result, |
| 161 base::string16 expected_fill_into_edit, |
| 162 base::string16 autocompletion); |
| 163 |
| 155 history::HistoryBackend* history_backend() { | 164 history::HistoryBackend* history_backend() { |
| 156 return history_service_->history_backend_; | 165 return history_service_->history_backend_; |
| 157 } | 166 } |
| 158 | 167 |
| 159 base::MessageLoopForUI message_loop_; | 168 base::MessageLoopForUI message_loop_; |
| 160 content::TestBrowserThread ui_thread_; | 169 content::TestBrowserThread ui_thread_; |
| 161 content::TestBrowserThread file_thread_; | 170 content::TestBrowserThread file_thread_; |
| 162 | 171 |
| 163 scoped_ptr<TestingProfile> profile_; | 172 scoped_ptr<TestingProfile> profile_; |
| 164 HistoryService* history_service_; | 173 HistoryService* history_service_; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 iter != matched_urls.end(); ++iter) | 257 iter != matched_urls.end(); ++iter) |
| 249 matches_.insert(iter->destination_url.spec()); | 258 matches_.insert(iter->destination_url.spec()); |
| 250 } | 259 } |
| 251 | 260 |
| 252 void HistoryQuickProviderTest::SetShouldContain::operator()( | 261 void HistoryQuickProviderTest::SetShouldContain::operator()( |
| 253 const std::string& expected) { | 262 const std::string& expected) { |
| 254 EXPECT_EQ(1U, matches_.erase(expected)) | 263 EXPECT_EQ(1U, matches_.erase(expected)) |
| 255 << "Results did not contain '" << expected << "' but should have."; | 264 << "Results did not contain '" << expected << "' but should have."; |
| 256 } | 265 } |
| 257 | 266 |
| 267 void HistoryQuickProviderTest::RunTest( |
| 268 const base::string16 text, |
| 269 bool prevent_inline_autocomplete, |
| 270 std::vector<std::string> expected_urls, |
| 271 bool can_inline_top_result, |
| 272 base::string16 expected_fill_into_edit, |
| 273 base::string16 expected_autocompletion) { |
| 274 RunTestWithCursor(text, base::string16::npos, prevent_inline_autocomplete, |
| 275 expected_urls, can_inline_top_result, |
| 276 expected_fill_into_edit, expected_autocompletion); |
| 277 } |
| 258 | 278 |
| 259 void HistoryQuickProviderTest::RunTest(const base::string16 text, | 279 void HistoryQuickProviderTest::RunTestWithCursor( |
| 260 bool prevent_inline_autocomplete, | 280 const base::string16 text, |
| 261 std::vector<std::string> expected_urls, | 281 const size_t cursor_position, |
| 262 bool can_inline_top_result, | 282 bool prevent_inline_autocomplete, |
| 263 base::string16 expected_fill_into_edit, | 283 std::vector<std::string> expected_urls, |
| 264 base::string16 expected_autocompletion) { | 284 bool can_inline_top_result, |
| 285 base::string16 expected_fill_into_edit, |
| 286 base::string16 expected_autocompletion) { |
| 265 SCOPED_TRACE(text); // Minimal hint to query being run. | 287 SCOPED_TRACE(text); // Minimal hint to query being run. |
| 266 base::MessageLoop::current()->RunUntilIdle(); | 288 base::MessageLoop::current()->RunUntilIdle(); |
| 267 AutocompleteInput input(text, base::string16::npos, base::string16(), | 289 AutocompleteInput input(text, cursor_position, base::string16(), |
| 268 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, | 290 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, |
| 269 prevent_inline_autocomplete, false, true, true, | 291 prevent_inline_autocomplete, false, true, true, |
| 270 ChromeAutocompleteSchemeClassifier(profile_.get())); | 292 ChromeAutocompleteSchemeClassifier(profile_.get())); |
| 271 provider_->Start(input, false); | 293 provider_->Start(input, false); |
| 272 EXPECT_TRUE(provider_->done()); | 294 EXPECT_TRUE(provider_->done()); |
| 273 | 295 |
| 274 ac_matches_ = provider_->matches(); | 296 ac_matches_ = provider_->matches(); |
| 275 | 297 |
| 276 // We should have gotten back at most AutocompleteProvider::kMaxMatches. | 298 // We should have gotten back at most AutocompleteProvider::kMaxMatches. |
| 277 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); | 299 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 337 } |
| 316 | 338 |
| 317 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { | 339 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { |
| 318 std::vector<std::string> expected_urls; | 340 std::vector<std::string> expected_urls; |
| 319 expected_urls.push_back("http://slashdot.org/favorite_page.html"); | 341 expected_urls.push_back("http://slashdot.org/favorite_page.html"); |
| 320 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, | 342 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true, |
| 321 ASCIIToUTF16("slashdot.org/favorite_page.html"), | 343 ASCIIToUTF16("slashdot.org/favorite_page.html"), |
| 322 ASCIIToUTF16(".org/favorite_page.html")); | 344 ASCIIToUTF16(".org/favorite_page.html")); |
| 323 } | 345 } |
| 324 | 346 |
| 347 TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) { |
| 348 std::vector<std::string> expected_urls; |
| 349 expected_urls.push_back("http://slashdot.org/favorite_page.html"); |
| 350 // With cursor after "slash", we should retrieve the desired result but it |
| 351 // should not be allowed to be the default match. |
| 352 RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false, |
| 353 expected_urls, false, |
| 354 ASCIIToUTF16("slashdot.org/favorite_page.html"), |
| 355 base::string16()); |
| 356 // If the cursor is in the middle of a valid URL suggestion, it should be |
| 357 // allowed to be the default match. The inline completion will be empty |
| 358 // though as no completion is necessary. |
| 359 RunTestWithCursor(ASCIIToUTF16("slashdot.org/favorite_page.html"), 5, false, |
| 360 expected_urls, true, |
| 361 ASCIIToUTF16("slashdot.org/favorite_page.html"), |
| 362 base::string16()); |
| 363 } |
| 364 |
| 325 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { | 365 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { |
| 326 std::vector<std::string> expected_urls; | 366 std::vector<std::string> expected_urls; |
| 327 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); | 367 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); |
| 328 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false, | 368 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false, |
| 329 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); | 369 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); |
| 330 } | 370 } |
| 331 | 371 |
| 332 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { | 372 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { |
| 333 std::vector<std::string> expected_urls; | 373 std::vector<std::string> expected_urls; |
| 334 expected_urls.push_back( | 374 expected_urls.push_back( |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 774 |
| 735 TEST_F(HQPOrderingTest, TEAMatch) { | 775 TEST_F(HQPOrderingTest, TEAMatch) { |
| 736 std::vector<std::string> expected_urls; | 776 std::vector<std::string> expected_urls; |
| 737 expected_urls.push_back("http://www.teamliquid.net/"); | 777 expected_urls.push_back("http://www.teamliquid.net/"); |
| 738 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 778 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
| 739 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 779 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
| 740 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 780 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
| 741 ASCIIToUTF16("www.teamliquid.net"), | 781 ASCIIToUTF16("www.teamliquid.net"), |
| 742 ASCIIToUTF16("mliquid.net")); | 782 ASCIIToUTF16("mliquid.net")); |
| 743 } | 783 } |
| OLD | NEW |