| OLD | NEW |
| 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 Loading... |
| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // be created and destroyed with no side effects. | 265 // be created and destroyed with no side effects. |
| 266 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 266 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
| 267 EXPECT_TRUE(component_updater() != NULL); | 267 EXPECT_TRUE(component_updater() != NULL); |
| 268 EXPECT_EQ(0ul, notification_tracker().size()); | 268 EXPECT_EQ(0ul, notification_tracker().size()); |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Verify that the component updater can be caught in a quick | 271 // Verify that the component updater can be caught in a quick |
| 272 // start-shutdown situation. Failure of this test will be a crash. Also | 272 // start-shutdown situation. Failure of this test will be a crash. Also |
| 273 // if there is no work to do, there are no notifications generated. | 273 // if there is no work to do, there are no notifications generated. |
| 274 TEST_F(ComponentUpdaterTest, StartStop) { | 274 TEST_F(ComponentUpdaterTest, StartStop) { |
| 275 MessageLoop message_loop; | 275 base::MessageLoop message_loop; |
| 276 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 276 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 277 | 277 |
| 278 component_updater()->Start(); | 278 component_updater()->Start(); |
| 279 message_loop.RunUntilIdle(); | 279 message_loop.RunUntilIdle(); |
| 280 component_updater()->Stop(); | 280 component_updater()->Stop(); |
| 281 | 281 |
| 282 EXPECT_EQ(0ul, notification_tracker().size()); | 282 EXPECT_EQ(0ul, notification_tracker().size()); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // Verify that when the server has no updates, we go back to sleep and | 285 // Verify that when the server has no updates, we go back to sleep and |
| 286 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications | 286 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
| 287 // are generated. | 287 // are generated. |
| 288 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 288 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| 289 MessageLoop message_loop; | 289 base::MessageLoop message_loop; |
| 290 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 290 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 291 content::TestBrowserThread file_thread(BrowserThread::FILE); | 291 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 292 content::TestBrowserThread io_thread(BrowserThread::IO); | 292 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 293 | 293 |
| 294 io_thread.StartIOThread(); | 294 io_thread.StartIOThread(); |
| 295 file_thread.Start(); | 295 file_thread.Start(); |
| 296 | 296 |
| 297 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 297 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 298 | 298 |
| 299 CrxComponent com; | 299 CrxComponent com; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 // Verify that we can check for updates and install one component. Besides | 359 // Verify that we can check for updates and install one component. Besides |
| 360 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and | 360 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and |
| 361 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops | 361 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops |
| 362 // so the second time around there should be nothing left to do. | 362 // so the second time around there should be nothing left to do. |
| 363 // We also check that only 3 network requests are issued: | 363 // We also check that only 3 network requests are issued: |
| 364 // 1- manifest check | 364 // 1- manifest check |
| 365 // 2- download crx | 365 // 2- download crx |
| 366 // 3- second manifest check. | 366 // 3- second manifest check. |
| 367 TEST_F(ComponentUpdaterTest, InstallCrx) { | 367 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 368 MessageLoop message_loop; | 368 base::MessageLoop message_loop; |
| 369 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 369 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 370 content::TestBrowserThread file_thread(BrowserThread::FILE); | 370 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 371 content::TestBrowserThread io_thread(BrowserThread::IO); | 371 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 372 | 372 |
| 373 io_thread.StartIOThread(); | 373 io_thread.StartIOThread(); |
| 374 file_thread.Start(); | 374 file_thread.Start(); |
| 375 | 375 |
| 376 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 376 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 377 | 377 |
| 378 CrxComponent com1; | 378 CrxComponent com1; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 423 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
| 424 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 424 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
| 425 | 425 |
| 426 component_updater()->Stop(); | 426 component_updater()->Stop(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 // This test is like the above InstallCrx but the second component | 429 // This test is like the above InstallCrx but the second component |
| 430 // has a different source. In this case there would be two manifest | 430 // has a different source. In this case there would be two manifest |
| 431 // checks to different urls, each only containing one component. | 431 // checks to different urls, each only containing one component. |
| 432 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { | 432 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { |
| 433 MessageLoop message_loop; | 433 base::MessageLoop message_loop; |
| 434 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 434 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 435 content::TestBrowserThread file_thread(BrowserThread::FILE); | 435 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 436 content::TestBrowserThread io_thread(BrowserThread::IO); | 436 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 437 | 437 |
| 438 io_thread.StartIOThread(); | 438 io_thread.StartIOThread(); |
| 439 file_thread.Start(); | 439 file_thread.Start(); |
| 440 | 440 |
| 441 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 441 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 442 | 442 |
| 443 CrxComponent com1; | 443 CrxComponent com1; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 TestNotificationTracker::Event ev4 = notification_tracker().at(5); | 495 TestNotificationTracker::Event ev4 = notification_tracker().at(5); |
| 496 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 496 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
| 497 | 497 |
| 498 component_updater()->Stop(); | 498 component_updater()->Stop(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 // This test checks that the "prodversionmin" value is handled correctly. In | 501 // This test checks that the "prodversionmin" value is handled correctly. In |
| 502 // particular there should not be an install because the minimum product | 502 // particular there should not be an install because the minimum product |
| 503 // version is much higher than of chrome. | 503 // version is much higher than of chrome. |
| 504 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 504 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| 505 MessageLoop message_loop; | 505 base::MessageLoop message_loop; |
| 506 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 506 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 507 content::TestBrowserThread file_thread(BrowserThread::FILE); | 507 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 508 content::TestBrowserThread io_thread(BrowserThread::IO); | 508 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 509 | 509 |
| 510 io_thread.StartIOThread(); | 510 io_thread.StartIOThread(); |
| 511 file_thread.Start(); | 511 file_thread.Start(); |
| 512 | 512 |
| 513 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 513 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 514 | 514 |
| 515 CrxComponent com; | 515 CrxComponent com; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 535 component_updater()->Stop(); | 535 component_updater()->Stop(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 // Test that a ping for an update check can cause installs. | 538 // Test that a ping for an update check can cause installs. |
| 539 // Here is the timeline: | 539 // Here is the timeline: |
| 540 // - First loop: we return a reply that indicates no update, so | 540 // - First loop: we return a reply that indicates no update, so |
| 541 // nothing happens. | 541 // nothing happens. |
| 542 // - We ping. | 542 // - We ping. |
| 543 // - This triggers a second loop, which has a reply that triggers an install. | 543 // - This triggers a second loop, which has a reply that triggers an install. |
| 544 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { | 544 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { |
| 545 MessageLoop message_loop; | 545 base::MessageLoop message_loop; |
| 546 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 546 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 547 content::TestBrowserThread file_thread(BrowserThread::FILE); | 547 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 548 content::TestBrowserThread io_thread(BrowserThread::IO); | 548 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 549 | 549 |
| 550 io_thread.StartIOThread(); | 550 io_thread.StartIOThread(); |
| 551 file_thread.Start(); | 551 file_thread.Start(); |
| 552 | 552 |
| 553 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 553 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 554 | 554 |
| 555 CrxComponent com1; | 555 CrxComponent com1; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 ev0 = notification_tracker().at(0); | 651 ev0 = notification_tracker().at(0); |
| 652 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 652 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 653 ev1 = notification_tracker().at(1); | 653 ev1 = notification_tracker().at(1); |
| 654 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 654 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 655 component_updater()->Stop(); | 655 component_updater()->Stop(); |
| 656 } | 656 } |
| 657 | 657 |
| 658 // Verify that a previously registered component can get re-registered | 658 // Verify that a previously registered component can get re-registered |
| 659 // with a different version. | 659 // with a different version. |
| 660 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 660 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| 661 MessageLoop message_loop; | 661 base::MessageLoop message_loop; |
| 662 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 662 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 663 content::TestBrowserThread file_thread(BrowserThread::FILE); | 663 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 664 content::TestBrowserThread io_thread(BrowserThread::IO); | 664 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 665 | 665 |
| 666 io_thread.StartIOThread(); | 666 io_thread.StartIOThread(); |
| 667 file_thread.Start(); | 667 file_thread.Start(); |
| 668 | 668 |
| 669 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 669 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 670 | 670 |
| 671 CrxComponent com1; | 671 CrxComponent com1; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 756 |
| 757 // The test harness's Register() function creates a new installer, | 757 // The test harness's Register() function creates a new installer, |
| 758 // so the counts go back to 0. | 758 // so the counts go back to 0. |
| 759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 760 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 760 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 762 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 762 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 763 | 763 |
| 764 component_updater()->Stop(); | 764 component_updater()->Stop(); |
| 765 } | 765 } |
| OLD | NEW |