| 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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>")) | 680 "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>")) |
| 681 << post_interceptor_->GetRequestsAsString(); | 681 << post_interceptor_->GetRequestsAsString(); |
| 682 EXPECT_NE( | 682 EXPECT_NE( |
| 683 string::npos, | 683 string::npos, |
| 684 post_interceptor_->GetRequests()[1].find( | 684 post_interceptor_->GetRequests()[1].find( |
| 685 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " | 685 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 686 "version=\"0.9\" nextversion=\"1.0\">" | 686 "version=\"0.9\" nextversion=\"1.0\">" |
| 687 "<event eventtype=\"3\" eventresult=\"1\"/>")) | 687 "<event eventtype=\"3\" eventresult=\"1\"/>")) |
| 688 << post_interceptor_->GetRequestsAsString(); | 688 << post_interceptor_->GetRequestsAsString(); |
| 689 | 689 |
| 690 // Also check what happens if previous check too soon. | 690 // Also check what happens if previous check too soon. It works, since this |
| 691 // direct OnDemand call does not implement a cooldown. |
| 691 test_configurator()->SetOnDemandTime(60 * 60); | 692 test_configurator()->SetOnDemandTime(60 * 60); |
| 692 EXPECT_EQ( | 693 EXPECT_EQ( |
| 693 ComponentUpdateService::kError, | 694 ComponentUpdateService::kOk, |
| 694 OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2))); | 695 OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2))); |
| 695 // Okay, now reset to 0 for the other tests. | 696 // Okay, now reset to 0 for the other tests. |
| 696 test_configurator()->SetOnDemandTime(0); | 697 test_configurator()->SetOnDemandTime(0); |
| 697 component_updater()->Stop(); | 698 component_updater()->Stop(); |
| 698 | 699 |
| 699 // Test a few error cases. NOTE: We don't have callbacks for | 700 // Test a few error cases. NOTE: We don't have callbacks for |
| 700 // when the updates failed yet. | 701 // when the updates failed yet. |
| 701 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); | 702 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
| 702 { | 703 { |
| 703 InSequence seq; | 704 InSequence seq; |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 CHECK(defer); | 1399 CHECK(defer); |
| 1399 } | 1400 } |
| 1400 | 1401 |
| 1401 private: | 1402 private: |
| 1402 void ResumeCalled() { ++resume_called_; } | 1403 void ResumeCalled() { ++resume_called_; } |
| 1403 | 1404 |
| 1404 content::ResourceThrottle* throttle_; | 1405 content::ResourceThrottle* throttle_; |
| 1405 int resume_called_; | 1406 int resume_called_; |
| 1406 }; | 1407 }; |
| 1407 | 1408 |
| 1409 // Tests the on-demand update with resource throttle, including the |
| 1410 // cooldown interval between calls. |
| 1408 TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) { | 1411 TEST_F(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate) { |
| 1409 MockServiceObserver observer; | 1412 MockServiceObserver observer; |
| 1410 { | 1413 { |
| 1411 InSequence seq; | 1414 InSequence seq; |
| 1412 EXPECT_CALL(observer, | 1415 EXPECT_CALL(observer, |
| 1413 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) | 1416 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1414 .Times(1); | 1417 .Times(1); |
| 1415 EXPECT_CALL(observer, | 1418 EXPECT_CALL(observer, |
| 1416 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, | 1419 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1417 "abagagagagagagagagagagagagagagag")) | 1420 "abagagagagagagagagagagagagagagag")) |
| 1418 .Times(1); | 1421 .Times(1); |
| 1419 EXPECT_CALL(observer, | 1422 EXPECT_CALL(observer, |
| 1420 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) | 1423 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1421 .Times(1); | 1424 .Times(1); |
| 1425 EXPECT_CALL(observer, |
| 1426 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1427 .Times(1); |
| 1428 EXPECT_CALL(observer, |
| 1429 OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED, |
| 1430 "abagagagagagagagagagagagagagagag")) |
| 1431 .Times(1); |
| 1432 EXPECT_CALL(observer, |
| 1433 OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, "")) |
| 1434 .Times(1); |
| 1435 EXPECT_CALL(observer, |
| 1436 OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, "")) |
| 1437 .Times(1); |
| 1422 } | 1438 } |
| 1423 | 1439 |
| 1424 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 1440 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
| 1425 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 1441 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 1426 | 1442 |
| 1427 TestInstaller installer; | 1443 TestInstaller installer; |
| 1428 CrxComponent com; | 1444 CrxComponent com; |
| 1429 component_updater()->AddObserver(&observer); | 1445 component_updater()->AddObserver(&observer); |
| 1430 EXPECT_EQ( | 1446 EXPECT_EQ( |
| 1431 ComponentUpdateService::kOk, | 1447 ComponentUpdateService::kOk, |
| 1432 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer)); | 1448 RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer)); |
| 1433 // The following two calls ensure that we don't do an update check via the | 1449 // The following two calls ensure that we don't do an update check via the |
| 1434 // timer, so the only update check should be the on-demand one. | 1450 // timer, so the only update check should be the on-demand one. |
| 1435 test_configurator()->SetInitialDelay(1000000); | 1451 test_configurator()->SetInitialDelay(1000000); |
| 1436 test_configurator()->SetRecheckTime(1000000); | 1452 test_configurator()->SetRecheckTime(1000000); |
| 1437 test_configurator()->SetLoopCount(1); | 1453 test_configurator()->SetLoopCount(1); |
| 1438 component_updater()->Start(); | 1454 component_updater()->Start(); |
| 1439 | 1455 |
| 1440 RunThreadsUntilIdle(); | 1456 RunThreadsUntilIdle(); |
| 1441 | 1457 |
| 1442 EXPECT_EQ(0, post_interceptor_->GetHitCount()); | 1458 EXPECT_EQ(0, post_interceptor_->GetHitCount()); |
| 1443 | 1459 |
| 1444 CancelResourceController controller; | 1460 { |
| 1461 // First on-demand update check is expected to succeeded. |
| 1462 CancelResourceController controller; |
| 1445 | 1463 |
| 1446 BrowserThread::PostTask( | 1464 BrowserThread::PostTask( |
| 1447 BrowserThread::IO, | 1465 BrowserThread::IO, |
| 1448 FROM_HERE, | 1466 FROM_HERE, |
| 1449 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), | 1467 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), |
| 1450 component_updater(), | 1468 component_updater(), |
| 1451 &controller, | 1469 &controller, |
| 1452 "abagagagagagagagagagagagagagagag")); | 1470 "abagagagagagagagagagagagagagagag")); |
| 1453 | 1471 |
| 1454 RunThreads(); | 1472 RunThreads(); |
| 1455 | 1473 |
| 1456 EXPECT_EQ(1, post_interceptor_->GetHitCount()); | 1474 EXPECT_EQ(1, post_interceptor_->GetHitCount()); |
| 1457 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1475 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1458 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 1476 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1459 | 1477 |
| 1460 component_updater()->Stop(); | 1478 component_updater()->Stop(); |
| 1479 } |
| 1480 |
| 1481 { |
| 1482 // Second on-demand update check is expected to succeed as well, since there |
| 1483 // is no cooldown interval between calls, due to calling SetOnDemandTime. |
| 1484 test_configurator()->SetOnDemandTime(0); |
| 1485 test_configurator()->SetLoopCount(1); |
| 1486 component_updater()->Start(); |
| 1487 |
| 1488 CancelResourceController controller; |
| 1489 |
| 1490 BrowserThread::PostTask( |
| 1491 BrowserThread::IO, |
| 1492 FROM_HERE, |
| 1493 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), |
| 1494 component_updater(), |
| 1495 &controller, |
| 1496 "abagagagagagagagagagagagagagagag")); |
| 1497 |
| 1498 RunThreads(); |
| 1499 |
| 1500 EXPECT_EQ(1, post_interceptor_->GetHitCount()); |
| 1501 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1502 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1503 |
| 1504 component_updater()->Stop(); |
| 1505 } |
| 1506 |
| 1507 { |
| 1508 // This on-demand call is expected not to trigger a component update check. |
| 1509 test_configurator()->SetOnDemandTime(1000000); |
| 1510 component_updater()->Start(); |
| 1511 |
| 1512 CancelResourceController controller; |
| 1513 |
| 1514 BrowserThread::PostTask( |
| 1515 BrowserThread::IO, |
| 1516 FROM_HERE, |
| 1517 base::Bind(base::IgnoreResult(&RequestTestResourceThrottle), |
| 1518 component_updater(), |
| 1519 &controller, |
| 1520 "abagagagagagagagagagagagagagagag")); |
| 1521 RunThreadsUntilIdle(); |
| 1522 } |
| 1461 } | 1523 } |
| 1462 | 1524 |
| 1463 // Tests adding and removing observers. | 1525 // Tests adding and removing observers. |
| 1464 TEST_F(ComponentUpdaterTest, Observer) { | 1526 TEST_F(ComponentUpdaterTest, Observer) { |
| 1465 MockServiceObserver observer1, observer2; | 1527 MockServiceObserver observer1, observer2; |
| 1466 | 1528 |
| 1467 // Expect that two observers see the events. | 1529 // Expect that two observers see the events. |
| 1468 { | 1530 { |
| 1469 InSequence seq; | 1531 InSequence seq; |
| 1470 EXPECT_CALL(observer1, | 1532 EXPECT_CALL(observer1, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 component_updater()->RemoveObserver(&observer2); | 1596 component_updater()->RemoveObserver(&observer2); |
| 1535 | 1597 |
| 1536 test_configurator()->SetLoopCount(1); | 1598 test_configurator()->SetLoopCount(1); |
| 1537 component_updater()->Start(); | 1599 component_updater()->Start(); |
| 1538 RunThreads(); | 1600 RunThreads(); |
| 1539 | 1601 |
| 1540 component_updater()->Stop(); | 1602 component_updater()->Stop(); |
| 1541 } | 1603 } |
| 1542 | 1604 |
| 1543 } // namespace component_updater | 1605 } // namespace component_updater |
| OLD | NEW |