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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 153 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
154 // The test directory is chrome/test/data/components. | 154 // The test directory is chrome/test/data/components. |
155 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 155 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
156 test_data_dir_ = test_data_dir_.AppendASCII("components"); | 156 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
157 | 157 |
158 // Subscribe to all component updater notifications. | 158 // Subscribe to all component updater notifications. |
159 const int notifications[] = { | 159 const int notifications[] = { |
160 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, | 160 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, |
161 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | 161 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
162 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, | 162 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, |
163 chrome::NOTIFICATION_COMPONENT_UPDATE_READY | 163 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, |
| 164 chrome::NOTIFICATION_COMPONENT_UPDATE_COMPLETE, |
| 165 chrome::NOTIFICATION_COMPONENT_UPDATE_NOT_UPDATED, |
| 166 chrome::NOTIFICATION_COMPONENT_UPDATE_FAILED |
164 }; | 167 }; |
165 | 168 |
166 for (int ix = 0; ix != arraysize(notifications); ++ix) { | 169 for (int ix = 0; ix != arraysize(notifications); ++ix) { |
167 notification_tracker_.ListenFor( | 170 notification_tracker_.ListenFor( |
168 notifications[ix], content::NotificationService::AllSources()); | 171 notifications[ix], content::NotificationService::AllSources()); |
169 } | 172 } |
170 net::URLFetcher::SetEnableInterceptionForTests(true); | 173 net::URLFetcher::SetEnableInterceptionForTests(true); |
171 } | 174 } |
172 | 175 |
173 ~ComponentUpdaterTest() { | 176 ~ComponentUpdaterTest() { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 376 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
374 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 377 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
375 | 378 |
376 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 379 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
377 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 380 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
378 | 381 |
379 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 382 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
380 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 383 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
381 | 384 |
382 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 385 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
383 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 386 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
384 | 387 |
385 component_updater()->Stop(); | 388 component_updater()->Stop(); |
386 } | 389 } |
387 | 390 |
388 // This test is like the above InstallCrx but the second component | 391 // This test is like the above InstallCrx but the second component |
389 // has a different source. In this case there would be two manifest | 392 // has a different source. In this case there would be two manifest |
390 // checks to different urls, each only containing one component. | 393 // checks to different urls, each only containing one component. |
391 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { | 394 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { |
392 MessageLoop message_loop; | 395 MessageLoop message_loop; |
393 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 396 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 TestNotificationTracker::Event ev1 = notification_tracker().at(2); | 448 TestNotificationTracker::Event ev1 = notification_tracker().at(2); |
446 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 449 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
447 | 450 |
448 TestNotificationTracker::Event ev2 = notification_tracker().at(3); | 451 TestNotificationTracker::Event ev2 = notification_tracker().at(3); |
449 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 452 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
450 | 453 |
451 TestNotificationTracker::Event ev3 = notification_tracker().at(4); | 454 TestNotificationTracker::Event ev3 = notification_tracker().at(4); |
452 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 455 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
453 | 456 |
454 TestNotificationTracker::Event ev4 = notification_tracker().at(5); | 457 TestNotificationTracker::Event ev4 = notification_tracker().at(5); |
455 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 458 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
456 | 459 |
457 component_updater()->Stop(); | 460 component_updater()->Stop(); |
458 } | 461 } |
459 | 462 |
460 // This test checks that the "prodversionmin" value is handled correctly. In | 463 // This test checks that the "prodversionmin" value is handled correctly. In |
461 // particular there should not be an install because the minimum product | 464 // particular there should not be an install because the minimum product |
462 // version is much higher than of chrome. | 465 // version is much higher than of chrome. |
463 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 466 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
464 MessageLoop message_loop; | 467 MessageLoop message_loop; |
465 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 468 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
(...skipping 20 matching lines...) Expand all Loading... |
486 test_configurator()->SetLoopCount(1); | 489 test_configurator()->SetLoopCount(1); |
487 component_updater()->Start(); | 490 component_updater()->Start(); |
488 message_loop.Run(); | 491 message_loop.Run(); |
489 | 492 |
490 EXPECT_EQ(1, interceptor.GetHitCount()); | 493 EXPECT_EQ(1, interceptor.GetHitCount()); |
491 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 494 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
492 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 495 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
493 | 496 |
494 component_updater()->Stop(); | 497 component_updater()->Stop(); |
495 } | 498 } |
| 499 |
| 500 // Test that a ping for an update check can cause installs. |
| 501 // Here is the timeline: |
| 502 // - First loop: we return a reply that indicates no update, so |
| 503 // nothing happens. |
| 504 // - We ping. |
| 505 // - This triggers a second loop, which has a reply that triggers an install. |
| 506 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { |
| 507 MessageLoop message_loop; |
| 508 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 509 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 510 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 511 |
| 512 io_thread.StartIOThread(); |
| 513 file_thread.Start(); |
| 514 |
| 515 content::URLRequestPrepackagedInterceptor interceptor; |
| 516 |
| 517 CrxComponent com1; |
| 518 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); |
| 519 CrxComponent com2; |
| 520 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); |
| 521 |
| 522 // The first the URL requests info for every registered component. |
| 523 const GURL expected_update_url_1( |
| 524 "http://localhost/upd?extra=foo&x=id%3D" |
| 525 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" |
| 526 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); |
| 527 |
| 528 // The second the URL only requests info for the pinged component. |
| 529 const GURL expected_update_url_2( |
| 530 "http://localhost/upd?extra=foo&x=id%3D" |
| 531 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); |
| 532 |
| 533 interceptor.SetResponse(expected_update_url_1, |
| 534 test_file("updatecheck_reply_empty")); |
| 535 interceptor.SetResponse(expected_update_url_2, |
| 536 test_file("updatecheck_reply_1.xml")); |
| 537 interceptor.SetResponse(GURL(expected_crx_url), |
| 538 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 539 |
| 540 test_configurator()->SetLoopCount(1); |
| 541 component_updater()->Start(); |
| 542 message_loop.Run(); |
| 543 |
| 544 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 545 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 546 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 547 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 548 |
| 549 // Test success. |
| 550 |
| 551 // CheckForUpdateSoon also requires a loop to ScheduleNextRun, |
| 552 // so we need to reset the component updater. The difference is that |
| 553 // it will give preference to checking for work for the single com1. |
| 554 component_updater()->Stop(); |
| 555 test_configurator()->SetLoopCount(1); |
| 556 component_updater()->Start(); |
| 557 EXPECT_EQ(ComponentUpdateService::kOk, |
| 558 component_updater()->CheckForUpdateSoon(com1)); |
| 559 EXPECT_EQ(ComponentUpdateService::kInProgress, |
| 560 component_updater()->CheckForUpdateSoon(com2)); |
| 561 message_loop.Run(); |
| 562 |
| 563 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 564 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 565 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 566 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 567 |
| 568 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 569 |
| 570 ASSERT_EQ(7ul, notification_tracker().size()); |
| 571 |
| 572 TestNotificationTracker::Event ev0= notification_tracker().at(0); |
| 573 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 574 |
| 575 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 576 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 577 |
| 578 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 579 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev2.type); |
| 580 |
| 581 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| 582 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev3.type); |
| 583 |
| 584 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
| 585 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev4.type); |
| 586 |
| 587 TestNotificationTracker::Event ev5 = notification_tracker().at(5); |
| 588 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_COMPLETE, ev5.type); |
| 589 |
| 590 TestNotificationTracker::Event ev6 = notification_tracker().at(6); |
| 591 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev6.type); |
| 592 |
| 593 component_updater()->Stop(); |
| 594 |
| 595 // Test a few error cases. |
| 596 const GURL expected_update_url_3( |
| 597 "http://localhost/upd?extra=foo&x=id%3D" |
| 598 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"); |
| 599 |
| 600 // No update: error from no server response |
| 601 interceptor.SetResponse(expected_update_url_3, |
| 602 test_file("updatecheck_reply_empty")); |
| 603 notification_tracker().Reset(); |
| 604 test_configurator()->SetLoopCount(1); |
| 605 component_updater()->Start(); |
| 606 EXPECT_EQ(ComponentUpdateService::kOk, |
| 607 component_updater()->CheckForUpdateSoon(com1)); |
| 608 |
| 609 message_loop.Run(); |
| 610 |
| 611 ASSERT_EQ(3ul, notification_tracker().size()); |
| 612 ev0 = notification_tracker().at(0); |
| 613 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 614 ev1 = notification_tracker().at(1); |
| 615 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FAILED, ev1.type); |
| 616 ev2 = notification_tracker().at(2); |
| 617 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 618 component_updater()->Stop(); |
| 619 |
| 620 // No update: already updated to 1.0 so nothing new |
| 621 interceptor.SetResponse(expected_update_url_3, |
| 622 test_file("updatecheck_reply_1.xml")); |
| 623 notification_tracker().Reset(); |
| 624 test_configurator()->SetLoopCount(1); |
| 625 component_updater()->Start(); |
| 626 EXPECT_EQ(ComponentUpdateService::kOk, |
| 627 component_updater()->CheckForUpdateSoon(com1)); |
| 628 |
| 629 message_loop.Run(); |
| 630 |
| 631 ASSERT_EQ(3ul, notification_tracker().size()); |
| 632 ev0 = notification_tracker().at(0); |
| 633 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 634 ev1 = notification_tracker().at(1); |
| 635 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_NOT_UPDATED, ev1.type); |
| 636 ev2 = notification_tracker().at(2); |
| 637 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 638 component_updater()->Stop(); |
| 639 } |
OLD | NEW |