| OLD | NEW |
| 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 "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" | 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { | 113 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { |
| 114 cus_ = cus; | 114 cus_ = cus; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { | 117 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { |
| 118 quit_closure_ = quit_closure; | 118 quit_closure_ = quit_closure; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Intercepts ping requests sent over http POST to localhost2. |
| 122 class PingInterceptor : public URLRequestPostInterceptor { |
| 123 public: |
| 124 PingInterceptor() : URLRequestPostInterceptor("http", "localhost2") {} |
| 125 |
| 126 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(PingInterceptor); |
| 128 }; |
| 129 |
| 121 ComponentUpdaterTest::ComponentUpdaterTest() | 130 ComponentUpdaterTest::ComponentUpdaterTest() |
| 122 : test_config_(NULL), | 131 : test_config_(NULL), |
| 123 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 132 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 124 // The component updater instance under test. | 133 // The component updater instance under test. |
| 125 test_config_ = new TestConfigurator; | 134 test_config_ = new TestConfigurator; |
| 126 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 135 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
| 127 test_config_->SetComponentUpdateService(component_updater_.get()); | 136 test_config_->SetComponentUpdateService(component_updater_.get()); |
| 128 | 137 |
| 129 // The test directory is chrome/test/data/components. | 138 // The test directory is chrome/test/data/components. |
| 130 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 139 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 void ComponentUpdaterTest::RunThreads() { | 186 void ComponentUpdaterTest::RunThreads() { |
| 178 base::RunLoop runloop; | 187 base::RunLoop runloop; |
| 179 test_configurator()->SetQuitClosure(runloop.QuitClosure()); | 188 test_configurator()->SetQuitClosure(runloop.QuitClosure()); |
| 180 runloop.Run(); | 189 runloop.Run(); |
| 181 } | 190 } |
| 182 | 191 |
| 183 void ComponentUpdaterTest::RunThreadsUntilIdle() { | 192 void ComponentUpdaterTest::RunThreadsUntilIdle() { |
| 184 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
| 185 } | 194 } |
| 186 | 195 |
| 187 PingChecker::PingChecker(const std::map<std::string, std::string>& attributes) | |
| 188 : num_hits_(0), num_misses_(0), attributes_(attributes) { | |
| 189 } | |
| 190 | |
| 191 PingChecker::~PingChecker() {} | |
| 192 | |
| 193 void PingChecker::Trial(net::URLRequest* request) { | |
| 194 if (Test(request)) | |
| 195 ++num_hits_; | |
| 196 else | |
| 197 ++num_misses_; | |
| 198 } | |
| 199 | |
| 200 bool PingChecker::Test(net::URLRequest* request) { | |
| 201 if (request->has_upload()) { | |
| 202 const net::UploadDataStream* stream = request->get_upload(); | |
| 203 const net::UploadBytesElementReader* reader = | |
| 204 stream->element_readers()[0]->AsBytesReader(); | |
| 205 int size = reader->length(); | |
| 206 scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size); | |
| 207 std::string data(reader->bytes()); | |
| 208 pings_.push_back(data); | |
| 209 // For now, we assume that there is only one ping per POST. | |
| 210 std::string::size_type start = data.find("<o:event"); | |
| 211 if (start != std::string::npos) { | |
| 212 std::string::size_type end = data.find(">", start); | |
| 213 if (end != std::string::npos) { | |
| 214 std::string ping = data.substr(start, end - start); | |
| 215 std::map<std::string, std::string>::const_iterator iter; | |
| 216 for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) { | |
| 217 // does the ping contain the specified attribute/value? | |
| 218 if (ping.find(std::string(" ") + (iter->first) + | |
| 219 std::string("=") + (iter->second)) == string::npos) { | |
| 220 return false; | |
| 221 } | |
| 222 } | |
| 223 return true; | |
| 224 } | |
| 225 } | |
| 226 } | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 230 std::string PingChecker::GetPings() const { | |
| 231 std::string pings_str = "Pings are:"; | |
| 232 int i = 0; | |
| 233 for (std::vector<std::string>::const_iterator it = pings_.begin(); | |
| 234 it != pings_.end(); ++it) { | |
| 235 pings_str.append(base::StringPrintf("\n (%d): %s", ++i, it->c_str())); | |
| 236 } | |
| 237 return pings_str; | |
| 238 } | |
| 239 | |
| 240 ComponentUpdateService::Status OnDemandTester::OnDemand( | 196 ComponentUpdateService::Status OnDemandTester::OnDemand( |
| 241 ComponentUpdateService* cus, const std::string& component_id) { | 197 ComponentUpdateService* cus, const std::string& component_id) { |
| 242 return cus->OnDemandUpdate(component_id); | 198 return cus->OnDemandUpdate(component_id); |
| 243 } | 199 } |
| 244 | 200 |
| 245 // Verify that our test fixture work and the component updater can | 201 // Verify that our test fixture work and the component updater can |
| 246 // be created and destroyed with no side effects. | 202 // be created and destroyed with no side effects. |
| 247 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 203 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
| 248 EXPECT_TRUE(component_updater() != NULL); | 204 EXPECT_TRUE(component_updater() != NULL); |
| 249 } | 205 } |
| 250 | 206 |
| 251 // Verify that the component updater can be caught in a quick | 207 // Verify that the component updater can be caught in a quick |
| 252 // start-shutdown situation. Failure of this test will be a crash. | 208 // start-shutdown situation. Failure of this test will be a crash. |
| 253 TEST_F(ComponentUpdaterTest, StartStop) { | 209 TEST_F(ComponentUpdaterTest, StartStop) { |
| 254 component_updater()->Start(); | 210 component_updater()->Start(); |
| 255 RunThreadsUntilIdle(); | 211 RunThreadsUntilIdle(); |
| 256 component_updater()->Stop(); | 212 component_updater()->Stop(); |
| 257 } | 213 } |
| 258 | 214 |
| 259 // Verify that when the server has no updates, we go back to sleep and | 215 // Verify that when the server has no updates, we go back to sleep and |
| 260 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications | 216 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
| 261 // are generated. | 217 // are generated. No pings are sent. |
| 262 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 218 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| 219 PingInterceptor ping_interceptor; |
| 263 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 220 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 264 | 221 |
| 265 MockComponentObserver observer; | 222 MockComponentObserver observer; |
| 266 | 223 |
| 267 TestInstaller installer; | 224 TestInstaller installer; |
| 268 CrxComponent com; | 225 CrxComponent com; |
| 269 com.observer = &observer; | 226 com.observer = &observer; |
| 270 EXPECT_EQ(ComponentUpdateService::kOk, | 227 EXPECT_EQ(ComponentUpdateService::kOk, |
| 271 RegisterComponent(&com, | 228 RegisterComponent(&com, |
| 272 kTestComponent_abag, | 229 kTestComponent_abag, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 276 |
| 320 EXPECT_CALL(observer, | 277 EXPECT_CALL(observer, |
| 321 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 278 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 322 .Times(2); | 279 .Times(2); |
| 323 EXPECT_CALL(observer, | 280 EXPECT_CALL(observer, |
| 324 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 281 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| 325 .Times(2); | 282 .Times(2); |
| 326 RunThreads(); | 283 RunThreads(); |
| 327 | 284 |
| 328 EXPECT_EQ(4, interceptor.GetHitCount()); | 285 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 286 EXPECT_EQ(0, ping_interceptor.GetHitCount()); |
| 329 | 287 |
| 330 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 288 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 331 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 289 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 332 | 290 |
| 333 component_updater()->Stop(); | 291 component_updater()->Stop(); |
| 334 } | 292 } |
| 335 | 293 |
| 336 // Verify that we can check for updates and install one component. Besides | 294 // Verify that we can check for updates and install one component. Besides |
| 337 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY | 295 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY |
| 338 // should have been fired. We do two loops so the second time around there | 296 // should have been fired. We do two loops so the second time around there |
| 339 // should be nothing left to do. | 297 // should be nothing left to do. |
| 340 // We also check that only 3 non-ping network requests are issued: | 298 // We also check that only 3 non-ping network requests are issued: |
| 341 // 1- manifest check | 299 // 1- manifest check |
| 342 // 2- download crx | 300 // 2- download crx |
| 343 // 3- second manifest check. | 301 // 3- second manifest check. |
| 344 TEST_F(ComponentUpdaterTest, InstallCrx) { | 302 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 345 std::map<std::string, std::string> map; | 303 PingInterceptor ping_interceptor; |
| 346 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 347 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | |
| 348 map.insert(std::pair<std::string, std::string>("previousversion", | |
| 349 "\"0.9\"")); | |
| 350 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | |
| 351 PingChecker ping_checker(map); | |
| 352 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 353 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 304 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 354 | 305 |
| 355 MockComponentObserver observer1; | 306 MockComponentObserver observer1; |
| 356 { | 307 { |
| 357 InSequence seq; | 308 InSequence seq; |
| 358 EXPECT_CALL(observer1, | 309 EXPECT_CALL(observer1, |
| 359 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 310 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 360 .Times(1); | 311 .Times(1); |
| 361 EXPECT_CALL(observer1, | 312 EXPECT_CALL(observer1, |
| 362 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | 313 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 379 |
| 429 component_updater()->Start(); | 380 component_updater()->Start(); |
| 430 RunThreads(); | 381 RunThreads(); |
| 431 | 382 |
| 432 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 383 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 433 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 384 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 434 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 385 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 435 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 386 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 436 | 387 |
| 437 EXPECT_EQ(3, interceptor.GetHitCount()); | 388 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 438 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); | 389 |
| 439 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); | 390 EXPECT_EQ(1, ping_interceptor.GetHitCount()) |
| 391 << ping_interceptor.GetRequestsAsString(); |
| 392 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 393 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| 394 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 395 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>")) |
| 396 << ping_interceptor.GetRequestsAsString(); |
| 397 |
| 440 | 398 |
| 441 component_updater()->Stop(); | 399 component_updater()->Stop(); |
| 442 } | 400 } |
| 443 | 401 |
| 444 // This test checks that the "prodversionmin" value is handled correctly. In | 402 // This test checks that the "prodversionmin" value is handled correctly. In |
| 445 // particular there should not be an install because the minimum product | 403 // particular there should not be an install because the minimum product |
| 446 // version is much higher than of chrome. | 404 // version is much higher than of chrome. |
| 447 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 405 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| 448 std::map<std::string, std::string> map; | 406 PingInterceptor ping_interceptor; |
| 449 PingChecker ping_checker(map); | |
| 450 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 451 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 407 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 452 | 408 |
| 453 TestInstaller installer; | 409 TestInstaller installer; |
| 454 CrxComponent com; | 410 CrxComponent com; |
| 455 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); | 411 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 456 | 412 |
| 457 const GURL expected_update_url( | 413 const GURL expected_update_url( |
| 458 "http://localhost/upd?extra=foo&x=id%3D" | 414 "http://localhost/upd?extra=foo&x=id%3D" |
| 459 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | 415 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 460 | 416 |
| 461 interceptor.SetResponse(expected_update_url, | 417 interceptor.SetResponse(expected_update_url, |
| 462 test_file("updatecheck_reply_2.xml")); | 418 test_file("updatecheck_reply_2.xml")); |
| 463 interceptor.SetResponse(GURL(expected_crx_url), | 419 interceptor.SetResponse(GURL(expected_crx_url), |
| 464 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 420 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 465 | 421 |
| 466 test_configurator()->SetLoopCount(1); | 422 test_configurator()->SetLoopCount(1); |
| 467 component_updater()->Start(); | 423 component_updater()->Start(); |
| 468 RunThreads(); | 424 RunThreads(); |
| 469 | 425 |
| 470 EXPECT_EQ(0, ping_checker.NumHits()) << ping_checker.GetPings(); | 426 EXPECT_EQ(0, ping_interceptor.GetHitCount()) |
| 471 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); | 427 << ping_interceptor.GetRequestsAsString(); |
| 472 EXPECT_EQ(1, interceptor.GetHitCount()); | 428 EXPECT_EQ(1, interceptor.GetHitCount()); |
| 429 |
| 473 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 430 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 474 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 431 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 475 | 432 |
| 476 component_updater()->Stop(); | 433 component_updater()->Stop(); |
| 477 } | 434 } |
| 478 | 435 |
| 479 // Test that a ping for an update check can cause installs. | 436 // Test that a ping for an update check can cause installs. |
| 480 // Here is the timeline: | 437 // Here is the timeline: |
| 481 // - First loop: we return a reply that indicates no update, so | 438 // - First loop: we return a reply that indicates no update, so |
| 482 // nothing happens. | 439 // nothing happens. |
| 483 // - We ping. | 440 // - We ping. |
| 484 // - This triggers a second loop, which has a reply that triggers an install. | 441 // - This triggers a second loop, which has a reply that triggers an install. |
| 485 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { | 442 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| 486 std::map<std::string, std::string> map; | 443 PingInterceptor ping_interceptor; |
| 487 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 488 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | |
| 489 map.insert(std::pair<std::string, std::string>("previousversion", | |
| 490 "\"0.9\"")); | |
| 491 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | |
| 492 PingChecker ping_checker(map); | |
| 493 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 494 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 444 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 495 | 445 |
| 496 MockComponentObserver observer1; | 446 MockComponentObserver observer1; |
| 497 { | 447 { |
| 498 InSequence seq; | 448 InSequence seq; |
| 499 EXPECT_CALL(observer1, | 449 EXPECT_CALL(observer1, |
| 500 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 450 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 501 .Times(1); | 451 .Times(1); |
| 502 EXPECT_CALL(observer1, | 452 EXPECT_CALL(observer1, |
| 503 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 453 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 interceptor.SetResponse(expected_update_url_3, | 629 interceptor.SetResponse(expected_update_url_3, |
| 680 test_file("updatecheck_reply_1.xml")); | 630 test_file("updatecheck_reply_1.xml")); |
| 681 test_configurator()->SetLoopCount(1); | 631 test_configurator()->SetLoopCount(1); |
| 682 component_updater()->Start(); | 632 component_updater()->Start(); |
| 683 EXPECT_EQ(ComponentUpdateService::kOk, | 633 EXPECT_EQ(ComponentUpdateService::kOk, |
| 684 OnDemandTester::OnDemand(component_updater(), | 634 OnDemandTester::OnDemand(component_updater(), |
| 685 GetCrxComponentID(com2))); | 635 GetCrxComponentID(com2))); |
| 686 | 636 |
| 687 RunThreads(); | 637 RunThreads(); |
| 688 | 638 |
| 689 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); | 639 EXPECT_EQ(1, ping_interceptor.GetHitCount()) |
| 690 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); | 640 << ping_interceptor.GetRequestsAsString(); |
| 641 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 642 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| 643 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 644 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>")) |
| 645 << ping_interceptor.GetRequestsAsString(); |
| 691 | 646 |
| 692 component_updater()->Stop(); | 647 component_updater()->Stop(); |
| 693 } | 648 } |
| 694 | 649 |
| 695 // Verify that a previously registered component can get re-registered | 650 // Verify that a previously registered component can get re-registered |
| 696 // with a different version. | 651 // with a different version. |
| 697 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 652 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| 698 std::map<std::string, std::string> map; | 653 PingInterceptor ping_interceptor; |
| 699 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 700 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | |
| 701 map.insert(std::pair<std::string, std::string>("previousversion", | |
| 702 "\"0.9\"")); | |
| 703 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | |
| 704 PingChecker ping_checker(map); | |
| 705 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 706 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 654 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 707 | 655 |
| 708 MockComponentObserver observer1; | 656 MockComponentObserver observer1; |
| 709 { | 657 { |
| 710 InSequence seq; | 658 InSequence seq; |
| 711 EXPECT_CALL(observer1, | 659 EXPECT_CALL(observer1, |
| 712 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 660 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 713 .Times(1); | 661 .Times(1); |
| 714 EXPECT_CALL(observer1, | 662 EXPECT_CALL(observer1, |
| 715 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | 663 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 test_configurator()->SetLoopCount(2); | 731 test_configurator()->SetLoopCount(2); |
| 784 | 732 |
| 785 component_updater()->Start(); | 733 component_updater()->Start(); |
| 786 RunThreads(); | 734 RunThreads(); |
| 787 | 735 |
| 788 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 736 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 789 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 737 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 790 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 738 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 791 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 739 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 792 | 740 |
| 793 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); | 741 EXPECT_EQ(1, ping_interceptor.GetHitCount()) |
| 794 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); | 742 << ping_interceptor.GetRequestsAsString(); |
| 743 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 744 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| 745 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 746 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>")) |
| 747 << ping_interceptor.GetRequestsAsString(); |
| 748 |
| 795 EXPECT_EQ(3, interceptor.GetHitCount()); | 749 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 796 | 750 |
| 797 component_updater()->Stop(); | 751 component_updater()->Stop(); |
| 798 | 752 |
| 799 // Now re-register, pretending to be an even newer version (2.2) | 753 // Now re-register, pretending to be an even newer version (2.2) |
| 800 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); | 754 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| 801 { | 755 { |
| 802 InSequence seq; | 756 InSequence seq; |
| 803 EXPECT_CALL(observer1, | 757 EXPECT_CALL(observer1, |
| 804 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 758 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 // nothing. | 817 // nothing. |
| 864 // We also check that exactly 5 non-ping network requests are issued: | 818 // We also check that exactly 5 non-ping network requests are issued: |
| 865 // 1- update check (response: v1 available) | 819 // 1- update check (response: v1 available) |
| 866 // 2- download crx (v1) | 820 // 2- download crx (v1) |
| 867 // 3- update check (response: v2 available) | 821 // 3- update check (response: v2 available) |
| 868 // 4- download differential crx (v1 to v2) | 822 // 4- download differential crx (v1 to v2) |
| 869 // 5- update check (response: no further update available) | 823 // 5- update check (response: no further update available) |
| 870 // There should be two pings, one for each update. The second will bear a | 824 // There should be two pings, one for each update. The second will bear a |
| 871 // diffresult=1, while the first will not. | 825 // diffresult=1, while the first will not. |
| 872 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { | 826 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { |
| 873 std::map<std::string, std::string> map; | 827 PingInterceptor ping_interceptor; |
| 874 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 875 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | |
| 876 map.insert(std::pair<std::string, std::string>("diffresult", "\"1\"")); | |
| 877 PingChecker ping_checker(map); | |
| 878 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 879 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 828 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 880 | 829 |
| 881 VersionedTestInstaller installer; | 830 VersionedTestInstaller installer; |
| 882 CrxComponent com; | 831 CrxComponent com; |
| 883 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); | 832 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 884 | 833 |
| 885 const GURL expected_update_url_0( | 834 const GURL expected_update_url_0( |
| 886 "http://localhost/upd?extra=foo" | 835 "http://localhost/upd?extra=foo" |
| 887 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); | 836 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 888 const GURL expected_update_url_1( | 837 const GURL expected_update_url_1( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 910 | 859 |
| 911 test_configurator()->SetLoopCount(3); | 860 test_configurator()->SetLoopCount(3); |
| 912 | 861 |
| 913 component_updater()->Start(); | 862 component_updater()->Start(); |
| 914 RunThreads(); | 863 RunThreads(); |
| 915 | 864 |
| 916 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 865 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 917 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 866 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 918 | 867 |
| 919 // One ping has the diffresult=1, the other does not. | 868 // One ping has the diffresult=1, the other does not. |
| 920 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); | 869 EXPECT_EQ(2, ping_interceptor.GetHitCount()) |
| 921 EXPECT_EQ(1, ping_checker.NumMisses()) << ping_checker.GetPings(); | 870 << ping_interceptor.GetRequestsAsString(); |
| 871 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 872 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| 873 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 874 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>")) |
| 875 << ping_interceptor.GetRequestsAsString(); |
| 876 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[1].find( |
| 877 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| 878 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 879 "previousversion=\"1.0\" nextversion=\"2.0\" " |
| 880 "diffresult=\"1\" previousfp=\"1\" nextfp=\"f22\"/></o:app>")) |
| 881 << ping_interceptor.GetRequestsAsString(); |
| 922 | 882 |
| 923 EXPECT_EQ(5, interceptor.GetHitCount()); | 883 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 924 | 884 |
| 925 component_updater()->Stop(); | 885 component_updater()->Stop(); |
| 926 } | 886 } |
| 927 | 887 |
| 928 // Verify that component installation falls back to downloading and installing | 888 // Verify that component installation falls back to downloading and installing |
| 929 // a full update if the differential update fails (in this case, because the | 889 // a full update if the differential update fails (in this case, because the |
| 930 // installer does not know about the existing files). We do two loops; the final | 890 // installer does not know about the existing files). We do two loops; the final |
| 931 // loop should do nothing. | 891 // loop should do nothing. |
| 932 // We also check that exactly 4 non-ping network requests are issued: | 892 // We also check that exactly 4 non-ping network requests are issued: |
| 933 // 1- update check (loop 1) | 893 // 1- update check (loop 1) |
| 934 // 2- download differential crx | 894 // 2- download differential crx |
| 935 // 3- download full crx | 895 // 3- download full crx |
| 936 // 4- update check (loop 2 - no update available) | 896 // 4- update check (loop 2 - no update available) |
| 937 // There should be one ping for the first attempted update. | 897 // There should be one ping for the first attempted update. |
| 938 | |
| 939 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { | 898 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { |
| 940 std::map<std::string, std::string> map; | 899 PingInterceptor ping_interceptor; |
| 941 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 942 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | |
| 943 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); | |
| 944 map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\"")); | |
| 945 PingChecker ping_checker(map); | |
| 946 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 947 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 900 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 948 | 901 |
| 949 TestInstaller installer; | 902 TestInstaller installer; |
| 950 CrxComponent com; | 903 CrxComponent com; |
| 951 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); | 904 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); |
| 952 | 905 |
| 953 const GURL expected_update_url_1( | 906 const GURL expected_update_url_1( |
| 954 "http://localhost/upd?extra=foo" | 907 "http://localhost/upd?extra=foo" |
| 955 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); | 908 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); |
| 956 const GURL expected_update_url_2( | 909 const GURL expected_update_url_2( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 977 | 930 |
| 978 test_configurator()->SetLoopCount(2); | 931 test_configurator()->SetLoopCount(2); |
| 979 | 932 |
| 980 component_updater()->Start(); | 933 component_updater()->Start(); |
| 981 RunThreads(); | 934 RunThreads(); |
| 982 | 935 |
| 983 // A failed differential update does not count as a failed install. | 936 // A failed differential update does not count as a failed install. |
| 984 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 937 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 985 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); | 938 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 986 | 939 |
| 987 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); | 940 EXPECT_EQ(1, ping_interceptor.GetHitCount()) |
| 988 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); | 941 << ping_interceptor.GetRequestsAsString(); |
| 942 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 943 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| 944 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 945 "previousversion=\"1.0\" nextversion=\"2.0\" " |
| 946 "diffresult=\"0\" differrorcat=\"2\" differrorcode=\"16\" " |
| 947 "nextfp=\"f22\"/></o:app>")) |
| 948 << ping_interceptor.GetRequestsAsString(); |
| 949 |
| 989 EXPECT_EQ(4, interceptor.GetHitCount()); | 950 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 990 | 951 |
| 991 component_updater()->Stop(); | 952 component_updater()->Stop(); |
| 992 } | 953 } |
| 993 | 954 |
| 994 // Verify that a failed installation causes an install failure ping. | 955 // Verify that a failed installation causes an install failure ping. |
| 995 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { | 956 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| 996 std::map<std::string, std::string> map; | 957 PingInterceptor ping_interceptor; |
| 997 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 998 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\"")); | |
| 999 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\"")); | |
| 1000 map.insert(std::pair<std::string, std::string>("previousversion", | |
| 1001 "\"0.9\"")); | |
| 1002 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | |
| 1003 PingChecker ping_checker(map); | |
| 1004 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 1005 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 958 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 1006 | 959 |
| 1007 // This test installer reports installation failure. | 960 // This test installer reports installation failure. |
| 1008 class : public TestInstaller { | 961 class : public TestInstaller { |
| 1009 virtual bool Install(const base::DictionaryValue& manifest, | 962 virtual bool Install(const base::DictionaryValue& manifest, |
| 1010 const base::FilePath& unpack_path) OVERRIDE { | 963 const base::FilePath& unpack_path) OVERRIDE { |
| 1011 ++install_count_; | 964 ++install_count_; |
| 1012 base::DeleteFile(unpack_path, true); | 965 base::DeleteFile(unpack_path, true); |
| 1013 return false; | 966 return false; |
| 1014 } | 967 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1038 // iteration. | 991 // iteration. |
| 1039 interceptor.SetResponse(expected_update_url_1, | 992 interceptor.SetResponse(expected_update_url_1, |
| 1040 test_file("updatecheck_reply_noupdate.xml")); | 993 test_file("updatecheck_reply_noupdate.xml")); |
| 1041 test_configurator()->SetLoopCount(1); | 994 test_configurator()->SetLoopCount(1); |
| 1042 component_updater()->Start(); | 995 component_updater()->Start(); |
| 1043 RunThreads(); | 996 RunThreads(); |
| 1044 | 997 |
| 1045 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 998 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1046 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 999 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1047 | 1000 |
| 1048 EXPECT_EQ(2, ping_checker.NumHits()) << ping_checker.GetPings(); | 1001 EXPECT_EQ(2, ping_interceptor.GetHitCount()) |
| 1049 EXPECT_EQ(0, ping_checker.NumMisses()) << ping_checker.GetPings(); | 1002 << ping_interceptor.GetRequestsAsString(); |
| 1003 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 1004 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 1005 "<o:event eventtype=\"3\" eventresult=\"0\" " |
| 1006 "previousversion=\"0.9\" nextversion=\"1.0\" " |
| 1007 "errorcat=\"3\" errorcode=\"9\"/></o:app>")) |
| 1008 << ping_interceptor.GetRequestsAsString(); |
| 1009 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[1].find( |
| 1010 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 1011 "<o:event eventtype=\"3\" eventresult=\"0\" " |
| 1012 "previousversion=\"0.9\" nextversion=\"1.0\" " |
| 1013 "errorcat=\"3\" errorcode=\"9\"/></o:app>")) |
| 1014 << ping_interceptor.GetRequestsAsString(); |
| 1015 |
| 1050 EXPECT_EQ(5, interceptor.GetHitCount()); | 1016 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 1051 | 1017 |
| 1052 component_updater()->Stop(); | 1018 component_updater()->Stop(); |
| 1053 } | 1019 } |
| 1054 | 1020 |
| 1055 // Verify that we successfully propagate a patcher error. | 1021 // Verify that we successfully propagate a patcher error. |
| 1056 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect | 1022 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect |
| 1057 // patching instruction that should fail. | 1023 // patching instruction that should fail. |
| 1058 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { | 1024 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { |
| 1059 std::map<std::string, std::string> map; | 1025 PingInterceptor ping_interceptor; |
| 1060 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | |
| 1061 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | |
| 1062 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); | |
| 1063 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\"")); | |
| 1064 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\"")); | |
| 1065 PingChecker ping_checker(map); | |
| 1066 URLRequestPostInterceptor post_interceptor(&ping_checker); | |
| 1067 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 1026 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 1068 | 1027 |
| 1069 VersionedTestInstaller installer; | 1028 VersionedTestInstaller installer; |
| 1070 CrxComponent com; | 1029 CrxComponent com; |
| 1071 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); | 1030 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 1072 | 1031 |
| 1073 const GURL expected_update_url_0( | 1032 const GURL expected_update_url_0( |
| 1074 "http://localhost/upd?extra=foo" | 1033 "http://localhost/upd?extra=foo" |
| 1075 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); | 1034 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 1076 const GURL expected_update_url_1( | 1035 const GURL expected_update_url_1( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1104 | 1063 |
| 1105 component_updater()->Start(); | 1064 component_updater()->Start(); |
| 1106 RunThreads(); | 1065 RunThreads(); |
| 1107 component_updater()->Stop(); | 1066 component_updater()->Stop(); |
| 1108 // There may still be pings in the queue. | 1067 // There may still be pings in the queue. |
| 1109 RunThreadsUntilIdle(); | 1068 RunThreadsUntilIdle(); |
| 1110 | 1069 |
| 1111 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1070 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1112 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 1071 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1113 | 1072 |
| 1114 EXPECT_EQ(1, ping_checker.NumHits()) << ping_checker.GetPings(); | 1073 EXPECT_EQ(2, ping_interceptor.GetHitCount()) |
| 1115 EXPECT_EQ(1, ping_checker.NumMisses()) << ping_checker.GetPings(); | 1074 << ping_interceptor.GetRequestsAsString(); |
| 1075 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[0].find( |
| 1076 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| 1077 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 1078 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>")) |
| 1079 << ping_interceptor.GetRequestsAsString(); |
| 1080 EXPECT_NE(string::npos, ping_interceptor.GetRequests()[1].find( |
| 1081 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| 1082 "<o:event eventtype=\"3\" eventresult=\"1\" " |
| 1083 "previousversion=\"1.0\" nextversion=\"2.0\" " |
| 1084 "diffresult=\"0\" differrorcat=\"2\" " |
| 1085 "differrorcode=\"14\" diffextracode1=\"305\" " |
| 1086 "previousfp=\"1\" nextfp=\"f22\"/></o:app>")) |
| 1087 << ping_interceptor.GetRequestsAsString(); |
| 1088 |
| 1116 EXPECT_EQ(5, interceptor.GetHitCount()); | 1089 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 1117 } | 1090 } |
| OLD | NEW |