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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 373 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
374 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 374 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
375 | 375 |
376 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 376 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
377 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 377 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
378 | 378 |
379 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 379 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
380 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 380 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
381 | 381 |
382 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 382 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
383 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 383 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
384 | 384 |
385 component_updater()->Stop(); | 385 component_updater()->Stop(); |
386 } | 386 } |
387 | 387 |
388 // This test is like the above InstallCrx but the second component | 388 // This test is like the above InstallCrx but the second component |
389 // has a different source. In this case there would be two manifest | 389 // has a different source. In this case there would be two manifest |
390 // checks to different urls, each only containing one component. | 390 // checks to different urls, each only containing one component. |
391 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { | 391 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { |
392 MessageLoop message_loop; | 392 MessageLoop message_loop; |
393 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 393 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); | 445 TestNotificationTracker::Event ev1 = notification_tracker().at(2); |
446 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 446 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
447 | 447 |
448 TestNotificationTracker::Event ev2 = notification_tracker().at(3); | 448 TestNotificationTracker::Event ev2 = notification_tracker().at(3); |
449 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 449 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
450 | 450 |
451 TestNotificationTracker::Event ev3 = notification_tracker().at(4); | 451 TestNotificationTracker::Event ev3 = notification_tracker().at(4); |
452 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 452 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
453 | 453 |
454 TestNotificationTracker::Event ev4 = notification_tracker().at(5); | 454 TestNotificationTracker::Event ev4 = notification_tracker().at(5); |
455 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 455 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
456 | 456 |
457 component_updater()->Stop(); | 457 component_updater()->Stop(); |
458 } | 458 } |
459 | 459 |
460 // This test checks that the "prodversionmin" value is handled correctly. In | 460 // This test checks that the "prodversionmin" value is handled correctly. In |
461 // particular there should not be an install because the minimum product | 461 // particular there should not be an install because the minimum product |
462 // version is much higher than of chrome. | 462 // version is much higher than of chrome. |
463 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 463 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
464 MessageLoop message_loop; | 464 MessageLoop message_loop; |
465 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 465 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
(...skipping 20 matching lines...) Expand all Loading... |
486 test_configurator()->SetLoopCount(1); | 486 test_configurator()->SetLoopCount(1); |
487 component_updater()->Start(); | 487 component_updater()->Start(); |
488 message_loop.Run(); | 488 message_loop.Run(); |
489 | 489 |
490 EXPECT_EQ(1, interceptor.GetHitCount()); | 490 EXPECT_EQ(1, interceptor.GetHitCount()); |
491 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 491 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
492 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 492 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
493 | 493 |
494 component_updater()->Stop(); | 494 component_updater()->Stop(); |
495 } | 495 } |
| 496 |
| 497 // Test that a ping for an update check can cause installs. |
| 498 // Here is the timeline: |
| 499 // - First loop: we return a reply that indicates no update, so |
| 500 // nothing happens. |
| 501 // - We ping. |
| 502 // - This triggers a second loop, which has a reply that triggers an install. |
| 503 TEST_F(ComponentUpdaterTest, PingUpdateCheck) { |
| 504 MessageLoop message_loop; |
| 505 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 506 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 507 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 508 |
| 509 io_thread.StartIOThread(); |
| 510 file_thread.Start(); |
| 511 |
| 512 content::URLRequestPrepackagedInterceptor interceptor; |
| 513 |
| 514 CrxComponent com1; |
| 515 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); |
| 516 CrxComponent com2; |
| 517 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); |
| 518 |
| 519 // The first the URL requests info for every registered component. |
| 520 const GURL expected_update_url_1( |
| 521 "http://localhost/upd?extra=foo&x=id%3D" |
| 522 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" |
| 523 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); |
| 524 |
| 525 // The second the URL only requests info for the pinged component. |
| 526 const GURL expected_update_url_2( |
| 527 "http://localhost/upd?extra=foo&x=id%3D" |
| 528 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); |
| 529 |
| 530 interceptor.SetResponse(expected_update_url_1, |
| 531 test_file("updatecheck_reply_empty")); |
| 532 interceptor.SetResponse(expected_update_url_2, |
| 533 test_file("updatecheck_reply_1.xml")); |
| 534 interceptor.SetResponse(GURL(expected_crx_url), |
| 535 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 536 |
| 537 test_configurator()->SetLoopCount(1); |
| 538 |
| 539 component_updater()->Start(); |
| 540 message_loop.Run(); |
| 541 |
| 542 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 543 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 544 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 545 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 546 |
| 547 EXPECT_EQ(ComponentUpdateService::kOk, |
| 548 component_updater()->PingUpdateCheck(com1)); |
| 549 message_loop.Run(); |
| 550 |
| 551 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 552 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 553 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 554 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 555 |
| 556 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 557 |
| 558 ASSERT_EQ(5ul, notification_tracker().size()); |
| 559 |
| 560 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 561 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 562 |
| 563 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 564 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev2.type); |
| 565 |
| 566 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| 567 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev3.type); |
| 568 |
| 569 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
| 570 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
| 571 |
| 572 component_updater()->Stop(); |
| 573 } |
OLD | NEW |