| 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 <string> | 6 #include <string> |
| 6 #include <vector> | 7 #include <vector> |
| 7 | 8 |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/component_updater/chrome_component_updater_configurator
.h" | 11 #include "chrome/browser/component_updater/chrome_component_updater_configurator
.h" |
| 11 #include "components/component_updater/component_updater_switches.h" | 12 #include "components/component_updater/component_updater_switches.h" |
| 12 #include "components/component_updater/component_updater_url_constants.h" | 13 #include "components/component_updater/component_updater_url_constants.h" |
| 13 #include "components/component_updater/configurator_impl.h" | 14 #include "components/component_updater/configurator_impl.h" |
| 15 #include "components/prefs/testing_pref_service.h" |
| 14 #include "components/update_client/configurator.h" | 16 #include "components/update_client/configurator.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 17 | 19 |
| 18 namespace component_updater { | 20 namespace component_updater { |
| 19 | 21 |
| 20 TEST(ChromeComponentUpdaterConfiguratorTest, TestDisablePings) { | 22 class ChromeComponentUpdaterConfiguratorTest : public testing::Test { |
| 23 public: |
| 24 ChromeComponentUpdaterConfiguratorTest(); |
| 25 ~ChromeComponentUpdaterConfiguratorTest() override{}; |
| 26 |
| 27 protected: |
| 28 PrefService* pref_service() { return pref_service_.get(); } |
| 29 |
| 30 private: |
| 31 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(ChromeComponentUpdaterConfiguratorTest); |
| 34 }; |
| 35 |
| 36 ChromeComponentUpdaterConfiguratorTest::ChromeComponentUpdaterConfiguratorTest() |
| 37 : pref_service_(new TestingPrefServiceSimple()) {} |
| 38 |
| 39 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestDisablePings) { |
| 21 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 40 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 22 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "disable-pings"); | 41 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "disable-pings"); |
| 23 | 42 |
| 24 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 43 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 44 pref_service())); |
| 25 | 45 |
| 26 const std::vector<GURL> pingUrls = config->PingUrl(); | 46 const std::vector<GURL> pingUrls = config->PingUrl(); |
| 27 EXPECT_TRUE(pingUrls.empty()); | 47 EXPECT_TRUE(pingUrls.empty()); |
| 28 } | 48 } |
| 29 | 49 |
| 30 TEST(ChromeComponentUpdaterConfiguratorTest, TestFastUpdate) { | 50 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestFastUpdate) { |
| 31 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 51 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 32 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "fast-update"); | 52 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "fast-update"); |
| 33 | 53 |
| 34 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 54 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 55 pref_service())); |
| 35 | 56 |
| 36 CHECK_EQ(10, config->InitialDelay()); | 57 CHECK_EQ(10, config->InitialDelay()); |
| 37 CHECK_EQ(6 * 60 * 60, config->NextCheckDelay()); | 58 CHECK_EQ(6 * 60 * 60, config->NextCheckDelay()); |
| 38 CHECK_EQ(1, config->StepDelay()); | 59 CHECK_EQ(1, config->StepDelay()); |
| 39 CHECK_EQ(2, config->OnDemandDelay()); | 60 CHECK_EQ(2, config->OnDemandDelay()); |
| 40 CHECK_EQ(10, config->UpdateDelay()); | 61 CHECK_EQ(10, config->UpdateDelay()); |
| 41 } | 62 } |
| 42 | 63 |
| 43 TEST(ChromeComponentUpdaterConfiguratorTest, TestOverrideUrl) { | 64 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestOverrideUrl) { |
| 44 const char overrideUrl[] = "http://0.0.0.0/"; | 65 const char overrideUrl[] = "http://0.0.0.0/"; |
| 45 | 66 |
| 46 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 67 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 47 | 68 |
| 48 std::string val = "url-source"; | 69 std::string val = "url-source"; |
| 49 val.append("="); | 70 val.append("="); |
| 50 val.append(overrideUrl); | 71 val.append(overrideUrl); |
| 51 cmdline.AppendSwitchASCII(switches::kComponentUpdater, val.c_str()); | 72 cmdline.AppendSwitchASCII(switches::kComponentUpdater, val.c_str()); |
| 52 | 73 |
| 53 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 74 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 75 pref_service())); |
| 54 | 76 |
| 55 const std::vector<GURL> urls = config->UpdateUrl(); | 77 const std::vector<GURL> urls = config->UpdateUrl(); |
| 56 | 78 |
| 57 ASSERT_EQ(1U, urls.size()); | 79 ASSERT_EQ(1U, urls.size()); |
| 58 ASSERT_EQ(overrideUrl, urls.at(0).possibly_invalid_spec()); | 80 ASSERT_EQ(overrideUrl, urls.at(0).possibly_invalid_spec()); |
| 59 } | 81 } |
| 60 | 82 |
| 61 TEST(ChromeComponentUpdaterConfiguratorTest, TestSwitchRequestParam) { | 83 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestSwitchRequestParam) { |
| 62 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 84 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 63 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "test-request"); | 85 cmdline.AppendSwitchASCII(switches::kComponentUpdater, "test-request"); |
| 64 | 86 |
| 65 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 87 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 88 pref_service())); |
| 66 | 89 |
| 67 EXPECT_FALSE(config->ExtraRequestParams().empty()); | 90 EXPECT_FALSE(config->ExtraRequestParams().empty()); |
| 68 } | 91 } |
| 69 | 92 |
| 70 TEST(ChromeComponentUpdaterConfiguratorTest, TestUpdaterDefaultUrl) { | 93 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestUpdaterDefaultUrl) { |
| 71 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 94 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 72 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 95 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 96 pref_service())); |
| 73 const auto urls = config->UpdateUrl(); | 97 const auto urls = config->UpdateUrl(); |
| 74 | 98 |
| 75 // Expect the default url to be cryptographically secure. | 99 // Expect the default url to be cryptographically secure. |
| 76 EXPECT_GE(urls.size(), 1u); | 100 EXPECT_GE(urls.size(), 1u); |
| 77 EXPECT_TRUE(urls.front().SchemeIsCryptographic()); | 101 EXPECT_TRUE(urls.front().SchemeIsCryptographic()); |
| 78 } | 102 } |
| 79 | 103 |
| 80 TEST(ChromeComponentUpdaterConfiguratorTest, TestEnabledCupSigning) { | 104 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestEnabledCupSigning) { |
| 81 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 105 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 82 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 106 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 107 pref_service())); |
| 83 | 108 |
| 84 EXPECT_TRUE(config->EnabledCupSigning()); | 109 EXPECT_TRUE(config->EnabledCupSigning()); |
| 85 } | 110 } |
| 86 | 111 |
| 87 TEST(ChromeComponentUpdaterConfiguratorTest, TestUseEncryption) { | 112 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestUseEncryption) { |
| 88 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 113 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 89 const auto config(MakeChromeComponentUpdaterConfigurator(cmdline, nullptr)); | 114 const auto config( |
| 115 MakeChromeComponentUpdaterConfigurator(cmdline, nullptr, pref_service())); |
| 90 | 116 |
| 91 const auto urls = config->UpdateUrl(); | 117 const auto urls = config->UpdateUrl(); |
| 92 ASSERT_EQ(2u, urls.size()); | 118 ASSERT_EQ(2u, urls.size()); |
| 93 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); | 119 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); |
| 94 ASSERT_STREQ(kUpdaterFallbackUrl, urls[1].spec().c_str()); | 120 ASSERT_STREQ(kUpdaterFallbackUrl, urls[1].spec().c_str()); |
| 95 | 121 |
| 96 ASSERT_EQ(config->UpdateUrl(), config->PingUrl()); | 122 ASSERT_EQ(config->UpdateUrl(), config->PingUrl()); |
| 97 | 123 |
| 98 // Use the configurator implementation to test the filtering of | 124 // Use the configurator implementation to test the filtering of |
| 99 // unencrypted URLs. | 125 // unencrypted URLs. |
| 100 { | 126 { |
| 101 const ConfiguratorImpl config(cmdline, nullptr, true); | 127 const ConfiguratorImpl config(cmdline, nullptr, true); |
| 102 const auto urls = config.UpdateUrl(); | 128 const auto urls = config.UpdateUrl(); |
| 103 ASSERT_EQ(1u, urls.size()); | 129 ASSERT_EQ(1u, urls.size()); |
| 104 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); | 130 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); |
| 105 ASSERT_EQ(config.UpdateUrl(), config.PingUrl()); | 131 ASSERT_EQ(config.UpdateUrl(), config.PingUrl()); |
| 106 } | 132 } |
| 107 | 133 |
| 108 { | 134 { |
| 109 const ConfiguratorImpl config(cmdline, nullptr, false); | 135 const ConfiguratorImpl config(cmdline, nullptr, false); |
| 110 const auto urls = config.UpdateUrl(); | 136 const auto urls = config.UpdateUrl(); |
| 111 ASSERT_EQ(2u, urls.size()); | 137 ASSERT_EQ(2u, urls.size()); |
| 112 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); | 138 ASSERT_STREQ(kUpdaterDefaultUrl, urls[0].spec().c_str()); |
| 113 ASSERT_STREQ(kUpdaterFallbackUrl, urls[1].spec().c_str()); | 139 ASSERT_STREQ(kUpdaterFallbackUrl, urls[1].spec().c_str()); |
| 114 ASSERT_EQ(config.UpdateUrl(), config.PingUrl()); | 140 ASSERT_EQ(config.UpdateUrl(), config.PingUrl()); |
| 115 } | 141 } |
| 116 } | 142 } |
| 117 | 143 |
| 118 TEST(ChromeComponentUpdaterConfiguratorTest, TestEnabledComponentUpdates) { | 144 TEST_F(ChromeComponentUpdaterConfiguratorTest, TestEnabledComponentUpdates) { |
| 119 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); | 145 base::CommandLine cmdline(*base::CommandLine::ForCurrentProcess()); |
| 120 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr)); | 146 const auto config(MakeChromeComponentUpdaterConfigurator(&cmdline, nullptr, |
| 147 pref_service())); |
| 121 EXPECT_TRUE(config->EnabledComponentUpdates()); | 148 EXPECT_TRUE(config->EnabledComponentUpdates()); |
| 122 } | 149 } |
| 123 | 150 |
| 124 } // namespace component_updater | 151 } // namespace component_updater |
| OLD | NEW |