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/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/component_updater/component_updater_service.h" | 14 #include "chrome/browser/component_updater/component_updater_service.h" |
15 #include "chrome/browser/component_updater/test/test_installer.h" | 15 #include "chrome/browser/component_updater/test/test_installer.h" |
16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/test/net/url_request_prepackaged_interceptor.h" | 18 #include "content/test/net/url_request_prepackaged_interceptor.h" |
19 #include "libxml/globals.h" | 19 #include "libxml/globals.h" |
20 #include "net/base/upload_bytes_element_reader.h" | 20 #include "net/base/upload_bytes_element_reader.h" |
21 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 using content::TestNotificationTracker; | 25 using content::TestNotificationTracker; |
26 | 26 |
| 27 using ::testing::_; |
| 28 using ::testing::InSequence; |
| 29 using ::testing::Mock; |
| 30 |
| 31 MockComponentObserver::MockComponentObserver() { |
| 32 } |
| 33 |
| 34 MockComponentObserver::~MockComponentObserver() { |
| 35 } |
| 36 |
27 TestConfigurator::TestConfigurator() | 37 TestConfigurator::TestConfigurator() |
28 : times_(1), | 38 : times_(1), |
29 recheck_time_(0), | 39 recheck_time_(0), |
30 ondemand_time_(0), | 40 ondemand_time_(0), |
31 cus_(NULL), | 41 cus_(NULL), |
32 context_(new net::TestURLRequestContextGetter( | 42 context_(new net::TestURLRequestContextGetter( |
33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { | 43 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { |
34 } | 44 } |
35 | 45 |
36 TestConfigurator::~TestConfigurator() { | 46 TestConfigurator::~TestConfigurator() { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 267 |
258 EXPECT_EQ(0ul, notification_tracker().size()); | 268 EXPECT_EQ(0ul, notification_tracker().size()); |
259 } | 269 } |
260 | 270 |
261 // Verify that when the server has no updates, we go back to sleep and | 271 // Verify that when the server has no updates, we go back to sleep and |
262 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications | 272 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
263 // are generated. | 273 // are generated. |
264 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 274 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
265 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 275 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
266 | 276 |
| 277 MockComponentObserver observer; |
| 278 |
267 TestInstaller installer; | 279 TestInstaller installer; |
268 CrxComponent com; | 280 CrxComponent com; |
| 281 com.observer = &observer; |
269 EXPECT_EQ(ComponentUpdateService::kOk, | 282 EXPECT_EQ(ComponentUpdateService::kOk, |
270 RegisterComponent(&com, | 283 RegisterComponent(&com, |
271 kTestComponent_abag, | 284 kTestComponent_abag, |
272 Version("1.1"), | 285 Version("1.1"), |
273 &installer)); | 286 &installer)); |
274 | 287 |
275 const GURL expected_update_url( | 288 const GURL expected_update_url( |
276 "http://localhost/upd?extra=foo" | 289 "http://localhost/upd?extra=foo" |
277 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); | 290 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); |
278 | 291 |
279 interceptor.SetResponse(expected_update_url, | 292 interceptor.SetResponse(expected_update_url, |
280 test_file("updatecheck_reply_1.xml")); | 293 test_file("updatecheck_reply_1.xml")); |
281 | 294 |
282 // We loop twice, but there are no updates so we expect two sleep messages. | 295 // We loop twice, but there are no updates so we expect two sleep messages. |
283 test_configurator()->SetLoopCount(2); | 296 test_configurator()->SetLoopCount(2); |
| 297 |
| 298 EXPECT_CALL(observer, |
| 299 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 300 .Times(1); |
284 component_updater()->Start(); | 301 component_updater()->Start(); |
285 | 302 |
286 ASSERT_EQ(1ul, notification_tracker().size()); | 303 ASSERT_EQ(1ul, notification_tracker().size()); |
287 TestNotificationTracker::Event ev1 = notification_tracker().at(0); | 304 TestNotificationTracker::Event ev1 = notification_tracker().at(0); |
288 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); | 305 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); |
289 | 306 |
| 307 EXPECT_CALL(observer, |
| 308 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 309 .Times(2); |
290 message_loop_.Run(); | 310 message_loop_.Run(); |
291 | 311 |
292 ASSERT_EQ(3ul, notification_tracker().size()); | 312 ASSERT_EQ(3ul, notification_tracker().size()); |
293 TestNotificationTracker::Event ev2 = notification_tracker().at(1); | 313 TestNotificationTracker::Event ev2 = notification_tracker().at(1); |
294 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 314 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
295 TestNotificationTracker::Event ev3 = notification_tracker().at(2); | 315 TestNotificationTracker::Event ev3 = notification_tracker().at(2); |
296 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 316 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
297 EXPECT_EQ(2, interceptor.GetHitCount()); | 317 EXPECT_EQ(2, interceptor.GetHitCount()); |
298 | 318 |
299 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 319 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
300 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 320 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
301 | 321 |
302 component_updater()->Stop(); | 322 component_updater()->Stop(); |
303 | 323 |
304 // Loop twice again but this case we simulate a server error by returning | 324 // Loop twice again but this case we simulate a server error by returning |
305 // an empty file. | 325 // an empty file. |
306 | 326 |
307 interceptor.SetResponse(expected_update_url, | 327 interceptor.SetResponse(expected_update_url, |
308 test_file("updatecheck_reply_empty")); | 328 test_file("updatecheck_reply_empty")); |
309 | 329 |
310 notification_tracker().Reset(); | 330 notification_tracker().Reset(); |
311 test_configurator()->SetLoopCount(2); | 331 test_configurator()->SetLoopCount(2); |
| 332 |
| 333 EXPECT_CALL(observer, |
| 334 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 335 .Times(1); |
312 component_updater()->Start(); | 336 component_updater()->Start(); |
313 | 337 |
| 338 EXPECT_CALL(observer, |
| 339 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 340 .Times(2); |
314 message_loop_.Run(); | 341 message_loop_.Run(); |
315 | 342 |
316 ASSERT_EQ(3ul, notification_tracker().size()); | 343 ASSERT_EQ(3ul, notification_tracker().size()); |
317 ev1 = notification_tracker().at(0); | 344 ev1 = notification_tracker().at(0); |
318 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); | 345 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); |
319 ev2 = notification_tracker().at(1); | 346 ev2 = notification_tracker().at(1); |
320 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 347 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
321 ev3 = notification_tracker().at(2); | 348 ev3 = notification_tracker().at(2); |
322 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 349 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
323 EXPECT_EQ(4, interceptor.GetHitCount()); | 350 EXPECT_EQ(4, interceptor.GetHitCount()); |
(...skipping 16 matching lines...) Expand all Loading... |
340 std::map<std::string, std::string> map; | 367 std::map<std::string, std::string> map; |
341 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | 368 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
342 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | 369 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
343 map.insert(std::pair<std::string, std::string>("previousversion", | 370 map.insert(std::pair<std::string, std::string>("previousversion", |
344 "\"0.9\"")); | 371 "\"0.9\"")); |
345 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | 372 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
346 PingChecker ping_checker(map); | 373 PingChecker ping_checker(map); |
347 URLRequestPostInterceptor post_interceptor(&ping_checker); | 374 URLRequestPostInterceptor post_interceptor(&ping_checker); |
348 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 375 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
349 | 376 |
| 377 MockComponentObserver observer1; |
| 378 { |
| 379 InSequence seq; |
| 380 EXPECT_CALL(observer1, |
| 381 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 382 .Times(1); |
| 383 EXPECT_CALL(observer1, |
| 384 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
| 385 .Times(1); |
| 386 EXPECT_CALL(observer1, |
| 387 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) |
| 388 .Times(1); |
| 389 EXPECT_CALL(observer1, |
| 390 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 391 .Times(2); |
| 392 } |
| 393 |
| 394 MockComponentObserver observer2; |
| 395 { |
| 396 InSequence seq; |
| 397 EXPECT_CALL(observer2, |
| 398 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 399 .Times(1); |
| 400 EXPECT_CALL(observer2, |
| 401 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 402 .Times(2); |
| 403 } |
| 404 |
350 TestInstaller installer1; | 405 TestInstaller installer1; |
351 CrxComponent com1; | 406 CrxComponent com1; |
| 407 com1.observer = &observer1; |
352 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 408 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
353 TestInstaller installer2; | 409 TestInstaller installer2; |
354 CrxComponent com2; | 410 CrxComponent com2; |
| 411 com2.observer = &observer2; |
355 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 412 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
356 | 413 |
357 const GURL expected_update_url_1( | 414 const GURL expected_update_url_1( |
358 "http://localhost/upd?extra=foo" | 415 "http://localhost/upd?extra=foo" |
359 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | 416 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
360 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | 417 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
361 | 418 |
362 const GURL expected_update_url_2( | 419 const GURL expected_update_url_2( |
363 "http://localhost/upd?extra=foo" | 420 "http://localhost/upd?extra=foo" |
364 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" | 421 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
(...skipping 15 matching lines...) Expand all Loading... |
380 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 437 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
381 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 438 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
382 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 439 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
383 | 440 |
384 EXPECT_EQ(3, interceptor.GetHitCount()); | 441 EXPECT_EQ(3, interceptor.GetHitCount()); |
385 EXPECT_EQ(1, ping_checker.NumHits()); | 442 EXPECT_EQ(1, ping_checker.NumHits()); |
386 EXPECT_EQ(0, ping_checker.NumMisses()); | 443 EXPECT_EQ(0, ping_checker.NumMisses()); |
387 | 444 |
388 ASSERT_EQ(5ul, notification_tracker().size()); | 445 ASSERT_EQ(5ul, notification_tracker().size()); |
389 | 446 |
| 447 TestNotificationTracker::Event ev0 = notification_tracker().at(0); |
| 448 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 449 |
390 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 450 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
391 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 451 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
392 | 452 |
393 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 453 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
394 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 454 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
395 | 455 |
396 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 456 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
397 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 457 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
398 | 458 |
399 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 459 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 std::map<std::string, std::string> map; | 507 std::map<std::string, std::string> map; |
448 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | 508 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
449 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | 509 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
450 map.insert(std::pair<std::string, std::string>("previousversion", | 510 map.insert(std::pair<std::string, std::string>("previousversion", |
451 "\"0.9\"")); | 511 "\"0.9\"")); |
452 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | 512 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
453 PingChecker ping_checker(map); | 513 PingChecker ping_checker(map); |
454 URLRequestPostInterceptor post_interceptor(&ping_checker); | 514 URLRequestPostInterceptor post_interceptor(&ping_checker); |
455 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 515 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
456 | 516 |
| 517 MockComponentObserver observer1; |
| 518 { |
| 519 InSequence seq; |
| 520 EXPECT_CALL(observer1, |
| 521 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 522 .Times(1); |
| 523 EXPECT_CALL(observer1, |
| 524 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 525 .Times(1); |
| 526 EXPECT_CALL(observer1, |
| 527 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 528 .Times(1); |
| 529 } |
| 530 |
| 531 MockComponentObserver observer2; |
| 532 { |
| 533 InSequence seq; |
| 534 EXPECT_CALL(observer2, |
| 535 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 536 .Times(1); |
| 537 EXPECT_CALL(observer2, |
| 538 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 539 .Times(1); |
| 540 EXPECT_CALL(observer2, |
| 541 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
| 542 .Times(1); |
| 543 EXPECT_CALL(observer2, |
| 544 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) |
| 545 .Times(1); |
| 546 EXPECT_CALL(observer2, |
| 547 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 548 .Times(1); |
| 549 } |
| 550 |
457 TestInstaller installer1; | 551 TestInstaller installer1; |
458 CrxComponent com1; | 552 CrxComponent com1; |
| 553 com1.observer = &observer1; |
459 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); | 554 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
460 TestInstaller installer2; | 555 TestInstaller installer2; |
461 CrxComponent com2; | 556 CrxComponent com2; |
| 557 com2.observer = &observer2; |
462 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); | 558 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
463 | 559 |
464 const GURL expected_update_url_1( | 560 const GURL expected_update_url_1( |
465 "http://localhost/upd?extra=foo" | 561 "http://localhost/upd?extra=foo" |
466 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" | 562 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
467 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | 563 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
468 | 564 |
469 const GURL expected_update_url_2( | 565 const GURL expected_update_url_2( |
470 "http://localhost/upd?extra=foo" | 566 "http://localhost/upd?extra=foo" |
471 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | 567 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 // Also check what happens if previous check too soon. | 607 // Also check what happens if previous check too soon. |
512 test_configurator()->SetOnDemandTime(60 * 60); | 608 test_configurator()->SetOnDemandTime(60 * 60); |
513 EXPECT_EQ(ComponentUpdateService::kError, | 609 EXPECT_EQ(ComponentUpdateService::kError, |
514 component_updater()->CheckForUpdateSoon(com2)); | 610 component_updater()->CheckForUpdateSoon(com2)); |
515 // Okay, now reset to 0 for the other tests. | 611 // Okay, now reset to 0 for the other tests. |
516 test_configurator()->SetOnDemandTime(0); | 612 test_configurator()->SetOnDemandTime(0); |
517 component_updater()->Stop(); | 613 component_updater()->Stop(); |
518 | 614 |
519 // Test a few error cases. NOTE: We don't have callbacks for | 615 // Test a few error cases. NOTE: We don't have callbacks for |
520 // when the updates failed yet. | 616 // when the updates failed yet. |
| 617 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| 618 { |
| 619 InSequence seq; |
| 620 EXPECT_CALL(observer1, |
| 621 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 622 .Times(1); |
| 623 EXPECT_CALL(observer1, |
| 624 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 625 .Times(1); |
| 626 } |
| 627 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); |
| 628 { |
| 629 InSequence seq; |
| 630 EXPECT_CALL(observer2, |
| 631 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 632 .Times(1); |
| 633 EXPECT_CALL(observer2, |
| 634 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 635 .Times(1); |
| 636 } |
| 637 |
521 const GURL expected_update_url_3( | 638 const GURL expected_update_url_3( |
522 "http://localhost/upd?extra=foo" | 639 "http://localhost/upd?extra=foo" |
523 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc" | 640 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc" |
524 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | 641 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
525 | 642 |
526 // No update: error from no server response | 643 // No update: error from no server response |
527 interceptor.SetResponse(expected_update_url_3, | 644 interceptor.SetResponse(expected_update_url_3, |
528 test_file("updatecheck_reply_empty")); | 645 test_file("updatecheck_reply_empty")); |
529 notification_tracker().Reset(); | 646 notification_tracker().Reset(); |
530 test_configurator()->SetLoopCount(1); | 647 test_configurator()->SetLoopCount(1); |
531 component_updater()->Start(); | 648 component_updater()->Start(); |
532 EXPECT_EQ(ComponentUpdateService::kOk, | 649 EXPECT_EQ(ComponentUpdateService::kOk, |
533 component_updater()->CheckForUpdateSoon(com2)); | 650 component_updater()->CheckForUpdateSoon(com2)); |
534 | 651 |
535 message_loop_.Run(); | 652 message_loop_.Run(); |
536 | 653 |
537 ASSERT_EQ(2ul, notification_tracker().size()); | 654 ASSERT_EQ(2ul, notification_tracker().size()); |
538 ev0 = notification_tracker().at(0); | 655 ev0 = notification_tracker().at(0); |
539 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 656 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
540 ev1 = notification_tracker().at(1); | 657 ev1 = notification_tracker().at(1); |
541 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 658 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
542 component_updater()->Stop(); | 659 component_updater()->Stop(); |
543 | 660 |
544 // No update: already updated to 1.0 so nothing new | 661 // No update: already updated to 1.0 so nothing new |
| 662 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| 663 { |
| 664 InSequence seq; |
| 665 EXPECT_CALL(observer1, |
| 666 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 667 .Times(1); |
| 668 EXPECT_CALL(observer1, |
| 669 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 670 .Times(1); |
| 671 } |
| 672 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); |
| 673 { |
| 674 InSequence seq; |
| 675 EXPECT_CALL(observer2, |
| 676 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 677 .Times(1); |
| 678 EXPECT_CALL(observer2, |
| 679 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 680 .Times(1); |
| 681 } |
| 682 |
545 interceptor.SetResponse(expected_update_url_3, | 683 interceptor.SetResponse(expected_update_url_3, |
546 test_file("updatecheck_reply_1.xml")); | 684 test_file("updatecheck_reply_1.xml")); |
547 notification_tracker().Reset(); | 685 notification_tracker().Reset(); |
548 test_configurator()->SetLoopCount(1); | 686 test_configurator()->SetLoopCount(1); |
549 component_updater()->Start(); | 687 component_updater()->Start(); |
550 EXPECT_EQ(ComponentUpdateService::kOk, | 688 EXPECT_EQ(ComponentUpdateService::kOk, |
551 component_updater()->CheckForUpdateSoon(com2)); | 689 component_updater()->CheckForUpdateSoon(com2)); |
552 | 690 |
553 message_loop_.Run(); | 691 message_loop_.Run(); |
554 | 692 |
(...skipping 13 matching lines...) Expand all Loading... |
568 std::map<std::string, std::string> map; | 706 std::map<std::string, std::string> map; |
569 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); | 707 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
570 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); | 708 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
571 map.insert(std::pair<std::string, std::string>("previousversion", | 709 map.insert(std::pair<std::string, std::string>("previousversion", |
572 "\"0.9\"")); | 710 "\"0.9\"")); |
573 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); | 711 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
574 PingChecker ping_checker(map); | 712 PingChecker ping_checker(map); |
575 URLRequestPostInterceptor post_interceptor(&ping_checker); | 713 URLRequestPostInterceptor post_interceptor(&ping_checker); |
576 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 714 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
577 | 715 |
| 716 MockComponentObserver observer1; |
| 717 { |
| 718 InSequence seq; |
| 719 EXPECT_CALL(observer1, |
| 720 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 721 .Times(1); |
| 722 EXPECT_CALL(observer1, |
| 723 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
| 724 .Times(1); |
| 725 EXPECT_CALL(observer1, |
| 726 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) |
| 727 .Times(1); |
| 728 EXPECT_CALL(observer1, |
| 729 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 730 .Times(1); |
| 731 EXPECT_CALL(observer1, |
| 732 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 733 .Times(1); |
| 734 } |
| 735 |
| 736 MockComponentObserver observer2; |
| 737 { |
| 738 InSequence seq; |
| 739 EXPECT_CALL(observer2, |
| 740 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 741 .Times(1); |
| 742 EXPECT_CALL(observer2, |
| 743 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 744 .Times(1); |
| 745 EXPECT_CALL(observer2, |
| 746 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 747 .Times(1); |
| 748 } |
| 749 |
578 TestInstaller installer1; | 750 TestInstaller installer1; |
579 CrxComponent com1; | 751 CrxComponent com1; |
| 752 com1.observer = &observer1; |
580 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 753 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
581 TestInstaller installer2; | 754 TestInstaller installer2; |
582 CrxComponent com2; | 755 CrxComponent com2; |
| 756 com2.observer = &observer2; |
583 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 757 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
584 | 758 |
585 // Start with 0.9, and update to 1.0 | 759 // Start with 0.9, and update to 1.0 |
586 const GURL expected_update_url_1( | 760 const GURL expected_update_url_1( |
587 "http://localhost/upd?extra=foo" | 761 "http://localhost/upd?extra=foo" |
588 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | 762 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
589 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | 763 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
590 | 764 |
591 const GURL expected_update_url_2( | 765 const GURL expected_update_url_2( |
592 "http://localhost/upd?extra=foo" | 766 "http://localhost/upd?extra=foo" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 | 800 |
627 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 801 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
628 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 802 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
629 | 803 |
630 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 804 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
631 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 805 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
632 | 806 |
633 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 807 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
634 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 808 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
635 | 809 |
| 810 component_updater()->Stop(); |
| 811 |
636 // Now re-register, pretending to be an even newer version (2.2) | 812 // Now re-register, pretending to be an even newer version (2.2) |
| 813 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
| 814 { |
| 815 InSequence seq; |
| 816 EXPECT_CALL(observer1, |
| 817 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 818 .Times(1); |
| 819 EXPECT_CALL(observer1, |
| 820 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 821 .Times(1); |
| 822 } |
| 823 |
| 824 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); |
| 825 { |
| 826 InSequence seq; |
| 827 EXPECT_CALL(observer2, |
| 828 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 829 .Times(1); |
| 830 EXPECT_CALL(observer2, |
| 831 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 832 .Times(1); |
| 833 } |
| 834 |
637 TestInstaller installer3; | 835 TestInstaller installer3; |
638 component_updater()->Stop(); | |
639 EXPECT_EQ(ComponentUpdateService::kReplaced, | 836 EXPECT_EQ(ComponentUpdateService::kReplaced, |
640 RegisterComponent(&com1, | 837 RegisterComponent(&com1, |
641 kTestComponent_jebg, | 838 kTestComponent_jebg, |
642 Version("2.2"), | 839 Version("2.2"), |
643 &installer3)); | 840 &installer3)); |
644 | 841 |
645 // Check that we send out 2.2 as our version. | 842 // Check that we send out 2.2 as our version. |
646 // Interceptor's hit count should go up by 1. | 843 // Interceptor's hit count should go up by 1. |
647 const GURL expected_update_url_3( | 844 const GURL expected_update_url_3( |
648 "http://localhost/upd?extra=foo" | 845 "http://localhost/upd?extra=foo" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 | 1123 |
927 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1124 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
928 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 1125 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
929 | 1126 |
930 EXPECT_EQ(1, ping_checker.NumHits()); | 1127 EXPECT_EQ(1, ping_checker.NumHits()); |
931 EXPECT_EQ(1, ping_checker.NumMisses()); | 1128 EXPECT_EQ(1, ping_checker.NumMisses()); |
932 EXPECT_EQ(6, interceptor.GetHitCount()); | 1129 EXPECT_EQ(6, interceptor.GetHitCount()); |
933 | 1130 |
934 component_updater()->Stop(); | 1131 component_updater()->Stop(); |
935 } | 1132 } |
OLD | NEW |