| 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 <list> | 5 #include <list> |
| 6 #include <utility> | 6 #include <utility> |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 int TestConfigurator::MinimumReCheckWait() { | 77 int TestConfigurator::MinimumReCheckWait() { |
| 78 return recheck_time_; | 78 return recheck_time_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 int TestConfigurator::OnDemandDelay() { | 81 int TestConfigurator::OnDemandDelay() { |
| 82 return ondemand_time_; | 82 return ondemand_time_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 GURL TestConfigurator::UpdateUrl() { | 85 GURL TestConfigurator::UpdateUrl() { |
| 86 return GURL("http://localhost/upd"); | 86 return GURL("http://localhost/upd"); |
| 87 } |
| 88 |
| 89 GURL TestConfigurator::PingUrl() { |
| 90 return GURL("http://localhost2/ping"); |
| 87 } | 91 } |
| 88 | 92 |
| 89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } | 93 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } |
| 90 | 94 |
| 91 size_t TestConfigurator::UrlSizeLimit() { return 256; } | 95 size_t TestConfigurator::UrlSizeLimit() { return 256; } |
| 92 | 96 |
| 93 net::URLRequestContextGetter* TestConfigurator::RequestContext() { | 97 net::URLRequestContextGetter* TestConfigurator::RequestContext() { |
| 94 return new net::TestURLRequestContextGetter( | 98 return new net::TestURLRequestContextGetter( |
| 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 99 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 96 } | 100 } |
| 97 | 101 |
| 98 // Don't use the utility process to decode files. | 102 // Don't use the utility process to decode files. |
| 99 bool TestConfigurator::InProcess() { return true; } | 103 bool TestConfigurator::InProcess() { return true; } |
| 100 | 104 |
| 101 void TestConfigurator::OnEvent(Events event, int extra) { } | |
| 102 | |
| 103 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { | 105 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { |
| 104 return new MockComponentPatcher(); | 106 return new MockComponentPatcher(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 bool TestConfigurator::DeltasEnabled() const { | 109 bool TestConfigurator::DeltasEnabled() const { |
| 108 return true; | 110 return true; |
| 109 } | 111 } |
| 110 | 112 |
| 111 // Set how many update checks are called, the default value is just once. | 113 // Set how many update checks are called, the default value is just once. |
| 112 void TestConfigurator::SetLoopCount(int times) { times_ = times; } | 114 void TestConfigurator::SetLoopCount(int times) { times_ = times; } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 192 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 191 } else { | 193 } else { |
| 192 com->name = "test_ihfo"; | 194 com->name = "test_ihfo"; |
| 193 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 195 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 194 } | 196 } |
| 195 com->version = version; | 197 com->version = version; |
| 196 com->installer = installer; | 198 com->installer = installer; |
| 197 return component_updater_->RegisterComponent(*com); | 199 return component_updater_->RegisterComponent(*com); |
| 198 } | 200 } |
| 199 | 201 |
| 202 PingChecker::PingChecker(const std::map<std::string, std::string>& attributes) |
| 203 : num_hits_(0), num_misses_(0), attributes_(attributes) { |
| 204 } |
| 205 |
| 206 PingChecker::~PingChecker() {} |
| 207 |
| 208 void PingChecker::Trial(net::URLRequest* request) { |
| 209 if (Test(request)) |
| 210 ++num_hits_; |
| 211 else |
| 212 ++num_misses_; |
| 213 } |
| 214 |
| 215 bool PingChecker::Test(net::URLRequest* request) { |
| 216 if (request->has_upload()) { |
| 217 const net::UploadDataStream* stream = request->get_upload(); |
| 218 const net::UploadBytesElementReader* reader = |
| 219 stream->element_readers()[0]->AsBytesReader(); |
| 220 int size = reader->length(); |
| 221 scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size); |
| 222 std::string data(reader->bytes()); |
| 223 // For now, we assume that there is only one ping per POST. |
| 224 std::string::size_type start = data.find("<o:event"); |
| 225 if (start != std::string::npos) { |
| 226 std::string::size_type end = data.find(">", start); |
| 227 if (end != std::string::npos) { |
| 228 std::string ping = data.substr(start, end - start); |
| 229 std::map<std::string, std::string>::const_iterator iter; |
| 230 for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) { |
| 231 // does the ping contain the specified attribute/value? |
| 232 if (ping.find(std::string(" ") + (iter->first) + |
| 233 std::string("=") + (iter->second)) == string::npos) { |
| 234 return false; |
| 235 } |
| 236 } |
| 237 return true; |
| 238 } |
| 239 } |
| 240 } |
| 241 return false; |
| 242 } |
| 243 |
| 200 // Verify that our test fixture work and the component updater can | 244 // Verify that our test fixture work and the component updater can |
| 201 // be created and destroyed with no side effects. | 245 // be created and destroyed with no side effects. |
| 202 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 246 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
| 203 EXPECT_TRUE(component_updater() != NULL); | 247 EXPECT_TRUE(component_updater() != NULL); |
| 204 EXPECT_EQ(0ul, notification_tracker().size()); | 248 EXPECT_EQ(0ul, notification_tracker().size()); |
| 205 } | 249 } |
| 206 | 250 |
| 207 // Verify that the component updater can be caught in a quick | 251 // Verify that the component updater can be caught in a quick |
| 208 // start-shutdown situation. Failure of this test will be a crash. Also | 252 // start-shutdown situation. Failure of this test will be a crash. Also |
| 209 // if there is no work to do, there are no notifications generated. | 253 // if there is no work to do, there are no notifications generated. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 337 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 294 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 338 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 295 | 339 |
| 296 component_updater()->Stop(); | 340 component_updater()->Stop(); |
| 297 } | 341 } |
| 298 | 342 |
| 299 // Verify that we can check for updates and install one component. Besides | 343 // Verify that we can check for updates and install one component. Besides |
| 300 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and | 344 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and |
| 301 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops | 345 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops |
| 302 // so the second time around there should be nothing left to do. | 346 // so the second time around there should be nothing left to do. |
| 303 // We also check that only 3 network requests are issued: | 347 // We also check that only 3 non-ping network requests are issued: |
| 304 // 1- manifest check | 348 // 1- manifest check |
| 305 // 2- download crx | 349 // 2- download crx |
| 306 // 3- second manifest check. | 350 // 3- second manifest check. |
| 307 TEST_F(ComponentUpdaterTest, InstallCrx) { | 351 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 308 base::MessageLoop message_loop; | 352 base::MessageLoop message_loop; |
| 309 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 353 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 310 content::TestBrowserThread file_thread(BrowserThread::FILE); | 354 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 311 content::TestBrowserThread io_thread(BrowserThread::IO); | 355 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 312 | 356 |
| 313 io_thread.StartIOThread(); | 357 io_thread.StartIOThread(); |
| 314 file_thread.Start(); | 358 file_thread.Start(); |
| 315 | 359 |
| 360 std::map<std::string, std::string> map; |
| 361 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 362 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 363 map.insert(std::pair<std::string, std::string>("previousversion", |
| 364 "\"0.9\"")); |
| 365 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 366 PingChecker ping_checker(map); |
| 367 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 316 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 368 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 317 | 369 |
| 318 TestInstaller installer1; | 370 TestInstaller installer1; |
| 319 CrxComponent com1; | 371 CrxComponent com1; |
| 320 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 372 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 321 TestInstaller installer2; | 373 TestInstaller installer2; |
| 322 CrxComponent com2; | 374 CrxComponent com2; |
| 323 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 375 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 324 | 376 |
| 325 const GURL expected_update_url_1( | 377 const GURL expected_update_url_1( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 343 | 395 |
| 344 component_updater()->Start(); | 396 component_updater()->Start(); |
| 345 message_loop.Run(); | 397 message_loop.Run(); |
| 346 | 398 |
| 347 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 399 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 348 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 400 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 349 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 401 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 350 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 402 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 351 | 403 |
| 352 EXPECT_EQ(3, interceptor.GetHitCount()); | 404 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 405 EXPECT_EQ(1, ping_checker.NumHits()); |
| 406 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 353 | 407 |
| 354 ASSERT_EQ(5ul, notification_tracker().size()); | 408 ASSERT_EQ(5ul, notification_tracker().size()); |
| 355 | 409 |
| 356 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 410 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 357 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 411 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 358 | 412 |
| 359 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 413 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 360 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 414 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 361 | 415 |
| 362 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 416 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 373 // version is much higher than of chrome. | 427 // version is much higher than of chrome. |
| 374 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 428 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| 375 base::MessageLoop message_loop; | 429 base::MessageLoop message_loop; |
| 376 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 430 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 377 content::TestBrowserThread file_thread(BrowserThread::FILE); | 431 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 378 content::TestBrowserThread io_thread(BrowserThread::IO); | 432 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 379 | 433 |
| 380 io_thread.StartIOThread(); | 434 io_thread.StartIOThread(); |
| 381 file_thread.Start(); | 435 file_thread.Start(); |
| 382 | 436 |
| 437 std::map<std::string, std::string> map; |
| 438 PingChecker ping_checker(map); |
| 439 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 383 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 440 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 384 | 441 |
| 385 TestInstaller installer; | 442 TestInstaller installer; |
| 386 CrxComponent com; | 443 CrxComponent com; |
| 387 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); | 444 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 388 | 445 |
| 389 const GURL expected_update_url( | 446 const GURL expected_update_url( |
| 390 "http://localhost/upd?extra=foo&x=id%3D" | 447 "http://localhost/upd?extra=foo&x=id%3D" |
| 391 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | 448 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 392 | 449 |
| 393 interceptor.SetResponse(expected_update_url, | 450 interceptor.SetResponse(expected_update_url, |
| 394 test_file("updatecheck_reply_2.xml")); | 451 test_file("updatecheck_reply_2.xml")); |
| 395 interceptor.SetResponse(GURL(expected_crx_url), | 452 interceptor.SetResponse(GURL(expected_crx_url), |
| 396 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 453 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 397 | 454 |
| 398 test_configurator()->SetLoopCount(1); | 455 test_configurator()->SetLoopCount(1); |
| 399 component_updater()->Start(); | 456 component_updater()->Start(); |
| 400 message_loop.Run(); | 457 message_loop.Run(); |
| 401 | 458 |
| 459 EXPECT_EQ(0, ping_checker.NumHits()); |
| 460 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 402 EXPECT_EQ(1, interceptor.GetHitCount()); | 461 EXPECT_EQ(1, interceptor.GetHitCount()); |
| 403 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 462 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 404 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 463 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 405 | 464 |
| 406 component_updater()->Stop(); | 465 component_updater()->Stop(); |
| 407 } | 466 } |
| 408 | 467 |
| 409 // Test that a ping for an update check can cause installs. | 468 // Test that a ping for an update check can cause installs. |
| 410 // Here is the timeline: | 469 // Here is the timeline: |
| 411 // - First loop: we return a reply that indicates no update, so | 470 // - First loop: we return a reply that indicates no update, so |
| 412 // nothing happens. | 471 // nothing happens. |
| 413 // - We ping. | 472 // - We ping. |
| 414 // - This triggers a second loop, which has a reply that triggers an install. | 473 // - This triggers a second loop, which has a reply that triggers an install. |
| 415 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { | 474 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { |
| 416 base::MessageLoop message_loop; | 475 base::MessageLoop message_loop; |
| 417 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 476 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 418 content::TestBrowserThread file_thread(BrowserThread::FILE); | 477 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 419 content::TestBrowserThread io_thread(BrowserThread::IO); | 478 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 420 | 479 |
| 421 io_thread.StartIOThread(); | 480 io_thread.StartIOThread(); |
| 422 file_thread.Start(); | 481 file_thread.Start(); |
| 423 | 482 |
| 483 std::map<std::string, std::string> map; |
| 484 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 485 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 486 map.insert(std::pair<std::string, std::string>("previousversion", |
| 487 "\"0.9\"")); |
| 488 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 489 PingChecker ping_checker(map); |
| 490 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 424 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 491 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 425 | 492 |
| 426 TestInstaller installer1; | 493 TestInstaller installer1; |
| 427 CrxComponent com1; | 494 CrxComponent com1; |
| 428 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); | 495 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
| 429 TestInstaller installer2; | 496 TestInstaller installer2; |
| 430 CrxComponent com2; | 497 CrxComponent com2; |
| 431 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); | 498 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
| 432 | 499 |
| 433 const GURL expected_update_url_1( | 500 const GURL expected_update_url_1( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 interceptor.SetResponse(expected_update_url_3, | 581 interceptor.SetResponse(expected_update_url_3, |
| 515 test_file("updatecheck_reply_1.xml")); | 582 test_file("updatecheck_reply_1.xml")); |
| 516 notification_tracker().Reset(); | 583 notification_tracker().Reset(); |
| 517 test_configurator()->SetLoopCount(1); | 584 test_configurator()->SetLoopCount(1); |
| 518 component_updater()->Start(); | 585 component_updater()->Start(); |
| 519 EXPECT_EQ(ComponentUpdateService::kOk, | 586 EXPECT_EQ(ComponentUpdateService::kOk, |
| 520 component_updater()->CheckForUpdateSoon(com2)); | 587 component_updater()->CheckForUpdateSoon(com2)); |
| 521 | 588 |
| 522 message_loop.Run(); | 589 message_loop.Run(); |
| 523 | 590 |
| 591 EXPECT_EQ(1, ping_checker.NumHits()); |
| 592 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 524 ASSERT_EQ(2ul, notification_tracker().size()); | 593 ASSERT_EQ(2ul, notification_tracker().size()); |
| 525 ev0 = notification_tracker().at(0); | 594 ev0 = notification_tracker().at(0); |
| 526 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 595 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 527 ev1 = notification_tracker().at(1); | 596 ev1 = notification_tracker().at(1); |
| 528 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 597 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 529 component_updater()->Stop(); | 598 component_updater()->Stop(); |
| 530 } | 599 } |
| 531 | 600 |
| 532 // Verify that a previously registered component can get re-registered | 601 // Verify that a previously registered component can get re-registered |
| 533 // with a different version. | 602 // with a different version. |
| 534 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 603 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| 535 base::MessageLoop message_loop; | 604 base::MessageLoop message_loop; |
| 536 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 605 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 537 content::TestBrowserThread file_thread(BrowserThread::FILE); | 606 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 538 content::TestBrowserThread io_thread(BrowserThread::IO); | 607 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 539 | 608 |
| 540 io_thread.StartIOThread(); | 609 io_thread.StartIOThread(); |
| 541 file_thread.Start(); | 610 file_thread.Start(); |
| 542 | 611 |
| 612 std::map<std::string, std::string> map; |
| 613 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 614 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 615 map.insert(std::pair<std::string, std::string>("previousversion", |
| 616 "\"0.9\"")); |
| 617 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 618 PingChecker ping_checker(map); |
| 619 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 543 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 620 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 544 | 621 |
| 545 TestInstaller installer1; | 622 TestInstaller installer1; |
| 546 CrxComponent com1; | 623 CrxComponent com1; |
| 547 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 624 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 548 TestInstaller installer2; | 625 TestInstaller installer2; |
| 549 CrxComponent com2; | 626 CrxComponent com2; |
| 550 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 627 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 551 | 628 |
| 552 // Start with 0.9, and update to 1.0 | 629 // Start with 0.9, and update to 1.0 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 572 test_configurator()->SetLoopCount(2); | 649 test_configurator()->SetLoopCount(2); |
| 573 | 650 |
| 574 component_updater()->Start(); | 651 component_updater()->Start(); |
| 575 message_loop.Run(); | 652 message_loop.Run(); |
| 576 | 653 |
| 577 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 654 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 578 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 655 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 579 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 656 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 580 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 657 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 581 | 658 |
| 659 EXPECT_EQ(1, ping_checker.NumHits()); |
| 660 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 582 EXPECT_EQ(3, interceptor.GetHitCount()); | 661 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 583 | 662 |
| 584 ASSERT_EQ(5ul, notification_tracker().size()); | 663 ASSERT_EQ(5ul, notification_tracker().size()); |
| 585 | 664 |
| 586 TestNotificationTracker::Event ev0 = notification_tracker().at(0); | 665 TestNotificationTracker::Event ev0 = notification_tracker().at(0); |
| 587 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 666 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 588 | 667 |
| 589 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 668 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 590 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 669 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 591 | 670 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 719 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 641 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 720 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 642 | 721 |
| 643 component_updater()->Stop(); | 722 component_updater()->Stop(); |
| 644 } | 723 } |
| 645 | 724 |
| 646 // Verify that component installation falls back to downloading and installing | 725 // Verify that component installation falls back to downloading and installing |
| 647 // a full update if the differential update fails (in this case, because the | 726 // a full update if the differential update fails (in this case, because the |
| 648 // installer does not know about the existing files). We do two loops; the final | 727 // installer does not know about the existing files). We do two loops; the final |
| 649 // loop should do nothing. | 728 // loop should do nothing. |
| 650 // We also check that exactly 4 network requests are issued: | 729 // We also check that exactly 4 non-ping network requests are issued: |
| 651 // 1- update check (loop 1) | 730 // 1- update check (loop 1) |
| 652 // 2- download differential crx | 731 // 2- download differential crx |
| 653 // 3- download full crx | 732 // 3- download full crx |
| 654 // 4- update check (loop 2 - no update available) | 733 // 4- update check (loop 2 - no update available) |
| 734 // There should be one ping for the first attempted update. |
| 655 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { | 735 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { |
| 656 base::MessageLoop message_loop; | 736 base::MessageLoop message_loop; |
| 657 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 737 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 658 content::TestBrowserThread file_thread(BrowserThread::FILE); | 738 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 659 content::TestBrowserThread io_thread(BrowserThread::IO); | 739 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 660 | 740 |
| 661 io_thread.StartIOThread(); | 741 io_thread.StartIOThread(); |
| 662 file_thread.Start(); | 742 file_thread.Start(); |
| 663 | 743 |
| 744 std::map<std::string, std::string> map; |
| 745 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 746 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 747 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); |
| 748 map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\"")); |
| 749 PingChecker ping_checker(map); |
| 750 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 664 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 751 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 665 | 752 |
| 666 TestInstaller installer; | 753 TestInstaller installer; |
| 667 CrxComponent com; | 754 CrxComponent com; |
| 668 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); | 755 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); |
| 669 | 756 |
| 670 const GURL expected_update_url_1( | 757 const GURL expected_update_url_1( |
| 671 "http://localhost/upd?extra=foo" | 758 "http://localhost/upd?extra=foo" |
| 672 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); | 759 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); |
| 673 const GURL expected_update_url_2( | 760 const GURL expected_update_url_2( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 694 | 781 |
| 695 test_configurator()->SetLoopCount(2); | 782 test_configurator()->SetLoopCount(2); |
| 696 | 783 |
| 697 component_updater()->Start(); | 784 component_updater()->Start(); |
| 698 message_loop.Run(); | 785 message_loop.Run(); |
| 699 | 786 |
| 700 // A failed differential update does not count as a failed install. | 787 // A failed differential update does not count as a failed install. |
| 701 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 788 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 702 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); | 789 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 703 | 790 |
| 791 EXPECT_EQ(1, ping_checker.NumHits()); |
| 792 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 704 EXPECT_EQ(4, interceptor.GetHitCount()); | 793 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 705 | 794 |
| 706 component_updater()->Stop(); | 795 component_updater()->Stop(); |
| 707 } | 796 } |
| 708 | 797 |
| 798 // Verify that a failed installation causes an install failure ping. |
| 799 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| 800 base::MessageLoop message_loop; |
| 801 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 802 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 803 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 804 |
| 805 io_thread.StartIOThread(); |
| 806 file_thread.Start(); |
| 807 |
| 808 std::map<std::string, std::string> map; |
| 809 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 810 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\"")); |
| 811 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\"")); |
| 812 map.insert(std::pair<std::string, std::string>("previousversion", |
| 813 "\"0.9\"")); |
| 814 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 815 PingChecker ping_checker(map); |
| 816 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 817 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 818 |
| 819 // This test installer reports installation failure. |
| 820 class : public TestInstaller { |
| 821 virtual bool Install(const base::DictionaryValue& manifest, |
| 822 const base::FilePath& unpack_path) OVERRIDE { |
| 823 ++install_count_; |
| 824 base::Delete(unpack_path, true); |
| 825 return false; |
| 826 } |
| 827 } installer; |
| 828 |
| 829 CrxComponent com; |
| 830 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 831 |
| 832 // Start with 0.9, and attempt update to 1.0 |
| 833 const GURL expected_update_url_1( |
| 834 "http://localhost/upd?extra=foo" |
| 835 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 836 |
| 837 interceptor.SetResponse(expected_update_url_1, |
| 838 test_file("updatecheck_reply_1.xml")); |
| 839 interceptor.SetResponse(GURL(expected_crx_url), |
| 840 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 841 |
| 842 // Loop twice to issue two checks: (1) with original 0.9 version |
| 843 // and (2), which should retry with 0.9. |
| 844 test_configurator()->SetLoopCount(2); |
| 845 component_updater()->Start(); |
| 846 message_loop.Run(); |
| 847 |
| 848 // Loop once more, but expect no ping because a noupdate response is issued. |
| 849 // This is necessary to clear out the fire-and-forget ping from the previous |
| 850 // iteration. |
| 851 interceptor.SetResponse(expected_update_url_1, |
| 852 test_file("updatecheck_reply_noupdate.xml")); |
| 853 test_configurator()->SetLoopCount(1); |
| 854 component_updater()->Start(); |
| 855 message_loop.Run(); |
| 856 |
| 857 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 858 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 859 |
| 860 EXPECT_EQ(2, ping_checker.NumHits()); |
| 861 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 862 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 863 |
| 864 component_updater()->Stop(); |
| 865 } |
| 866 |
| 709 // Verify that we successfully propagate a patcher error. | 867 // Verify that we successfully propagate a patcher error. |
| 710 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect | 868 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect |
| 711 // patching instruction that should fail. | 869 // patching instruction that should fail. |
| 712 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { | 870 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { |
| 713 base::MessageLoop message_loop; | 871 base::MessageLoop message_loop; |
| 714 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 872 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 715 content::TestBrowserThread file_thread(BrowserThread::FILE); | 873 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 716 content::TestBrowserThread io_thread(BrowserThread::IO); | 874 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 717 | 875 |
| 718 io_thread.StartIOThread(); | 876 io_thread.StartIOThread(); |
| 719 file_thread.Start(); | 877 file_thread.Start(); |
| 720 | 878 |
| 879 std::map<std::string, std::string> map; |
| 880 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 881 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 882 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); |
| 883 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\"")); |
| 884 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\"")); |
| 885 PingChecker ping_checker(map); |
| 886 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 721 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 887 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 722 | 888 |
| 723 VersionedTestInstaller installer; | 889 VersionedTestInstaller installer; |
| 724 CrxComponent com; | 890 CrxComponent com; |
| 725 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); | 891 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 726 | 892 |
| 727 const GURL expected_update_url_0( | 893 const GURL expected_update_url_0( |
| 728 "http://localhost/upd?extra=foo" | 894 "http://localhost/upd?extra=foo" |
| 729 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); | 895 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 730 const GURL expected_update_url_1( | 896 const GURL expected_update_url_1( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 755 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | 921 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| 756 | 922 |
| 757 test_configurator()->SetLoopCount(3); | 923 test_configurator()->SetLoopCount(3); |
| 758 | 924 |
| 759 component_updater()->Start(); | 925 component_updater()->Start(); |
| 760 message_loop.Run(); | 926 message_loop.Run(); |
| 761 | 927 |
| 762 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 928 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 763 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 929 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 764 | 930 |
| 931 EXPECT_EQ(1, ping_checker.NumHits()); |
| 932 EXPECT_EQ(1, ping_checker.NumMisses()); |
| 765 EXPECT_EQ(6, interceptor.GetHitCount()); | 933 EXPECT_EQ(6, interceptor.GetHitCount()); |
| 766 | 934 |
| 767 component_updater()->Stop(); | 935 component_updater()->Stop(); |
| 768 } | 936 } |
| OLD | NEW |