Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
|
sreeram
2013/04/24 20:25:03
No "(c)".
beaudoin
2013/04/25 14:57:54
Done.
| |
| 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/command_line.h" | |
| 6 #include "base/prefs/pref_service.h" | |
| 7 #include "chrome/browser/autocomplete/autocomplete_controller.h" | |
| 8 #include "chrome/browser/autocomplete/autocomplete_provider.h" | |
| 9 #include "chrome/browser/ui/omnibox/omnibox_controller.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "chrome/test/base/testing_profile.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class OmniboxControllerTest : public testing::Test { | |
| 18 public: | |
| 19 virtual void SetUp() OVERRIDE { | |
| 20 profile_.reset(new TestingProfile); | |
| 21 } | |
| 22 | |
| 23 virtual void TearDown() OVERRIDE { | |
| 24 omnibox_controller_.reset(); | |
| 25 profile_.reset(); | |
| 26 } | |
| 27 | |
| 28 protected: | |
| 29 void CreateController() { | |
| 30 omnibox_controller_.reset(new OmniboxController(NULL, profile_.get())); | |
| 31 } | |
| 32 | |
| 33 void AssertProviders(int expected_providers); | |
| 34 | |
| 35 scoped_ptr<TestingProfile> profile_; | |
| 36 scoped_ptr<OmniboxController> omnibox_controller_; | |
| 37 }; | |
| 38 | |
| 39 // Checks that the list of autocomplete providers used by the OmniboxController | |
| 40 // matches the one in the |expected_providers| bit field. | |
| 41 void OmniboxControllerTest::AssertProviders(int expected_providers) { | |
| 42 const ACProviders* providers = | |
| 43 omnibox_controller_->autocomplete_controller()->providers(); | |
| 44 | |
| 45 for (size_t i = 0; i < providers->size(); ++i) { | |
| 46 // Ensure this is a provider we wanted. | |
| 47 int type = providers->at(i)->type(); | |
| 48 ASSERT_EQ(type, expected_providers & type); | |
| 49 | |
| 50 // Remove it from expectations so we fail if it's there twice. | |
| 51 expected_providers &= ~type; | |
| 52 } | |
| 53 | |
| 54 // Ensure we saw all the providers we expected. | |
| 55 ASSERT_EQ(0, expected_providers); | |
| 56 } | |
| 57 | |
| 58 TEST_F(OmniboxControllerTest, CheckDefaultAutocompleteProviders) { | |
| 59 CreateController(); | |
| 60 // List of the autocomplete providers we expect by default. | |
| 61 int expected_providers = | |
| 62 AutocompleteProvider::TYPE_BOOKMARK | | |
| 63 AutocompleteProvider::TYPE_BUILTIN | | |
| 64 AutocompleteProvider::TYPE_HISTORY_CONTENTS | | |
| 65 AutocompleteProvider::TYPE_HISTORY_QUICK | | |
| 66 AutocompleteProvider::TYPE_HISTORY_URL | | |
| 67 AutocompleteProvider::TYPE_KEYWORD | | |
| 68 AutocompleteProvider::TYPE_SEARCH | | |
| 69 AutocompleteProvider::TYPE_SHORTCUTS; | |
|
sreeram
2013/04/24 20:25:03
I don't this test buys us much.
In my opinion, th
beaudoin
2013/04/25 14:57:54
Not sure this test should live in the Autocomplete
| |
| 70 AssertProviders(expected_providers); | |
| 71 | |
| 72 // With a valid kInstantUIZeroSuggestUrlPrefix we also expect | |
| 73 // TYPE_ZERO_SUGGEST. | |
| 74 profile_->GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, | |
| 75 std::string("http://dummy.url.com/")); | |
| 76 CreateController(); | |
| 77 AssertProviders(expected_providers | AutocompleteProvider::TYPE_ZERO_SUGGEST); | |
| 78 } | |
| 79 | |
| 80 TEST_F(OmniboxControllerTest, CheckAutocompleteProvidersWithInstant) { | |
| 81 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 82 switches::kEnableInstantExtendedAPI); | |
|
sreeram
2013/04/24 20:25:03
You might also instead consider #including "c/b/se
beaudoin
2013/04/25 14:57:54
Done.
| |
| 83 | |
| 84 CreateController(); | |
| 85 // List of the autocomplete providers we expect by default. | |
| 86 int expected_providers = | |
| 87 AutocompleteProvider::TYPE_BOOKMARK | | |
| 88 AutocompleteProvider::TYPE_BUILTIN | | |
| 89 AutocompleteProvider::TYPE_HISTORY_QUICK | | |
| 90 AutocompleteProvider::TYPE_HISTORY_URL | | |
| 91 AutocompleteProvider::TYPE_KEYWORD | | |
| 92 // TODO(beaudoin): remove TYPE_SEARCH once it's no longer needed to pass | |
| 93 // the Instant suggestion through via FinalizeInstantQuery. | |
| 94 AutocompleteProvider::TYPE_SEARCH; | |
| 95 AssertProviders(expected_providers); | |
| 96 | |
| 97 // With a valid kInstantUIZeroSuggestUrlPrefix we also expect | |
| 98 // TYPE_ZERO_SUGGEST. | |
| 99 profile_->GetPrefs()->SetString(prefs::kInstantUIZeroSuggestUrlPrefix, | |
| 100 std::string("http://dummy.url.com/")); | |
| 101 CreateController(); | |
| 102 AssertProviders(expected_providers | AutocompleteProvider::TYPE_ZERO_SUGGEST); | |
| 103 } | |
| 104 | |
| 105 } // namespace | |
| OLD | NEW |