OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/prefs/pref_service.h" |
| 6 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 7 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 8 #include "chrome/browser/search/search.h" |
| 9 #include "chrome/browser/ui/omnibox/omnibox_controller.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 class OmniboxControllerTest : public testing::Test { |
| 17 protected: |
| 18 OmniboxControllerTest(); |
| 19 virtual ~OmniboxControllerTest(); |
| 20 |
| 21 void CreateController(); |
| 22 void AssertProviders(int expected_providers); |
| 23 |
| 24 PrefService* GetPrefs() { return profile_.GetPrefs(); } |
| 25 const ACProviders* GetAutocompleteProviders() const { |
| 26 return omnibox_controller_->autocomplete_controller()->providers(); |
| 27 } |
| 28 |
| 29 private: |
| 30 TestingProfile profile_; |
| 31 scoped_ptr<OmniboxController> omnibox_controller_; |
| 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(OmniboxControllerTest); |
| 34 }; |
| 35 |
| 36 OmniboxControllerTest::OmniboxControllerTest() { |
| 37 } |
| 38 |
| 39 OmniboxControllerTest::~OmniboxControllerTest() { |
| 40 } |
| 41 |
| 42 void OmniboxControllerTest::CreateController() { |
| 43 omnibox_controller_.reset(new OmniboxController(NULL, &profile_)); |
| 44 } |
| 45 |
| 46 // Checks that the list of autocomplete providers used by the OmniboxController |
| 47 // matches the one in the |expected_providers| bit field. |
| 48 void OmniboxControllerTest::AssertProviders(int expected_providers) { |
| 49 const ACProviders* providers = GetAutocompleteProviders(); |
| 50 |
| 51 for (size_t i = 0; i < providers->size(); ++i) { |
| 52 // Ensure this is a provider we wanted. |
| 53 int type = providers->at(i)->type(); |
| 54 ASSERT_TRUE(expected_providers & type); |
| 55 |
| 56 // Remove it from expectations so we fail if it's there twice. |
| 57 expected_providers &= ~type; |
| 58 } |
| 59 |
| 60 // Ensure we saw all the providers we expected. |
| 61 ASSERT_EQ(0, expected_providers); |
| 62 } |
| 63 |
| 64 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { |
| 65 CreateController(); |
| 66 // First collect the basic providers. |
| 67 int observed_providers = 0; |
| 68 const ACProviders* providers = GetAutocompleteProviders(); |
| 69 for (size_t i = 0; i < providers->size(); ++i) |
| 70 observed_providers |= providers->at(i)->type(); |
| 71 // Ensure we have at least one provider. |
| 72 ASSERT_NE(0, observed_providers); |
| 73 |
| 74 // Ensure that a valid kInstantUIZeroSuggestUrlPrefix adds TYPE_ZERO_SUGGEST. |
| 75 int providers_with_zero_suggest = |
| 76 observed_providers | AutocompleteProvider::TYPE_ZERO_SUGGEST; |
| 77 GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, |
| 78 "http://dummy.url.com/"); |
| 79 CreateController(); |
| 80 AssertProviders(providers_with_zero_suggest); |
| 81 GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, std::string()); |
| 82 |
| 83 // Ensure instant extended includes all the basic ones save for those that are |
| 84 // not expected to run in instant extended. |
| 85 int providers_with_instant_extended = |
| 86 observed_providers & |
| 87 ~AutocompleteProvider::TYPE_HISTORY_CONTENTS & |
| 88 ~AutocompleteProvider::TYPE_SHORTCUTS; |
| 89 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass |
| 90 // the Instant suggestion through via FinalizeInstantQuery. |
| 91 chrome::EnableInstantExtendedAPIForTesting(); |
| 92 CreateController(); |
| 93 AssertProviders(providers_with_instant_extended); |
| 94 |
| 95 } |
| 96 |
| 97 } // namespace |
OLD | NEW |