Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Unified Diff: chrome/browser/ui/omnibox/omnibox_controller_unittest.cc

Issue 13932034: Omnibox refactor, introduced OmniboxController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Answered Peter's comments. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698