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

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: Modified tests, answered Sreeram. 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..a3f913514cfd4606fac75b6f165143f054813a8e
--- /dev/null
+++ b/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc
@@ -0,0 +1,96 @@
+// 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 {
+ public:
+ virtual void SetUp() OVERRIDE {
Peter Kasting 2013/04/25 18:24:55 Nit: Do not define virtual (and other non-cheap) f
beaudoin 2013/04/25 20:34:51 Done.
+ profile_.reset(new TestingProfile);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ omnibox_controller_.reset();
+ profile_.reset();
Peter Kasting 2013/04/25 18:24:55 Nit: Do we actually need to tear these down here i
beaudoin 2013/04/25 20:34:51 Done.
+ }
+
+ protected:
+ void CreateController() {
+ omnibox_controller_.reset(new OmniboxController(NULL, profile_.get()));
+ }
+
+ void AssertProviders(int expected_providers);
+
+ scoped_ptr<TestingProfile> profile_;
Peter Kasting 2013/04/25 18:24:55 Google style bans non-private data members in clas
beaudoin 2013/04/25 20:34:51 Done.
+ scoped_ptr<OmniboxController> omnibox_controller_;
+};
Peter Kasting 2013/04/25 18:24:55 Nit: DISALLOW_COPY_AND_ASSIGN
beaudoin 2013/04/25 20:34:51 Forced me to add an empty constructor though, so I
+
+// 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_EQ(type, expected_providers & type);
Peter Kasting 2013/04/25 18:24:55 Nit: What about just ASSERT_TRUE(expected_provider
beaudoin 2013/04/25 20:34:51 Done.
+
+ // 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();
+ // List of the autocomplete providers we expect by default.
+ int expected_providers =
+ AutocompleteProvider::TYPE_BOOKMARK |
+ AutocompleteProvider::TYPE_BUILTIN |
+ AutocompleteProvider::TYPE_HISTORY_CONTENTS |
+ AutocompleteProvider::TYPE_HISTORY_QUICK |
+ AutocompleteProvider::TYPE_HISTORY_URL |
+ AutocompleteProvider::TYPE_KEYWORD |
+ AutocompleteProvider::TYPE_SEARCH |
+ AutocompleteProvider::TYPE_SHORTCUTS;
Peter Kasting 2013/04/25 18:24:55 I'm a little unhappy about this. It doesn't seem
sreeram 2013/04/25 18:47:51 I think the test is valuable. If somebody changes
Peter Kasting 2013/04/25 19:05:07 We define the two sets right next to each other.
beaudoin 2013/04/25 19:14:57 What if I only checked the difference, instead of
Peter Kasting 2013/04/25 19:45:27 That would improve things. I still feel like it's
beaudoin 2013/04/25 20:34:51 I'm leaving it in, if only because it tests that t
+ AssertProviders(expected_providers);
+
+ // With a valid kInstantUIZeroSuggestUrlPrefix we expect the exact same set
+ // in addition to TYPE_ZERO_SUGGEST.
+ int providers_with_zero_suggest =
+ expected_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());
+
+ // With instant extended we expect the exact same set, save from a couple of
+ // providers that should not be running.
+ int providers_with_instant_extended =
+ expected_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