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 "components/omnibox/browser/history_url_provider.h" | 5 #include "components/omnibox/browser/history_url_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
| 11 #include "base/files/scoped_temp_dir.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 19 #include "components/history/core/browser/history_database_params.h" |
19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | |
20 #include "chrome/browser/history/history_service_factory.h" | |
21 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" | |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
23 #include "chrome/common/pref_names.h" | |
24 #include "chrome/test/base/testing_browser_process.h" | |
25 #include "chrome/test/base/testing_profile.h" | |
26 #include "components/history/core/browser/history_service.h" | 20 #include "components/history/core/browser/history_service.h" |
27 #include "components/history/core/browser/url_database.h" | 21 #include "components/history/core/browser/url_database.h" |
| 22 #include "components/history/core/test/test_history_database.h" |
28 #include "components/metrics/proto/omnibox_event.pb.h" | 23 #include "components/metrics/proto/omnibox_event.pb.h" |
29 #include "components/metrics/proto/omnibox_input_type.pb.h" | 24 #include "components/metrics/proto/omnibox_input_type.pb.h" |
30 #include "components/omnibox/browser/autocomplete_match.h" | 25 #include "components/omnibox/browser/autocomplete_match.h" |
31 #include "components/omnibox/browser/autocomplete_provider.h" | 26 #include "components/omnibox/browser/autocomplete_provider.h" |
32 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
33 #include "components/omnibox/browser/autocomplete_result.h" | 28 #include "components/omnibox/browser/autocomplete_result.h" |
34 #include "components/omnibox/browser/history_quick_provider.h" | 29 #include "components/omnibox/browser/history_quick_provider.h" |
| 30 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 31 #include "components/omnibox/browser/test_scheme_classifier.h" |
35 #include "components/search_engines/default_search_manager.h" | 32 #include "components/search_engines/default_search_manager.h" |
36 #include "components/search_engines/search_terms_data.h" | 33 #include "components/search_engines/search_terms_data.h" |
37 #include "components/search_engines/template_url.h" | 34 #include "components/search_engines/template_url.h" |
38 #include "components/search_engines/template_url_service.h" | 35 #include "components/search_engines/template_url_service.h" |
39 #include "components/url_formatter/url_fixer.h" | 36 #include "components/url_formatter/url_fixer.h" |
40 #include "content/public/test/test_browser_thread_bundle.h" | |
41 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
42 | 38 |
43 using base::ASCIIToUTF16; | 39 using base::ASCIIToUTF16; |
44 using base::Time; | 40 using base::Time; |
45 using base::TimeDelta; | 41 using base::TimeDelta; |
46 | 42 |
47 using content::TestBrowserThreadBundle; | 43 namespace { |
48 | 44 |
49 struct TestURLInfo { | 45 struct TestURLInfo { |
50 const char* url; | 46 const char* url; |
51 const char* title; | 47 const char* title; |
52 int visit_count; | 48 int visit_count; |
53 int typed_count; | 49 int typed_count; |
54 int age_in_days; | 50 int age_in_days; |
55 } test_db[] = { | 51 } test_db[] = { |
56 {"http://www.google.com/", "Google", 3, 3, 80}, | 52 {"http://www.google.com/", "Google", 3, 3, 80}, |
57 | 53 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // For experimental HUP scoring test. | 146 // For experimental HUP scoring test. |
151 {"http://7.com/1a", "One", 8, 4, 4}, | 147 {"http://7.com/1a", "One", 8, 4, 4}, |
152 {"http://7.com/2a", "Two A", 4, 2, 8}, | 148 {"http://7.com/2a", "Two A", 4, 2, 8}, |
153 {"http://7.com/2b", "Two B", 4, 1, 8}, | 149 {"http://7.com/2b", "Two B", 4, 1, 8}, |
154 {"http://7.com/3a", "Three", 2, 1, 16}, | 150 {"http://7.com/3a", "Three", 2, 1, 16}, |
155 {"http://7.com/4a", "Four A", 1, 1, 32}, | 151 {"http://7.com/4a", "Four A", 1, 1, 32}, |
156 {"http://7.com/4b", "Four B", 1, 1, 64}, | 152 {"http://7.com/4b", "Four B", 1, 1, 64}, |
157 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. | 153 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. |
158 }; | 154 }; |
159 | 155 |
| 156 class QuitTask : public history::HistoryDBTask { |
| 157 public: |
| 158 QuitTask() {} |
| 159 |
| 160 bool RunOnDBThread(history::HistoryBackend* backend, |
| 161 history::HistoryDatabase* db) override { |
| 162 return true; |
| 163 } |
| 164 |
| 165 void DoneRunOnMainThread() override { |
| 166 base::MessageLoop::current()->QuitWhenIdle(); |
| 167 } |
| 168 |
| 169 private: |
| 170 ~QuitTask() override {} |
| 171 |
| 172 DISALLOW_COPY_AND_ASSIGN(QuitTask); |
| 173 }; |
| 174 |
| 175 class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient { |
| 176 public: |
| 177 FakeAutocompleteProviderClient() { |
| 178 set_template_url_service( |
| 179 make_scoped_ptr(new TemplateURLService(nullptr, 0))); |
| 180 } |
| 181 |
| 182 const AutocompleteSchemeClassifier& GetSchemeClassifier() const override { |
| 183 return scheme_classifier_; |
| 184 } |
| 185 |
| 186 const SearchTermsData& GetSearchTermsData() const override { |
| 187 return search_terms_data_; |
| 188 } |
| 189 |
| 190 history::HistoryService* GetHistoryService() override { |
| 191 return &history_service_; |
| 192 } |
| 193 |
| 194 private: |
| 195 TestSchemeClassifier scheme_classifier_; |
| 196 SearchTermsData search_terms_data_; |
| 197 history::HistoryService history_service_; |
| 198 |
| 199 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient); |
| 200 }; |
| 201 |
| 202 } // namespace |
| 203 |
160 class HistoryURLProviderTest : public testing::Test, | 204 class HistoryURLProviderTest : public testing::Test, |
161 public AutocompleteProviderListener { | 205 public AutocompleteProviderListener { |
162 public: | 206 public: |
163 struct UrlAndLegalDefault { | 207 struct UrlAndLegalDefault { |
164 std::string url; | 208 std::string url; |
165 bool allowed_to_be_default_match; | 209 bool allowed_to_be_default_match; |
166 }; | 210 }; |
167 | 211 |
168 HistoryURLProviderTest() | 212 HistoryURLProviderTest() |
169 : sort_matches_(false) { | 213 : sort_matches_(false) { |
170 HistoryQuickProvider::set_disabled(true); | 214 HistoryQuickProvider::set_disabled(true); |
171 } | 215 } |
172 | 216 |
173 ~HistoryURLProviderTest() override { | 217 ~HistoryURLProviderTest() override { |
174 HistoryQuickProvider::set_disabled(false); | 218 HistoryQuickProvider::set_disabled(false); |
175 } | 219 } |
176 | 220 |
177 // AutocompleteProviderListener: | 221 // AutocompleteProviderListener: |
178 void OnProviderUpdate(bool updated_matches) override; | 222 void OnProviderUpdate(bool updated_matches) override; |
179 | 223 |
180 protected: | 224 protected: |
181 static scoped_ptr<KeyedService> CreateTemplateURLService( | |
182 content::BrowserContext* context) { | |
183 Profile* profile = static_cast<Profile*>(context); | |
184 return make_scoped_ptr(new TemplateURLService( | |
185 profile->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL, | |
186 scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient( | |
187 HistoryServiceFactory::GetForProfile( | |
188 profile, ServiceAccessType::EXPLICIT_ACCESS))), | |
189 NULL, NULL, base::Closure())); | |
190 } | |
191 | |
192 // testing::Test | 225 // testing::Test |
193 void SetUp() override { | 226 void SetUp() override { |
194 ASSERT_TRUE(SetUpImpl(false)); | 227 ASSERT_TRUE(SetUpImpl(false)); |
195 } | 228 } |
196 void TearDown() override; | 229 void TearDown() override; |
197 | 230 |
198 // Does the real setup. | 231 // Does the real setup. |
199 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT; | 232 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT; |
200 | 233 |
201 // Fills test data into the history system. | 234 // Fills test data into the history system. |
(...skipping 13 matching lines...) Expand all Loading... |
215 void RunTest(const base::string16& text, | 248 void RunTest(const base::string16& text, |
216 const std::string& desired_tld, | 249 const std::string& desired_tld, |
217 bool prevent_inline_autocomplete, | 250 bool prevent_inline_autocomplete, |
218 const UrlAndLegalDefault* expected_urls, | 251 const UrlAndLegalDefault* expected_urls, |
219 size_t num_results) { | 252 size_t num_results) { |
220 metrics::OmniboxInputType::Type type; | 253 metrics::OmniboxInputType::Type type; |
221 return RunTest(text, desired_tld, prevent_inline_autocomplete, | 254 return RunTest(text, desired_tld, prevent_inline_autocomplete, |
222 expected_urls, num_results, &type); | 255 expected_urls, num_results, &type); |
223 } | 256 } |
224 | 257 |
225 content::TestBrowserThreadBundle thread_bundle_; | 258 // Helper functions to initialize the HistoryService. |
| 259 bool InitializeHistoryService(bool delete_file, bool no_db); |
| 260 void BlockUntilHistoryProcessesPendingRequests(); |
| 261 |
| 262 base::MessageLoop message_loop_; |
| 263 base::ScopedTempDir history_dir_; |
226 ACMatches matches_; | 264 ACMatches matches_; |
227 scoped_ptr<TestingProfile> profile_; | 265 scoped_ptr<FakeAutocompleteProviderClient> client_; |
228 scoped_ptr<ChromeAutocompleteProviderClient> client_; | |
229 history::HistoryService* history_service_; | 266 history::HistoryService* history_service_; |
230 scoped_refptr<HistoryURLProvider> autocomplete_; | 267 scoped_refptr<HistoryURLProvider> autocomplete_; |
231 // Should the matches be sorted and duplicates removed? | 268 // Should the matches be sorted and duplicates removed? |
232 bool sort_matches_; | 269 bool sort_matches_; |
| 270 |
| 271 private: |
| 272 DISALLOW_COPY_AND_ASSIGN(HistoryURLProviderTest); |
233 }; | 273 }; |
234 | 274 |
235 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { | 275 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { |
236 protected: | 276 protected: |
237 void SetUp() override { | 277 void SetUp() override { |
238 ASSERT_TRUE(SetUpImpl(true)); | 278 ASSERT_TRUE(SetUpImpl(true)); |
239 } | 279 } |
240 }; | 280 }; |
241 | 281 |
242 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest { | 282 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest { |
243 protected: | 283 protected: |
244 void SetUp() override { | 284 void SetUp() override { |
245 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); | 285 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); |
246 HistoryURLProviderTest::SetUp(); | 286 HistoryURLProviderTest::SetUp(); |
247 } | 287 } |
248 | 288 |
249 void TearDown() override { | 289 void TearDown() override { |
250 HistoryURLProviderTest::TearDown(); | 290 HistoryURLProviderTest::TearDown(); |
251 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); | 291 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); |
252 } | 292 } |
253 }; | 293 }; |
254 | 294 |
255 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { | 295 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { |
256 if (autocomplete_->done()) | 296 if (autocomplete_->done()) |
257 base::MessageLoop::current()->QuitWhenIdle(); | 297 base::MessageLoop::current()->QuitWhenIdle(); |
258 } | 298 } |
259 | 299 |
| 300 bool HistoryURLProviderTest::InitializeHistoryService( |
| 301 bool delete_file, bool no_db) { |
| 302 if (!history_dir_.CreateUniqueTempDir()) |
| 303 return false; |
| 304 |
| 305 history_service_ = client_->GetHistoryService(); |
| 306 if (!history_service_->Init( |
| 307 no_db, std::string(), |
| 308 history::TestHistoryDatabaseParamsForPath(history_dir_.path()))) |
| 309 return false; |
| 310 |
| 311 if (!no_db) |
| 312 BlockUntilHistoryProcessesPendingRequests(); |
| 313 |
| 314 return true; |
| 315 } |
| 316 |
| 317 void HistoryURLProviderTest::BlockUntilHistoryProcessesPendingRequests() { |
| 318 base::CancelableTaskTracker tracker; |
| 319 client_->GetHistoryService()->ScheduleDBTask( |
| 320 scoped_ptr<history::HistoryDBTask>(new QuitTask()), &tracker); |
| 321 base::MessageLoop::current()->Run(); |
| 322 } |
| 323 |
260 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { | 324 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { |
261 profile_.reset(new TestingProfile()); | 325 client_.reset(new FakeAutocompleteProviderClient()); |
262 client_.reset(new ChromeAutocompleteProviderClient(profile_.get())); | 326 |
263 if (!(profile_->CreateHistoryService(true, no_db))) | 327 if (!InitializeHistoryService(true, no_db)) |
264 return false; | 328 return false; |
265 if (!no_db) { | 329 EXPECT_CALL(*client_, GetAcceptLanguages()) |
266 profile_->BlockUntilHistoryProcessesPendingRequests(); | 330 .WillRepeatedly(testing::Return("en-US,en,ko")); |
267 profile_->BlockUntilHistoryIndexIsRefreshed(); | |
268 } | |
269 profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en-US,en,ko"); | |
270 history_service_ = HistoryServiceFactory::GetForProfile( | |
271 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS); | |
272 | 331 |
273 autocomplete_ = new HistoryURLProvider(client_.get(), this); | 332 autocomplete_ = new HistoryURLProvider(client_.get(), this); |
274 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
275 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); | |
276 FillData(); | 333 FillData(); |
277 return true; | 334 return true; |
278 } | 335 } |
279 | 336 |
280 void HistoryURLProviderTest::TearDown() { | 337 void HistoryURLProviderTest::TearDown() { |
281 autocomplete_ = NULL; | 338 autocomplete_ = NULL; |
282 } | 339 } |
283 | 340 |
284 void HistoryURLProviderTest::FillData() { | 341 void HistoryURLProviderTest::FillData() { |
285 // Most visits are a long time ago (some tests require this since we do some | 342 // Most visits are a long time ago (some tests require this since we do some |
(...skipping 24 matching lines...) Expand all Loading... |
310 void HistoryURLProviderTest::RunTest( | 367 void HistoryURLProviderTest::RunTest( |
311 const base::string16& text, | 368 const base::string16& text, |
312 const std::string& desired_tld, | 369 const std::string& desired_tld, |
313 bool prevent_inline_autocomplete, | 370 bool prevent_inline_autocomplete, |
314 const UrlAndLegalDefault* expected_urls, | 371 const UrlAndLegalDefault* expected_urls, |
315 size_t num_results, | 372 size_t num_results, |
316 metrics::OmniboxInputType::Type* identified_input_type) { | 373 metrics::OmniboxInputType::Type* identified_input_type) { |
317 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), | 374 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), |
318 metrics::OmniboxEventProto::INVALID_SPEC, | 375 metrics::OmniboxEventProto::INVALID_SPEC, |
319 prevent_inline_autocomplete, false, true, true, false, | 376 prevent_inline_autocomplete, false, true, true, false, |
320 ChromeAutocompleteSchemeClassifier(profile_.get())); | 377 TestSchemeClassifier()); |
321 *identified_input_type = input.type(); | 378 *identified_input_type = input.type(); |
322 autocomplete_->Start(input, false); | 379 autocomplete_->Start(input, false); |
323 if (!autocomplete_->done()) | 380 if (!autocomplete_->done()) |
324 base::MessageLoop::current()->Run(); | 381 base::MessageLoop::current()->Run(); |
325 | 382 |
326 matches_ = autocomplete_->matches(); | 383 matches_ = autocomplete_->matches(); |
327 if (sort_matches_) { | 384 if (sort_matches_) { |
328 TemplateURLService* service = | 385 TemplateURLService* service = client_->GetTemplateURLService(); |
329 TemplateURLServiceFactory::GetForProfile(profile_.get()); | |
330 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { | 386 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { |
331 i->ComputeStrippedDestinationURL( | 387 i->ComputeStrippedDestinationURL( |
332 input, client_->GetAcceptLanguages(), service); | 388 input, client_->GetAcceptLanguages(), service); |
333 } | 389 } |
334 AutocompleteResult::DedupMatchesByDestination( | 390 AutocompleteResult::DedupMatchesByDestination( |
335 input.current_page_classification(), false, &matches_); | 391 input.current_page_classification(), false, &matches_); |
336 std::sort(matches_.begin(), matches_.end(), | 392 std::sort(matches_.begin(), matches_.end(), |
337 &AutocompleteMatch::MoreRelevant); | 393 &AutocompleteMatch::MoreRelevant); |
338 } | 394 } |
339 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text | 395 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 { "http://www.17173.com/", true } | 690 { "http://www.17173.com/", true } |
635 }; | 691 }; |
636 RunTest(ASCIIToUTF16("17173"), std::string(), false, fixup_5, | 692 RunTest(ASCIIToUTF16("17173"), std::string(), false, fixup_5, |
637 arraysize(fixup_5)); | 693 arraysize(fixup_5)); |
638 } | 694 } |
639 | 695 |
640 // Make sure the results for the input 'p' don't change between the first and | 696 // Make sure the results for the input 'p' don't change between the first and |
641 // second passes. | 697 // second passes. |
642 TEST_F(HistoryURLProviderTest, EmptyVisits) { | 698 TEST_F(HistoryURLProviderTest, EmptyVisits) { |
643 // Wait for history to create the in memory DB. | 699 // Wait for history to create the in memory DB. |
644 profile_->BlockUntilHistoryProcessesPendingRequests(); | 700 BlockUntilHistoryProcessesPendingRequests(); |
645 | 701 |
646 AutocompleteInput input( | 702 AutocompleteInput input( |
647 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(), | 703 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(), |
648 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | 704 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, |
649 ChromeAutocompleteSchemeClassifier(profile_.get())); | 705 TestSchemeClassifier()); |
650 autocomplete_->Start(input, false); | 706 autocomplete_->Start(input, false); |
651 // HistoryURLProvider shouldn't be done (waiting on async results). | 707 // HistoryURLProvider shouldn't be done (waiting on async results). |
652 EXPECT_FALSE(autocomplete_->done()); | 708 EXPECT_FALSE(autocomplete_->done()); |
653 | 709 |
654 // We should get back an entry for pandora. | 710 // We should get back an entry for pandora. |
655 matches_ = autocomplete_->matches(); | 711 matches_ = autocomplete_->matches(); |
656 ASSERT_GT(matches_.size(), 0u); | 712 ASSERT_GT(matches_.size(), 0u); |
657 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); | 713 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); |
658 int pandora_relevance = matches_[0].relevance; | 714 int pandora_relevance = matches_[0].relevance; |
659 | 715 |
(...skipping 21 matching lines...) Expand all Loading... |
681 RunTest(ASCIIToUTF16("slash"), std::string(), false, navigation_2, | 737 RunTest(ASCIIToUTF16("slash"), std::string(), false, navigation_2, |
682 arraysize(navigation_2)); | 738 arraysize(navigation_2)); |
683 | 739 |
684 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); | 740 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); |
685 } | 741 } |
686 | 742 |
687 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { | 743 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { |
688 AutocompleteInput input( | 744 AutocompleteInput input( |
689 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(), | 745 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(), |
690 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | 746 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, |
691 ChromeAutocompleteSchemeClassifier(profile_.get())); | 747 TestSchemeClassifier()); |
692 autocomplete_->Start(input, false); | 748 autocomplete_->Start(input, false); |
693 if (!autocomplete_->done()) | 749 if (!autocomplete_->done()) |
694 base::MessageLoop::current()->Run(); | 750 base::MessageLoop::current()->Run(); |
695 | 751 |
696 // None of the matches should attempt to autocomplete. | 752 // None of the matches should attempt to autocomplete. |
697 matches_ = autocomplete_->matches(); | 753 matches_ = autocomplete_->matches(); |
698 for (size_t i = 0; i < matches_.size(); ++i) { | 754 for (size_t i = 0; i < matches_.size(); ++i) { |
699 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); | 755 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); |
700 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); | 756 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); |
701 } | 757 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 // This test passes if we don't crash. The results don't matter. | 875 // This test passes if we don't crash. The results don't matter. |
820 const char* const test_cases[] = { | 876 const char* const test_cases[] = { |
821 "//c", | 877 "//c", |
822 "\\@st", | 878 "\\@st", |
823 "view-source:x", | 879 "view-source:x", |
824 }; | 880 }; |
825 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 881 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
826 AutocompleteInput input( | 882 AutocompleteInput input( |
827 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(), | 883 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(), |
828 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, | 884 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, |
829 true, false, ChromeAutocompleteSchemeClassifier(profile_.get())); | 885 true, false, TestSchemeClassifier()); |
830 autocomplete_->Start(input, false); | 886 autocomplete_->Start(input, false); |
831 if (!autocomplete_->done()) | 887 if (!autocomplete_->done()) |
832 base::MessageLoop::current()->Run(); | 888 base::MessageLoop::current()->Run(); |
833 } | 889 } |
834 } | 890 } |
835 | 891 |
836 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { | 892 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { |
837 AutocompleteInput input( | 893 AutocompleteInput input( |
838 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), | 894 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), |
839 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, | 895 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, |
840 ChromeAutocompleteSchemeClassifier(profile_.get())); | 896 TestSchemeClassifier()); |
841 autocomplete_->Start(input, false); | 897 autocomplete_->Start(input, false); |
842 EXPECT_TRUE(autocomplete_->matches().empty()); | 898 EXPECT_TRUE(autocomplete_->matches().empty()); |
843 } | 899 } |
844 | 900 |
845 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) { | 901 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) { |
846 // A URL that matches due to a match in the punycode URL are allowed to be the | 902 // A URL that matches due to a match in the punycode URL are allowed to be the |
847 // default match if the URL doesn't get rendered as international characters | 903 // default match if the URL doesn't get rendered as international characters |
848 // in the given locale. | 904 // in the given locale. |
849 const UrlAndLegalDefault expected_true[] = { | 905 const UrlAndLegalDefault expected_true[] = { |
850 { "http://puny.xn--1lq90ic7f1rc.cn/", true }, | 906 { "http://puny.xn--1lq90ic7f1rc.cn/", true }, |
(...skipping 14 matching lines...) Expand all Loading... |
865 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_true, | 921 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_true, |
866 arraysize(expected_true)); | 922 arraysize(expected_true)); |
867 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, | 923 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, |
868 expected_true, arraysize(expected_true)); | 924 expected_true, arraysize(expected_true)); |
869 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, | 925 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, |
870 expected_true, arraysize(expected_true)); | 926 expected_true, arraysize(expected_true)); |
871 // Set the language so the punycode part of the URL is rendered as | 927 // Set the language so the punycode part of the URL is rendered as |
872 // international characters. Then this match should not be allowed to be | 928 // international characters. Then this match should not be allowed to be |
873 // the default match if the inline autocomplete text starts in the middle | 929 // the default match if the inline autocomplete text starts in the middle |
874 // of the international characters. | 930 // of the international characters. |
875 profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "zh-CN"); | 931 EXPECT_CALL(*client_, GetAcceptLanguages()) |
| 932 .WillRepeatedly(testing::Return("zh-CN")); |
876 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected_true, | 933 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected_true, |
877 arraysize(expected_true)); | 934 arraysize(expected_true)); |
878 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected_true, | 935 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected_true, |
879 arraysize(expected_true)); | 936 arraysize(expected_true)); |
880 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected_false, | 937 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected_false, |
881 arraysize(expected_false)); | 938 arraysize(expected_false)); |
882 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected_false, | 939 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected_false, |
883 arraysize(expected_false)); | 940 arraysize(expected_false)); |
884 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected_false, | 941 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected_false, |
885 arraysize(expected_false)); | 942 arraysize(expected_false)); |
886 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_false, | 943 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_false, |
887 arraysize(expected_false)); | 944 arraysize(expected_false)); |
888 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, | 945 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, |
889 expected_true, arraysize(expected_true)); | 946 expected_true, arraysize(expected_true)); |
890 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, | 947 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, |
891 expected_true, arraysize(expected_true)); | 948 expected_true, arraysize(expected_true)); |
892 } | 949 } |
893 | 950 |
894 TEST_F(HistoryURLProviderTest, CullSearchResults) { | 951 TEST_F(HistoryURLProviderTest, CullSearchResults) { |
895 // Set up a default search engine. | 952 // Set up a default search engine. |
896 TemplateURLData data; | 953 TemplateURLData data; |
897 data.SetShortName(ASCIIToUTF16("TestEngine")); | 954 data.SetShortName(ASCIIToUTF16("TestEngine")); |
898 data.SetKeyword(ASCIIToUTF16("TestEngine")); | 955 data.SetKeyword(ASCIIToUTF16("TestEngine")); |
899 data.SetURL("http://testsearch.com/?q={searchTerms}"); | 956 data.SetURL("http://testsearch.com/?q={searchTerms}"); |
900 TemplateURLService* template_url_service = | 957 TemplateURLService* template_url_service = client_->GetTemplateURLService(); |
901 TemplateURLServiceFactory::GetForProfile(profile_.get()); | |
902 TemplateURL* template_url = new TemplateURL(data); | 958 TemplateURL* template_url = new TemplateURL(data); |
903 template_url_service->Add(template_url); | 959 template_url_service->Add(template_url); |
904 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 960 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
905 template_url_service->Load(); | 961 template_url_service->Load(); |
906 | 962 |
907 // URLs we will be using, plus the visit counts they will initially get | 963 // URLs we will be using, plus the visit counts they will initially get |
908 // (the redirect set below will also increment the visit counts). We want | 964 // (the redirect set below will also increment the visit counts). We want |
909 // the results to be in A,B,C order. Note also that our visit counts are | 965 // the results to be in A,B,C order. Note also that our visit counts are |
910 // all high enough so that domain synthesizing won't get triggered. | 966 // all high enough so that domain synthesizing won't get triggered. |
911 struct TestCase { | 967 struct TestCase { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 }; | 1052 }; |
997 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 1053 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
998 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " | 1054 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " |
999 << test_cases[i].input << ", trim_http: " | 1055 << test_cases[i].input << ", trim_http: " |
1000 << test_cases[i].trim_http); | 1056 << test_cases[i].trim_http); |
1001 | 1057 |
1002 AutocompleteInput input( | 1058 AutocompleteInput input( |
1003 ASCIIToUTF16(test_cases[i].input), base::string16::npos, std::string(), | 1059 ASCIIToUTF16(test_cases[i].input), base::string16::npos, std::string(), |
1004 GURL("about:blank"), metrics::OmniboxEventProto::INVALID_SPEC, false, | 1060 GURL("about:blank"), metrics::OmniboxEventProto::INVALID_SPEC, false, |
1005 false, true, true, false, | 1061 false, true, true, false, |
1006 ChromeAutocompleteSchemeClassifier(profile_.get())); | 1062 TestSchemeClassifier()); |
1007 AutocompleteMatch match(autocomplete_->SuggestExactInput( | 1063 AutocompleteMatch match(autocomplete_->SuggestExactInput( |
1008 input, input.canonicalized_url(), test_cases[i].trim_http)); | 1064 input, input.canonicalized_url(), test_cases[i].trim_http)); |
1009 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); | 1065 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); |
1010 for (size_t match_index = 0; match_index < match.contents_class.size(); | 1066 for (size_t match_index = 0; match_index < match.contents_class.size(); |
1011 ++match_index) { | 1067 ++match_index) { |
1012 EXPECT_EQ(test_cases[i].offsets[match_index], | 1068 EXPECT_EQ(test_cases[i].offsets[match_index], |
1013 match.contents_class[match_index].offset); | 1069 match.contents_class[match_index].offset); |
1014 EXPECT_EQ(ACMatchClassification::URL | | 1070 EXPECT_EQ(ACMatchClassification::URL | |
1015 (match_index == test_cases[i].match_classification_index ? | 1071 (match_index == test_cases[i].match_classification_index ? |
1016 ACMatchClassification::MATCH : 0), | 1072 ACMatchClassification::MATCH : 0), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 // the default experimental scoring. | 1165 // the default experimental scoring. |
1110 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 1166 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
1111 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 1167 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
1112 std::string(), false, output, max_matches)); | 1168 std::string(), false, output, max_matches)); |
1113 for (int j = 0; j < max_matches; ++j) { | 1169 for (int j = 0; j < max_matches; ++j) { |
1114 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 1170 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
1115 matches_[j].relevance); | 1171 matches_[j].relevance); |
1116 } | 1172 } |
1117 } | 1173 } |
1118 } | 1174 } |
OLD | NEW |