Chromium Code Reviews| 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 693e3e50d783b22614848589be0a162eb47623bf..3cd30d2614356dc78c2680ade450c3a2af25c554 100644 |
| --- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc |
| +++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc |
| @@ -12,7 +12,6 @@ |
| #include "chrome/browser/component_updater/test/test_installer.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "content/test/net/url_request_prepackaged_interceptor.h" |
| #include "libxml/globals.h" |
| #include "net/base/upload_bytes_element_reader.h" |
| #include "net/url_request/url_fetcher.h" |
| @@ -26,6 +25,10 @@ using ::testing::Mock; |
| namespace component_updater { |
| +#define POST_INTERCEPT_SCHEME "http" |
| +#define POST_INTERCEPT_HOSTNAME "localhost2" |
| +#define POST_INTERCEPT_PATH "/update2" |
| + |
| MockComponentObserver::MockComponentObserver() { |
| } |
| @@ -75,11 +78,12 @@ int TestConfigurator::OnDemandDelay() { |
| } |
| GURL TestConfigurator::UpdateUrl() { |
| - return GURL("http://localhost/upd"); |
| + return GURL(POST_INTERCEPT_SCHEME "://" |
| + POST_INTERCEPT_HOSTNAME POST_INTERCEPT_PATH); |
| } |
| GURL TestConfigurator::PingUrl() { |
| - return GURL("http://localhost2/update2"); |
| + return UpdateUrl(); |
| } |
| const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } |
| @@ -122,12 +126,14 @@ void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { |
| InterceptorFactory::InterceptorFactory() |
| - : URLRequestPostInterceptorFactory("http", "localhost2") {} |
| + : URLRequestPostInterceptorFactory(POST_INTERCEPT_SCHEME, |
| + POST_INTERCEPT_HOSTNAME) {} |
| InterceptorFactory::~InterceptorFactory() {} |
| URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() { |
| - return URLRequestPostInterceptorFactory::CreateInterceptor("/update2"); |
| + return URLRequestPostInterceptorFactory::CreateInterceptor( |
| + base::FilePath::FromUTF8Unsafe(POST_INTERCEPT_PATH)); |
| } |
| class PartialMatch : public URLRequestPostInterceptor::RequestMatcher { |
| @@ -163,11 +169,15 @@ ComponentUpdaterTest::~ComponentUpdaterTest() { |
| } |
| void ComponentUpdaterTest::SetUp() { |
| + get_interceptor_.reset(new GetInterceptor); |
| interceptor_factory_.reset(new InterceptorFactory); |
| + post_interceptor_ = interceptor_factory_->CreateInterceptor(); |
| + EXPECT_TRUE(post_interceptor_); |
| } |
| void ComponentUpdaterTest::TearDown() { |
| interceptor_factory_.reset(); |
| + get_interceptor_.reset(); |
| xmlCleanupGlobals(); |
| } |
| @@ -208,6 +218,7 @@ void ComponentUpdaterTest::RunThreads() { |
| base::RunLoop runloop; |
| test_configurator()->SetQuitClosure(runloop.QuitClosure()); |
| runloop.Run(); |
| + RunThreadsUntilIdle(); |
|
waffles
2013/11/18 22:15:59
Are you certain that this is safe?
runloop.Run()
Sorin Jianu
2013/11/19 04:25:45
I am not sure about it and I removed the call.
waffles
2013/11/19 18:33:58
Ok, looks like it was needed after all? (As mentio
|
| } |
| void ComponentUpdaterTest::RunThreadsUntilIdle() { |
| @@ -237,15 +248,22 @@ TEST_F(ComponentUpdaterTest, StartStop) { |
| // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
| // are generated. No pings are sent. |
| TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "event eventtype"))); |
| + MockComponentObserver observer; |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| + EXPECT_CALL(observer, |
| + OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| + .Times(1); |
| + EXPECT_CALL(observer, |
| + OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| + .Times(2); |
| + EXPECT_CALL(observer, |
| + OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| + .Times(2); |
| - MockComponentObserver observer; |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| TestInstaller installer; |
| CrxComponent com; |
| @@ -256,68 +274,69 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| Version("1.1"), |
| &installer)); |
| - const GURL expected_update_url( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); |
| - |
| - interceptor.SetResponse(expected_update_url, |
| - test_file("updatecheck_reply_1.xml")); |
| - |
| // We loop twice, but there are no updates so we expect two sleep messages. |
| test_configurator()->SetLoopCount(2); |
| - |
| - EXPECT_CALL(observer, |
| - OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| - .Times(1); |
| component_updater()->Start(); |
| - |
| - EXPECT_CALL(observer, |
| - OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| - .Times(2); |
| - |
| - EXPECT_CALL(observer, |
| - OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| - .Times(2); |
| RunThreads(); |
| - EXPECT_EQ(2, interceptor.GetHitCount()); |
| - |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| + // Expect to see the two update check requests and no other requests, |
| + // including pings. |
| + EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(2, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| component_updater()->Stop(); |
| // Loop twice again but this case we simulate a server error by returning |
| - // an empty file. |
| - |
| - interceptor.SetResponse(expected_update_url, |
| - test_file("updatecheck_reply_empty")); |
| - |
| - test_configurator()->SetLoopCount(2); |
| - |
| + // an empty file. Expect the behavior of the service to be the same as before. |
| EXPECT_CALL(observer, |
| OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| .Times(1); |
| - component_updater()->Start(); |
| - |
| EXPECT_CALL(observer, |
| OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| .Times(2); |
| EXPECT_CALL(observer, |
| OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| .Times(2); |
| - RunThreads(); |
| - EXPECT_EQ(0, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| + post_interceptor_->Reset(); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_empty"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_empty"))); |
| - EXPECT_EQ(4, interceptor.GetHitCount()); |
| + test_configurator()->SetLoopCount(2); |
| + component_updater()->Start(); |
| + RunThreads(); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| + EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(2, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| component_updater()->Stop(); |
| } |
| @@ -325,22 +344,12 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| // the notifications above COMPONENT_UPDATE_FOUND and 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 non-ping network requests are issued: |
| +// We also check that the following network requests are issued: |
| // 1- manifest check |
| // 2- download crx |
| -// 3- second manifest check. |
| -// Only one ping is sent. |
| +// 3- ping |
| +// 4- second manifest check. |
| TEST_F(ComponentUpdaterTest, InstallCrx) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| - |
| MockComponentObserver observer1; |
| { |
| InSequence seq; |
| @@ -387,6 +396,16 @@ TEST_F(ComponentUpdaterTest, InstallCrx) { |
| .Times(1); |
| } |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + |
| + get_interceptor_->SetResponse( |
| + GURL(expected_crx_url), |
| + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| + |
| TestInstaller installer1; |
| CrxComponent com1; |
| com1.observer = &observer1; |
| @@ -396,25 +415,7 @@ TEST_F(ComponentUpdaterTest, InstallCrx) { |
| com2.observer = &observer2; |
| RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| - const GURL expected_update_url_1( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| - |
| - const GURL expected_update_url_2( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); |
| - |
| - interceptor.SetResponse(expected_update_url_1, |
| - test_file("updatecheck_reply_1.xml")); |
| - 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(2); |
| - |
| component_updater()->Start(); |
| RunThreads(); |
| @@ -423,12 +424,37 @@ TEST_F(ComponentUpdaterTest, InstallCrx) { |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| - EXPECT_EQ(3, interceptor.GetHitCount()); |
| - |
| - EXPECT_EQ(1, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| + // Expect three request in total: two update checks and one ping. |
| + EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(3, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + // Expect one component download. |
| + EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| + "version=\"0.9\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| + "<updatecheck /></app>")); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| component_updater()->Stop(); |
| } |
| @@ -437,34 +463,29 @@ TEST_F(ComponentUpdaterTest, InstallCrx) { |
| // particular there should not be an install because the minimum product |
| // version is much higher than of chrome. |
| TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "event eventtype"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_2.xml"))); |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| + get_interceptor_->SetResponse( |
| + GURL(expected_crx_url), |
| + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| TestInstaller installer; |
| CrxComponent com; |
| RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| - const GURL expected_update_url( |
| - "http://localhost/upd?extra=foo&x=id%3D" |
| - "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| - |
| - interceptor.SetResponse(expected_update_url, |
| - test_file("updatecheck_reply_2.xml")); |
| - interceptor.SetResponse(GURL(expected_crx_url), |
| - test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| - |
| test_configurator()->SetLoopCount(1); |
| component_updater()->Start(); |
| RunThreads(); |
| - EXPECT_EQ(0, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(1, interceptor.GetHitCount()); |
| + // Expect one update check and no ping. |
| + EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + // Expect no download to occur. |
| + EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| @@ -479,16 +500,6 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| // - We make an on demand call. |
| // - This triggers a second loop, which has a reply that triggers an install. |
| TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| - |
| MockComponentObserver observer1; |
| { |
| InSequence seq; |
| @@ -541,6 +552,13 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| .Times(1); |
| } |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_empty"))); |
| + |
| + get_interceptor_->SetResponse( |
| + GURL(expected_crx_url), |
| + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| + |
| TestInstaller installer1; |
| CrxComponent com1; |
| com1.observer = &observer1; |
| @@ -550,30 +568,25 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| com2.observer = &observer2; |
| RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &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.9%26fp%3D%26uc"); |
| - |
| - const GURL expected_update_url_2( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%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")); |
| // No update normally. |
| test_configurator()->SetLoopCount(1); |
| component_updater()->Start(); |
| RunThreads(); |
| component_updater()->Stop(); |
| + EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
| + |
| // Update after an on-demand check is issued. |
| + post_interceptor_->Reset(); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + |
| EXPECT_EQ(ComponentUpdateService::kOk, |
| OnDemandTester::OnDemand(component_updater(), |
| GetCrxComponentID(com2))); |
| @@ -586,7 +599,28 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| - EXPECT_EQ(3, interceptor.GetHitCount()); |
| + EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(2, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| + |
| + // Expect the update check to contain an "ondemand" request for the |
| + // second component (com2) and a normal request for the other component. |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"abagagagagagagagagagagagagagagag\" " |
| + "version=\"2.2\"><updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| + "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| + "version=\"0.9\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| // Also check what happens if previous check too soon. |
| test_configurator()->SetOnDemandTime(60 * 60); |
| @@ -626,24 +660,24 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| .Times(1); |
| } |
| - 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")); |
| + post_interceptor_->Reset(); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_empty"))); |
| + |
| test_configurator()->SetLoopCount(1); |
| component_updater()->Start(); |
| EXPECT_EQ(ComponentUpdateService::kOk, |
| OnDemandTester::OnDemand(component_updater(), |
| GetCrxComponentID(com2))); |
| - |
| RunThreads(); |
| - |
| component_updater()->Stop(); |
| + EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| // No update: already updated to 1.0 so nothing new |
| EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| { |
| @@ -672,20 +706,21 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| .Times(1); |
| } |
| - interceptor.SetResponse(expected_update_url_3, |
| - test_file("updatecheck_reply_1.xml")); |
| + post_interceptor_->Reset(); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + |
| test_configurator()->SetLoopCount(1); |
| component_updater()->Start(); |
| EXPECT_EQ(ComponentUpdateService::kOk, |
| OnDemandTester::OnDemand(component_updater(), |
| GetCrxComponentID(com2))); |
| - |
| RunThreads(); |
| - EXPECT_EQ(1, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| component_updater()->Stop(); |
| } |
| @@ -693,16 +728,6 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| // Verify that a previously registered component can get re-registered |
| // with a different version. |
| TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| - |
| MockComponentObserver observer1; |
| { |
| InSequence seq; |
| @@ -749,6 +774,16 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| .Times(1); |
| } |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + |
| + get_interceptor_->SetResponse( |
| + GURL(expected_crx_url), |
| + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| + |
| TestInstaller installer1; |
| CrxComponent com1; |
| com1.observer = &observer1; |
| @@ -758,28 +793,9 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| com2.observer = &observer2; |
| RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| - // Start with 0.9, and update to 1.0 |
| - const GURL expected_update_url_1( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| - |
| - const GURL expected_update_url_2( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); |
| - |
| - interceptor.SetResponse(expected_update_url_1, |
| - test_file("updatecheck_reply_1.xml")); |
| - interceptor.SetResponse(expected_update_url_2, |
| - 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) with the updated 1.0 version. |
| + // Loop twice to issue two checks: (1) with original 0.9 version, update to |
| + // 1.0, and do the second check (2) with the updated 1.0 version. |
| test_configurator()->SetLoopCount(2); |
| - |
| component_updater()->Start(); |
| RunThreads(); |
| @@ -788,12 +804,23 @@ 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, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - |
| - EXPECT_EQ(3, interceptor.GetHitCount()); |
| + EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| + "version=\"0.9\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| component_updater()->Stop(); |
| @@ -826,6 +853,10 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| .Times(1); |
| } |
| + post_interceptor_->Reset(); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + |
| TestInstaller installer3; |
| EXPECT_EQ(ComponentUpdateService::kReplaced, |
| RegisterComponent(&com1, |
| @@ -833,35 +864,27 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| Version("2.2"), |
| &installer3)); |
| - // Check that we send out 2.2 as our version. |
| - // Interceptor's hit count should go up by 1. |
| - const GURL expected_update_url_3( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc" |
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| - |
| - interceptor.SetResponse(expected_update_url_3, |
| - test_file("updatecheck_reply_1.xml")); |
| - |
| // Loop once just to notice the check happening with the re-register version. |
| test_configurator()->SetLoopCount(1); |
| component_updater()->Start(); |
| RunThreads(); |
| - EXPECT_EQ(4, interceptor.GetHitCount()); |
| - |
| - // No additional pings are expected. |
| - EXPECT_EQ(1, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - |
| // We created a new installer, so the counts go back to 0. |
| 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()); |
| + // One update check and no additional pings are expected. |
| + EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"2.2\">" |
| + "<updatecheck /></app>")); |
| + |
| component_updater()->Stop(); |
| } |
| @@ -877,67 +900,63 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| // There should be two pings, one for each update. The second will bear a |
| // diffresult=1, while the first will not. |
| TEST_F(ComponentUpdaterTest, DifferentialUpdate) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"))); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"1.0\" nextversion=\"2.0\" " |
| - "diffresult=\"1\" previousfp=\"1\" nextfp=\"f22\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_2.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_3.xml"))); |
| + |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/" |
| + "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| VersionedTestInstaller installer; |
| CrxComponent com; |
| RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| - const GURL expected_update_url_0( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| - const GURL expected_update_url_1( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); |
| - const GURL expected_update_url_2( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| - const GURL expected_crx_url_1( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| - const GURL expected_crx_url_1_diff_2( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| - |
| - interceptor.SetResponse(expected_update_url_0, |
| - test_file("updatecheck_diff_reply_1.xml")); |
| - interceptor.SetResponse(expected_update_url_1, |
| - test_file("updatecheck_diff_reply_2.xml")); |
| - interceptor.SetResponse(expected_update_url_2, |
| - test_file("updatecheck_diff_reply_3.xml")); |
| - interceptor.SetResponse(expected_crx_url_1, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| - interceptor.SetResponse( |
| - expected_crx_url_1_diff_2, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| - |
| test_configurator()->SetLoopCount(3); |
| - |
| component_updater()->Start(); |
| RunThreads(); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| - // One ping has the diffresult=1, the other does not. |
| - EXPECT_EQ(2, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - |
| - EXPECT_EQ(5, interceptor.GetHitCount()); |
| - |
| + EXPECT_EQ(5, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(5, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| + "version=\"0.0\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| + "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| + "version=\"1.0\" nextversion=\"2.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"1\" " |
| + "previousfp=\"1\" nextfp=\"22\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[4].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| + "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| component_updater()->Stop(); |
| } |
| @@ -952,49 +971,28 @@ TEST_F(ComponentUpdaterTest, DifferentialUpdate) { |
| // 4- update check (loop 2 - no update available) |
| // There should be one ping for the first attempted update. |
| TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"1.0\" nextversion=\"2.0\" " |
| - "diffresult=\"0\" differrorcat=\"2\" differrorcode=\"16\" " |
| - "nextfp=\"f22\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_2.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_3.xml"))); |
| + |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/" |
| + "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| TestInstaller installer; |
| CrxComponent com; |
| RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); |
| - const GURL expected_update_url_1( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); |
| - const GURL expected_update_url_2( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| - const GURL expected_crx_url_1( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| - const GURL expected_crx_url_1_diff_2( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| - const GURL expected_crx_url_2( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"); |
| - |
| - interceptor.SetResponse(expected_update_url_1, |
| - test_file("updatecheck_diff_reply_2.xml")); |
| - interceptor.SetResponse(expected_update_url_2, |
| - test_file("updatecheck_diff_reply_3.xml")); |
| - interceptor.SetResponse(expected_crx_url_1, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| - interceptor.SetResponse( |
| - expected_crx_url_1_diff_2, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| - interceptor.SetResponse(expected_crx_url_2, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| - |
| test_configurator()->SetLoopCount(2); |
| - |
| component_updater()->Start(); |
| RunThreads(); |
| @@ -1002,34 +1000,32 @@ 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, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - |
| - EXPECT_EQ(4, interceptor.GetHitCount()); |
| + EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(3, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| + "version=\"1.0\" nextversion=\"2.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"0\" " |
| + "differrorcat=\"2\" differrorcode=\"16\" nextfp=\"22\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| + "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| component_updater()->Stop(); |
| } |
| // Verify that a failed installation causes an install failure ping. |
| TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| - "<o:event eventtype=\"3\" eventresult=\"0\" " |
| - "previousversion=\"0.9\" nextversion=\"1.0\" " |
| - "errorcat=\"3\" errorcode=\"9\"/></o:app>"))); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| - "<o:event eventtype=\"3\" eventresult=\"0\" " |
| - "previousversion=\"0.9\" nextversion=\"1.0\" " |
| - "errorcat=\"3\" errorcode=\"9\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| - |
| // This test installer reports installation failure. |
| class : public TestInstaller { |
| virtual bool Install(const base::DictionaryValue& manifest, |
| @@ -1040,30 +1036,58 @@ TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| } |
| } installer; |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + get_interceptor_->SetResponse( |
| + GURL(expected_crx_url), |
| + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| + |
| + // Start with 0.9, and attempt update to 1.0. |
| + // Loop twice to issue two checks: (1) with original 0.9 version |
| + // and (2), which should retry with 0.9. |
| 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(); |
| RunThreads(); |
| + EXPECT_EQ(4, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| + "version=\"0.9\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"0\" " |
| + "errorcat=\"3\" errorcode=\"9\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| + "version=\"0.9\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"0\" " |
| + "errorcat=\"3\" errorcode=\"9\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + |
| // 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")); |
| + post_interceptor_->Reset(); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_reply_noupdate.xml"))); |
| + |
| test_configurator()->SetLoopCount(1); |
| component_updater()->Start(); |
| RunThreads(); |
| @@ -1071,12 +1095,15 @@ TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| - EXPECT_EQ(2, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(1, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| - EXPECT_EQ(5, interceptor.GetHitCount()); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| component_updater()->Stop(); |
| } |
| @@ -1085,74 +1112,73 @@ TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect |
| // patching instruction that should fail. |
| TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { |
| - URLRequestPostInterceptor* post_interceptor( |
| - interceptor_factory_->CreateInterceptor()); |
| - EXPECT_TRUE(post_interceptor != NULL); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"))); |
| - EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( |
| - "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| - "<o:event eventtype=\"3\" eventresult=\"1\" " |
| - "previousversion=\"1.0\" nextversion=\"2.0\" " |
| - "diffresult=\"0\" differrorcat=\"2\" " |
| - "differrorcode=\"14\" diffextracode1=\"305\" " |
| - "previousfp=\"1\" nextfp=\"f22\"/></o:app>"))); |
| - |
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_1.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_2.xml"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| + EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| + "updatecheck"), test_file("updatecheck_diff_reply_3.xml"))); |
| + |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| + // This intercept returns a different file than what is specified in the |
| + // update check response and requested in the download. The file that is |
| + // actually dowloaded contains a patching error, an therefore, an error |
| + // is injected at the time of patching. |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/" |
| + "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); |
| + get_interceptor_->SetResponse( |
| + GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), |
| + test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| VersionedTestInstaller installer; |
| CrxComponent com; |
| RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| - const GURL expected_update_url_0( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| - const GURL expected_update_url_1( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); |
| - const GURL expected_update_url_2( |
| - "http://localhost/upd?extra=foo" |
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| - const GURL expected_crx_url_1( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| - const GURL expected_crx_url_1_diff_2( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| - const GURL expected_crx_url_2( |
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"); |
| - |
| - interceptor.SetResponse(expected_update_url_0, |
| - test_file("updatecheck_diff_reply_1.xml")); |
| - interceptor.SetResponse(expected_update_url_1, |
| - test_file("updatecheck_diff_reply_2.xml")); |
| - interceptor.SetResponse(expected_update_url_2, |
| - test_file("updatecheck_diff_reply_3.xml")); |
| - interceptor.SetResponse(expected_crx_url_1, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| - interceptor.SetResponse( |
| - expected_crx_url_1_diff_2, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); |
| - interceptor.SetResponse(expected_crx_url_2, |
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| - |
| - test_configurator()->SetLoopCount(2); |
| - |
| + test_configurator()->SetLoopCount(3); |
| component_updater()->Start(); |
| RunThreads(); |
| component_updater()->Stop(); |
| - // There may still be pings in the queue. |
| - RunThreadsUntilIdle(); |
| EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| - EXPECT_EQ(2, post_interceptor->GetHitCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - EXPECT_EQ(0, post_interceptor->GetMissCount()) |
| - << post_interceptor->GetRequestsAsString(); |
| - |
| - EXPECT_EQ(5, interceptor.GetHitCount()); |
| + EXPECT_EQ(5, post_interceptor_->GetHitCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(5, post_interceptor_->GetCount()) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_EQ(3, get_interceptor_->GetHitCount()); |
| + |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" |
| + "<updatecheck /></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| + "version=\"0.0\" nextversion=\"1.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| + "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| + "version=\"1.0\" nextversion=\"2.0\">" |
| + "<event eventtype=\"3\" eventresult=\"1\" " |
| + "diffresult=\"0\" differrorcat=\"2\" " |
| + "differrorcode=\"14\" diffextracode1=\"305\" " |
| + "previousfp=\"1\" nextfp=\"22\"/></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| + EXPECT_NE(string::npos, post_interceptor_->GetRequests()[4].find( |
| + "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| + "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
| + << post_interceptor_->GetRequestsAsString(); |
| } |
| } // namespace component_updater |