Chromium Code Reviews| Index: chrome/browser/ui/omnibox/omnibox_controller_unittest.cc |
| diff --git a/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc b/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..de8a4fa5834aca1ef672df37db82dcad583c5c2a |
| --- /dev/null |
| +++ b/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/prefs/pref_service.h" |
| +#include "chrome/browser/autocomplete/autocomplete_controller.h" |
| +#include "chrome/browser/autocomplete/autocomplete_provider.h" |
| +#include "chrome/browser/search/search.h" |
| +#include "chrome/browser/ui/omnibox/omnibox_controller.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +class OmniboxControllerTest : public testing::Test { |
| + protected: |
| + OmniboxControllerTest(); |
| + virtual ~OmniboxControllerTest(); |
| + |
| + void CreateController(); |
| + void AssertProviders(int expected_providers); |
| + |
| + TestingProfile& profile() { return profile_; } |
|
Peter Kasting
2013/04/25 20:52:09
Nit: It seems like callers only want the PrefServi
beaudoin
2013/04/25 21:09:46
Done.
|
| + OmniboxController* omnibox_controller() { return omnibox_controller_.get(); } |
|
Peter Kasting
2013/04/25 20:52:09
Nit: It seems like callers only want the providers
beaudoin
2013/04/25 21:09:46
Done.
|
| + |
| + private: |
| + TestingProfile profile_; |
| + scoped_ptr<OmniboxController> omnibox_controller_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OmniboxControllerTest); |
| +}; |
| + |
| +OmniboxControllerTest::OmniboxControllerTest() { |
| +} |
| + |
| +OmniboxControllerTest::~OmniboxControllerTest() { |
| +} |
| + |
| +void OmniboxControllerTest::CreateController() { |
| + omnibox_controller_.reset(new OmniboxController(NULL, &profile_)); |
| +} |
| + |
| +// Checks that the list of autocomplete providers used by the OmniboxController |
| +// matches the one in the |expected_providers| bit field. |
| +void OmniboxControllerTest::AssertProviders(int expected_providers) { |
| + const ACProviders* providers = |
| + omnibox_controller()->autocomplete_controller()->providers(); |
| + |
| + for (size_t i = 0; i < providers->size(); ++i) { |
| + // Ensure this is a provider we wanted. |
| + int type = providers->at(i)->type(); |
| + ASSERT_TRUE(expected_providers & type); |
| + |
| + // Remove it from expectations so we fail if it's there twice. |
| + expected_providers &= ~type; |
| + } |
| + |
| + // Ensure we saw all the providers we expected. |
| + ASSERT_EQ(0, expected_providers); |
| +} |
| + |
| +TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { |
| + CreateController(); |
| + // First collect the basic providers. |
| + int observed_providers = 0; |
| + const ACProviders* providers = |
| + omnibox_controller()->autocomplete_controller()->providers(); |
| + for (size_t i = 0; i < providers->size(); ++i) |
| + observed_providers |= providers->at(i)->type(); |
| + // Ensure we have at least one provider. |
| + ASSERT_NE(0, observed_providers); |
| + |
| + // Ensure that a valid kInstantUIZeroSuggestUrlPrefix adds TYPE_ZERO_SUGGEST. |
| + int providers_with_zero_suggest = |
| + observed_providers | AutocompleteProvider::TYPE_ZERO_SUGGEST; |
| + profile().GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, |
| + "http://dummy.url.com/"); |
| + CreateController(); |
| + AssertProviders(providers_with_zero_suggest); |
| + profile().GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, |
| + std::string()); |
| + |
| + // Ensure instant extended includes all the basic ones save for those that are |
| + // not expected to run in instant extended. |
| + int providers_with_instant_extended = |
| + observed_providers & |
| + ~AutocompleteProvider::TYPE_HISTORY_CONTENTS & |
| + ~AutocompleteProvider::TYPE_SHORTCUTS; |
| + // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass |
| + // the Instant suggestion through via FinalizeInstantQuery. |
| + chrome::EnableInstantExtendedAPIForTesting(); |
| + CreateController(); |
| + AssertProviders(providers_with_instant_extended); |
| + |
| +} |
| + |
| +} // namespace |