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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = | 372 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = |
373 FindRegistrationForPattern(pattern); | 373 FindRegistrationForPattern(pattern); |
374 | 374 |
375 ASSERT_EQ(new_registration, old_registration); | 375 ASSERT_EQ(new_registration, old_registration); |
376 } | 376 } |
377 | 377 |
378 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { | 378 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { |
379 public: | 379 public: |
380 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 380 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
381 | 381 |
382 void OnStartWorker( | 382 void OnStartWorker(int embedded_worker_id, |
383 int embedded_worker_id, | 383 int64_t service_worker_version_id, |
384 int64_t service_worker_version_id, | 384 const GURL& scope, |
385 const GURL& scope, | 385 const GURL& script_url, |
386 const GURL& script_url, | 386 bool pause_after_download, |
387 bool pause_after_download, | 387 mojom::ServiceWorkerEventDispatcherRequest request, |
388 mojom::ServiceWorkerEventDispatcherRequest request) override { | 388 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |
| 389 instance_host) override { |
389 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 390 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
390 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 391 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
391 } | 392 } |
392 }; | 393 }; |
393 | 394 |
394 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 395 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
395 helper_.reset(new FailToStartWorkerTestHelper); | 396 helper_.reset(new FailToStartWorkerTestHelper); |
396 | 397 |
397 scoped_refptr<ServiceWorkerRegistration> registration = | 398 scoped_refptr<ServiceWorkerRegistration> registration = |
398 RunRegisterJob(GURL("http://www.example.com/"), | 399 RunRegisterJob(GURL("http://www.example.com/"), |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 EXPECT_TRUE(called); | 834 EXPECT_TRUE(called); |
834 EXPECT_TRUE(registration.get()); | 835 EXPECT_TRUE(registration.get()); |
835 EXPECT_TRUE(registration->active_version()); | 836 EXPECT_TRUE(registration->active_version()); |
836 EXPECT_FALSE(registration->installing_version()); | 837 EXPECT_FALSE(registration->installing_version()); |
837 EXPECT_FALSE(registration->waiting_version()); | 838 EXPECT_FALSE(registration->waiting_version()); |
838 registration_ = registration; | 839 registration_ = registration; |
839 return registration; | 840 return registration; |
840 } | 841 } |
841 | 842 |
842 // EmbeddedWorkerTestHelper overrides | 843 // EmbeddedWorkerTestHelper overrides |
843 void OnStartWorker( | 844 void OnStartWorker(int embedded_worker_id, |
844 int embedded_worker_id, | 845 int64_t version_id, |
845 int64_t version_id, | 846 const GURL& scope, |
846 const GURL& scope, | 847 const GURL& script, |
847 const GURL& script, | 848 bool pause_after_download, |
848 bool pause_after_download, | 849 mojom::ServiceWorkerEventDispatcherRequest request, |
849 mojom::ServiceWorkerEventDispatcherRequest request) override { | 850 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |
| 851 instance_host) override { |
850 const std::string kMockScriptBody = "mock_script"; | 852 const std::string kMockScriptBody = "mock_script"; |
851 const uint64_t kMockScriptSize = 19284; | 853 const uint64_t kMockScriptSize = 19284; |
852 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 854 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); |
853 ServiceWorkerRegistration* registration = | 855 ServiceWorkerRegistration* registration = |
854 context()->GetLiveRegistration(version->registration_id()); | 856 context()->GetLiveRegistration(version->registration_id()); |
855 bool is_update = registration->active_version() && | 857 bool is_update = registration->active_version() && |
856 version != registration->active_version(); | 858 version != registration->active_version(); |
857 | 859 |
858 ASSERT_TRUE(version); | 860 ASSERT_TRUE(version); |
859 version->AddListener(this); | 861 version->AddListener(this); |
(...skipping 29 matching lines...) Expand all Loading... |
889 } | 891 } |
890 | 892 |
891 // Spoof caching the script for the new version. | 893 // Spoof caching the script for the new version. |
892 WriteStringResponse(storage(), resource_id, "mock_different_script"); | 894 WriteStringResponse(storage(), resource_id, "mock_different_script"); |
893 version->script_cache_map()->NotifyFinishedCaching( | 895 version->script_cache_map()->NotifyFinishedCaching( |
894 script, kMockScriptSize, net::OK, std::string()); | 896 script, kMockScriptSize, net::OK, std::string()); |
895 version->SetMainScriptHttpResponseInfo( | 897 version->SetMainScriptHttpResponseInfo( |
896 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); | 898 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); |
897 } | 899 } |
898 | 900 |
899 EmbeddedWorkerTestHelper::OnStartWorker(embedded_worker_id, version_id, | 901 EmbeddedWorkerTestHelper::OnStartWorker( |
900 scope, script, pause_after_download, | 902 embedded_worker_id, version_id, scope, script, pause_after_download, |
901 std::move(request)); | 903 std::move(request), std::move(instance_host)); |
902 } | 904 } |
903 | 905 |
904 void OnResumeAfterDownload(int embedded_worker_id) override { | 906 void OnResumeAfterDownload(int embedded_worker_id) override { |
905 if (!force_start_worker_failure_) { | 907 if (!force_start_worker_failure_) { |
906 EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id); | 908 EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id); |
907 } else { | 909 } else { |
908 SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id); | 910 SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id); |
909 SimulateWorkerScriptEvaluated(embedded_worker_id, false); | 911 SimulateWorkerScriptEvaluated(embedded_worker_id, false); |
910 } | 912 } |
911 } | 913 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 bool force_start_worker_failure_ = false; | 948 bool force_start_worker_failure_ = false; |
947 }; | 949 }; |
948 | 950 |
949 // Helper class for update tests that evicts the active version when the update | 951 // Helper class for update tests that evicts the active version when the update |
950 // worker is about to be started. | 952 // worker is about to be started. |
951 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { | 953 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { |
952 public: | 954 public: |
953 EvictIncumbentVersionHelper() {} | 955 EvictIncumbentVersionHelper() {} |
954 ~EvictIncumbentVersionHelper() override {} | 956 ~EvictIncumbentVersionHelper() override {} |
955 | 957 |
956 void OnStartWorker( | 958 void OnStartWorker(int embedded_worker_id, |
957 int embedded_worker_id, | 959 int64_t version_id, |
958 int64_t version_id, | 960 const GURL& scope, |
959 const GURL& scope, | 961 const GURL& script, |
960 const GURL& script, | 962 bool pause_after_download, |
961 bool pause_after_download, | 963 mojom::ServiceWorkerEventDispatcherRequest request, |
962 mojom::ServiceWorkerEventDispatcherRequest request) override { | 964 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |
| 965 instance_host) override { |
963 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 966 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); |
964 ServiceWorkerRegistration* registration = | 967 ServiceWorkerRegistration* registration = |
965 context()->GetLiveRegistration(version->registration_id()); | 968 context()->GetLiveRegistration(version->registration_id()); |
966 bool is_update = registration->active_version() && | 969 bool is_update = registration->active_version() && |
967 version != registration->active_version(); | 970 version != registration->active_version(); |
968 if (is_update) { | 971 if (is_update) { |
969 // Evict the incumbent worker. | 972 // Evict the incumbent worker. |
970 ASSERT_FALSE(registration->waiting_version()); | 973 ASSERT_FALSE(registration->waiting_version()); |
971 registration->DeleteVersion( | 974 registration->DeleteVersion( |
972 make_scoped_refptr(registration->active_version())); | 975 make_scoped_refptr(registration->active_version())); |
973 } | 976 } |
974 UpdateJobTestHelper::OnStartWorker(embedded_worker_id, version_id, scope, | 977 UpdateJobTestHelper::OnStartWorker( |
975 script, pause_after_download, | 978 embedded_worker_id, version_id, scope, script, pause_after_download, |
976 std::move(request)); | 979 std::move(request), std::move(instance_host)); |
977 } | 980 } |
978 | 981 |
979 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { | 982 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { |
980 registration_failed_ = true; | 983 registration_failed_ = true; |
981 } | 984 } |
982 | 985 |
983 bool registration_failed_ = false; | 986 bool registration_failed_ = false; |
984 }; | 987 }; |
985 | 988 |
986 } // namespace | 989 } // namespace |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 public: | 1640 public: |
1638 explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( | 1641 explicit CheckPauseAfterDownloadEmbeddedWorkerInstanceClient( |
1639 base::WeakPtr<EmbeddedWorkerTestHelper> helper) | 1642 base::WeakPtr<EmbeddedWorkerTestHelper> helper) |
1640 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} | 1643 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} |
1641 int num_of_startworker() const { return num_of_startworker_; } | 1644 int num_of_startworker() const { return num_of_startworker_; } |
1642 void set_next_pause_after_download(bool expectation) { | 1645 void set_next_pause_after_download(bool expectation) { |
1643 next_pause_after_download_ = expectation; | 1646 next_pause_after_download_ = expectation; |
1644 } | 1647 } |
1645 | 1648 |
1646 protected: | 1649 protected: |
1647 void StartWorker( | 1650 void StartWorker(const EmbeddedWorkerStartParams& params, |
1648 const EmbeddedWorkerStartParams& params, | 1651 mojom::ServiceWorkerEventDispatcherRequest request, |
1649 mojom::ServiceWorkerEventDispatcherRequest request) override { | 1652 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |
| 1653 instance_host) override { |
1650 ASSERT_TRUE(next_pause_after_download_.has_value()); | 1654 ASSERT_TRUE(next_pause_after_download_.has_value()); |
1651 EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); | 1655 EXPECT_EQ(next_pause_after_download_.value(), params.pause_after_download); |
1652 num_of_startworker_++; | 1656 num_of_startworker_++; |
1653 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( | 1657 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( |
1654 params, std::move(request)); | 1658 params, std::move(request), std::move(instance_host)); |
1655 } | 1659 } |
1656 | 1660 |
1657 private: | 1661 private: |
1658 base::Optional<bool> next_pause_after_download_; | 1662 base::Optional<bool> next_pause_after_download_; |
1659 int num_of_startworker_ = 0; | 1663 int num_of_startworker_ = 0; |
1660 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); | 1664 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); |
1661 }; | 1665 }; |
1662 | 1666 |
1663 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { | 1667 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { |
1664 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; | 1668 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 // should not be promoted to ACTIVATED because failure occur | 1741 // should not be promoted to ACTIVATED because failure occur |
1738 // during shutdown. | 1742 // during shutdown. |
1739 runner->RunUntilIdle(); | 1743 runner->RunUntilIdle(); |
1740 base::RunLoop().RunUntilIdle(); | 1744 base::RunLoop().RunUntilIdle(); |
1741 EXPECT_EQ(new_version.get(), registration->active_version()); | 1745 EXPECT_EQ(new_version.get(), registration->active_version()); |
1742 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1746 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1743 registration->RemoveListener(update_helper); | 1747 registration->RemoveListener(update_helper); |
1744 } | 1748 } |
1745 | 1749 |
1746 } // namespace content | 1750 } // namespace content |
OLD | NEW |