| 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/files/scoped_temp_dir.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/history/core/browser/history_database_params.h" | |
| 20 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
| 21 #include "components/history/core/browser/url_database.h" | 20 #include "components/history/core/browser/url_database.h" |
| 22 #include "components/history/core/test/test_history_database.h" | 21 #include "components/history/core/test/history_service_test_util.h" |
| 23 #include "components/metrics/proto/omnibox_event.pb.h" | 22 #include "components/metrics/proto/omnibox_event.pb.h" |
| 24 #include "components/metrics/proto/omnibox_input_type.pb.h" | 23 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 25 #include "components/omnibox/browser/autocomplete_match.h" | 24 #include "components/omnibox/browser/autocomplete_match.h" |
| 26 #include "components/omnibox/browser/autocomplete_provider.h" | 25 #include "components/omnibox/browser/autocomplete_provider.h" |
| 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 26 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 28 #include "components/omnibox/browser/autocomplete_result.h" | 27 #include "components/omnibox/browser/autocomplete_result.h" |
| 29 #include "components/omnibox/browser/history_quick_provider.h" | 28 #include "components/omnibox/browser/history_quick_provider.h" |
| 30 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | 29 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 31 #include "components/omnibox/browser/test_scheme_classifier.h" | 30 #include "components/omnibox/browser/test_scheme_classifier.h" |
| 32 #include "components/search_engines/default_search_manager.h" | 31 #include "components/search_engines/default_search_manager.h" |
| 33 #include "components/search_engines/search_terms_data.h" | 32 #include "components/search_engines/search_terms_data.h" |
| 34 #include "components/search_engines/template_url.h" | 33 #include "components/search_engines/template_url.h" |
| 35 #include "components/search_engines/template_url_service.h" | 34 #include "components/search_engines/template_url_service.h" |
| 36 #include "components/url_formatter/url_fixer.h" | 35 #include "components/url_formatter/url_fixer.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 37 |
| 39 using base::ASCIIToUTF16; | 38 using base::ASCIIToUTF16; |
| 40 using base::Time; | 39 using base::Time; |
| 41 using base::TimeDelta; | 40 using base::TimeDelta; |
| 42 | 41 |
| 43 namespace { | 42 namespace { |
| 44 | 43 |
| 44 const char kDefaultAcceptLanguages[] = "en-US,en,ko"; |
| 45 |
| 45 struct TestURLInfo { | 46 struct TestURLInfo { |
| 46 const char* url; | 47 const char* url; |
| 47 const char* title; | 48 const char* title; |
| 48 int visit_count; | 49 int visit_count; |
| 49 int typed_count; | 50 int typed_count; |
| 50 int age_in_days; | 51 int age_in_days; |
| 51 } test_db[] = { | 52 } test_db[] = { |
| 52 {"http://www.google.com/", "Google", 3, 3, 80}, | 53 {"http://www.google.com/", "Google", 3, 3, 80}, |
| 53 | 54 |
| 54 // High-quality pages should get a host synthesized as a lower-quality match. | 55 // High-quality pages should get a host synthesized as a lower-quality match. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // For experimental HUP scoring test. | 147 // For experimental HUP scoring test. |
| 147 {"http://7.com/1a", "One", 8, 4, 4}, | 148 {"http://7.com/1a", "One", 8, 4, 4}, |
| 148 {"http://7.com/2a", "Two A", 4, 2, 8}, | 149 {"http://7.com/2a", "Two A", 4, 2, 8}, |
| 149 {"http://7.com/2b", "Two B", 4, 1, 8}, | 150 {"http://7.com/2b", "Two B", 4, 1, 8}, |
| 150 {"http://7.com/3a", "Three", 2, 1, 16}, | 151 {"http://7.com/3a", "Three", 2, 1, 16}, |
| 151 {"http://7.com/4a", "Four A", 1, 1, 32}, | 152 {"http://7.com/4a", "Four A", 1, 1, 32}, |
| 152 {"http://7.com/4b", "Four B", 1, 1, 64}, | 153 {"http://7.com/4b", "Four B", 1, 1, 64}, |
| 153 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. | 154 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. |
| 154 }; | 155 }; |
| 155 | 156 |
| 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 { | 157 class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient { |
| 176 public: | 158 public: |
| 177 FakeAutocompleteProviderClient() { | 159 FakeAutocompleteProviderClient(bool create_history_db) { |
| 178 set_template_url_service( | 160 set_template_url_service( |
| 179 make_scoped_ptr(new TemplateURLService(nullptr, 0))); | 161 make_scoped_ptr(new TemplateURLService(nullptr, 0))); |
| 162 if (history_dir_.CreateUniqueTempDir()) { |
| 163 history_service_ = history::CreateHistoryService( |
| 164 history_dir_.path(), kDefaultAcceptLanguages, create_history_db); |
| 165 } |
| 180 } | 166 } |
| 181 | 167 |
| 182 const AutocompleteSchemeClassifier& GetSchemeClassifier() const override { | 168 const AutocompleteSchemeClassifier& GetSchemeClassifier() const override { |
| 183 return scheme_classifier_; | 169 return scheme_classifier_; |
| 184 } | 170 } |
| 185 | 171 |
| 186 const SearchTermsData& GetSearchTermsData() const override { | 172 const SearchTermsData& GetSearchTermsData() const override { |
| 187 return search_terms_data_; | 173 return search_terms_data_; |
| 188 } | 174 } |
| 189 | 175 |
| 190 history::HistoryService* GetHistoryService() override { | 176 history::HistoryService* GetHistoryService() override { |
| 191 return &history_service_; | 177 return history_service_.get(); |
| 192 } | 178 } |
| 193 | 179 |
| 194 private: | 180 private: |
| 195 TestSchemeClassifier scheme_classifier_; | 181 TestSchemeClassifier scheme_classifier_; |
| 196 SearchTermsData search_terms_data_; | 182 SearchTermsData search_terms_data_; |
| 197 history::HistoryService history_service_; | 183 base::ScopedTempDir history_dir_; |
| 184 scoped_ptr<history::HistoryService> history_service_; |
| 198 | 185 |
| 199 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient); | 186 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient); |
| 200 }; | 187 }; |
| 201 | 188 |
| 202 } // namespace | 189 } // namespace |
| 203 | 190 |
| 204 class HistoryURLProviderTest : public testing::Test, | 191 class HistoryURLProviderTest : public testing::Test, |
| 205 public AutocompleteProviderListener { | 192 public AutocompleteProviderListener { |
| 206 public: | 193 public: |
| 207 struct UrlAndLegalDefault { | 194 struct UrlAndLegalDefault { |
| 208 std::string url; | 195 std::string url; |
| 209 bool allowed_to_be_default_match; | 196 bool allowed_to_be_default_match; |
| 210 }; | 197 }; |
| 211 | 198 |
| 212 HistoryURLProviderTest() | 199 HistoryURLProviderTest() |
| 213 : sort_matches_(false) { | 200 : sort_matches_(false) { |
| 214 HistoryQuickProvider::set_disabled(true); | 201 HistoryQuickProvider::set_disabled(true); |
| 215 } | 202 } |
| 216 | 203 |
| 217 ~HistoryURLProviderTest() override { | 204 ~HistoryURLProviderTest() override { |
| 218 HistoryQuickProvider::set_disabled(false); | 205 HistoryQuickProvider::set_disabled(false); |
| 219 } | 206 } |
| 220 | 207 |
| 221 // AutocompleteProviderListener: | 208 // AutocompleteProviderListener: |
| 222 void OnProviderUpdate(bool updated_matches) override; | 209 void OnProviderUpdate(bool updated_matches) override; |
| 223 | 210 |
| 224 protected: | 211 protected: |
| 225 // testing::Test | 212 // testing::Test |
| 226 void SetUp() override { | 213 void SetUp() override { ASSERT_TRUE(SetUpImpl(true)); } |
| 227 ASSERT_TRUE(SetUpImpl(false)); | |
| 228 } | |
| 229 void TearDown() override; | 214 void TearDown() override; |
| 230 | 215 |
| 231 // Does the real setup. | 216 // Does the real setup. |
| 232 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT; | 217 bool SetUpImpl(bool create_history_db) WARN_UNUSED_RESULT; |
| 233 | 218 |
| 234 // Fills test data into the history system. | 219 // Fills test data into the history system. |
| 235 void FillData(); | 220 void FillData(); |
| 236 | 221 |
| 237 // Runs an autocomplete query on |text| and checks to see that the returned | 222 // Runs an autocomplete query on |text| and checks to see that the returned |
| 238 // results' destination URLs match those provided. Also allows checking | 223 // results' destination URLs match those provided. Also allows checking |
| 239 // that the input type was identified correctly. | 224 // that the input type was identified correctly. |
| 240 void RunTest(const base::string16& text, | 225 void RunTest(const base::string16& text, |
| 241 const std::string& desired_tld, | 226 const std::string& desired_tld, |
| 242 bool prevent_inline_autocomplete, | 227 bool prevent_inline_autocomplete, |
| 243 const UrlAndLegalDefault* expected_urls, | 228 const UrlAndLegalDefault* expected_urls, |
| 244 size_t num_results, | 229 size_t num_results, |
| 245 metrics::OmniboxInputType::Type* identified_input_type); | 230 metrics::OmniboxInputType::Type* identified_input_type); |
| 246 | 231 |
| 247 // A version of the above without the final |type| output parameter. | 232 // A version of the above without the final |type| output parameter. |
| 248 void RunTest(const base::string16& text, | 233 void RunTest(const base::string16& text, |
| 249 const std::string& desired_tld, | 234 const std::string& desired_tld, |
| 250 bool prevent_inline_autocomplete, | 235 bool prevent_inline_autocomplete, |
| 251 const UrlAndLegalDefault* expected_urls, | 236 const UrlAndLegalDefault* expected_urls, |
| 252 size_t num_results) { | 237 size_t num_results) { |
| 253 metrics::OmniboxInputType::Type type; | 238 metrics::OmniboxInputType::Type type; |
| 254 return RunTest(text, desired_tld, prevent_inline_autocomplete, | 239 return RunTest(text, desired_tld, prevent_inline_autocomplete, |
| 255 expected_urls, num_results, &type); | 240 expected_urls, num_results, &type); |
| 256 } | 241 } |
| 257 | 242 |
| 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_; | 243 base::MessageLoop message_loop_; |
| 263 base::ScopedTempDir history_dir_; | |
| 264 ACMatches matches_; | 244 ACMatches matches_; |
| 265 scoped_ptr<FakeAutocompleteProviderClient> client_; | 245 scoped_ptr<FakeAutocompleteProviderClient> client_; |
| 266 history::HistoryService* history_service_; | |
| 267 scoped_refptr<HistoryURLProvider> autocomplete_; | 246 scoped_refptr<HistoryURLProvider> autocomplete_; |
| 268 // Should the matches be sorted and duplicates removed? | 247 // Should the matches be sorted and duplicates removed? |
| 269 bool sort_matches_; | 248 bool sort_matches_; |
| 270 | 249 |
| 271 private: | 250 private: |
| 272 DISALLOW_COPY_AND_ASSIGN(HistoryURLProviderTest); | 251 DISALLOW_COPY_AND_ASSIGN(HistoryURLProviderTest); |
| 273 }; | 252 }; |
| 274 | 253 |
| 275 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { | 254 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { |
| 276 protected: | 255 protected: |
| 277 void SetUp() override { | 256 void SetUp() override { ASSERT_TRUE(SetUpImpl(false)); } |
| 278 ASSERT_TRUE(SetUpImpl(true)); | |
| 279 } | |
| 280 }; | 257 }; |
| 281 | 258 |
| 282 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest { | 259 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest { |
| 283 protected: | 260 protected: |
| 284 void SetUp() override { | 261 void SetUp() override { |
| 285 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); | 262 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); |
| 286 HistoryURLProviderTest::SetUp(); | 263 HistoryURLProviderTest::SetUp(); |
| 287 } | 264 } |
| 288 | 265 |
| 289 void TearDown() override { | 266 void TearDown() override { |
| 290 HistoryURLProviderTest::TearDown(); | 267 HistoryURLProviderTest::TearDown(); |
| 291 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); | 268 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); |
| 292 } | 269 } |
| 293 }; | 270 }; |
| 294 | 271 |
| 295 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { | 272 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { |
| 296 if (autocomplete_->done()) | 273 if (autocomplete_->done()) |
| 297 base::MessageLoop::current()->QuitWhenIdle(); | 274 base::MessageLoop::current()->QuitWhenIdle(); |
| 298 } | 275 } |
| 299 | 276 |
| 300 bool HistoryURLProviderTest::InitializeHistoryService( | 277 bool HistoryURLProviderTest::SetUpImpl(bool create_history_db) { |
| 301 bool delete_file, bool no_db) { | 278 client_.reset(new FakeAutocompleteProviderClient(create_history_db)); |
| 302 if (!history_dir_.CreateUniqueTempDir()) | 279 if (!client_->GetHistoryService()) |
| 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 | |
| 324 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { | |
| 325 client_.reset(new FakeAutocompleteProviderClient()); | |
| 326 | |
| 327 if (!InitializeHistoryService(true, no_db)) | |
| 328 return false; | 280 return false; |
| 329 EXPECT_CALL(*client_, GetAcceptLanguages()) | 281 EXPECT_CALL(*client_, GetAcceptLanguages()) |
| 330 .WillRepeatedly(testing::Return("en-US,en,ko")); | 282 .WillRepeatedly(testing::Return(kDefaultAcceptLanguages)); |
| 331 | |
| 332 autocomplete_ = new HistoryURLProvider(client_.get(), this); | 283 autocomplete_ = new HistoryURLProvider(client_.get(), this); |
| 333 FillData(); | 284 FillData(); |
| 334 return true; | 285 return true; |
| 335 } | 286 } |
| 336 | 287 |
| 337 void HistoryURLProviderTest::TearDown() { | 288 void HistoryURLProviderTest::TearDown() { |
| 338 autocomplete_ = NULL; | 289 autocomplete_ = NULL; |
| 339 } | 290 } |
| 340 | 291 |
| 341 void HistoryURLProviderTest::FillData() { | 292 void HistoryURLProviderTest::FillData() { |
| 342 // Most visits are a long time ago (some tests require this since we do some | 293 // Most visits are a long time ago (some tests require this since we do some |
| 343 // special logic for things visited very recently). Note that this time must | 294 // special logic for things visited very recently). Note that this time must |
| 344 // be more recent than the "expire history" threshold for the data to be kept | 295 // be more recent than the "expire history" threshold for the data to be kept |
| 345 // in the main database. | 296 // in the main database. |
| 346 // | 297 // |
| 347 // TODO(brettw) It would be nice if we could test this behavior, in which | 298 // TODO(brettw) It would be nice if we could test this behavior, in which |
| 348 // case the time would be specifed in the test_db structure. | 299 // case the time would be specifed in the test_db structure. |
| 349 const Time now = Time::Now(); | 300 const Time now = Time::Now(); |
| 350 | 301 |
| 351 for (size_t i = 0; i < arraysize(test_db); ++i) { | 302 for (size_t i = 0; i < arraysize(test_db); ++i) { |
| 352 const TestURLInfo& cur = test_db[i]; | 303 const TestURLInfo& cur = test_db[i]; |
| 353 const GURL current_url(cur.url); | 304 const GURL current_url(cur.url); |
| 354 history_service_->AddPageWithDetails( | 305 client_->GetHistoryService()->AddPageWithDetails( |
| 355 current_url, base::UTF8ToUTF16(cur.title), cur.visit_count, | 306 current_url, base::UTF8ToUTF16(cur.title), cur.visit_count, |
| 356 cur.typed_count, now - TimeDelta::FromDays(cur.age_in_days), false, | 307 cur.typed_count, now - TimeDelta::FromDays(cur.age_in_days), false, |
| 357 history::SOURCE_BROWSED); | 308 history::SOURCE_BROWSED); |
| 358 } | 309 } |
| 359 | 310 |
| 360 history_service_->AddPageWithDetails( | 311 client_->GetHistoryService()->AddPageWithDetails( |
| 361 GURL("http://pa/"), base::UTF8ToUTF16("pa"), 0, 0, | 312 GURL("http://pa/"), base::UTF8ToUTF16("pa"), 0, 0, |
| 362 Time::Now() - | 313 Time::Now() - |
| 363 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), | 314 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), |
| 364 false, history::SOURCE_BROWSED); | 315 false, history::SOURCE_BROWSED); |
| 365 } | 316 } |
| 366 | 317 |
| 367 void HistoryURLProviderTest::RunTest( | 318 void HistoryURLProviderTest::RunTest( |
| 368 const base::string16& text, | 319 const base::string16& text, |
| 369 const std::string& desired_tld, | 320 const std::string& desired_tld, |
| 370 bool prevent_inline_autocomplete, | 321 bool prevent_inline_autocomplete, |
| 371 const UrlAndLegalDefault* expected_urls, | 322 const UrlAndLegalDefault* expected_urls, |
| 372 size_t num_results, | 323 size_t num_results, |
| 373 metrics::OmniboxInputType::Type* identified_input_type) { | 324 metrics::OmniboxInputType::Type* identified_input_type) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // all high enough so that domain synthesizing won't get triggered. | 492 // all high enough so that domain synthesizing won't get triggered. |
| 542 struct TestCase { | 493 struct TestCase { |
| 543 const char* url; | 494 const char* url; |
| 544 int count; | 495 int count; |
| 545 } test_cases[] = { | 496 } test_cases[] = { |
| 546 {"http://redirects/A", 30}, | 497 {"http://redirects/A", 30}, |
| 547 {"http://redirects/B", 20}, | 498 {"http://redirects/B", 20}, |
| 548 {"http://redirects/C", 10} | 499 {"http://redirects/C", 10} |
| 549 }; | 500 }; |
| 550 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 501 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 551 history_service_->AddPageWithDetails(GURL(test_cases[i].url), | 502 client_->GetHistoryService()->AddPageWithDetails( |
| 552 ASCIIToUTF16("Title"), test_cases[i].count, test_cases[i].count, | 503 GURL(test_cases[i].url), ASCIIToUTF16("Title"), test_cases[i].count, |
| 553 Time::Now(), false, history::SOURCE_BROWSED); | 504 test_cases[i].count, Time::Now(), false, history::SOURCE_BROWSED); |
| 554 } | 505 } |
| 555 | 506 |
| 556 // Create a B->C->A redirect chain, but set the visit counts such that they | 507 // Create a B->C->A redirect chain, but set the visit counts such that they |
| 557 // will appear in A,B,C order in the results. The autocomplete query will | 508 // will appear in A,B,C order in the results. The autocomplete query will |
| 558 // search for the most recent visit when looking for redirects, so this will | 509 // search for the most recent visit when looking for redirects, so this will |
| 559 // be found even though the previous visits had no redirects. | 510 // be found even though the previous visits had no redirects. |
| 560 history::RedirectList redirects_to_a; | 511 history::RedirectList redirects_to_a; |
| 561 redirects_to_a.push_back(GURL(test_cases[1].url)); | 512 redirects_to_a.push_back(GURL(test_cases[1].url)); |
| 562 redirects_to_a.push_back(GURL(test_cases[2].url)); | 513 redirects_to_a.push_back(GURL(test_cases[2].url)); |
| 563 redirects_to_a.push_back(GURL(test_cases[0].url)); | 514 redirects_to_a.push_back(GURL(test_cases[0].url)); |
| 564 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), | 515 client_->GetHistoryService()->AddPage( |
| 565 NULL, 0, GURL(), redirects_to_a, ui::PAGE_TRANSITION_TYPED, | 516 GURL(test_cases[0].url), base::Time::Now(), NULL, 0, GURL(), |
| 566 history::SOURCE_BROWSED, true); | 517 redirects_to_a, ui::PAGE_TRANSITION_TYPED, history::SOURCE_BROWSED, true); |
| 567 | 518 |
| 568 // Because all the results are part of a redirect chain with other results, | 519 // Because all the results are part of a redirect chain with other results, |
| 569 // all but the first one (A) should be culled. We should get the default | 520 // all but the first one (A) should be culled. We should get the default |
| 570 // "what you typed" result, plus this one. | 521 // "what you typed" result, plus this one. |
| 571 const base::string16 typing(ASCIIToUTF16("http://redirects/")); | 522 const base::string16 typing(ASCIIToUTF16("http://redirects/")); |
| 572 const UrlAndLegalDefault expected_results[] = { | 523 const UrlAndLegalDefault expected_results[] = { |
| 573 { test_cases[0].url, false }, | 524 { test_cases[0].url, false }, |
| 574 { base::UTF16ToUTF8(typing), true } | 525 { base::UTF16ToUTF8(typing), true } |
| 575 }; | 526 }; |
| 576 RunTest(typing, std::string(), true, expected_results, | 527 RunTest(typing, std::string(), true, expected_results, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 { "http://www.17173.com/", true } | 641 { "http://www.17173.com/", true } |
| 691 }; | 642 }; |
| 692 RunTest(ASCIIToUTF16("17173"), std::string(), false, fixup_5, | 643 RunTest(ASCIIToUTF16("17173"), std::string(), false, fixup_5, |
| 693 arraysize(fixup_5)); | 644 arraysize(fixup_5)); |
| 694 } | 645 } |
| 695 | 646 |
| 696 // Make sure the results for the input 'p' don't change between the first and | 647 // Make sure the results for the input 'p' don't change between the first and |
| 697 // second passes. | 648 // second passes. |
| 698 TEST_F(HistoryURLProviderTest, EmptyVisits) { | 649 TEST_F(HistoryURLProviderTest, EmptyVisits) { |
| 699 // Wait for history to create the in memory DB. | 650 // Wait for history to create the in memory DB. |
| 700 BlockUntilHistoryProcessesPendingRequests(); | 651 history::BlockUntilHistoryProcessesPendingRequests( |
| 652 client_->GetHistoryService()); |
| 701 | 653 |
| 702 AutocompleteInput input( | 654 AutocompleteInput input( |
| 703 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(), | 655 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(), |
| 704 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | 656 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, |
| 705 TestSchemeClassifier()); | 657 TestSchemeClassifier()); |
| 706 autocomplete_->Start(input, false); | 658 autocomplete_->Start(input, false); |
| 707 // HistoryURLProvider shouldn't be done (waiting on async results). | 659 // HistoryURLProvider shouldn't be done (waiting on async results). |
| 708 EXPECT_FALSE(autocomplete_->done()); | 660 EXPECT_FALSE(autocomplete_->done()); |
| 709 | 661 |
| 710 // We should get back an entry for pandora. | 662 // We should get back an entry for pandora. |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 // all high enough so that domain synthesizing won't get triggered. | 918 // all high enough so that domain synthesizing won't get triggered. |
| 967 struct TestCase { | 919 struct TestCase { |
| 968 const char* url; | 920 const char* url; |
| 969 int count; | 921 int count; |
| 970 } test_cases[] = { | 922 } test_cases[] = { |
| 971 {"https://testsearch.com/", 30}, | 923 {"https://testsearch.com/", 30}, |
| 972 {"https://testsearch.com/?q=foobar", 20}, | 924 {"https://testsearch.com/?q=foobar", 20}, |
| 973 {"http://foobar.com/", 10} | 925 {"http://foobar.com/", 10} |
| 974 }; | 926 }; |
| 975 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 927 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 976 history_service_->AddPageWithDetails(GURL(test_cases[i].url), | 928 client_->GetHistoryService()->AddPageWithDetails( |
| 977 base::UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, | 929 GURL(test_cases[i].url), base::UTF8ToUTF16("Title"), |
| 978 Time::Now(), false, history::SOURCE_BROWSED); | 930 test_cases[i].count, test_cases[i].count, Time::Now(), false, |
| 931 history::SOURCE_BROWSED); |
| 979 } | 932 } |
| 980 | 933 |
| 981 // We should not see search URLs when typing a previously used query. | 934 // We should not see search URLs when typing a previously used query. |
| 982 const UrlAndLegalDefault expected_when_searching_query[] = { | 935 const UrlAndLegalDefault expected_when_searching_query[] = { |
| 983 { test_cases[2].url, false } | 936 { test_cases[2].url, false } |
| 984 }; | 937 }; |
| 985 RunTest(ASCIIToUTF16("foobar"), std::string(), true, | 938 RunTest(ASCIIToUTF16("foobar"), std::string(), true, |
| 986 expected_when_searching_query, arraysize(expected_when_searching_query)); | 939 expected_when_searching_query, arraysize(expected_when_searching_query)); |
| 987 | 940 |
| 988 // We should not see search URLs when typing the search engine name. | 941 // We should not see search URLs when typing the search engine name. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 // the default experimental scoring. | 1118 // the default experimental scoring. |
| 1166 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 1119 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
| 1167 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 1120 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
| 1168 std::string(), false, output, max_matches)); | 1121 std::string(), false, output, max_matches)); |
| 1169 for (int j = 0; j < max_matches; ++j) { | 1122 for (int j = 0; j < max_matches; ++j) { |
| 1170 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 1123 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
| 1171 matches_[j].relevance); | 1124 matches_[j].relevance); |
| 1172 } | 1125 } |
| 1173 } | 1126 } |
| 1174 } | 1127 } |
| OLD | NEW |