OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/service_worker/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceTest); | 146 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceTest); |
147 }; | 147 }; |
148 | 148 |
149 // A helper to simulate the start worker sequence is stalled in a worker | 149 // A helper to simulate the start worker sequence is stalled in a worker |
150 // process. | 150 // process. |
151 class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper { | 151 class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper { |
152 public: | 152 public: |
153 StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 153 StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
154 ~StalledInStartWorkerHelper() override{}; | 154 ~StalledInStartWorkerHelper() override{}; |
155 | 155 |
156 void OnStartWorker( | 156 void OnStartWorker(int embedded_worker_id, |
157 int embedded_worker_id, | 157 int64_t service_worker_version_id, |
158 int64_t service_worker_version_id, | 158 const GURL& scope, |
159 const GURL& scope, | 159 const GURL& script_url, |
160 const GURL& script_url, | 160 bool pause_after_download, |
161 bool pause_after_download, | 161 mojom::ServiceWorkerEventDispatcherRequest request, |
162 mojom::ServiceWorkerEventDispatcherRequest request) override { | 162 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |
| 163 instance_host) override { |
163 if (force_stall_in_start_) { | 164 if (force_stall_in_start_) { |
164 // Do nothing to simulate a stall in the worker process. | 165 // Do nothing to simulate a stall in the worker process. |
165 return; | 166 return; |
166 } | 167 } |
167 EmbeddedWorkerTestHelper::OnStartWorker( | 168 EmbeddedWorkerTestHelper::OnStartWorker( |
168 embedded_worker_id, service_worker_version_id, scope, script_url, | 169 embedded_worker_id, service_worker_version_id, scope, script_url, |
169 pause_after_download, std::move(request)); | 170 pause_after_download, std::move(request), std::move(instance_host)); |
170 } | 171 } |
171 | 172 |
172 void set_force_stall_in_start(bool force_stall_in_start) { | 173 void set_force_stall_in_start(bool force_stall_in_start) { |
173 force_stall_in_start_ = force_stall_in_start; | 174 force_stall_in_start_ = force_stall_in_start; |
174 } | 175 } |
175 | 176 |
176 private: | 177 private: |
177 bool force_stall_in_start_ = true; | 178 bool force_stall_in_start_ = true; |
178 }; | 179 }; |
179 | 180 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 class FailEmbeddedWorkerInstanceClientImpl | 703 class FailEmbeddedWorkerInstanceClientImpl |
703 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { | 704 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { |
704 public: | 705 public: |
705 explicit FailEmbeddedWorkerInstanceClientImpl( | 706 explicit FailEmbeddedWorkerInstanceClientImpl( |
706 base::WeakPtr<EmbeddedWorkerTestHelper> helper) | 707 base::WeakPtr<EmbeddedWorkerTestHelper> helper) |
707 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} | 708 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} |
708 | 709 |
709 private: | 710 private: |
710 void StartWorker( | 711 void StartWorker( |
711 const EmbeddedWorkerStartParams& /* unused */, | 712 const EmbeddedWorkerStartParams& /* unused */, |
712 mojom::ServiceWorkerEventDispatcherRequest /* unused */) override { | 713 mojom::ServiceWorkerEventDispatcherRequest /* unused */, |
| 714 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo /* unused */) |
| 715 override { |
713 helper_->mock_instance_clients()->clear(); | 716 helper_->mock_instance_clients()->clear(); |
714 } | 717 } |
715 }; | 718 }; |
716 | 719 |
717 TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) { | 720 TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) { |
718 const int64_t version_id = 55L; | 721 const int64_t version_id = 55L; |
719 const GURL pattern("http://example.com/"); | 722 const GURL pattern("http://example.com/"); |
720 const GURL url("http://example.com/worker.js"); | 723 const GURL url("http://example.com/worker.js"); |
721 | 724 |
722 // Let StartWorker fail; binding is discarded in the middle of IPC | 725 // Let StartWorker fail; binding is discarded in the middle of IPC |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 ASSERT_EQ(1UL, instance_client_rawptr->message().size()); | 814 ASSERT_EQ(1UL, instance_client_rawptr->message().size()); |
812 EXPECT_EQ(test_message, instance_client_rawptr->message()[0]); | 815 EXPECT_EQ(test_message, instance_client_rawptr->message()[0]); |
813 | 816 |
814 // Ensure the worker is stopped. | 817 // Ensure the worker is stopped. |
815 worker->Stop(); | 818 worker->Stop(); |
816 base::RunLoop().RunUntilIdle(); | 819 base::RunLoop().RunUntilIdle(); |
817 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); | 820 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); |
818 } | 821 } |
819 | 822 |
820 } // namespace content | 823 } // namespace content |
OLD | NEW |