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 <limits> | 5 #include <limits> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 void(const std::string& id, | 64 void(const std::string& id, |
65 const CrxDataCallback& crx_data_callback, | 65 const CrxDataCallback& crx_data_callback, |
66 const CompletionCallback& completion_callback)); | 66 const CompletionCallback& completion_callback)); |
67 MOCK_METHOD3(Update, | 67 MOCK_METHOD3(Update, |
68 void(const std::vector<std::string>& ids, | 68 void(const std::vector<std::string>& ids, |
69 const CrxDataCallback& crx_data_callback, | 69 const CrxDataCallback& crx_data_callback, |
70 const CompletionCallback& completion_callback)); | 70 const CompletionCallback& completion_callback)); |
71 MOCK_CONST_METHOD2(GetCrxUpdateState, | 71 MOCK_CONST_METHOD2(GetCrxUpdateState, |
72 bool(const std::string& id, CrxUpdateItem* update_item)); | 72 bool(const std::string& id, CrxUpdateItem* update_item)); |
73 MOCK_CONST_METHOD1(IsUpdating, bool(const std::string& id)); | 73 MOCK_CONST_METHOD1(IsUpdating, bool(const std::string& id)); |
74 MOCK_METHOD0(Stop, void()); | |
75 | 74 |
76 private: | 75 private: |
77 ~MockUpdateClient() override; | 76 ~MockUpdateClient() override; |
78 }; | 77 }; |
79 | 78 |
80 class MockServiceObserver : public ServiceObserver { | 79 class MockServiceObserver : public ServiceObserver { |
81 public: | 80 public: |
82 MockServiceObserver(); | 81 MockServiceObserver(); |
83 ~MockServiceObserver() override; | 82 ~MockServiceObserver() override; |
84 | 83 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 void ComponentUpdaterTest::TearDown() { | 183 void ComponentUpdaterTest::TearDown() { |
185 } | 184 } |
186 | 185 |
187 void ComponentUpdaterTest::RunThreads() { | 186 void ComponentUpdaterTest::RunThreads() { |
188 runloop_.Run(); | 187 runloop_.Run(); |
189 } | 188 } |
190 | 189 |
191 TEST_F(ComponentUpdaterTest, AddObserver) { | 190 TEST_F(ComponentUpdaterTest, AddObserver) { |
192 MockServiceObserver observer; | 191 MockServiceObserver observer; |
193 EXPECT_CALL(update_client(), AddObserver(&observer)).Times(1); | 192 EXPECT_CALL(update_client(), AddObserver(&observer)).Times(1); |
194 EXPECT_CALL(update_client(), Stop()).Times(1); | |
195 component_updater().AddObserver(&observer); | 193 component_updater().AddObserver(&observer); |
196 } | 194 } |
197 | 195 |
198 TEST_F(ComponentUpdaterTest, RemoveObserver) { | 196 TEST_F(ComponentUpdaterTest, RemoveObserver) { |
199 MockServiceObserver observer; | 197 MockServiceObserver observer; |
200 EXPECT_CALL(update_client(), RemoveObserver(&observer)).Times(1); | 198 EXPECT_CALL(update_client(), RemoveObserver(&observer)).Times(1); |
201 EXPECT_CALL(update_client(), Stop()).Times(1); | |
202 component_updater().RemoveObserver(&observer); | 199 component_updater().RemoveObserver(&observer); |
203 } | 200 } |
204 | 201 |
205 // Tests that UpdateClient::Update is called by the timer loop when | 202 // Tests that UpdateClient::Update is called by the timer loop when |
206 // components are registered, and the component update starts. | 203 // components are registered, and the component update starts. |
207 // Also tests that Uninstall is called when a component is unregistered. | 204 // Also tests that Uninstall is called when a component is unregistered. |
208 TEST_F(ComponentUpdaterTest, RegisterComponent) { | 205 TEST_F(ComponentUpdaterTest, RegisterComponent) { |
209 class LoopHandler { | 206 class LoopHandler { |
210 public: | 207 public: |
211 LoopHandler(int max_cnt, const base::Closure& quit_closure) | 208 LoopHandler(int max_cnt, const base::Closure& quit_closure) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 crx_component2.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 243 crx_component2.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
247 crx_component2.version = Version("0.9"); | 244 crx_component2.version = Version("0.9"); |
248 crx_component2.installer = installer; | 245 crx_component2.installer = installer; |
249 | 246 |
250 // Quit after two update checks have fired. | 247 // Quit after two update checks have fired. |
251 LoopHandler loop_handler(2, quit_closure()); | 248 LoopHandler loop_handler(2, quit_closure()); |
252 EXPECT_CALL(update_client(), Update(ids, _, _)) | 249 EXPECT_CALL(update_client(), Update(ids, _, _)) |
253 .WillRepeatedly(Invoke(&loop_handler, &LoopHandler::OnUpdate)); | 250 .WillRepeatedly(Invoke(&loop_handler, &LoopHandler::OnUpdate)); |
254 | 251 |
255 EXPECT_CALL(update_client(), IsUpdating(id1)).Times(1); | 252 EXPECT_CALL(update_client(), IsUpdating(id1)).Times(1); |
256 EXPECT_CALL(update_client(), Stop()).Times(1); | |
257 | 253 |
258 EXPECT_TRUE(component_updater().RegisterComponent(crx_component1)); | 254 EXPECT_TRUE(component_updater().RegisterComponent(crx_component1)); |
259 EXPECT_TRUE(component_updater().RegisterComponent(crx_component2)); | 255 EXPECT_TRUE(component_updater().RegisterComponent(crx_component2)); |
260 | 256 |
261 RunThreads(); | 257 RunThreads(); |
262 | 258 |
263 EXPECT_TRUE(component_updater().UnregisterComponent(id1)); | 259 EXPECT_TRUE(component_updater().UnregisterComponent(id1)); |
264 } | 260 } |
265 | 261 |
266 // Tests that on-demand updates invoke UpdateClient::Install. | 262 // Tests that on-demand updates invoke UpdateClient::Install. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 using update_client::jebg_hash; | 294 using update_client::jebg_hash; |
299 CrxComponent crx_component; | 295 CrxComponent crx_component; |
300 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 296 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
301 crx_component.version = Version("0.9"); | 297 crx_component.version = Version("0.9"); |
302 crx_component.installer = installer; | 298 crx_component.installer = installer; |
303 | 299 |
304 LoopHandler loop_handler(1, quit_closure()); | 300 LoopHandler loop_handler(1, quit_closure()); |
305 EXPECT_CALL(update_client(), | 301 EXPECT_CALL(update_client(), |
306 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _)) | 302 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _)) |
307 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall)); | 303 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall)); |
308 EXPECT_CALL(update_client(), Stop()).Times(1); | |
309 | 304 |
310 EXPECT_TRUE(cus.RegisterComponent(crx_component)); | 305 EXPECT_TRUE(cus.RegisterComponent(crx_component)); |
311 EXPECT_TRUE(OnDemandTester::OnDemand(&cus, id)); | 306 EXPECT_TRUE(OnDemandTester::OnDemand(&cus, id)); |
312 | 307 |
313 RunThreads(); | 308 RunThreads(); |
314 } | 309 } |
315 | 310 |
316 // Tests that throttling an update invokes UpdateClient::Install. | 311 // Tests that throttling an update invokes UpdateClient::Install. |
317 TEST_F(ComponentUpdaterTest, MaybeThrottle) { | 312 TEST_F(ComponentUpdaterTest, MaybeThrottle) { |
318 class LoopHandler { | 313 class LoopHandler { |
(...skipping 24 matching lines...) Expand all Loading... |
343 using update_client::jebg_hash; | 338 using update_client::jebg_hash; |
344 CrxComponent crx_component; | 339 CrxComponent crx_component; |
345 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 340 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
346 crx_component.version = Version("0.9"); | 341 crx_component.version = Version("0.9"); |
347 crx_component.installer = installer; | 342 crx_component.installer = installer; |
348 | 343 |
349 LoopHandler loop_handler(1, quit_closure()); | 344 LoopHandler loop_handler(1, quit_closure()); |
350 EXPECT_CALL(update_client(), | 345 EXPECT_CALL(update_client(), |
351 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _)) | 346 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _)) |
352 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall)); | 347 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall)); |
353 EXPECT_CALL(update_client(), Stop()).Times(1); | |
354 | 348 |
355 EXPECT_TRUE(component_updater().RegisterComponent(crx_component)); | 349 EXPECT_TRUE(component_updater().RegisterComponent(crx_component)); |
356 component_updater().MaybeThrottle( | 350 component_updater().MaybeThrottle( |
357 "jebgalgnebhfojomionfpkfelancnnkf", | 351 "jebgalgnebhfojomionfpkfelancnnkf", |
358 base::Bind(&ComponentUpdaterTest::ReadyCallback)); | 352 base::Bind(&ComponentUpdaterTest::ReadyCallback)); |
359 | 353 |
360 RunThreads(); | 354 RunThreads(); |
361 } | 355 } |
362 | 356 |
363 } // namespace component_updater | 357 } // namespace component_updater |
OLD | NEW |