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

Unified Diff: chrome/browser/component_updater/test/component_updater_service_unittest.cc

Issue 12054003: Add an API to component_updater that asks to do an update check "now". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 7 years, 10 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 6db95a9efa0262bdcd910c60a1e4594f6331febb..f55d6cd25688ad6336fca8f2336c260cac4d02c3 100644
--- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc
+++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
@@ -160,7 +160,10 @@ class ComponentUpdaterTest : public testing::Test {
chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
- chrome::NOTIFICATION_COMPONENT_UPDATE_READY
+ chrome::NOTIFICATION_COMPONENT_UPDATE_READY,
+ chrome::NOTIFICATION_COMPONENT_UPDATE_COMPLETE,
+ chrome::NOTIFICATION_COMPONENT_UPDATE_NOT_UPDATED,
+ chrome::NOTIFICATION_COMPONENT_UPDATE_FAILED
};
for (int ix = 0; ix != arraysize(notifications); ++ix) {
@@ -380,7 +383,7 @@ TEST_F(ComponentUpdaterTest, InstallCrx) {
EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
TestNotificationTracker::Event ev4 = notification_tracker().at(4);
- EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
component_updater()->Stop();
}
@@ -452,7 +455,7 @@ TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) {
EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
TestNotificationTracker::Event ev4 = notification_tracker().at(5);
- EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
component_updater()->Stop();
}
@@ -493,3 +496,144 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
component_updater()->Stop();
}
+
+// Test that a ping for an update check can cause installs.
+// Here is the timeline:
+// - First loop: we return a reply that indicates no update, so
+// nothing happens.
+// - We ping.
+// - This triggers a second loop, which has a reply that triggers an install.
+TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
+ 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::URLRequestPrepackagedInterceptor interceptor;
+
+ CrxComponent com1;
+ RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"));
+ CrxComponent com2;
+ RegisterComponent(&com2, kTestComponent_abag, Version("2.2"));
+
+ // The first the URL requests info for every registered component.
+ const GURL expected_update_url_1(
+ "http://localhost/upd?extra=foo&x=id%3D"
+ "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D"
+ "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
+
+ // The second the URL only requests info for the pinged component.
+ const GURL expected_update_url_2(
+ "http://localhost/upd?extra=foo&x=id%3D"
+ "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%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_configurator()->SetLoopCount(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(0, static_cast<TestInstaller*>(com2.installer)->install_count());
+
+ // Test success.
+
+ // CheckForUpdateSoon also requires a loop to ScheduleNextRun,
+ // so we need to reset the component updater. The difference is that
+ // it will give preference to checking for work for the single com1.
+ component_updater()->Stop();
+ test_configurator()->SetLoopCount(1);
+ component_updater()->Start();
+ EXPECT_EQ(ComponentUpdateService::kOk,
+ component_updater()->CheckForUpdateSoon(com1));
+ EXPECT_EQ(ComponentUpdateService::kInProgress,
+ component_updater()->CheckForUpdateSoon(com2));
+ message_loop.Run();
+
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
+ EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
+
+ EXPECT_EQ(4, interceptor.GetHitCount());
+
+ ASSERT_EQ(7ul, 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_UPDATER_STARTED, ev2.type);
+
+ TestNotificationTracker::Event ev3 = notification_tracker().at(3);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev3.type);
+
+ TestNotificationTracker::Event ev4 = notification_tracker().at(4);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev4.type);
+
+ TestNotificationTracker::Event ev5 = notification_tracker().at(5);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_COMPLETE, ev5.type);
+
+ TestNotificationTracker::Event ev6 = notification_tracker().at(6);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev6.type);
+
+ component_updater()->Stop();
+
+ // Test a few error cases.
+ const GURL expected_update_url_3(
+ "http://localhost/upd?extra=foo&x=id%3D"
+ "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%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(com1));
+
+ message_loop.Run();
+
+ ASSERT_EQ(3ul, 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_UPDATE_FAILED, ev1.type);
+ ev2 = notification_tracker().at(2);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.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(com1));
+
+ message_loop.Run();
+
+ ASSERT_EQ(3ul, 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_UPDATE_NOT_UPDATED, ev1.type);
+ ev2 = notification_tracker().at(2);
+ EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
+ component_updater()->Stop();
+}

Powered by Google App Engine
This is Rietveld 408576698