OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 6 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
7 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 7 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
8 #include "chrome/browser/ui/omnibox/omnibox_controller.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_controller.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 class OmniboxControllerTest : public testing::Test { | 13 class OmniboxControllerTest : public testing::Test { |
14 protected: | 14 protected: |
15 OmniboxControllerTest(); | 15 OmniboxControllerTest(); |
16 virtual ~OmniboxControllerTest(); | 16 virtual ~OmniboxControllerTest(); |
17 | 17 |
18 void CreateController(); | 18 void CreateController(); |
19 void AssertProviders(int expected_providers); | 19 void AssertProviders(int expected_providers); |
20 | 20 |
21 PrefService* GetPrefs() { return profile_.GetPrefs(); } | 21 PrefService* GetPrefs() { return profile_.GetPrefs(); } |
22 const ACProviders* GetAutocompleteProviders() const { | 22 const AutocompleteController::Providers& GetAutocompleteProviders() const { |
23 return omnibox_controller_->autocomplete_controller()->providers(); | 23 return omnibox_controller_->autocomplete_controller()->providers(); |
24 } | 24 } |
25 | 25 |
26 private: | 26 private: |
27 TestingProfile profile_; | 27 TestingProfile profile_; |
28 scoped_ptr<OmniboxController> omnibox_controller_; | 28 scoped_ptr<OmniboxController> omnibox_controller_; |
29 | 29 |
30 DISALLOW_COPY_AND_ASSIGN(OmniboxControllerTest); | 30 DISALLOW_COPY_AND_ASSIGN(OmniboxControllerTest); |
31 }; | 31 }; |
32 | 32 |
33 OmniboxControllerTest::OmniboxControllerTest() { | 33 OmniboxControllerTest::OmniboxControllerTest() { |
34 } | 34 } |
35 | 35 |
36 OmniboxControllerTest::~OmniboxControllerTest() { | 36 OmniboxControllerTest::~OmniboxControllerTest() { |
37 } | 37 } |
38 | 38 |
39 void OmniboxControllerTest::CreateController() { | 39 void OmniboxControllerTest::CreateController() { |
40 omnibox_controller_.reset(new OmniboxController(NULL, &profile_)); | 40 omnibox_controller_.reset(new OmniboxController(NULL, &profile_)); |
41 } | 41 } |
42 | 42 |
43 // Checks that the list of autocomplete providers used by the OmniboxController | 43 // Checks that the list of autocomplete providers used by the OmniboxController |
44 // matches the one in the |expected_providers| bit field. | 44 // matches the one in the |expected_providers| bit field. |
45 void OmniboxControllerTest::AssertProviders(int expected_providers) { | 45 void OmniboxControllerTest::AssertProviders(int expected_providers) { |
46 const ACProviders* providers = GetAutocompleteProviders(); | 46 const AutocompleteController::Providers& providers = |
| 47 GetAutocompleteProviders(); |
47 | 48 |
48 for (size_t i = 0; i < providers->size(); ++i) { | 49 for (size_t i = 0; i < providers.size(); ++i) { |
49 // Ensure this is a provider we wanted. | 50 // Ensure this is a provider we wanted. |
50 int type = providers->at(i)->type(); | 51 int type = providers[i]->type(); |
51 ASSERT_TRUE(expected_providers & type); | 52 ASSERT_TRUE(expected_providers & type); |
52 | 53 |
53 // Remove it from expectations so we fail if it's there twice. | 54 // Remove it from expectations so we fail if it's there twice. |
54 expected_providers &= ~type; | 55 expected_providers &= ~type; |
55 } | 56 } |
56 | 57 |
57 // Ensure we saw all the providers we expected. | 58 // Ensure we saw all the providers we expected. |
58 ASSERT_EQ(0, expected_providers); | 59 ASSERT_EQ(0, expected_providers); |
59 } | 60 } |
60 | 61 |
61 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { | 62 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { |
62 CreateController(); | 63 CreateController(); |
63 // First collect the basic providers. | 64 // First collect the basic providers. |
64 int observed_providers = 0; | 65 int observed_providers = 0; |
65 const ACProviders* providers = GetAutocompleteProviders(); | 66 const AutocompleteController::Providers& providers = |
66 for (size_t i = 0; i < providers->size(); ++i) | 67 GetAutocompleteProviders(); |
67 observed_providers |= providers->at(i)->type(); | 68 for (size_t i = 0; i < providers.size(); ++i) |
| 69 observed_providers |= providers[i]->type(); |
68 // Ensure we have at least one provider. | 70 // Ensure we have at least one provider. |
69 ASSERT_NE(0, observed_providers); | 71 ASSERT_NE(0, observed_providers); |
70 | 72 |
71 // Ensure instant extended includes all the provides in classic Chrome. | 73 // Ensure instant extended includes all the provides in classic Chrome. |
72 int providers_with_instant_extended = observed_providers; | 74 int providers_with_instant_extended = observed_providers; |
73 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass | 75 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass |
74 // the Instant suggestion through via FinalizeInstantQuery. | 76 // the Instant suggestion through via FinalizeInstantQuery. |
75 CreateController(); | 77 CreateController(); |
76 AssertProviders(providers_with_instant_extended); | 78 AssertProviders(providers_with_instant_extended); |
77 } | 79 } |
OLD | NEW |