| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/test/scoped_feature_list.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 23 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 23 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 24 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
| 24 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 25 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
| 26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 27 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 27 #include "chrome/browser/signin/account_tracker_service_factory.h" | 28 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 28 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| (...skipping 3486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3516 } | 3517 } |
| 3517 | 3518 |
| 3518 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3519 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
| 3519 AutocompleteInput input( | 3520 AutocompleteInput input( |
| 3520 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), | 3521 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
| 3521 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, | 3522 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
| 3522 ChromeAutocompleteSchemeClassifier(&profile_)); | 3523 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3523 provider_->Start(input, false); | 3524 provider_->Start(input, false); |
| 3524 EXPECT_TRUE(provider_->matches().empty()); | 3525 EXPECT_TRUE(provider_->matches().empty()); |
| 3525 } | 3526 } |
| 3527 |
| 3528 TEST_F(SearchProviderTest, SendsWarmUpRequestOnFocus) { |
| 3529 AutocompleteInput input( |
| 3530 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
| 3531 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
| 3532 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3533 |
| 3534 // First, verify that without the warm-up feature enabled, the provider |
| 3535 // immediately terminates with no matches. |
| 3536 provider_->Start(input, false); |
| 3537 // RunUntilIdle so that SearchProvider has a chance to create the URLFetchers |
| 3538 // (if it wants to, which it shouldn't in this case). |
| 3539 base::RunLoop().RunUntilIdle(); |
| 3540 EXPECT_TRUE(provider_->done()); |
| 3541 EXPECT_TRUE(provider_->matches().empty()); |
| 3542 |
| 3543 // Then, check the behavior with the warm-up feature enabled. |
| 3544 base::test::ScopedFeatureList feature_list; |
| 3545 feature_list.InitAndEnableFeature(omnibox::kSearchProviderWarmUpOnFocus); |
| 3546 provider_->Start(input, false); |
| 3547 // RunUntilIdle so that SearchProvider create the URLFetcher. |
| 3548 base::RunLoop().RunUntilIdle(); |
| 3549 EXPECT_FALSE(provider_->done()); |
| 3550 EXPECT_TRUE(provider_->matches().empty()); |
| 3551 // Make sure the default provider's suggest service was queried. |
| 3552 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 3553 SearchProvider::kDefaultProviderURLFetcherID); |
| 3554 EXPECT_TRUE(fetcher); |
| 3555 // Even if the fetcher returns results, we should still have no suggestions |
| 3556 // (though the provider should now be done). |
| 3557 fetcher->set_response_code(200); |
| 3558 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])"); |
| 3559 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 3560 RunTillProviderDone(); |
| 3561 EXPECT_TRUE(provider_->done()); |
| 3562 EXPECT_TRUE(provider_->matches().empty()); |
| 3563 } |
| OLD | NEW |