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 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.
| |
25 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.
| |
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 = | |
48 omnibox_controller()->autocomplete_controller()->providers(); | |
49 | |
50 for (size_t i = 0; i < providers->size(); ++i) { | |
51 // Ensure this is a provider we wanted. | |
52 int type = providers->at(i)->type(); | |
53 ASSERT_TRUE(expected_providers & type); | |
54 | |
55 // Remove it from expectations so we fail if it's there twice. | |
56 expected_providers &= ~type; | |
57 } | |
58 | |
59 // Ensure we saw all the providers we expected. | |
60 ASSERT_EQ(0, expected_providers); | |
61 } | |
62 | |
63 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { | |
64 CreateController(); | |
65 // First collect the basic providers. | |
66 int observed_providers = 0; | |
67 const ACProviders* providers = | |
68 omnibox_controller()->autocomplete_controller()->providers(); | |
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 profile().GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, | |
78 "http://dummy.url.com/"); | |
79 CreateController(); | |
80 AssertProviders(providers_with_zero_suggest); | |
81 profile().GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, | |
82 std::string()); | |
83 | |
84 // Ensure instant extended includes all the basic ones save for those that are | |
85 // not expected to run in instant extended. | |
86 int providers_with_instant_extended = | |
87 observed_providers & | |
88 ~AutocompleteProvider::TYPE_HISTORY_CONTENTS & | |
89 ~AutocompleteProvider::TYPE_SHORTCUTS; | |
90 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass | |
91 // the Instant suggestion through via FinalizeInstantQuery. | |
92 chrome::EnableInstantExtendedAPIForTesting(); | |
93 CreateController(); | |
94 AssertProviders(providers_with_instant_extended); | |
95 | |
96 } | |
97 | |
98 } // namespace | |
OLD | NEW |