| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 using ::testing::_; | 28 using ::testing::_; |
| 29 using ::testing::InSequence; | 29 using ::testing::InSequence; |
| 30 using ::testing::Mock; | 30 using ::testing::Mock; |
| 31 | 31 |
| 32 namespace component_updater { | 32 namespace component_updater { |
| 33 | 33 |
| 34 #define POST_INTERCEPT_SCHEME "https" | 34 #define POST_INTERCEPT_SCHEME "https" |
| 35 #define POST_INTERCEPT_HOSTNAME "localhost2" | 35 #define POST_INTERCEPT_HOSTNAME "localhost2" |
| 36 #define POST_INTERCEPT_PATH "/update2" | 36 #define POST_INTERCEPT_PATH "/update2" |
| 37 | 37 |
| 38 MockComponentObserver::MockComponentObserver() { | 38 MockServiceObserver::MockServiceObserver() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 MockComponentObserver::~MockComponentObserver() { | 41 MockServiceObserver::~MockServiceObserver() { |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool PartialMatch::Match(const std::string& actual) const { | 44 bool PartialMatch::Match(const std::string& actual) const { |
| 45 return actual.find(expected_) != std::string::npos; | 45 return actual.find(expected_) != std::string::npos; |
| 46 } | 46 } |
| 47 | 47 |
| 48 TestConfigurator::TestConfigurator() | 48 TestConfigurator::TestConfigurator() |
| 49 : initial_time_(0), | 49 : initial_time_(0), |
| 50 times_(1), | 50 times_(1), |
| 51 recheck_time_(0), | 51 recheck_time_(0), |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 TEST_F(ComponentUpdaterTest, StartStop) { | 247 TEST_F(ComponentUpdaterTest, StartStop) { |
| 248 component_updater()->Start(); | 248 component_updater()->Start(); |
| 249 RunThreadsUntilIdle(); | 249 RunThreadsUntilIdle(); |
| 250 component_updater()->Stop(); | 250 component_updater()->Stop(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 // Verify that when the server has no updates, we go back to sleep and | 253 // Verify that when the server has no updates, we go back to sleep and |
| 254 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications | 254 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
| 255 // are generated. No pings are sent. | 255 // are generated. No pings are sent. |
| 256 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 256 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| 257 MockComponentObserver observer; | 257 MockServiceObserver observer; |
| 258 | 258 |
| 259 EXPECT_CALL(observer, | 259 EXPECT_CALL(observer, |
| 260 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 260 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 261 .Times(1); | 261 .Times(1); |
| 262 EXPECT_CALL(observer, | 262 EXPECT_CALL(observer, |
| 263 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 263 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 264 .Times(2); | 264 .Times(2); |
| 265 EXPECT_CALL(observer, | 265 EXPECT_CALL(observer, |
| 266 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 266 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 267 "abagagagagagagagagagagagagagagag")) |
| 267 .Times(2); | 268 .Times(2); |
| 268 | 269 |
| 269 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 270 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 270 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 271 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 271 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 272 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 272 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 273 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 273 | 274 |
| 274 TestInstaller installer; | 275 TestInstaller installer; |
| 275 CrxComponent com; | 276 CrxComponent com; |
| 276 com.observer = &observer; | 277 component_updater()->AddObserver(&observer); |
| 277 EXPECT_EQ(ComponentUpdateService::kOk, | 278 EXPECT_EQ(ComponentUpdateService::kOk, |
| 278 RegisterComponent(&com, | 279 RegisterComponent(&com, |
| 279 kTestComponent_abag, | 280 kTestComponent_abag, |
| 280 Version("1.1"), | 281 Version("1.1"), |
| 281 &installer)); | 282 &installer)); |
| 282 | 283 |
| 283 // We loop twice, but there are no updates so we expect two sleep messages. | 284 // We loop twice, but there are no updates so we expect two sleep messages. |
| 284 test_configurator()->SetLoopCount(2); | 285 test_configurator()->SetLoopCount(2); |
| 285 component_updater()->Start(); | 286 component_updater()->Start(); |
| 286 RunThreads(); | 287 RunThreads(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 301 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( | 302 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 302 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" | 303 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| 303 "<updatecheck /></app>")) | 304 "<updatecheck /></app>")) |
| 304 << post_interceptor_->GetRequestsAsString(); | 305 << post_interceptor_->GetRequestsAsString(); |
| 305 | 306 |
| 306 component_updater()->Stop(); | 307 component_updater()->Stop(); |
| 307 | 308 |
| 308 // Loop twice again but this case we simulate a server error by returning | 309 // Loop twice again but this case we simulate a server error by returning |
| 309 // an empty file. Expect the behavior of the service to be the same as before. | 310 // an empty file. Expect the behavior of the service to be the same as before. |
| 310 EXPECT_CALL(observer, | 311 EXPECT_CALL(observer, |
| 311 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 312 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 312 .Times(1); | 313 .Times(1); |
| 313 EXPECT_CALL(observer, | 314 EXPECT_CALL(observer, |
| 314 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 315 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 315 .Times(2); | 316 .Times(2); |
| 316 EXPECT_CALL(observer, | 317 EXPECT_CALL(observer, |
| 317 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 318 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 319 "abagagagagagagagagagagagagagagag")) |
| 318 .Times(2); | 320 .Times(2); |
| 319 | 321 |
| 320 post_interceptor_->Reset(); | 322 post_interceptor_->Reset(); |
| 321 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 323 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 322 "updatecheck"), test_file("updatecheck_reply_empty"))); | 324 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 323 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 325 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 324 "updatecheck"), test_file("updatecheck_reply_empty"))); | 326 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 325 | 327 |
| 326 test_configurator()->SetLoopCount(2); | 328 test_configurator()->SetLoopCount(2); |
| 327 component_updater()->Start(); | 329 component_updater()->Start(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 349 // Verify that we can check for updates and install one component. Besides | 351 // Verify that we can check for updates and install one component. Besides |
| 350 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY | 352 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY |
| 351 // should have been fired. We do two loops so the second time around there | 353 // should have been fired. We do two loops so the second time around there |
| 352 // should be nothing left to do. | 354 // should be nothing left to do. |
| 353 // We also check that the following network requests are issued: | 355 // We also check that the following network requests are issued: |
| 354 // 1- update check | 356 // 1- update check |
| 355 // 2- download crx | 357 // 2- download crx |
| 356 // 3- ping | 358 // 3- ping |
| 357 // 4- second update check. | 359 // 4- second update check. |
| 358 TEST_F(ComponentUpdaterTest, InstallCrx) { | 360 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 359 MockComponentObserver observer1; | 361 MockServiceObserver observer; |
| 360 { | 362 { |
| 361 InSequence seq; | 363 InSequence seq; |
| 362 EXPECT_CALL(observer1, | 364 EXPECT_CALL(observer, |
| 363 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 365 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 364 .Times(1); | 366 .Times(1); |
| 365 EXPECT_CALL(observer1, | 367 EXPECT_CALL(observer, |
| 366 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | 368 OnEvent(ServiceObserver::COMPONENT_UPDATE_FOUND, |
| 369 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 367 .Times(1); | 370 .Times(1); |
| 368 EXPECT_CALL(observer1, | 371 EXPECT_CALL(observer, |
| 369 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) | 372 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 373 "abagagagagagagagagagagagagagagag")) |
| 370 .Times(1); | 374 .Times(1); |
| 371 EXPECT_CALL(observer1, | 375 EXPECT_CALL(observer, |
| 372 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0)) | 376 OnEvent(ServiceObserver::COMPONENT_UPDATE_READY, |
| 377 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 373 .Times(1); | 378 .Times(1); |
| 374 EXPECT_CALL(observer1, | 379 EXPECT_CALL(observer, |
| 375 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 380 OnEvent(ServiceObserver::COMPONENT_UPDATED, |
| 381 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 376 .Times(1); | 382 .Times(1); |
| 377 EXPECT_CALL(observer1, | 383 EXPECT_CALL(observer, |
| 378 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 384 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 379 .Times(1); | 385 .Times(1); |
| 380 EXPECT_CALL(observer1, | 386 EXPECT_CALL(observer, |
| 381 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 387 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 388 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 389 .Times(1); |
| 390 EXPECT_CALL(observer, |
| 391 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 392 "abagagagagagagagagagagagagagagag")) |
| 393 .Times(1); |
| 394 EXPECT_CALL(observer, |
| 395 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 382 .Times(1); | 396 .Times(1); |
| 383 } | 397 } |
| 384 | 398 |
| 385 MockComponentObserver observer2; | |
| 386 { | |
| 387 InSequence seq; | |
| 388 EXPECT_CALL(observer2, | |
| 389 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 390 .Times(1); | |
| 391 EXPECT_CALL(observer2, | |
| 392 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 393 .Times(1); | |
| 394 EXPECT_CALL(observer2, | |
| 395 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 396 .Times(1); | |
| 397 EXPECT_CALL(observer2, | |
| 398 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 399 .Times(1); | |
| 400 EXPECT_CALL(observer2, | |
| 401 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 402 .Times(1); | |
| 403 } | |
| 404 | |
| 405 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 399 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 406 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 400 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 407 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); | 401 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 408 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 402 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 409 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 403 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 410 | 404 |
| 411 get_interceptor_->SetResponse( | 405 get_interceptor_->SetResponse( |
| 412 GURL(expected_crx_url), | 406 GURL(expected_crx_url), |
| 413 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 407 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 414 | 408 |
| 409 component_updater()->AddObserver(&observer); |
| 410 |
| 415 TestInstaller installer1; | 411 TestInstaller installer1; |
| 416 CrxComponent com1; | 412 CrxComponent com1; |
| 417 com1.observer = &observer1; | |
| 418 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 413 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 419 TestInstaller installer2; | 414 TestInstaller installer2; |
| 420 CrxComponent com2; | 415 CrxComponent com2; |
| 421 com2.observer = &observer2; | |
| 422 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 416 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 423 | 417 |
| 424 test_configurator()->SetLoopCount(2); | 418 test_configurator()->SetLoopCount(2); |
| 425 component_updater()->Start(); | 419 component_updater()->Start(); |
| 426 RunThreads(); | 420 RunThreads(); |
| 427 | 421 |
| 428 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 422 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 429 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 423 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 430 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 424 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 431 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 425 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 component_updater()->Stop(); | 524 component_updater()->Stop(); |
| 531 } | 525 } |
| 532 | 526 |
| 533 // Test that a update check due to an on demand call can cause installs. | 527 // Test that a update check due to an on demand call can cause installs. |
| 534 // Here is the timeline: | 528 // Here is the timeline: |
| 535 // - First loop: we return a reply that indicates no update, so | 529 // - First loop: we return a reply that indicates no update, so |
| 536 // nothing happens. | 530 // nothing happens. |
| 537 // - We make an on demand call. | 531 // - We make an on demand call. |
| 538 // - This triggers a second loop, which has a reply that triggers an install. | 532 // - This triggers a second loop, which has a reply that triggers an install. |
| 539 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { | 533 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
| 540 MockComponentObserver observer1; | 534 MockServiceObserver observer; |
| 541 { | 535 { |
| 542 InSequence seq; | 536 InSequence seq; |
| 543 EXPECT_CALL(observer1, | 537 EXPECT_CALL(observer, |
| 544 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 538 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 545 .Times(1); | 539 .Times(1); |
| 546 EXPECT_CALL(observer1, | 540 EXPECT_CALL(observer, |
| 547 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 541 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 542 "abagagagagagagagagagagagagagagag")) |
| 548 .Times(1); | 543 .Times(1); |
| 549 EXPECT_CALL(observer1, | 544 EXPECT_CALL(observer, |
| 550 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 545 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 546 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 551 .Times(1); | 547 .Times(1); |
| 552 EXPECT_CALL(observer1, | 548 EXPECT_CALL(observer, |
| 553 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 549 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 554 .Times(1); | 550 .Times(1); |
| 555 EXPECT_CALL(observer1, | 551 EXPECT_CALL(observer, |
| 556 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 552 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 557 .Times(1); | 553 .Times(1); |
| 558 EXPECT_CALL(observer1, | 554 EXPECT_CALL(observer, |
| 559 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 555 OnEvent(ServiceObserver::COMPONENT_UPDATE_FOUND, |
| 556 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 557 .Times(1); |
| 558 EXPECT_CALL(observer, |
| 559 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 560 "abagagagagagagagagagagagagagagag")) |
| 561 .Times(1); |
| 562 EXPECT_CALL(observer, |
| 563 OnEvent(ServiceObserver::COMPONENT_UPDATE_READY, |
| 564 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 565 .Times(1); |
| 566 EXPECT_CALL(observer, |
| 567 OnEvent(ServiceObserver::COMPONENT_UPDATED, |
| 568 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 569 .Times(1); |
| 570 EXPECT_CALL(observer, |
| 571 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 560 .Times(1); | 572 .Times(1); |
| 561 } | 573 } |
| 562 | 574 |
| 563 MockComponentObserver observer2; | |
| 564 { | |
| 565 InSequence seq; | |
| 566 EXPECT_CALL(observer2, | |
| 567 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 568 .Times(1); | |
| 569 EXPECT_CALL(observer2, | |
| 570 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 571 .Times(1); | |
| 572 EXPECT_CALL(observer2, | |
| 573 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 574 .Times(1); | |
| 575 EXPECT_CALL(observer2, | |
| 576 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 577 .Times(1); | |
| 578 EXPECT_CALL(observer2, | |
| 579 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | |
| 580 .Times(1); | |
| 581 EXPECT_CALL(observer2, | |
| 582 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) | |
| 583 .Times(1); | |
| 584 EXPECT_CALL(observer2, | |
| 585 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0)) | |
| 586 .Times(1); | |
| 587 EXPECT_CALL(observer2, | |
| 588 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 589 .Times(1); | |
| 590 } | |
| 591 | |
| 592 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 575 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 593 "updatecheck"), test_file("updatecheck_reply_empty"))); | 576 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 594 | 577 |
| 595 get_interceptor_->SetResponse( | 578 get_interceptor_->SetResponse( |
| 596 GURL(expected_crx_url), | 579 GURL(expected_crx_url), |
| 597 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 580 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 598 | 581 |
| 582 component_updater()->AddObserver(&observer); |
| 583 |
| 599 TestInstaller installer1; | 584 TestInstaller installer1; |
| 600 CrxComponent com1; | 585 CrxComponent com1; |
| 601 com1.observer = &observer1; | |
| 602 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); | 586 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
| 603 TestInstaller installer2; | 587 TestInstaller installer2; |
| 604 CrxComponent com2; | 588 CrxComponent com2; |
| 605 com2.observer = &observer2; | |
| 606 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); | 589 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
| 607 | 590 |
| 608 // No update normally. | 591 // No update normally. |
| 609 test_configurator()->SetLoopCount(1); | 592 test_configurator()->SetLoopCount(1); |
| 610 component_updater()->Start(); | 593 component_updater()->Start(); |
| 611 RunThreads(); | 594 RunThreads(); |
| 612 component_updater()->Stop(); | 595 component_updater()->Stop(); |
| 613 | 596 |
| 614 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 597 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 615 << post_interceptor_->GetRequestsAsString(); | 598 << post_interceptor_->GetRequestsAsString(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 test_configurator()->SetOnDemandTime(60 * 60); | 646 test_configurator()->SetOnDemandTime(60 * 60); |
| 664 EXPECT_EQ(ComponentUpdateService::kError, | 647 EXPECT_EQ(ComponentUpdateService::kError, |
| 665 OnDemandTester::OnDemand(component_updater(), | 648 OnDemandTester::OnDemand(component_updater(), |
| 666 GetCrxComponentID(com2))); | 649 GetCrxComponentID(com2))); |
| 667 // Okay, now reset to 0 for the other tests. | 650 // Okay, now reset to 0 for the other tests. |
| 668 test_configurator()->SetOnDemandTime(0); | 651 test_configurator()->SetOnDemandTime(0); |
| 669 component_updater()->Stop(); | 652 component_updater()->Stop(); |
| 670 | 653 |
| 671 // Test a few error cases. NOTE: We don't have callbacks for | 654 // Test a few error cases. NOTE: We don't have callbacks for |
| 672 // when the updates failed yet. | 655 // when the updates failed yet. |
| 673 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); | 656 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
| 674 { | 657 { |
| 675 InSequence seq; | 658 InSequence seq; |
| 676 EXPECT_CALL(observer1, | 659 EXPECT_CALL(observer, |
| 677 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 660 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 678 .Times(1); | 661 .Times(1); |
| 679 EXPECT_CALL(observer1, | 662 EXPECT_CALL(observer, |
| 680 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 663 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 664 "abagagagagagagagagagagagagagagag")) |
| 681 .Times(1); | 665 .Times(1); |
| 682 EXPECT_CALL(observer1, | 666 EXPECT_CALL(observer, |
| 683 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 667 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 668 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 684 .Times(1); | 669 .Times(1); |
| 685 } | 670 EXPECT_CALL(observer, |
| 686 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); | 671 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 687 { | |
| 688 InSequence seq; | |
| 689 EXPECT_CALL(observer2, | |
| 690 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 691 .Times(1); | |
| 692 EXPECT_CALL(observer2, | |
| 693 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 694 .Times(1); | |
| 695 EXPECT_CALL(observer2, | |
| 696 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 697 .Times(1); | 672 .Times(1); |
| 698 } | 673 } |
| 699 | 674 |
| 700 // No update: error from no server response | 675 // No update: error from no server response |
| 701 post_interceptor_->Reset(); | 676 post_interceptor_->Reset(); |
| 702 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 677 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 703 "updatecheck"), test_file("updatecheck_reply_empty"))); | 678 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 704 | 679 |
| 705 test_configurator()->SetLoopCount(1); | 680 test_configurator()->SetLoopCount(1); |
| 706 component_updater()->Start(); | 681 component_updater()->Start(); |
| 707 EXPECT_EQ(ComponentUpdateService::kOk, | 682 EXPECT_EQ(ComponentUpdateService::kOk, |
| 708 OnDemandTester::OnDemand(component_updater(), | 683 OnDemandTester::OnDemand(component_updater(), |
| 709 GetCrxComponentID(com2))); | 684 GetCrxComponentID(com2))); |
| 710 RunThreads(); | 685 RunThreads(); |
| 711 component_updater()->Stop(); | 686 component_updater()->Stop(); |
| 712 | 687 |
| 713 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 688 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 714 << post_interceptor_->GetRequestsAsString(); | 689 << post_interceptor_->GetRequestsAsString(); |
| 715 EXPECT_EQ(1, post_interceptor_->GetCount()) | 690 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 716 << post_interceptor_->GetRequestsAsString(); | 691 << post_interceptor_->GetRequestsAsString(); |
| 717 | 692 |
| 718 // No update: already updated to 1.0 so nothing new | 693 // No update: already updated to 1.0 so nothing new |
| 719 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); | 694 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
| 720 { | 695 { |
| 721 InSequence seq; | 696 InSequence seq; |
| 722 EXPECT_CALL(observer1, | 697 EXPECT_CALL(observer, |
| 723 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 698 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 724 .Times(1); | 699 .Times(1); |
| 725 EXPECT_CALL(observer1, | 700 EXPECT_CALL(observer, |
| 726 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 701 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 702 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 727 .Times(1); | 703 .Times(1); |
| 728 EXPECT_CALL(observer1, | 704 EXPECT_CALL(observer, |
| 729 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 705 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 706 "abagagagagagagagagagagagagagagag")) |
| 730 .Times(1); | 707 .Times(1); |
| 731 } | 708 EXPECT_CALL(observer, |
| 732 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); | 709 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 733 { | |
| 734 InSequence seq; | |
| 735 EXPECT_CALL(observer2, | |
| 736 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 737 .Times(1); | |
| 738 EXPECT_CALL(observer2, | |
| 739 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 740 .Times(1); | |
| 741 EXPECT_CALL(observer2, | |
| 742 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 743 .Times(1); | 710 .Times(1); |
| 744 } | 711 } |
| 745 | 712 |
| 746 post_interceptor_->Reset(); | 713 post_interceptor_->Reset(); |
| 747 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 714 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 748 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 715 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 749 | 716 |
| 750 test_configurator()->SetLoopCount(1); | 717 test_configurator()->SetLoopCount(1); |
| 751 component_updater()->Start(); | 718 component_updater()->Start(); |
| 752 EXPECT_EQ(ComponentUpdateService::kOk, | 719 EXPECT_EQ(ComponentUpdateService::kOk, |
| 753 OnDemandTester::OnDemand(component_updater(), | 720 OnDemandTester::OnDemand(component_updater(), |
| 754 GetCrxComponentID(com2))); | 721 GetCrxComponentID(com2))); |
| 755 RunThreads(); | 722 RunThreads(); |
| 756 | 723 |
| 757 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 724 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 758 << post_interceptor_->GetRequestsAsString(); | 725 << post_interceptor_->GetRequestsAsString(); |
| 759 EXPECT_EQ(1, post_interceptor_->GetCount()) | 726 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 760 << post_interceptor_->GetRequestsAsString(); | 727 << post_interceptor_->GetRequestsAsString(); |
| 761 | 728 |
| 762 component_updater()->Stop(); | 729 component_updater()->Stop(); |
| 763 } | 730 } |
| 764 | 731 |
| 765 // Verify that a previously registered component can get re-registered | 732 // Verify that a previously registered component can get re-registered |
| 766 // with a different version. | 733 // with a different version. |
| 767 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 734 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| 768 MockComponentObserver observer1; | 735 MockServiceObserver observer; |
| 769 { | 736 { |
| 770 InSequence seq; | 737 InSequence seq; |
| 771 EXPECT_CALL(observer1, | 738 EXPECT_CALL(observer, |
| 772 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 739 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 773 .Times(1); | 740 .Times(1); |
| 774 EXPECT_CALL(observer1, | 741 EXPECT_CALL(observer, |
| 775 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | 742 OnEvent(ServiceObserver::COMPONENT_UPDATE_FOUND, |
| 743 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 776 .Times(1); | 744 .Times(1); |
| 777 EXPECT_CALL(observer1, | 745 EXPECT_CALL(observer, |
| 778 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) | 746 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 747 "abagagagagagagagagagagagagagagag")) |
| 779 .Times(1); | 748 .Times(1); |
| 780 EXPECT_CALL(observer1, | 749 EXPECT_CALL(observer, |
| 781 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0)) | 750 OnEvent(ServiceObserver::COMPONENT_UPDATE_READY, |
| 751 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 782 .Times(1); | 752 .Times(1); |
| 783 EXPECT_CALL(observer1, | 753 EXPECT_CALL(observer, |
| 784 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 754 OnEvent(ServiceObserver::COMPONENT_UPDATED, |
| 755 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 785 .Times(1); | 756 .Times(1); |
| 786 EXPECT_CALL(observer1, | 757 EXPECT_CALL(observer, |
| 787 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 758 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 788 .Times(1); | 759 .Times(1); |
| 789 EXPECT_CALL(observer1, | 760 EXPECT_CALL(observer, |
| 790 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 761 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 762 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 763 .Times(1); |
| 764 EXPECT_CALL(observer, |
| 765 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 766 "abagagagagagagagagagagagagagagag")) |
| 767 .Times(1); |
| 768 EXPECT_CALL(observer, |
| 769 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 791 .Times(1); | 770 .Times(1); |
| 792 } | 771 } |
| 793 | 772 |
| 794 MockComponentObserver observer2; | |
| 795 { | |
| 796 InSequence seq; | |
| 797 EXPECT_CALL(observer2, | |
| 798 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 799 .Times(1); | |
| 800 EXPECT_CALL(observer2, | |
| 801 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 802 .Times(1); | |
| 803 EXPECT_CALL(observer2, | |
| 804 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 805 .Times(1); | |
| 806 EXPECT_CALL(observer2, | |
| 807 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 808 .Times(1); | |
| 809 EXPECT_CALL(observer2, | |
| 810 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 811 .Times(1); | |
| 812 } | |
| 813 | |
| 814 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 773 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 815 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 774 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 816 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); | 775 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 817 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 776 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 818 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 777 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 819 | 778 |
| 820 get_interceptor_->SetResponse( | 779 get_interceptor_->SetResponse( |
| 821 GURL(expected_crx_url), | 780 GURL(expected_crx_url), |
| 822 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 781 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 823 | 782 |
| 783 component_updater()->AddObserver(&observer); |
| 784 |
| 824 TestInstaller installer1; | 785 TestInstaller installer1; |
| 825 CrxComponent com1; | 786 CrxComponent com1; |
| 826 com1.observer = &observer1; | |
| 827 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 787 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 828 TestInstaller installer2; | 788 TestInstaller installer2; |
| 829 CrxComponent com2; | 789 CrxComponent com2; |
| 830 com2.observer = &observer2; | |
| 831 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 790 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 832 | 791 |
| 833 // Loop twice to issue two checks: (1) with original 0.9 version, update to | 792 // Loop twice to issue two checks: (1) with original 0.9 version, update to |
| 834 // 1.0, and do the second check (2) with the updated 1.0 version. | 793 // 1.0, and do the second check (2) with the updated 1.0 version. |
| 835 test_configurator()->SetLoopCount(2); | 794 test_configurator()->SetLoopCount(2); |
| 836 component_updater()->Start(); | 795 component_updater()->Start(); |
| 837 RunThreads(); | 796 RunThreads(); |
| 838 | 797 |
| 839 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 798 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 840 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 799 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 855 "<event eventtype=\"3\" eventresult=\"1\"/>")) | 814 "<event eventtype=\"3\" eventresult=\"1\"/>")) |
| 856 << post_interceptor_->GetRequestsAsString(); | 815 << post_interceptor_->GetRequestsAsString(); |
| 857 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( | 816 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 858 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" | 817 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| 859 "<updatecheck /></app>")) | 818 "<updatecheck /></app>")) |
| 860 << post_interceptor_->GetRequestsAsString(); | 819 << post_interceptor_->GetRequestsAsString(); |
| 861 | 820 |
| 862 component_updater()->Stop(); | 821 component_updater()->Stop(); |
| 863 | 822 |
| 864 // Now re-register, pretending to be an even newer version (2.2) | 823 // Now re-register, pretending to be an even newer version (2.2) |
| 865 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); | 824 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
| 866 { | 825 { |
| 867 InSequence seq; | 826 InSequence seq; |
| 868 EXPECT_CALL(observer1, | 827 EXPECT_CALL(observer, |
| 869 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 828 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 870 .Times(1); | 829 .Times(1); |
| 871 EXPECT_CALL(observer1, | 830 EXPECT_CALL(observer, |
| 872 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 831 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 832 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 873 .Times(1); | 833 .Times(1); |
| 874 EXPECT_CALL(observer1, | 834 EXPECT_CALL(observer, |
| 875 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 835 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 836 "abagagagagagagagagagagagagagagag")) |
| 837 .Times(1); |
| 838 EXPECT_CALL(observer, |
| 839 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 876 .Times(1); | 840 .Times(1); |
| 877 } | 841 } |
| 878 | 842 |
| 879 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); | |
| 880 { | |
| 881 InSequence seq; | |
| 882 EXPECT_CALL(observer2, | |
| 883 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
| 884 .Times(1); | |
| 885 EXPECT_CALL(observer2, | |
| 886 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
| 887 .Times(1); | |
| 888 EXPECT_CALL(observer2, | |
| 889 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
| 890 .Times(1); | |
| 891 } | |
| 892 | |
| 893 post_interceptor_->Reset(); | 843 post_interceptor_->Reset(); |
| 894 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 844 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 895 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 845 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 896 | 846 |
| 897 TestInstaller installer3; | 847 TestInstaller installer3; |
| 898 EXPECT_EQ(ComponentUpdateService::kReplaced, | 848 EXPECT_EQ(ComponentUpdateService::kReplaced, |
| 899 RegisterComponent(&com1, | 849 RegisterComponent(&com1, |
| 900 kTestComponent_jebg, | 850 kTestComponent_jebg, |
| 901 Version("2.2"), | 851 Version("2.2"), |
| 902 &installer3)); | 852 &installer3)); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 virtual void Cancel() OVERRIDE { CHECK(false); } | 1209 virtual void Cancel() OVERRIDE { CHECK(false); } |
| 1260 virtual void CancelAndIgnore() OVERRIDE { CHECK(false); } | 1210 virtual void CancelAndIgnore() OVERRIDE { CHECK(false); } |
| 1261 virtual void CancelWithError(int error_code) OVERRIDE { CHECK(false); } | 1211 virtual void CancelWithError(int error_code) OVERRIDE { CHECK(false); } |
| 1262 virtual void Resume() OVERRIDE { CHECK(false); } | 1212 virtual void Resume() OVERRIDE { CHECK(false); } |
| 1263 } controller; | 1213 } controller; |
| 1264 | 1214 |
| 1265 delete RequestTestResourceThrottle(cus, &controller, crx_id); | 1215 delete RequestTestResourceThrottle(cus, &controller, crx_id); |
| 1266 } | 1216 } |
| 1267 | 1217 |
| 1268 TEST_F(ComponentUpdaterTest, ResourceThrottleDeletedNoUpdate) { | 1218 TEST_F(ComponentUpdaterTest, ResourceThrottleDeletedNoUpdate) { |
| 1269 MockComponentObserver observer; | 1219 MockServiceObserver observer; |
| 1270 EXPECT_CALL(observer, | 1220 { |
| 1271 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 1221 InSequence seq; |
| 1272 .Times(1); | 1222 EXPECT_CALL(observer, |
| 1273 EXPECT_CALL(observer, | 1223 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1274 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 1224 .Times(1); |
| 1275 .Times(1); | 1225 EXPECT_CALL(observer, |
| 1276 EXPECT_CALL(observer, | 1226 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1277 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 1227 "abagagagagagagagagagagagagagagag")) |
| 1278 .Times(1); | 1228 .Times(1); |
| 1229 EXPECT_CALL(observer, |
| 1230 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1231 .Times(1); |
| 1232 } |
| 1279 | 1233 |
| 1280 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 1234 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 1281 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 1235 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 1282 | 1236 |
| 1283 TestInstaller installer; | 1237 TestInstaller installer; |
| 1284 CrxComponent com; | 1238 CrxComponent com; |
| 1285 com.observer = &observer; | 1239 component_updater()->AddObserver(&observer); |
| 1286 EXPECT_EQ(ComponentUpdateService::kOk, | 1240 EXPECT_EQ(ComponentUpdateService::kOk, |
| 1287 RegisterComponent(&com, | 1241 RegisterComponent(&com, |
| 1288 kTestComponent_abag, | 1242 kTestComponent_abag, |
| 1289 Version("1.1"), | 1243 Version("1.1"), |
| 1290 &installer)); | 1244 &installer)); |
| 1291 // The following two calls ensure that we don't do an update check via the | 1245 // The following two calls ensure that we don't do an update check via the |
| 1292 // timer, so the only update check should be the on-demand one. | 1246 // timer, so the only update check should be the on-demand one. |
| 1293 test_configurator()->SetInitialDelay(1000000); | 1247 test_configurator()->SetInitialDelay(1000000); |
| 1294 test_configurator()->SetRecheckTime(1000000); | 1248 test_configurator()->SetRecheckTime(1000000); |
| 1295 test_configurator()->SetLoopCount(1); | 1249 test_configurator()->SetLoopCount(1); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 } | 1298 } |
| 1345 | 1299 |
| 1346 private: | 1300 private: |
| 1347 void ResumeCalled() { ++resume_called_; } | 1301 void ResumeCalled() { ++resume_called_; } |
| 1348 | 1302 |
| 1349 content::ResourceThrottle* throttle_; | 1303 content::ResourceThrottle* throttle_; |
| 1350 int resume_called_; | 1304 int resume_called_; |
| 1351 }; | 1305 }; |
| 1352 | 1306 |
| 1353 TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) { | 1307 TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) { |
| 1354 MockComponentObserver observer; | 1308 MockServiceObserver observer; |
| 1355 EXPECT_CALL(observer, | 1309 { |
| 1356 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 1310 InSequence seq; |
| 1357 .Times(1); | 1311 EXPECT_CALL(observer, |
| 1358 EXPECT_CALL(observer, | 1312 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1359 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 1313 .Times(1); |
| 1360 .Times(1); | 1314 EXPECT_CALL(observer, |
| 1361 EXPECT_CALL(observer, | 1315 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1362 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 1316 "abagagagagagagagagagagagagagagag")) |
| 1363 .Times(1); | 1317 .Times(1); |
| 1318 EXPECT_CALL(observer, |
| 1319 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1320 .Times(1); |
| 1321 } |
| 1364 | 1322 |
| 1365 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( | 1323 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 1366 "updatecheck"), test_file("updatecheck_reply_1.xml"))); | 1324 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 1367 | 1325 |
| 1368 TestInstaller installer; | 1326 TestInstaller installer; |
| 1369 CrxComponent com; | 1327 CrxComponent com; |
| 1370 com.observer = &observer; | 1328 component_updater()->AddObserver(&observer); |
| 1371 EXPECT_EQ(ComponentUpdateService::kOk, | 1329 EXPECT_EQ(ComponentUpdateService::kOk, |
| 1372 RegisterComponent(&com, | 1330 RegisterComponent(&com, |
| 1373 kTestComponent_abag, | 1331 kTestComponent_abag, |
| 1374 Version("1.1"), | 1332 Version("1.1"), |
| 1375 &installer)); | 1333 &installer)); |
| 1376 // The following two calls ensure that we don't do an update check via the | 1334 // The following two calls ensure that we don't do an update check via the |
| 1377 // timer, so the only update check should be the on-demand one. | 1335 // timer, so the only update check should be the on-demand one. |
| 1378 test_configurator()->SetInitialDelay(1000000); | 1336 test_configurator()->SetInitialDelay(1000000); |
| 1379 test_configurator()->SetRecheckTime(1000000); | 1337 test_configurator()->SetRecheckTime(1000000); |
| 1380 test_configurator()->SetLoopCount(1); | 1338 test_configurator()->SetLoopCount(1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1396 | 1354 |
| 1397 RunThreads(); | 1355 RunThreads(); |
| 1398 | 1356 |
| 1399 EXPECT_EQ(1, post_interceptor_->GetHitCount()); | 1357 EXPECT_EQ(1, post_interceptor_->GetHitCount()); |
| 1400 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1358 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1401 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 1359 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1402 | 1360 |
| 1403 component_updater()->Stop(); | 1361 component_updater()->Stop(); |
| 1404 } | 1362 } |
| 1405 | 1363 |
| 1364 // Tests adding and removing observers. |
| 1365 TEST_F(ComponentUpdaterTest, Observer) { |
| 1366 MockServiceObserver observer1, observer2; |
| 1367 |
| 1368 // Expect that two observers see the events. |
| 1369 { |
| 1370 InSequence seq; |
| 1371 EXPECT_CALL(observer1, |
| 1372 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1373 .Times(1); |
| 1374 EXPECT_CALL(observer2, |
| 1375 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1376 .Times(1); |
| 1377 EXPECT_CALL(observer1, |
| 1378 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1379 "abagagagagagagagagagagagagagagag")) |
| 1380 .Times(1); |
| 1381 EXPECT_CALL(observer2, |
| 1382 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1383 "abagagagagagagagagagagagagagagag")) |
| 1384 .Times(1); |
| 1385 EXPECT_CALL(observer1, |
| 1386 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1387 .Times(1); |
| 1388 EXPECT_CALL(observer2, |
| 1389 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1390 .Times(1); |
| 1391 } |
| 1392 |
| 1393 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 1394 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 1395 |
| 1396 component_updater()->AddObserver(&observer1); |
| 1397 component_updater()->AddObserver(&observer2); |
| 1398 |
| 1399 TestInstaller installer; |
| 1400 CrxComponent com; |
| 1401 EXPECT_EQ(ComponentUpdateService::kOk, |
| 1402 RegisterComponent(&com, |
| 1403 kTestComponent_abag, |
| 1404 Version("1.1"), |
| 1405 &installer)); |
| 1406 test_configurator()->SetLoopCount(1); |
| 1407 component_updater()->Start(); |
| 1408 RunThreads(); |
| 1409 |
| 1410 // After removing the first observer, it's only the second observer that |
| 1411 // gets the events. |
| 1412 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| 1413 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); |
| 1414 { |
| 1415 InSequence seq; |
| 1416 EXPECT_CALL(observer2, |
| 1417 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1418 .Times(1); |
| 1419 EXPECT_CALL(observer2, |
| 1420 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1421 "abagagagagagagagagagagagagagagag")) |
| 1422 .Times(1); |
| 1423 EXPECT_CALL(observer2, |
| 1424 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1425 .Times(1); |
| 1426 } |
| 1427 |
| 1428 component_updater()->RemoveObserver(&observer1); |
| 1429 |
| 1430 test_configurator()->SetLoopCount(1); |
| 1431 component_updater()->Start(); |
| 1432 RunThreads(); |
| 1433 |
| 1434 // Both observers are removed and no one gets the events. |
| 1435 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| 1436 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); |
| 1437 component_updater()->RemoveObserver(&observer2); |
| 1438 |
| 1439 test_configurator()->SetLoopCount(1); |
| 1440 component_updater()->Start(); |
| 1441 RunThreads(); |
| 1442 |
| 1443 component_updater()->Stop(); |
| 1444 } |
| 1406 | 1445 |
| 1407 } // namespace component_updater | 1446 } // namespace component_updater |
| 1408 | |
| OLD | NEW |