OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <tuple> | 6 #include <tuple> |
7 | 7 |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( | 1617 explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( |
1618 base::WeakPtr<EmbeddedWorkerTestHelper> helper) | 1618 base::WeakPtr<EmbeddedWorkerTestHelper> helper) |
1619 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} | 1619 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} |
1620 int num_of_startworker() const { return num_of_startworker_; } | 1620 int num_of_startworker() const { return num_of_startworker_; } |
1621 void set_next_pause_after_download(bool expectation) { | 1621 void set_next_pause_after_download(bool expectation) { |
1622 next_pause_after_download_ = expectation; | 1622 next_pause_after_download_ = expectation; |
1623 } | 1623 } |
1624 | 1624 |
1625 protected: | 1625 protected: |
1626 void StartWorker( | 1626 void StartWorker( |
1627 const EmbeddedWorkerStartParams& params, | 1627 const EmbeddedWorkerStartParamsInternal& params, |
1628 service_manager::mojom::InterfaceProviderPtr browser_interfaces, | 1628 mojom::ServiceWorkerEventDispatcherRequest request) override { |
1629 service_manager::mojom::InterfaceProviderRequest renderer_request) | |
1630 override { | |
1631 ASSERT_TRUE(next_pause_after_download_.has_value()); | 1629 ASSERT_TRUE(next_pause_after_download_.has_value()); |
1632 EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); | 1630 EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); |
1633 num_of_startworker_++; | 1631 num_of_startworker_++; |
1634 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( | 1632 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( |
1635 params, std::move(browser_interfaces), std::move(renderer_request)); | 1633 params, std::move(request)); |
1636 } | 1634 } |
1637 | 1635 |
1638 private: | 1636 private: |
1639 base::Optional<bool> next_pause_after_download_; | 1637 base::Optional<bool> next_pause_after_download_; |
1640 int num_of_startworker_ = 0; | 1638 int num_of_startworker_ = 0; |
1641 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); | 1639 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); |
1642 }; | 1640 }; |
1643 | 1641 |
1644 TEST_P(ServiceWorkerJobTestP, Update_PauseAfterDownload) { | 1642 TEST_P(ServiceWorkerJobTestP, Update_PauseAfterDownload) { |
1645 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1643 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
(...skipping 16 matching lines...) Expand all Loading... |
1662 scoped_refptr<ServiceWorkerRegistration> registration = | 1660 scoped_refptr<ServiceWorkerRegistration> registration = |
1663 update_helper->SetupInitialRegistration(kNewVersionOrigin); | 1661 update_helper->SetupInitialRegistration(kNewVersionOrigin); |
1664 if (is_mojo_enabled()) { | 1662 if (is_mojo_enabled()) { |
1665 ASSERT_EQ(1, clients[0]->num_of_startworker()); | 1663 ASSERT_EQ(1, clients[0]->num_of_startworker()); |
1666 } else { | 1664 } else { |
1667 const IPC::Message* start_msg = | 1665 const IPC::Message* start_msg = |
1668 sink->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID); | 1666 sink->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID); |
1669 ASSERT_TRUE(start_msg); | 1667 ASSERT_TRUE(start_msg); |
1670 EmbeddedWorkerMsg_StartWorker::Param param; | 1668 EmbeddedWorkerMsg_StartWorker::Param param; |
1671 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); | 1669 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); |
1672 const EmbeddedWorkerStartParams& start_params = std::get<0>(param); | 1670 const EmbeddedWorkerStartParamsInternal& start_params = std::get<0>(param); |
1673 EXPECT_FALSE(start_params.pause_after_download); | 1671 EXPECT_FALSE(start_params.pause_after_download); |
1674 sink->ClearMessages(); | 1672 sink->ClearMessages(); |
1675 } | 1673 } |
1676 | 1674 |
1677 // The updated version should pause after download. | 1675 // The updated version should pause after download. |
1678 if (is_mojo_enabled()) | 1676 if (is_mojo_enabled()) |
1679 clients[1]->set_next_pause_after_download(true); | 1677 clients[1]->set_next_pause_after_download(true); |
1680 registration->AddListener(update_helper); | 1678 registration->AddListener(update_helper); |
1681 registration->active_version()->StartUpdate(); | 1679 registration->active_version()->StartUpdate(); |
1682 base::RunLoop().RunUntilIdle(); | 1680 base::RunLoop().RunUntilIdle(); |
1683 if (is_mojo_enabled()) { | 1681 if (is_mojo_enabled()) { |
1684 ASSERT_EQ(1, clients[1]->num_of_startworker()); | 1682 ASSERT_EQ(1, clients[1]->num_of_startworker()); |
1685 } else { | 1683 } else { |
1686 const IPC::Message* start_msg = | 1684 const IPC::Message* start_msg = |
1687 sink->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID); | 1685 sink->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID); |
1688 ASSERT_TRUE(start_msg); | 1686 ASSERT_TRUE(start_msg); |
1689 EmbeddedWorkerMsg_StartWorker::Param param; | 1687 EmbeddedWorkerMsg_StartWorker::Param param; |
1690 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); | 1688 EmbeddedWorkerMsg_StartWorker::Read(start_msg, ¶m); |
1691 const EmbeddedWorkerStartParams& start_params = std::get<0>(param); | 1689 const EmbeddedWorkerStartParamsInternal& start_params = std::get<0>(param); |
1692 EXPECT_TRUE(start_params.pause_after_download); | 1690 EXPECT_TRUE(start_params.pause_after_download); |
1693 sink->ClearMessages(); | 1691 sink->ClearMessages(); |
1694 } | 1692 } |
1695 } | 1693 } |
1696 | 1694 |
1697 // Test that activation doesn't complete if it's triggered by removing a | 1695 // Test that activation doesn't complete if it's triggered by removing a |
1698 // controllee and starting the worker failed due to shutdown. | 1696 // controllee and starting the worker failed due to shutdown. |
1699 TEST_P(ServiceWorkerJobTestP, ActivateCancelsOnShutdown) { | 1697 TEST_P(ServiceWorkerJobTestP, ActivateCancelsOnShutdown) { |
1700 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1698 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
1701 helper_.reset(update_helper); | 1699 helper_.reset(update_helper); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 EXPECT_EQ(new_version.get(), registration->active_version()); | 1747 EXPECT_EQ(new_version.get(), registration->active_version()); |
1750 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1748 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1751 registration->RemoveListener(update_helper); | 1749 registration->RemoveListener(update_helper); |
1752 } | 1750 } |
1753 | 1751 |
1754 INSTANTIATE_TEST_CASE_P(ServiceWorkerJobTest, | 1752 INSTANTIATE_TEST_CASE_P(ServiceWorkerJobTest, |
1755 ServiceWorkerJobTestP, | 1753 ServiceWorkerJobTestP, |
1756 ::testing::Values(false, true)); | 1754 ::testing::Values(false, true)); |
1757 | 1755 |
1758 } // namespace content | 1756 } // namespace content |
OLD | NEW |