| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <iterator> | 5 #include <iterator> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 15 #include "base/test/sequenced_worker_pool_owner.h" | 14 #include "base/task_scheduler/post_task.h" |
| 15 #include "base/test/scoped_task_environment.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/version.h" | 17 #include "base/version.h" |
| 17 #include "components/component_updater/component_updater_service.h" | 18 #include "components/component_updater/component_updater_service.h" |
| 18 #include "components/component_updater/component_updater_service_internal.h" | 19 #include "components/component_updater/component_updater_service_internal.h" |
| 19 #include "components/component_updater/default_component_installer.h" | 20 #include "components/component_updater/default_component_installer.h" |
| 20 #include "components/update_client/crx_update_item.h" | 21 #include "components/update_client/crx_update_item.h" |
| 21 #include "components/update_client/test_configurator.h" | 22 #include "components/update_client/test_configurator.h" |
| 22 #include "components/update_client/update_client.h" | 23 #include "components/update_client/update_client.h" |
| 23 #include "components/update_client/update_client_errors.h" | 24 #include "components/update_client/update_client_errors.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 ComponentUpdateService* component_updater() { | 130 ComponentUpdateService* component_updater() { |
| 130 return component_updater_.get(); | 131 return component_updater_.get(); |
| 131 } | 132 } |
| 132 scoped_refptr<TestConfigurator> configurator() const { return config_; } | 133 scoped_refptr<TestConfigurator> configurator() const { return config_; } |
| 133 base::Closure quit_closure() const { return quit_closure_; } | 134 base::Closure quit_closure() const { return quit_closure_; } |
| 134 | 135 |
| 135 protected: | 136 protected: |
| 136 void RunThreads(); | 137 void RunThreads(); |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 static const int kNumWorkerThreads_ = 2; | 140 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 140 | |
| 141 base::MessageLoopForUI message_loop_; | |
| 142 base::RunLoop runloop_; | 141 base::RunLoop runloop_; |
| 143 base::Closure quit_closure_; | 142 base::Closure quit_closure_; |
| 144 | 143 |
| 145 std::unique_ptr<base::SequencedWorkerPoolOwner> worker_pool_; | |
| 146 | |
| 147 scoped_refptr<TestConfigurator> config_; | 144 scoped_refptr<TestConfigurator> config_; |
| 148 scoped_refptr<MockUpdateClient> update_client_; | 145 scoped_refptr<MockUpdateClient> update_client_; |
| 149 std::unique_ptr<ComponentUpdateService> component_updater_; | 146 std::unique_ptr<ComponentUpdateService> component_updater_; |
| 150 }; | 147 }; |
| 151 | 148 |
| 152 DefaultComponentInstallerTest::DefaultComponentInstallerTest() | 149 DefaultComponentInstallerTest::DefaultComponentInstallerTest() |
| 153 : worker_pool_( | 150 : scoped_task_environment_( |
| 154 new base::SequencedWorkerPoolOwner(kNumWorkerThreads_, "test")) { | 151 base::test::ScopedTaskEnvironment::MainThreadType::UI) { |
| 155 quit_closure_ = runloop_.QuitClosure(); | 152 quit_closure_ = runloop_.QuitClosure(); |
| 156 | 153 |
| 157 auto pool = worker_pool_->pool(); | |
| 158 config_ = new TestConfigurator( | 154 config_ = new TestConfigurator( |
| 159 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), | 155 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}), |
| 160 message_loop_.task_runner()); | 156 base::ThreadTaskRunnerHandle::Get()); |
| 161 | 157 |
| 162 update_client_ = new MockUpdateClient(); | 158 update_client_ = new MockUpdateClient(); |
| 163 EXPECT_CALL(update_client(), AddObserver(_)).Times(1); | 159 EXPECT_CALL(update_client(), AddObserver(_)).Times(1); |
| 164 component_updater_.reset(new CrxUpdateService(config_, update_client_)); | 160 component_updater_.reset(new CrxUpdateService(config_, update_client_)); |
| 165 } | 161 } |
| 166 | 162 |
| 167 DefaultComponentInstallerTest::~DefaultComponentInstallerTest() { | 163 DefaultComponentInstallerTest::~DefaultComponentInstallerTest() { |
| 168 EXPECT_CALL(update_client(), RemoveObserver(_)).Times(1); | 164 EXPECT_CALL(update_client(), RemoveObserver(_)).Times(1); |
| 169 component_updater_.reset(); | 165 component_updater_.reset(); |
| 170 } | 166 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 component.pk_hash); | 226 component.pk_hash); |
| 231 EXPECT_EQ(base::Version("0.0.0.0"), component.version); | 227 EXPECT_EQ(base::Version("0.0.0.0"), component.version); |
| 232 EXPECT_TRUE(component.fingerprint.empty()); | 228 EXPECT_TRUE(component.fingerprint.empty()); |
| 233 EXPECT_STREQ("fake name", component.name.c_str()); | 229 EXPECT_STREQ("fake name", component.name.c_str()); |
| 234 EXPECT_EQ(expected_attrs, component.installer_attributes); | 230 EXPECT_EQ(expected_attrs, component.installer_attributes); |
| 235 EXPECT_TRUE(component.requires_network_encryption); | 231 EXPECT_TRUE(component.requires_network_encryption); |
| 236 EXPECT_TRUE(component.supports_group_policy_enable_component_updates); | 232 EXPECT_TRUE(component.supports_group_policy_enable_component_updates); |
| 237 } | 233 } |
| 238 | 234 |
| 239 } // namespace component_updater | 235 } // namespace component_updater |
| OLD | NEW |