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 class OmniboxControllerTest : public testing::Test { 15 protected: 16 OmniboxControllerTest(); 17 virtual ~OmniboxControllerTest(); 18 19 void CreateController(); 20 void AssertProviders(int expected_providers); 21 22 PrefService* GetPrefs() { return profile_.GetPrefs(); } 23 const ACProviders* GetAutocompleteProviders() const { 24 return omnibox_controller_->autocomplete_controller()->providers(); 25 } 26 27 private: 28 TestingProfile profile_; 29 scoped_ptr<OmniboxController> omnibox_controller_; 30 31 DISALLOW_COPY_AND_ASSIGN(OmniboxControllerTest); 32 }; 33 34 OmniboxControllerTest::OmniboxControllerTest() { 35 } 36 37 OmniboxControllerTest::~OmniboxControllerTest() { 38 } 39 40 void OmniboxControllerTest::CreateController() { 41 omnibox_controller_.reset(new OmniboxController(NULL, &profile_)); 42 } 43 44 // Checks that the list of autocomplete providers used by the OmniboxController 45 // matches the one in the |expected_providers| bit field. 46 void OmniboxControllerTest::AssertProviders(int expected_providers) { 47 const ACProviders* providers = GetAutocompleteProviders(); 48 49 for (size_t i = 0; i < providers->size(); ++i) { 50 // Ensure this is a provider we wanted. 51 int type = providers->at(i)->type(); 52 ASSERT_TRUE(expected_providers & type); 53 54 // Remove it from expectations so we fail if it's there twice. 55 expected_providers &= ~type; 56 } 57 58 // Ensure we saw all the providers we expected. 59 ASSERT_EQ(0, expected_providers); 60 } 61 62 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { 63 CreateController(); 64 // First collect the basic providers. 65 int observed_providers = 0; 66 const ACProviders* providers = GetAutocompleteProviders(); 67 for (size_t i = 0; i < providers->size(); ++i) 68 observed_providers |= providers->at(i)->type(); 69 // Ensure we have at least one provider. 70 ASSERT_NE(0, observed_providers); 71 72 // Ensure instant extended includes all the provides in classic Chrome. 73 int providers_with_instant_extended = observed_providers; 74 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass 75 // the Instant suggestion through via FinalizeInstantQuery. 76 chrome::EnableInstantExtendedAPIForTesting(); 77 CreateController(); 78 AssertProviders(providers_with_instant_extended); 79 } 80