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

Side by Side Diff: chrome/browser/component_updater/test/component_updater_service_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/component_updater/component_updater_service.h" 5 #include "chrome/browser/component_updater/component_updater_service.h"
6 6
7 #include <list> 7 #include <list>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 virtual int InitialDelay() OVERRIDE { return 0; } 42 virtual int InitialDelay() OVERRIDE { return 0; }
43 43
44 typedef std::pair<CrxComponent*, int> CheckAtLoopCount; 44 typedef std::pair<CrxComponent*, int> CheckAtLoopCount;
45 45
46 virtual int NextCheckDelay() OVERRIDE { 46 virtual int NextCheckDelay() OVERRIDE {
47 // This is called when a new full cycle of checking for updates is going 47 // This is called when a new full cycle of checking for updates is going
48 // to happen. In test we normally only test one cycle so it is a good 48 // to happen. In test we normally only test one cycle so it is a good
49 // time to break from the test messageloop Run() method so the test can 49 // time to break from the test messageloop Run() method so the test can
50 // finish. 50 // finish.
51 if (--times_ <= 0) { 51 if (--times_ <= 0) {
52 MessageLoop::current()->Quit(); 52 base::MessageLoop::current()->Quit();
53 return 0; 53 return 0;
54 54
55 } 55 }
56 56
57 // Look for checks to issue in the middle of the loop. 57 // Look for checks to issue in the middle of the loop.
58 for (std::list<CheckAtLoopCount>::iterator 58 for (std::list<CheckAtLoopCount>::iterator
59 i = components_to_check_.begin(); 59 i = components_to_check_.begin();
60 i != components_to_check_.end(); ) { 60 i != components_to_check_.end(); ) {
61 if (i->second == times_) { 61 if (i->second == times_) {
62 cus_->CheckForUpdateSoon(*i->first); 62 cus_->CheckForUpdateSoon(*i->first);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // be created and destroyed with no side effects. 264 // be created and destroyed with no side effects.
265 TEST_F(ComponentUpdaterTest, VerifyFixture) { 265 TEST_F(ComponentUpdaterTest, VerifyFixture) {
266 EXPECT_TRUE(component_updater() != NULL); 266 EXPECT_TRUE(component_updater() != NULL);
267 EXPECT_EQ(0ul, notification_tracker().size()); 267 EXPECT_EQ(0ul, notification_tracker().size());
268 } 268 }
269 269
270 // Verify that the component updater can be caught in a quick 270 // Verify that the component updater can be caught in a quick
271 // start-shutdown situation. Failure of this test will be a crash. Also 271 // start-shutdown situation. Failure of this test will be a crash. Also
272 // if there is no work to do, there are no notifications generated. 272 // if there is no work to do, there are no notifications generated.
273 TEST_F(ComponentUpdaterTest, StartStop) { 273 TEST_F(ComponentUpdaterTest, StartStop) {
274 MessageLoop message_loop; 274 base::MessageLoop message_loop;
275 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 275 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
276 276
277 component_updater()->Start(); 277 component_updater()->Start();
278 message_loop.RunUntilIdle(); 278 message_loop.RunUntilIdle();
279 component_updater()->Stop(); 279 component_updater()->Stop();
280 280
281 EXPECT_EQ(0ul, notification_tracker().size()); 281 EXPECT_EQ(0ul, notification_tracker().size());
282 } 282 }
283 283
284 // Verify that when the server has no updates, we go back to sleep and 284 // Verify that when the server has no updates, we go back to sleep and
285 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications 285 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications
286 // are generated. 286 // are generated.
287 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { 287 TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
288 MessageLoop message_loop; 288 base::MessageLoop message_loop;
289 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 289 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
290 content::TestBrowserThread file_thread(BrowserThread::FILE); 290 content::TestBrowserThread file_thread(BrowserThread::FILE);
291 content::TestBrowserThread io_thread(BrowserThread::IO); 291 content::TestBrowserThread io_thread(BrowserThread::IO);
292 292
293 io_thread.StartIOThread(); 293 io_thread.StartIOThread();
294 file_thread.Start(); 294 file_thread.Start();
295 295
296 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 296 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
297 297
298 CrxComponent com; 298 CrxComponent com;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 357
358 // Verify that we can check for updates and install one component. Besides 358 // Verify that we can check for updates and install one component. Besides
359 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and 359 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and
360 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops 360 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops
361 // so the second time around there should be nothing left to do. 361 // so the second time around there should be nothing left to do.
362 // We also check that only 3 network requests are issued: 362 // We also check that only 3 network requests are issued:
363 // 1- manifest check 363 // 1- manifest check
364 // 2- download crx 364 // 2- download crx
365 // 3- second manifest check. 365 // 3- second manifest check.
366 TEST_F(ComponentUpdaterTest, InstallCrx) { 366 TEST_F(ComponentUpdaterTest, InstallCrx) {
367 MessageLoop message_loop; 367 base::MessageLoop message_loop;
368 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 368 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
369 content::TestBrowserThread file_thread(BrowserThread::FILE); 369 content::TestBrowserThread file_thread(BrowserThread::FILE);
370 content::TestBrowserThread io_thread(BrowserThread::IO); 370 content::TestBrowserThread io_thread(BrowserThread::IO);
371 371
372 io_thread.StartIOThread(); 372 io_thread.StartIOThread();
373 file_thread.Start(); 373 file_thread.Start();
374 374
375 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 375 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
376 376
377 CrxComponent com1; 377 CrxComponent com1;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 TestNotificationTracker::Event ev4 = notification_tracker().at(4); 422 TestNotificationTracker::Event ev4 = notification_tracker().at(4);
423 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); 423 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
424 424
425 component_updater()->Stop(); 425 component_updater()->Stop();
426 } 426 }
427 427
428 // This test is like the above InstallCrx but the second component 428 // This test is like the above InstallCrx but the second component
429 // has a different source. In this case there would be two manifest 429 // has a different source. In this case there would be two manifest
430 // checks to different urls, each only containing one component. 430 // checks to different urls, each only containing one component.
431 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { 431 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) {
432 MessageLoop message_loop; 432 base::MessageLoop message_loop;
433 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 433 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
434 content::TestBrowserThread file_thread(BrowserThread::FILE); 434 content::TestBrowserThread file_thread(BrowserThread::FILE);
435 content::TestBrowserThread io_thread(BrowserThread::IO); 435 content::TestBrowserThread io_thread(BrowserThread::IO);
436 436
437 io_thread.StartIOThread(); 437 io_thread.StartIOThread();
438 file_thread.Start(); 438 file_thread.Start();
439 439
440 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 440 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
441 441
442 CrxComponent com1; 442 CrxComponent com1;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 TestNotificationTracker::Event ev4 = notification_tracker().at(5); 494 TestNotificationTracker::Event ev4 = notification_tracker().at(5);
495 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); 495 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
496 496
497 component_updater()->Stop(); 497 component_updater()->Stop();
498 } 498 }
499 499
500 // This test checks that the "prodversionmin" value is handled correctly. In 500 // This test checks that the "prodversionmin" value is handled correctly. In
501 // particular there should not be an install because the minimum product 501 // particular there should not be an install because the minimum product
502 // version is much higher than of chrome. 502 // version is much higher than of chrome.
503 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { 503 TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
504 MessageLoop message_loop; 504 base::MessageLoop message_loop;
505 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 505 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
506 content::TestBrowserThread file_thread(BrowserThread::FILE); 506 content::TestBrowserThread file_thread(BrowserThread::FILE);
507 content::TestBrowserThread io_thread(BrowserThread::IO); 507 content::TestBrowserThread io_thread(BrowserThread::IO);
508 508
509 io_thread.StartIOThread(); 509 io_thread.StartIOThread();
510 file_thread.Start(); 510 file_thread.Start();
511 511
512 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 512 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
513 513
514 CrxComponent com; 514 CrxComponent com;
(...skipping 19 matching lines...) Expand all
534 component_updater()->Stop(); 534 component_updater()->Stop();
535 } 535 }
536 536
537 // Test that a ping for an update check can cause installs. 537 // Test that a ping for an update check can cause installs.
538 // Here is the timeline: 538 // Here is the timeline:
539 // - First loop: we return a reply that indicates no update, so 539 // - First loop: we return a reply that indicates no update, so
540 // nothing happens. 540 // nothing happens.
541 // - We ping. 541 // - We ping.
542 // - This triggers a second loop, which has a reply that triggers an install. 542 // - This triggers a second loop, which has a reply that triggers an install.
543 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { 543 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
544 MessageLoop message_loop; 544 base::MessageLoop message_loop;
545 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 545 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
546 content::TestBrowserThread file_thread(BrowserThread::FILE); 546 content::TestBrowserThread file_thread(BrowserThread::FILE);
547 content::TestBrowserThread io_thread(BrowserThread::IO); 547 content::TestBrowserThread io_thread(BrowserThread::IO);
548 548
549 io_thread.StartIOThread(); 549 io_thread.StartIOThread();
550 file_thread.Start(); 550 file_thread.Start();
551 551
552 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 552 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
553 553
554 CrxComponent com1; 554 CrxComponent com1;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 ev0 = notification_tracker().at(0); 650 ev0 = notification_tracker().at(0);
651 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 651 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
652 ev1 = notification_tracker().at(1); 652 ev1 = notification_tracker().at(1);
653 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 653 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
654 component_updater()->Stop(); 654 component_updater()->Stop();
655 } 655 }
656 656
657 // Verify that a previously registered component can get re-registered 657 // Verify that a previously registered component can get re-registered
658 // with a different version. 658 // with a different version.
659 TEST_F(ComponentUpdaterTest, CheckReRegistration) { 659 TEST_F(ComponentUpdaterTest, CheckReRegistration) {
660 MessageLoop message_loop; 660 base::MessageLoop message_loop;
661 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 661 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
662 content::TestBrowserThread file_thread(BrowserThread::FILE); 662 content::TestBrowserThread file_thread(BrowserThread::FILE);
663 content::TestBrowserThread io_thread(BrowserThread::IO); 663 content::TestBrowserThread io_thread(BrowserThread::IO);
664 664
665 io_thread.StartIOThread(); 665 io_thread.StartIOThread();
666 file_thread.Start(); 666 file_thread.Start();
667 667
668 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 668 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
669 669
670 CrxComponent com1; 670 CrxComponent com1;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 755
756 // The test harness's Register() function creates a new installer, 756 // The test harness's Register() function creates a new installer,
757 // so the counts go back to 0. 757 // so the counts go back to 0.
758 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 758 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
760 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 760 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
762 762
763 component_updater()->Stop(); 763 component_updater()->Stop();
764 } 764 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698