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.
5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/autocomplete/autocomplete_controller.h"
7 #include "chrome/browser/ui/omnibox/omnibox_controller.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "components/omnibox/autocomplete_provider.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 class OmniboxControllerTest
: public testing::Test
{
14 OmniboxControllerTest();
15 ~OmniboxControllerTest() override
;
17 void CreateController();
18 void AssertProviders(int expected_providers
);
20 PrefService
* GetPrefs() { return profile_
.GetPrefs(); }
21 const AutocompleteController::Providers
& GetAutocompleteProviders() const {
22 return omnibox_controller_
->autocomplete_controller()->providers();
26 TestingProfile profile_
;
27 scoped_ptr
<OmniboxController
> omnibox_controller_
;
29 DISALLOW_COPY_AND_ASSIGN(OmniboxControllerTest
);
32 OmniboxControllerTest::OmniboxControllerTest() {
35 OmniboxControllerTest::~OmniboxControllerTest() {
38 void OmniboxControllerTest::CreateController() {
39 omnibox_controller_
.reset(new OmniboxController(NULL
, &profile_
));
42 // Checks that the list of autocomplete providers used by the OmniboxController
43 // matches the one in the |expected_providers| bit field.
44 void OmniboxControllerTest::AssertProviders(int expected_providers
) {
45 const AutocompleteController::Providers
& providers
=
46 GetAutocompleteProviders();
48 for (size_t i
= 0; i
< providers
.size(); ++i
) {
49 // Ensure this is a provider we wanted.
50 int type
= providers
[i
]->type();
51 ASSERT_TRUE(expected_providers
& type
);
53 // Remove it from expectations so we fail if it's there twice.
54 expected_providers
&= ~type
;
57 // Ensure we saw all the providers we expected.
58 ASSERT_EQ(0, expected_providers
);
61 TEST_F(OmniboxControllerTest
, CheckDefaultAutocompleteProviders
) {
63 // First collect the basic providers.
64 int observed_providers
= 0;
65 const AutocompleteController::Providers
& providers
=
66 GetAutocompleteProviders();
67 for (size_t i
= 0; i
< providers
.size(); ++i
)
68 observed_providers
|= providers
[i
]->type();
69 // Ensure we have at least one provider.
70 ASSERT_NE(0, observed_providers
);
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.
77 AssertProviders(providers_with_instant_extended
);