OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "chrome/browser/component_updater/chrome_component_updater_configurator
.h" | 12 #include "chrome/browser/component_updater/chrome_component_updater_configurator
.h" |
12 #include "components/component_updater/component_updater_switches.h" | 13 #include "components/component_updater/component_updater_switches.h" |
13 #include "components/component_updater/component_updater_url_constants.h" | 14 #include "components/component_updater/component_updater_url_constants.h" |
14 #include "components/component_updater/configurator_impl.h" | 15 #include "components/component_updater/configurator_impl.h" |
15 #include "components/prefs/testing_pref_service.h" | 16 #include "components/prefs/testing_pref_service.h" |
16 #include "components/update_client/configurator.h" | 17 #include "components/update_client/configurator.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
| 21 std::unique_ptr<TestingPrefServiceSimple> pref(new TestingPrefServiceSimple()); |
| 22 |
20 namespace component_updater { | 23 namespace component_updater { |
21 | 24 |
22 class ChromeComponentUpdaterConfiguratorTest : public testing::Test { | 25 class ChromeComponentUpdaterConfiguratorTest : public testing::Test { |
23 public: | 26 public: |
24 ChromeComponentUpdaterConfiguratorTest(); | 27 ChromeComponentUpdaterConfiguratorTest() {} |
25 ~ChromeComponentUpdaterConfiguratorTest() override{}; | 28 ~ChromeComponentUpdaterConfiguratorTest() override{}; |
26 | 29 |
| 30 // Overrides from testing::Test. |
| 31 void SetUp() override; |
| 32 |
27 protected: | 33 protected: |
28 PrefService* pref_service() { return pref_service_.get(); } | 34 TestingPrefServiceSimple* pref_service() { return pref_service_.get(); } |
29 | 35 |
30 private: | 36 private: |
31 std::unique_ptr<TestingPrefServiceSimple> pref_service_; | 37 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
32 | 38 |
33 DISALLOW_COPY_AND_ASSIGN(ChromeComponentUpdaterConfiguratorTest); | 39 DISALLOW_COPY_AND_ASSIGN(ChromeComponentUpdaterConfiguratorTest); |
34 }; | 40 }; |
35 | 41 |
36 ChromeComponentUpdaterConfiguratorTest::ChromeComponentUpdaterConfiguratorTest() | 42 void ChromeComponentUpdaterConfiguratorTest::SetUp() { |
37 : pref_service_(new TestingPrefServiceSimple()) {} | 43 pref_service_ = base::MakeUnique<TestingPrefServiceSimple>(); |
| 44 RegisterPrefsForChromeComponentUpdaterConfigurator(pref_service_->registry()); |
| 45 } |
38 | 46 |
39 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestDisablePings) { | 47 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestDisablePings) { |
40 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 48 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
41 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "disable-pings"); | 49 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "disable-pings"); |
42 | 50 |
43 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, | 51 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
44 pref_service())); | 52 pref_service())); |
45 | 53 |
46 const std::vector<GURL> pingUrls = config->PingUrl(); | 54 const std::vector<GURL> pingUrls = config->PingUrl(); |
47 EXPECT_TRUE(pingUrls.empty()); | 55 EXPECT_TRUE(pingUrls.empty()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); | 146 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); |
139 ASSERT_STREQ(kUpdaterFallbackUrl, urls[1].spec().c_str()); | 147 ASSERT_STREQ(kUpdaterFallbackUrl, urls[1].spec().c_str()); |
140 ASSERT_EQ(config.UpdateUrl(), config.PingUrl()); | 148 ASSERT_EQ(config.UpdateUrl(), config.PingUrl()); |
141 } | 149 } |
142 } | 150 } |
143 | 151 |
144 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestEnabledComponentUpdates) { | 152 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestEnabledComponentUpdates) { |
145 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 153 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
146 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, | 154 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
147 pref_service())); | 155 pref_service())); |
| 156 // Tests the default is set to |true| and the component updates are enabled. |
| 157 EXPECT_TRUE(config->EnabledComponentUpdates()); |
| 158 |
| 159 // Tests the component updates are disabled. |
| 160 pref_service()->SetManagedPref("component_updates.component_updates_enabled", |
| 161 new base::FundamentalValue(false)); |
| 162 EXPECT_FALSE(config->EnabledComponentUpdates()); |
| 163 |
| 164 // Tests the component updates are enabled. |
| 165 pref_service()->SetManagedPref("component_updates.component_updates_enabled", |
| 166 new base::FundamentalValue(true)); |
| 167 EXPECT_TRUE(config->EnabledComponentUpdates()); |
| 168 |
| 169 // Sanity check setting the preference back to |false| and then removing it. |
| 170 pref_service()->SetManagedPref("component_updates.component_updates_enabled", |
| 171 new base::FundamentalValue(false)); |
| 172 EXPECT_FALSE(config->EnabledComponentUpdates()); |
| 173 pref_service()->RemoveManagedPref( |
| 174 "component_updates.component_updates_enabled"); |
148 EXPECT_TRUE(config->EnabledComponentUpdates()); | 175 EXPECT_TRUE(config->EnabledComponentUpdates()); |
149 } | 176 } |
150 | 177 |
151 } // namespace component_updater | 178 } // namespace component_updater |
OLD | NEW |