Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: content/browser/service_worker/embedded_worker_instance_unittest.cc

Issue 2787883003: [ServiceWorker] Add EmbeddedWorkerInstanceHost Interface. (Closed)
Patch Set: Address comments from shimazu@ Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_) {
165 // Prepare for OnStopWorker().
166 instance_host_ptr_map_[embedded_worker_id].Bind(std::move(instance_host));
164 // Do nothing to simulate a stall in the worker process. 167 // Do nothing to simulate a stall in the worker process.
165 return; 168 return;
166 } 169 }
167 EmbeddedWorkerTestHelper::OnStartWorker( 170 EmbeddedWorkerTestHelper::OnStartWorker(
168 embedded_worker_id, service_worker_version_id, scope, script_url, 171 embedded_worker_id, service_worker_version_id, scope, script_url,
169 pause_after_download, std::move(request)); 172 pause_after_download, std::move(request), std::move(instance_host));
173 }
174
175 void OnStopWorker(int embedded_worker_id) override {
176 if (instance_host_ptr_map_[embedded_worker_id]) {
177 instance_host_ptr_map_[embedded_worker_id]->OnStopped();
178 base::RunLoop().RunUntilIdle();
179 return;
180 }
181 EmbeddedWorkerTestHelper::OnStopWorker(embedded_worker_id);
170 } 182 }
171 183
172 void set_force_stall_in_start(bool force_stall_in_start) { 184 void set_force_stall_in_start(bool force_stall_in_start) {
173 force_stall_in_start_ = force_stall_in_start; 185 force_stall_in_start_ = force_stall_in_start;
174 } 186 }
175 187
176 private: 188 private:
177 bool force_stall_in_start_ = true; 189 bool force_stall_in_start_ = true;
190
191 std::map<
192 int /* embedded_worker_id */,
193 mojom::EmbeddedWorkerInstanceHostAssociatedPtr /* instance_host_ptr */>
194 instance_host_ptr_map_;
178 }; 195 };
179 196
180 TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) { 197 TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
181 std::unique_ptr<EmbeddedWorkerInstance> worker = 198 std::unique_ptr<EmbeddedWorkerInstance> worker =
182 embedded_worker_registry()->CreateWorker(); 199 embedded_worker_registry()->CreateWorker();
183 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 200 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
184 worker->AddListener(this); 201 worker->AddListener(this);
185 202
186 const int64_t service_worker_version_id = 55L; 203 const int64_t service_worker_version_id = 55L;
187 const GURL pattern("http://example.com/"); 204 const GURL pattern("http://example.com/");
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 class FailEmbeddedWorkerInstanceClientImpl 719 class FailEmbeddedWorkerInstanceClientImpl
703 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { 720 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient {
704 public: 721 public:
705 explicit FailEmbeddedWorkerInstanceClientImpl( 722 explicit FailEmbeddedWorkerInstanceClientImpl(
706 base::WeakPtr<EmbeddedWorkerTestHelper> helper) 723 base::WeakPtr<EmbeddedWorkerTestHelper> helper)
707 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} 724 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {}
708 725
709 private: 726 private:
710 void StartWorker( 727 void StartWorker(
711 const EmbeddedWorkerStartParams& /* unused */, 728 const EmbeddedWorkerStartParams& /* unused */,
712 mojom::ServiceWorkerEventDispatcherRequest /* unused */) override { 729 mojom::ServiceWorkerEventDispatcherRequest /* unused */,
730 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo /* unused */)
731 override {
713 helper_->mock_instance_clients()->clear(); 732 helper_->mock_instance_clients()->clear();
714 } 733 }
715 }; 734 };
716 735
717 TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) { 736 TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) {
718 const int64_t version_id = 55L; 737 const int64_t version_id = 55L;
719 const GURL pattern("http://example.com/"); 738 const GURL pattern("http://example.com/");
720 const GURL url("http://example.com/worker.js"); 739 const GURL url("http://example.com/worker.js");
721 740
722 // Let StartWorker fail; binding is discarded in the middle of IPC 741 // Let StartWorker fail; binding is discarded in the middle of IPC
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 ASSERT_EQ(1UL, instance_client_rawptr->message().size()); 830 ASSERT_EQ(1UL, instance_client_rawptr->message().size());
812 EXPECT_EQ(test_message, instance_client_rawptr->message()[0]); 831 EXPECT_EQ(test_message, instance_client_rawptr->message()[0]);
813 832
814 // Ensure the worker is stopped. 833 // Ensure the worker is stopped.
815 worker->Stop(); 834 worker->Stop();
816 base::RunLoop().RunUntilIdle(); 835 base::RunLoop().RunUntilIdle();
817 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 836 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
818 } 837 }
819 838
820 } // namespace content 839 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698