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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/test/component_updater_service_unittest.cc
diff --git a/chrome/browser/component_updater/test/component_updater_service_unittest.cc b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
index b389e80bd79e6764f9ec90774437267380a1c8f6..0e33f2ec2dcf3b7a2599c0c289368fa3dd492f82 100644
--- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc
+++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
@@ -719,6 +719,124 @@ TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
component_updater()->Stop();
}
+// Like the above test, but sending an on-demand ping.
+TEST_F(ComponentUpdaterTest, CheckForUpdateSoonOnDemand) {
+ base::MessageLoop message_loop;
+ content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
+ content::TestBrowserThread file_thread(BrowserThread::FILE);
+ content::TestBrowserThread io_thread(BrowserThread::IO);
+
+ io_thread.StartIOThread();
+ file_thread.Start();
+
+ content::URLLocalHostRequestPrepackagedInterceptor interceptor;
+
+ TestInstaller installer1;
+ CrxComponent com1;
+ RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
+ TestInstaller installer2;
+ CrxComponent com2;
+ RegisterComponent(&com2, kTestComponent_jebg, Version("0.0"), &installer2);
+
+ const GURL expected_update_url_1(
+ "http://localhost/upd?extra=foo"
+ "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
+ "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.0%26fp%3D%26uc");
+
+ const GURL expected_update_url_2(
+ "http://localhost/upd?extra=foo"
+ "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.0%26fp%3D%26uc"
+ "%26installsource%3Dondemand"
+ "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
+
+ interceptor.SetResponse(expected_update_url_1,
+ test_file("updatecheck_reply_empty"));
+ interceptor.SetResponse(expected_update_url_2,
+ test_file("updatecheck_reply_1.xml"));
+ interceptor.SetResponse(GURL(expected_crx_url),
+ test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
+ // Test success.
+ test_configurator()->SetLoopCount(2);
+ test_configurator()->AddComponentToCheck(&com2, 1);
+ component_updater()->Start();
+ message_loop.Run();
+
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
+ EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
+
+ EXPECT_EQ(3, interceptor.GetHitCount());
+
+ ASSERT_EQ(5ul, notification_tracker().size());
+
+ TestNotificationTracker::Event ev0= notification_tracker().at(0);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
+
+ TestNotificationTracker::Event ev1 = notification_tracker().at(1);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
+
+ TestNotificationTracker::Event ev2 = notification_tracker().at(2);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev2.type);
+
+ TestNotificationTracker::Event ev3 = notification_tracker().at(3);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev3.type);
+
+ TestNotificationTracker::Event ev4 = notification_tracker().at(4);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
+
+ // Also check what happens if previous check too soon.
+ test_configurator()->SetOnDemandTime(60 * 60);
+ EXPECT_EQ(ComponentUpdateService::kError,
+ component_updater()->CheckForUpdateSoon(com2));
+ // Okay, now reset to 0 for the other tests.
+ test_configurator()->SetOnDemandTime(0);
+ component_updater()->Stop();
+
+ // Test a few error cases. NOTE: We don't have callbacks for
+ // when the updates failed yet.
+ const GURL expected_update_url_3(
+ "http://localhost/upd?extra=foo"
+ "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"
+ "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
+
+ // No update: error from no server response
+ interceptor.SetResponse(expected_update_url_3,
+ test_file("updatecheck_reply_empty"));
+ notification_tracker().Reset();
+ test_configurator()->SetLoopCount(1);
+ component_updater()->Start();
+ EXPECT_EQ(ComponentUpdateService::kOk,
+ component_updater()->CheckForUpdateSoon(com2));
+
+ message_loop.Run();
+
+ ASSERT_EQ(2ul, notification_tracker().size());
+ ev0 = notification_tracker().at(0);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
+ ev1 = notification_tracker().at(1);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
+ component_updater()->Stop();
+
+ // No update: already updated to 1.0 so nothing new
+ interceptor.SetResponse(expected_update_url_3,
+ test_file("updatecheck_reply_1.xml"));
+ notification_tracker().Reset();
+ test_configurator()->SetLoopCount(1);
+ component_updater()->Start();
+ EXPECT_EQ(ComponentUpdateService::kOk,
+ component_updater()->CheckForUpdateSoon(com2));
+
+ message_loop.Run();
+
+ ASSERT_EQ(2ul, notification_tracker().size());
+ ev0 = notification_tracker().at(0);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
+ ev1 = notification_tracker().at(1);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
+ component_updater()->Stop();
+}
+
// Verify that a previously registered component can get re-registered
// with a different version.
TEST_F(ComponentUpdaterTest, CheckReRegistration) {

Powered by Google App Engine
This is Rietveld 408576698