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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 virtual void TearDown(); | 125 virtual void TearDown(); |
126 | 126 |
127 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data); | 127 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data); |
128 | 128 |
129 // Fills test data into the history system. | 129 // Fills test data into the history system. |
130 void FillData(); | 130 void FillData(); |
131 | 131 |
132 // Runs an autocomplete query on |text| and checks to see that the returned | 132 // Runs an autocomplete query on |text| and checks to see that the returned |
133 // results' destination URLs match those provided. |expected_urls| does not | 133 // results' destination URLs match those provided. |expected_urls| does not |
134 // need to be in sorted order. | 134 // need to be in sorted order. |
135 void RunTest(const string16 text, | 135 void RunTest(const base::string16 text, |
136 std::vector<std::string> expected_urls, | 136 std::vector<std::string> expected_urls, |
137 bool can_inline_top_result, | 137 bool can_inline_top_result, |
138 string16 expected_fill_into_edit); | 138 base::string16 expected_fill_into_edit); |
139 | 139 |
140 base::MessageLoopForUI message_loop_; | 140 base::MessageLoopForUI message_loop_; |
141 content::TestBrowserThread ui_thread_; | 141 content::TestBrowserThread ui_thread_; |
142 content::TestBrowserThread file_thread_; | 142 content::TestBrowserThread file_thread_; |
143 | 143 |
144 scoped_ptr<TestingProfile> profile_; | 144 scoped_ptr<TestingProfile> profile_; |
145 HistoryService* history_service_; | 145 HistoryService* history_service_; |
146 | 146 |
147 ACMatches ac_matches_; // The resulting matches after running RunTest. | 147 ACMatches ac_matches_; // The resulting matches after running RunTest. |
148 | 148 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 matches_.insert(iter->destination_url.spec()); | 230 matches_.insert(iter->destination_url.spec()); |
231 } | 231 } |
232 | 232 |
233 void HistoryQuickProviderTest::SetShouldContain::operator()( | 233 void HistoryQuickProviderTest::SetShouldContain::operator()( |
234 const std::string& expected) { | 234 const std::string& expected) { |
235 EXPECT_EQ(1U, matches_.erase(expected)) | 235 EXPECT_EQ(1U, matches_.erase(expected)) |
236 << "Results did not contain '" << expected << "' but should have."; | 236 << "Results did not contain '" << expected << "' but should have."; |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 void HistoryQuickProviderTest::RunTest(const string16 text, | 240 void HistoryQuickProviderTest::RunTest(const base::string16 text, |
241 std::vector<std::string> expected_urls, | 241 std::vector<std::string> expected_urls, |
242 bool can_inline_top_result, | 242 bool can_inline_top_result, |
243 string16 expected_fill_into_edit) { | 243 base::string16 expected_fill_into_edit) { |
244 SCOPED_TRACE(text); // Minimal hint to query being run. | 244 SCOPED_TRACE(text); // Minimal hint to query being run. |
245 base::MessageLoop::current()->RunUntilIdle(); | 245 base::MessageLoop::current()->RunUntilIdle(); |
246 AutocompleteInput input(text, string16::npos, string16(), GURL(), | 246 AutocompleteInput input(text, base::string16::npos, base::string16(), |
247 AutocompleteInput::INVALID_SPEC, false, false, true, | 247 GURL(), AutocompleteInput::INVALID_SPEC, false, |
248 AutocompleteInput::ALL_MATCHES); | 248 false, true, AutocompleteInput::ALL_MATCHES); |
249 provider_->Start(input, false); | 249 provider_->Start(input, false); |
250 EXPECT_TRUE(provider_->done()); | 250 EXPECT_TRUE(provider_->done()); |
251 | 251 |
252 ac_matches_ = provider_->matches(); | 252 ac_matches_ = provider_->matches(); |
253 | 253 |
254 // We should have gotten back at most AutocompleteProvider::kMaxMatches. | 254 // We should have gotten back at most AutocompleteProvider::kMaxMatches. |
255 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); | 255 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); |
256 | 256 |
257 // If the number of expected and actual matches aren't equal then we need | 257 // If the number of expected and actual matches aren't equal then we need |
258 // test no further, but let's do anyway so that we know which URLs failed. | 258 // test no further, but let's do anyway so that we know which URLs failed. |
(...skipping 28 matching lines...) Expand all Loading... |
287 } | 287 } |
288 | 288 |
289 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match); | 289 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match); |
290 if (can_inline_top_result) { | 290 if (can_inline_top_result) { |
291 // When the top scorer is inline-able make sure we get the expected | 291 // When the top scorer is inline-able make sure we get the expected |
292 // fill_into_edit and autocomplete offset. | 292 // fill_into_edit and autocomplete offset. |
293 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit) | 293 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit) |
294 << "fill_into_edit was: '" << ac_matches_[0].fill_into_edit | 294 << "fill_into_edit was: '" << ac_matches_[0].fill_into_edit |
295 << "' but we expected '" << expected_fill_into_edit << "'."; | 295 << "' but we expected '" << expected_fill_into_edit << "'."; |
296 size_t text_pos = expected_fill_into_edit.find(text); | 296 size_t text_pos = expected_fill_into_edit.find(text); |
297 ASSERT_NE(string16::npos, text_pos); | 297 ASSERT_NE(base::string16::npos, text_pos); |
298 EXPECT_EQ(ac_matches_[0].fill_into_edit.substr(text_pos + text.size()), | 298 EXPECT_EQ(ac_matches_[0].fill_into_edit.substr(text_pos + text.size()), |
299 ac_matches_[0].inline_autocompletion); | 299 ac_matches_[0].inline_autocompletion); |
300 } else { | 300 } else { |
301 // When the top scorer is not inline-able autocomplete offset must be npos. | 301 // When the top scorer is not inline-able autocomplete offset must be npos. |
302 EXPECT_TRUE(ac_matches_[0].inline_autocompletion.empty()); | 302 EXPECT_TRUE(ac_matches_[0].inline_autocompletion.empty()); |
303 // Also, the score must be too low to be inlineable. | 303 // Also, the score must be too low to be inlineable. |
304 // TODO(mpearson): when the controller reorders for inlining, there's no | 304 // TODO(mpearson): when the controller reorders for inlining, there's no |
305 // longer any connection between scores and what's inlineable / allowed | 305 // longer any connection between scores and what's inlineable / allowed |
306 // to be the default match. Remove this test. | 306 // to be the default match. Remove this test. |
307 EXPECT_LT(ac_matches_[0].relevance, | 307 EXPECT_LT(ac_matches_[0].relevance, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 TemplateURLService* template_url_service = | 548 TemplateURLService* template_url_service = |
549 TemplateURLServiceFactory::GetForProfile(profile_.get()); | 549 TemplateURLServiceFactory::GetForProfile(profile_.get()); |
550 TemplateURL* template_url = new TemplateURL(profile_.get(), data); | 550 TemplateURL* template_url = new TemplateURL(profile_.get(), data); |
551 template_url_service->Add(template_url); | 551 template_url_service->Add(template_url); |
552 template_url_service->SetDefaultSearchProvider(template_url); | 552 template_url_service->SetDefaultSearchProvider(template_url); |
553 template_url_service->Load(); | 553 template_url_service->Load(); |
554 | 554 |
555 // A search results page should not be returned when typing a query. | 555 // A search results page should not be returned when typing a query. |
556 std::vector<std::string> expected_urls; | 556 std::vector<std::string> expected_urls; |
557 expected_urls.push_back("http://anotherengine.com/?q=thequery"); | 557 expected_urls.push_back("http://anotherengine.com/?q=thequery"); |
558 RunTest(ASCIIToUTF16("thequery"), expected_urls, false, string16()); | 558 RunTest(ASCIIToUTF16("thequery"), expected_urls, false, base::string16()); |
559 | 559 |
560 // A search results page should not be returned when typing the engine URL. | 560 // A search results page should not be returned when typing the engine URL. |
561 expected_urls.clear(); | 561 expected_urls.clear(); |
562 expected_urls.push_back("http://testsearch.com/"); | 562 expected_urls.push_back("http://testsearch.com/"); |
563 RunTest(ASCIIToUTF16("testsearch"), expected_urls, true, | 563 RunTest(ASCIIToUTF16("testsearch"), expected_urls, true, |
564 ASCIIToUTF16("testsearch.com")); | 564 ASCIIToUTF16("testsearch.com")); |
565 } | 565 } |
566 | 566 |
567 // HQPOrderingTest ------------------------------------------------------------- | 567 // HQPOrderingTest ------------------------------------------------------------- |
568 | 568 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 } | 624 } |
625 | 625 |
626 TEST_F(HQPOrderingTest, TEAMatch) { | 626 TEST_F(HQPOrderingTest, TEAMatch) { |
627 std::vector<std::string> expected_urls; | 627 std::vector<std::string> expected_urls; |
628 expected_urls.push_back("http://www.teamliquid.net/"); | 628 expected_urls.push_back("http://www.teamliquid.net/"); |
629 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 629 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
630 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 630 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
631 RunTest(ASCIIToUTF16("tea"), expected_urls, true, | 631 RunTest(ASCIIToUTF16("tea"), expected_urls, true, |
632 ASCIIToUTF16("www.teamliquid.net")); | 632 ASCIIToUTF16("www.teamliquid.net")); |
633 } | 633 } |
OLD | NEW |