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

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

Issue 17419011: Implement coarse "on demand" functionality for update checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sync
Patch Set: Added a comment. 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
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 <list> 5 #include <list>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 message_loop.Run(); 712 message_loop.Run();
713 713
714 ASSERT_EQ(2ul, notification_tracker().size()); 714 ASSERT_EQ(2ul, notification_tracker().size());
715 ev0 = notification_tracker().at(0); 715 ev0 = notification_tracker().at(0);
716 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 716 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
717 ev1 = notification_tracker().at(1); 717 ev1 = notification_tracker().at(1);
718 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 718 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
719 component_updater()->Stop(); 719 component_updater()->Stop();
720 } 720 }
721 721
722 // Like the above test, but sending an on-demand ping.
723 TEST_F(ComponentUpdaterTest, CheckForUpdateSoonOnDemand) {
724 base::MessageLoop message_loop;
725 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
726 content::TestBrowserThread file_thread(BrowserThread::FILE);
727 content::TestBrowserThread io_thread(BrowserThread::IO);
728
729 io_thread.StartIOThread();
730 file_thread.Start();
731
732 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
733
734 TestInstaller installer1;
735 CrxComponent com1;
736 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
737 TestInstaller installer2;
738 CrxComponent com2;
739 RegisterComponent(&com2, kTestComponent_jebg, Version("0.0"), &installer2);
740
741 const GURL expected_update_url_1(
742 "http://localhost/upd?extra=foo"
743 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
744 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.0%26fp%3D%26uc");
745
746 const GURL expected_update_url_2(
747 "http://localhost/upd?extra=foo"
748 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.0%26fp%3D%26uc"
749 "%26installsource%3Dondemand"
750 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
751
752 interceptor.SetResponse(expected_update_url_1,
753 test_file("updatecheck_reply_empty"));
754 interceptor.SetResponse(expected_update_url_2,
755 test_file("updatecheck_reply_1.xml"));
756 interceptor.SetResponse(GURL(expected_crx_url),
757 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
758 // Test success.
759 test_configurator()->SetLoopCount(2);
760 test_configurator()->AddComponentToCheck(&com2, 1);
761 component_updater()->Start();
762 message_loop.Run();
763
764 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
765 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
766 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
767 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
768
769 EXPECT_EQ(3, interceptor.GetHitCount());
770
771 ASSERT_EQ(5ul, notification_tracker().size());
772
773 TestNotificationTracker::Event ev0= notification_tracker().at(0);
774 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
775
776 TestNotificationTracker::Event ev1 = notification_tracker().at(1);
777 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
778
779 TestNotificationTracker::Event ev2 = notification_tracker().at(2);
780 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev2.type);
781
782 TestNotificationTracker::Event ev3 = notification_tracker().at(3);
783 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev3.type);
784
785 TestNotificationTracker::Event ev4 = notification_tracker().at(4);
786 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
787
788 // Also check what happens if previous check too soon.
789 test_configurator()->SetOnDemandTime(60 * 60);
790 EXPECT_EQ(ComponentUpdateService::kError,
791 component_updater()->CheckForUpdateSoon(com2));
792 // Okay, now reset to 0 for the other tests.
793 test_configurator()->SetOnDemandTime(0);
794 component_updater()->Stop();
795
796 // Test a few error cases. NOTE: We don't have callbacks for
797 // when the updates failed yet.
798 const GURL expected_update_url_3(
799 "http://localhost/upd?extra=foo"
800 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"
801 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
802
803 // No update: error from no server response
804 interceptor.SetResponse(expected_update_url_3,
805 test_file("updatecheck_reply_empty"));
806 notification_tracker().Reset();
807 test_configurator()->SetLoopCount(1);
808 component_updater()->Start();
809 EXPECT_EQ(ComponentUpdateService::kOk,
810 component_updater()->CheckForUpdateSoon(com2));
811
812 message_loop.Run();
813
814 ASSERT_EQ(2ul, notification_tracker().size());
815 ev0 = notification_tracker().at(0);
816 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
817 ev1 = notification_tracker().at(1);
818 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
819 component_updater()->Stop();
820
821 // No update: already updated to 1.0 so nothing new
822 interceptor.SetResponse(expected_update_url_3,
823 test_file("updatecheck_reply_1.xml"));
824 notification_tracker().Reset();
825 test_configurator()->SetLoopCount(1);
826 component_updater()->Start();
827 EXPECT_EQ(ComponentUpdateService::kOk,
828 component_updater()->CheckForUpdateSoon(com2));
829
830 message_loop.Run();
831
832 ASSERT_EQ(2ul, notification_tracker().size());
833 ev0 = notification_tracker().at(0);
834 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
835 ev1 = notification_tracker().at(1);
836 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
837 component_updater()->Stop();
838 }
839
722 // Verify that a previously registered component can get re-registered 840 // Verify that a previously registered component can get re-registered
723 // with a different version. 841 // with a different version.
724 TEST_F(ComponentUpdaterTest, CheckReRegistration) { 842 TEST_F(ComponentUpdaterTest, CheckReRegistration) {
725 base::MessageLoop message_loop; 843 base::MessageLoop message_loop;
726 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 844 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
727 content::TestBrowserThread file_thread(BrowserThread::FILE); 845 content::TestBrowserThread file_thread(BrowserThread::FILE);
728 content::TestBrowserThread io_thread(BrowserThread::IO); 846 content::TestBrowserThread io_thread(BrowserThread::IO);
729 847
730 io_thread.StartIOThread(); 848 io_thread.StartIOThread();
731 file_thread.Start(); 849 file_thread.Start();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 component_updater()->Start(); 1130 component_updater()->Start();
1013 message_loop.Run(); 1131 message_loop.Run();
1014 1132
1015 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 1133 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1016 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 1134 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
1017 1135
1018 EXPECT_EQ(6, interceptor.GetHitCount()); 1136 EXPECT_EQ(6, interceptor.GetHitCount());
1019 1137
1020 component_updater()->Stop(); 1138 component_updater()->Stop();
1021 } 1139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698