Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: components/component_updater/component_updater_service_unittest.cc

Issue 1440393002: Reland of Change the update_client task runner behavior to continue on shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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());
74 75
75 private: 76 private:
76 ~MockUpdateClient() override; 77 ~MockUpdateClient() override;
77 }; 78 };
78 79
79 class MockServiceObserver : public ServiceObserver { 80 class MockServiceObserver : public ServiceObserver {
80 public: 81 public:
81 MockServiceObserver(); 82 MockServiceObserver();
82 ~MockServiceObserver() override; 83 ~MockServiceObserver() override;
83 84
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 void ComponentUpdaterTest::TearDown() { 184 void ComponentUpdaterTest::TearDown() {
184 } 185 }
185 186
186 void ComponentUpdaterTest::RunThreads() { 187 void ComponentUpdaterTest::RunThreads() {
187 runloop_.Run(); 188 runloop_.Run();
188 } 189 }
189 190
190 TEST_F(ComponentUpdaterTest, AddObserver) { 191 TEST_F(ComponentUpdaterTest, AddObserver) {
191 MockServiceObserver observer; 192 MockServiceObserver observer;
192 EXPECT_CALL(update_client(), AddObserver(&observer)).Times(1); 193 EXPECT_CALL(update_client(), AddObserver(&observer)).Times(1);
194 EXPECT_CALL(update_client(), Stop()).Times(1);
193 component_updater().AddObserver(&observer); 195 component_updater().AddObserver(&observer);
194 } 196 }
195 197
196 TEST_F(ComponentUpdaterTest, RemoveObserver) { 198 TEST_F(ComponentUpdaterTest, RemoveObserver) {
197 MockServiceObserver observer; 199 MockServiceObserver observer;
198 EXPECT_CALL(update_client(), RemoveObserver(&observer)).Times(1); 200 EXPECT_CALL(update_client(), RemoveObserver(&observer)).Times(1);
201 EXPECT_CALL(update_client(), Stop()).Times(1);
199 component_updater().RemoveObserver(&observer); 202 component_updater().RemoveObserver(&observer);
200 } 203 }
201 204
202 // Tests that UpdateClient::Update is called by the timer loop when 205 // Tests that UpdateClient::Update is called by the timer loop when
203 // components are registered, and the component update starts. 206 // components are registered, and the component update starts.
204 // Also tests that Uninstall is called when a component is unregistered. 207 // Also tests that Uninstall is called when a component is unregistered.
205 TEST_F(ComponentUpdaterTest, RegisterComponent) { 208 TEST_F(ComponentUpdaterTest, RegisterComponent) {
206 class LoopHandler { 209 class LoopHandler {
207 public: 210 public:
208 LoopHandler(int max_cnt, const base::Closure& quit_closure) 211 LoopHandler(int max_cnt, const base::Closure& quit_closure)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 crx_component2.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 246 crx_component2.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
244 crx_component2.version = Version("0.9"); 247 crx_component2.version = Version("0.9");
245 crx_component2.installer = installer; 248 crx_component2.installer = installer;
246 249
247 // Quit after two update checks have fired. 250 // Quit after two update checks have fired.
248 LoopHandler loop_handler(2, quit_closure()); 251 LoopHandler loop_handler(2, quit_closure());
249 EXPECT_CALL(update_client(), Update(ids, _, _)) 252 EXPECT_CALL(update_client(), Update(ids, _, _))
250 .WillRepeatedly(Invoke(&loop_handler, &LoopHandler::OnUpdate)); 253 .WillRepeatedly(Invoke(&loop_handler, &LoopHandler::OnUpdate));
251 254
252 EXPECT_CALL(update_client(), IsUpdating(id1)).Times(1); 255 EXPECT_CALL(update_client(), IsUpdating(id1)).Times(1);
256 EXPECT_CALL(update_client(), Stop()).Times(1);
253 257
254 EXPECT_TRUE(component_updater().RegisterComponent(crx_component1)); 258 EXPECT_TRUE(component_updater().RegisterComponent(crx_component1));
255 EXPECT_TRUE(component_updater().RegisterComponent(crx_component2)); 259 EXPECT_TRUE(component_updater().RegisterComponent(crx_component2));
256 260
257 RunThreads(); 261 RunThreads();
258 262
259 EXPECT_TRUE(component_updater().UnregisterComponent(id1)); 263 EXPECT_TRUE(component_updater().UnregisterComponent(id1));
260 } 264 }
261 265
262 // Tests that on-demand updates invoke UpdateClient::Install. 266 // Tests that on-demand updates invoke UpdateClient::Install.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 using update_client::jebg_hash; 298 using update_client::jebg_hash;
295 CrxComponent crx_component; 299 CrxComponent crx_component;
296 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 300 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
297 crx_component.version = Version("0.9"); 301 crx_component.version = Version("0.9");
298 crx_component.installer = installer; 302 crx_component.installer = installer;
299 303
300 LoopHandler loop_handler(1, quit_closure()); 304 LoopHandler loop_handler(1, quit_closure());
301 EXPECT_CALL(update_client(), 305 EXPECT_CALL(update_client(),
302 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _)) 306 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _))
303 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall)); 307 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall));
308 EXPECT_CALL(update_client(), Stop()).Times(1);
304 309
305 EXPECT_TRUE(cus.RegisterComponent(crx_component)); 310 EXPECT_TRUE(cus.RegisterComponent(crx_component));
306 EXPECT_TRUE(OnDemandTester::OnDemand(&cus, id)); 311 EXPECT_TRUE(OnDemandTester::OnDemand(&cus, id));
307 312
308 RunThreads(); 313 RunThreads();
309 } 314 }
310 315
311 // Tests that throttling an update invokes UpdateClient::Install. 316 // Tests that throttling an update invokes UpdateClient::Install.
312 TEST_F(ComponentUpdaterTest, MaybeThrottle) { 317 TEST_F(ComponentUpdaterTest, MaybeThrottle) {
313 class LoopHandler { 318 class LoopHandler {
(...skipping 24 matching lines...) Expand all
338 using update_client::jebg_hash; 343 using update_client::jebg_hash;
339 CrxComponent crx_component; 344 CrxComponent crx_component;
340 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 345 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
341 crx_component.version = Version("0.9"); 346 crx_component.version = Version("0.9");
342 crx_component.installer = installer; 347 crx_component.installer = installer;
343 348
344 LoopHandler loop_handler(1, quit_closure()); 349 LoopHandler loop_handler(1, quit_closure());
345 EXPECT_CALL(update_client(), 350 EXPECT_CALL(update_client(),
346 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _)) 351 Install("jebgalgnebhfojomionfpkfelancnnkf", _, _))
347 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall)); 352 .WillOnce(Invoke(&loop_handler, &LoopHandler::OnInstall));
353 EXPECT_CALL(update_client(), Stop()).Times(1);
348 354
349 EXPECT_TRUE(component_updater().RegisterComponent(crx_component)); 355 EXPECT_TRUE(component_updater().RegisterComponent(crx_component));
350 component_updater().MaybeThrottle( 356 component_updater().MaybeThrottle(
351 "jebgalgnebhfojomionfpkfelancnnkf", 357 "jebgalgnebhfojomionfpkfelancnnkf",
352 base::Bind(&ComponentUpdaterTest::ReadyCallback)); 358 base::Bind(&ComponentUpdaterTest::ReadyCallback));
353 359
354 RunThreads(); 360 RunThreads();
355 } 361 }
356 362
357 } // namespace component_updater 363 } // namespace component_updater
OLDNEW
« no previous file with comments | « components/component_updater/component_updater_service.cc ('k') | components/update_client/task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698