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 public: | |
18 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.
| |
19 profile_.reset(new TestingProfile); | |
20 } | |
21 | |
22 virtual void TearDown() OVERRIDE { | |
23 omnibox_controller_.reset(); | |
24 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.
| |
25 } | |
26 | |
27 protected: | |
28 void CreateController() { | |
29 omnibox_controller_.reset(new OmniboxController(NULL, profile_.get())); | |
30 } | |
31 | |
32 void AssertProviders(int expected_providers); | |
33 | |
34 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.
| |
35 scoped_ptr<OmniboxController> omnibox_controller_; | |
36 }; | |
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
| |
37 | |
38 // Checks that the list of autocomplete providers used by the OmniboxController | |
39 // matches the one in the |expected_providers| bit field. | |
40 void OmniboxControllerTest::AssertProviders(int expected_providers) { | |
41 const ACProviders* providers = | |
42 omnibox_controller_->autocomplete_controller()->providers(); | |
43 | |
44 for (size_t i = 0; i < providers->size(); ++i) { | |
45 // Ensure this is a provider we wanted. | |
46 int type = providers->at(i)->type(); | |
47 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.
| |
48 | |
49 // Remove it from expectations so we fail if it's there twice. | |
50 expected_providers &= ~type; | |
51 } | |
52 | |
53 // Ensure we saw all the providers we expected. | |
54 ASSERT_EQ(0, expected_providers); | |
55 } | |
56 | |
57 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { | |
58 CreateController(); | |
59 // List of the autocomplete providers we expect by default. | |
60 int expected_providers = | |
61 AutocompleteProvider::TYPE_BOOKMARK | | |
62 AutocompleteProvider::TYPE_BUILTIN | | |
63 AutocompleteProvider::TYPE_HISTORY_CONTENTS | | |
64 AutocompleteProvider::TYPE_HISTORY_QUICK | | |
65 AutocompleteProvider::TYPE_HISTORY_URL | | |
66 AutocompleteProvider::TYPE_KEYWORD | | |
67 AutocompleteProvider::TYPE_SEARCH | | |
68 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
| |
69 AssertProviders(expected_providers); | |
70 | |
71 // With a valid kInstantUIZeroSuggestUrlPrefix we expect the exact same set | |
72 // in addition to TYPE_ZERO_SUGGEST. | |
73 int providers_with_zero_suggest = | |
74 expected_providers | AutocompleteProvider::TYPE_ZERO_SUGGEST; | |
75 profile_->GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, | |
76 "http://dummy.url.com/"); | |
77 CreateController(); | |
78 AssertProviders(providers_with_zero_suggest); | |
79 profile_->GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, | |
80 std::string()); | |
81 | |
82 // With instant extended we expect the exact same set, save from a couple of | |
83 // providers that should not be running. | |
84 int providers_with_instant_extended = | |
85 expected_providers & | |
86 ~AutocompleteProvider::TYPE_HISTORY_CONTENTS & | |
87 ~AutocompleteProvider::TYPE_SHORTCUTS; | |
88 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass | |
89 // the Instant suggestion through via FinalizeInstantQuery. | |
90 chrome::EnableInstantExtendedAPIForTesting(); | |
91 CreateController(); | |
92 AssertProviders(providers_with_instant_extended); | |
93 | |
94 } | |
95 | |
96 } // namespace | |
OLD | NEW |