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

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

Issue 18516010: Implemented completion pings for component updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 9277e887a7a001b74d988ed9f9a0edbc4123d4e2..50b3ad72ac16d020f1a1ffb2b11baadde6e1beba 100644
--- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc
+++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
@@ -83,7 +83,11 @@ int TestConfigurator::OnDemandDelay() {
}
GURL TestConfigurator::UpdateUrl() {
- return GURL("http://localhost/upd");
+ return GURL("http://localhost/upd");
+}
+
+GURL TestConfigurator::PingUrl() {
+ return GURL("http://localhost2/ping");
}
const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
@@ -98,8 +102,6 @@ net::URLRequestContextGetter* TestConfigurator::RequestContext() {
// Don't use the utility process to decode files.
bool TestConfigurator::InProcess() { return true; }
-void TestConfigurator::OnEvent(Events event, int extra) { }
-
ComponentPatcher* TestConfigurator::CreateComponentPatcher() {
return new MockComponentPatcher();
}
@@ -197,6 +199,48 @@ ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
return component_updater_->RegisterComponent(*com);
}
+PingChecker::PingChecker(const std::map<std::string, std::string>& attributes)
+ : num_hits_(0), num_misses_(0), attributes_(attributes) {
+}
+
+PingChecker::~PingChecker() {}
+
+void PingChecker::Trial(net::URLRequest* request) {
+ if (Test(request))
+ ++num_hits_;
+ else
+ ++num_misses_;
+}
+
+bool PingChecker::Test(net::URLRequest* request) {
+ if (request->has_upload()) {
+ const net::UploadDataStream* stream = request->get_upload();
+ const net::UploadBytesElementReader* reader =
+ stream->element_readers()[0]->AsBytesReader();
+ int size = reader->length();
+ scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size);
+ std::string data(reader->bytes());
+ // For now, we assume that there is only one ping per POST.
+ std::string::size_type start = data.find("<o:event");
+ if (start != std::string::npos) {
+ std::string::size_type end = data.find(">", start);
+ if (end != std::string::npos) {
+ std::string ping = data.substr(start, end - start);
+ std::map<std::string, std::string>::const_iterator iter;
+ for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) {
+ // does the ping contain the specified attribute/value?
+ if (ping.find(std::string(" ") + (iter->first) +
+ std::string("=") + (iter->second)) == string::npos) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
// Verify that our test fixture work and the component updater can
// be created and destroyed with no side effects.
TEST_F(ComponentUpdaterTest, VerifyFixture) {
@@ -300,7 +344,7 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
// the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and
// NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops
// so the second time around there should be nothing left to do.
-// We also check that only 3 network requests are issued:
+// We also check that only 3 non-ping network requests are issued:
// 1- manifest check
// 2- download crx
// 3- second manifest check.
@@ -313,6 +357,14 @@ TEST_F(ComponentUpdaterTest, InstallCrx) {
io_thread.StartIOThread();
file_thread.Start();
+ std::map<std::string, std::string> map;
+ map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
+ map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
+ map.insert(std::pair<std::string, std::string>("previousversion",
+ "\"0.9\""));
+ map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
TestInstaller installer1;
@@ -350,6 +402,8 @@ TEST_F(ComponentUpdaterTest, InstallCrx) {
EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
EXPECT_EQ(3, interceptor.GetHitCount());
+ EXPECT_EQ(1, ping_checker.NumHits());
+ EXPECT_EQ(0, ping_checker.NumMisses());
ASSERT_EQ(5ul, notification_tracker().size());
@@ -380,6 +434,9 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
io_thread.StartIOThread();
file_thread.Start();
+ std::map<std::string, std::string> map;
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
TestInstaller installer;
@@ -399,6 +456,8 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
component_updater()->Start();
message_loop.Run();
+ EXPECT_EQ(0, ping_checker.NumHits());
+ EXPECT_EQ(0, ping_checker.NumMisses());
EXPECT_EQ(1, interceptor.GetHitCount());
EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
@@ -421,6 +480,14 @@ TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
io_thread.StartIOThread();
file_thread.Start();
+ std::map<std::string, std::string> map;
+ map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
+ map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
+ map.insert(std::pair<std::string, std::string>("previousversion",
+ "\"0.9\""));
+ map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
TestInstaller installer1;
@@ -521,6 +588,8 @@ TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
message_loop.Run();
+ EXPECT_EQ(1, ping_checker.NumHits());
+ EXPECT_EQ(0, ping_checker.NumMisses());
ASSERT_EQ(2ul, notification_tracker().size());
ev0 = notification_tracker().at(0);
EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
@@ -540,6 +609,14 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
io_thread.StartIOThread();
file_thread.Start();
+ std::map<std::string, std::string> map;
+ map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
+ map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
+ map.insert(std::pair<std::string, std::string>("previousversion",
+ "\"0.9\""));
+ map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
TestInstaller installer1;
@@ -579,6 +656,8 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
+ EXPECT_EQ(1, ping_checker.NumHits());
+ EXPECT_EQ(0, ping_checker.NumMisses());
EXPECT_EQ(3, interceptor.GetHitCount());
ASSERT_EQ(5ul, notification_tracker().size());
@@ -647,11 +726,12 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
// a full update if the differential update fails (in this case, because the
// installer does not know about the existing files). We do two loops; the final
// loop should do nothing.
-// We also check that exactly 4 network requests are issued:
+// We also check that exactly 4 non-ping network requests are issued:
// 1- update check (loop 1)
// 2- download differential crx
// 3- download full crx
// 4- update check (loop 2 - no update available)
+// There should be one ping for the first attempted update.
TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
base::MessageLoop message_loop;
content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
@@ -661,6 +741,13 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
io_thread.StartIOThread();
file_thread.Start();
+ std::map<std::string, std::string> map;
+ map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
+ map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
+ map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
+ map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\""));
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
TestInstaller installer;
@@ -701,11 +788,82 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(1, ping_checker.NumHits());
+ EXPECT_EQ(0, ping_checker.NumMisses());
EXPECT_EQ(4, interceptor.GetHitCount());
component_updater()->Stop();
}
+// Verify that a failed installation causes an install failure ping.
+TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) {
+ 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();
+
+ std::map<std::string, std::string> map;
+ map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
+ map.insert(std::pair<std::string, std::string>("eventresult", "\"0\""));
+ map.insert(std::pair<std::string, std::string>("errorcode", "\"9\""));
+ map.insert(std::pair<std::string, std::string>("previousversion",
+ "\"0.9\""));
+ map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
+ content::URLLocalHostRequestPrepackagedInterceptor interceptor;
+
+ // This test installer reports installation failure.
+ class : public TestInstaller {
+ virtual bool Install(const base::DictionaryValue& manifest,
+ const base::FilePath& unpack_path) OVERRIDE {
+ ++install_count_;
+ base::Delete(unpack_path, true);
+ return false;
+ }
+ } installer;
+
+ CrxComponent com;
+ RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
+
+ // Start with 0.9, and attempt update to 1.0
+ const GURL expected_update_url_1(
+ "http://localhost/upd?extra=foo"
+ "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
+
+ interceptor.SetResponse(expected_update_url_1,
+ test_file("updatecheck_reply_1.xml"));
+ interceptor.SetResponse(GURL(expected_crx_url),
+ test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
+
+ // Loop twice to issue two checks: (1) with original 0.9 version
+ // and (2), which should retry with 0.9.
+ test_configurator()->SetLoopCount(2);
+ component_updater()->Start();
+ message_loop.Run();
+
+ // Loop once more, but expect no ping because a noupdate response is issued.
+ // This is necessary to clear out the fire-and-forget ping from the previous
+ // iteration.
+ interceptor.SetResponse(expected_update_url_1,
+ test_file("updatecheck_reply_noupdate.xml"));
+ test_configurator()->SetLoopCount(1);
+ component_updater()->Start();
+ message_loop.Run();
+
+ EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
+ EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
+
+ EXPECT_EQ(2, ping_checker.NumHits());
+ EXPECT_EQ(0, ping_checker.NumMisses());
+ EXPECT_EQ(5, interceptor.GetHitCount());
+
+ component_updater()->Stop();
+}
+
// Verify that we successfully propagate a patcher error.
// ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
// patching instruction that should fail.
@@ -718,6 +876,14 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
io_thread.StartIOThread();
file_thread.Start();
+ std::map<std::string, std::string> map;
+ map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
+ map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
+ map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
+ map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\""));
+ map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\""));
+ PingChecker ping_checker(map);
+ URLRequestPostInterceptor post_interceptor(&ping_checker);
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
VersionedTestInstaller installer;
@@ -762,6 +928,8 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
+ EXPECT_EQ(1, ping_checker.NumHits());
+ EXPECT_EQ(1, ping_checker.NumMisses());
EXPECT_EQ(6, interceptor.GetHitCount());
component_updater()->Stop();

Powered by Google App Engine
This is Rietveld 408576698