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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Pass the param of BindWithProviderInfo by value instead of pointer Created 3 years, 6 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 26 matching lines...) Expand all
37 37
38 void SaveStatusAndCall(ServiceWorkerStatusCode* out, 38 void SaveStatusAndCall(ServiceWorkerStatusCode* out,
39 const base::Closure& callback, 39 const base::Closure& callback,
40 ServiceWorkerStatusCode status) { 40 ServiceWorkerStatusCode status) {
41 *out = status; 41 *out = status;
42 callback.Run(); 42 callback.Run();
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 class ProviderHostEndpoints : public mojom::ServiceWorkerProviderHost {
48 public:
49 ProviderHostEndpoints() : binding_(this) {}
50
51 ~ProviderHostEndpoints() override {}
52
53 mojom::ServiceWorkerProviderInfoForStartWorkerPtr CreateProviderInfoPtr() {
54 DCHECK(!binding_.is_bound());
55 DCHECK(!client_.is_bound());
56 // Just keep the endpoints.
57 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info =
58 mojom::ServiceWorkerProviderInfoForStartWorker::New();
59 binding_.Bind(mojo::MakeRequest(&provider_info->host_ptr_info));
60 provider_info->client_request = mojo::MakeRequest(&client_);
61 return provider_info;
62 }
63
64 private:
65 mojom::ServiceWorkerProviderAssociatedPtr client_;
66 mojo::AssociatedBinding<mojom::ServiceWorkerProviderHost> binding_;
67
68 DISALLOW_COPY_AND_ASSIGN(ProviderHostEndpoints);
69 };
70
47 class EmbeddedWorkerInstanceTest : public testing::Test, 71 class EmbeddedWorkerInstanceTest : public testing::Test,
48 public EmbeddedWorkerInstance::Listener { 72 public EmbeddedWorkerInstance::Listener {
49 protected: 73 protected:
50 EmbeddedWorkerInstanceTest() 74 EmbeddedWorkerInstanceTest()
51 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} 75 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
52 76
53 enum EventType { 77 enum EventType {
54 PROCESS_ALLOCATED, 78 PROCESS_ALLOCATED,
55 START_WORKER_MESSAGE_SENT, 79 START_WORKER_MESSAGE_SENT,
56 STARTED, 80 STARTED,
(...skipping 18 matching lines...) Expand all
75 RecordEvent(START_WORKER_MESSAGE_SENT); 99 RecordEvent(START_WORKER_MESSAGE_SENT);
76 } 100 }
77 void OnStarted() override { RecordEvent(STARTED); } 101 void OnStarted() override { RecordEvent(STARTED); }
78 void OnStopped(EmbeddedWorkerStatus old_status) override { 102 void OnStopped(EmbeddedWorkerStatus old_status) override {
79 RecordEvent(STOPPED, old_status); 103 RecordEvent(STOPPED, old_status);
80 } 104 }
81 void OnDetached(EmbeddedWorkerStatus old_status) override { 105 void OnDetached(EmbeddedWorkerStatus old_status) override {
82 RecordEvent(DETACHED, old_status); 106 RecordEvent(DETACHED, old_status);
83 } 107 }
84 108
85 bool OnMessageReceived(const IPC::Message& message) override { return false; } 109 bool OnMessageReceived(const IPC::Message&) override { return false; }
86 110
87 void SetUp() override { 111 void SetUp() override {
88 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); 112 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
89 } 113 }
90 114
91 void TearDown() override { helper_.reset(); } 115 void TearDown() override { helper_.reset(); }
92 116
93 ServiceWorkerStatusCode StartWorker(EmbeddedWorkerInstance* worker, 117 ServiceWorkerStatusCode StartWorker(EmbeddedWorkerInstance* worker,
94 int id, const GURL& pattern, 118 int id, const GURL& pattern,
95 const GURL& url) { 119 const GURL& url) {
96 ServiceWorkerStatusCode status; 120 ServiceWorkerStatusCode status;
97 base::RunLoop run_loop; 121 base::RunLoop run_loop;
98 std::unique_ptr<EmbeddedWorkerStartParams> params = 122 std::unique_ptr<EmbeddedWorkerStartParams> params =
99 CreateStartParams(id, pattern, url); 123 CreateStartParams(id, pattern, url);
100 worker->Start( 124 worker->Start(
101 std::move(params), CreateEventDispatcher(), 125 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
102 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 126 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
103 run_loop.Run(); 127 run_loop.Run();
104 return status; 128 return status;
105 } 129 }
106 130
107 std::unique_ptr<EmbeddedWorkerStartParams> 131 std::unique_ptr<EmbeddedWorkerStartParams>
108 CreateStartParams(int version_id, const GURL& scope, const GURL& script_url) { 132 CreateStartParams(int version_id, const GURL& scope, const GURL& script_url) {
109 std::unique_ptr<EmbeddedWorkerStartParams> params = 133 std::unique_ptr<EmbeddedWorkerStartParams> params =
110 base::MakeUnique<EmbeddedWorkerStartParams>(); 134 base::MakeUnique<EmbeddedWorkerStartParams>();
111 params->service_worker_version_id = version_id; 135 params->service_worker_version_id = version_id;
112 params->scope = scope; 136 params->scope = scope;
113 params->script_url = script_url; 137 params->script_url = script_url;
114 params->pause_after_download = false; 138 params->pause_after_download = false;
115 params->is_installed = false; 139 params->is_installed = false;
116 return params; 140 return params;
117 } 141 }
118 142
143 mojom::ServiceWorkerProviderInfoForStartWorkerPtr CreateProviderInfo(
144 int /* process_id */) {
145 provider_host_endpoints_.emplace_back(
146 base::MakeUnique<ProviderHostEndpoints>());
147 return provider_host_endpoints_.back()->CreateProviderInfoPtr();
148 }
149
150 EmbeddedWorkerInstance::ProviderInfoGetter CreateProviderInfoGetter() {
151 return base::BindOnce(&EmbeddedWorkerInstanceTest::CreateProviderInfo,
152 base::Unretained(this));
153 }
154
119 mojom::ServiceWorkerEventDispatcherRequest CreateEventDispatcher() { 155 mojom::ServiceWorkerEventDispatcherRequest CreateEventDispatcher() {
120 dispatchers_.emplace_back(); 156 dispatchers_.emplace_back();
121 return mojo::MakeRequest(&dispatchers_.back()); 157 return mojo::MakeRequest(&dispatchers_.back());
122 } 158 }
123 159
124 ServiceWorkerContextCore* context() { return helper_->context(); } 160 ServiceWorkerContextCore* context() { return helper_->context(); }
125 161
126 EmbeddedWorkerRegistry* embedded_worker_registry() { 162 EmbeddedWorkerRegistry* embedded_worker_registry() {
127 DCHECK(context()); 163 DCHECK(context());
128 return context()->embedded_worker_registry(); 164 return context()->embedded_worker_registry();
129 } 165 }
130 166
131 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } 167 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); }
132 168
133 std::vector<std::unique_ptr< 169 std::vector<std::unique_ptr<
134 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient>>* 170 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient>>*
135 mock_instance_clients() { 171 mock_instance_clients() {
136 return helper_->mock_instance_clients(); 172 return helper_->mock_instance_clients();
137 } 173 }
138 174
139 std::vector<mojom::ServiceWorkerEventDispatcherPtr> dispatchers_; 175 std::vector<mojom::ServiceWorkerEventDispatcherPtr> dispatchers_;
176 std::vector<std::unique_ptr<ProviderHostEndpoints>> provider_host_endpoints_;
140 177
141 TestBrowserThreadBundle thread_bundle_; 178 TestBrowserThreadBundle thread_bundle_;
142 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 179 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
143 std::vector<EventLog> events_; 180 std::vector<EventLog> events_;
144 181
145 private: 182 private:
146 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceTest); 183 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceTest);
147 }; 184 };
148 185
149 // A helper to simulate the start worker sequence is stalled in a worker 186 // A helper to simulate the start worker sequence is stalled in a worker
150 // process. 187 // process.
151 class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper { 188 class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper {
152 public: 189 public:
153 StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} 190 StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
154 ~StalledInStartWorkerHelper() override {} 191 ~StalledInStartWorkerHelper() override {}
155 192
156 void OnStartWorker(int embedded_worker_id, 193 void OnStartWorker(
157 int64_t service_worker_version_id, 194 int embedded_worker_id,
158 const GURL& scope, 195 int64_t service_worker_version_id,
159 const GURL& script_url, 196 const GURL& scope,
160 bool pause_after_download, 197 const GURL& script_url,
161 mojom::ServiceWorkerEventDispatcherRequest request, 198 bool pause_after_download,
162 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo 199 mojom::ServiceWorkerEventDispatcherRequest request,
163 instance_host) override { 200 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
201 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
202 override {
164 if (force_stall_in_start_) { 203 if (force_stall_in_start_) {
165 // Prepare for OnStopWorker(). 204 // Prepare for OnStopWorker().
166 instance_host_ptr_map_[embedded_worker_id].Bind(std::move(instance_host)); 205 instance_host_ptr_map_[embedded_worker_id].Bind(std::move(instance_host));
167 // Do nothing to simulate a stall in the worker process. 206 // Do nothing to simulate a stall in the worker process.
168 return; 207 return;
169 } 208 }
170 EmbeddedWorkerTestHelper::OnStartWorker( 209 EmbeddedWorkerTestHelper::OnStartWorker(
171 embedded_worker_id, service_worker_version_id, scope, script_url, 210 embedded_worker_id, service_worker_version_id, scope, script_url,
172 pause_after_download, std::move(request), std::move(instance_host)); 211 pause_after_download, std::move(request), std::move(instance_host),
212 std::move(provider_info));
173 } 213 }
174 214
175 void OnStopWorker(int embedded_worker_id) override { 215 void OnStopWorker(int embedded_worker_id) override {
176 if (instance_host_ptr_map_[embedded_worker_id]) { 216 if (instance_host_ptr_map_[embedded_worker_id]) {
177 instance_host_ptr_map_[embedded_worker_id]->OnStopped(); 217 instance_host_ptr_map_[embedded_worker_id]->OnStopped();
178 base::RunLoop().RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
179 return; 219 return;
180 } 220 }
181 EmbeddedWorkerTestHelper::OnStopWorker(embedded_worker_id); 221 EmbeddedWorkerTestHelper::OnStopWorker(embedded_worker_id);
182 } 222 }
(...skipping 24 matching lines...) Expand all
207 // Simulate adding one process to the pattern. 247 // Simulate adding one process to the pattern.
208 helper_->SimulateAddProcessToPattern(pattern, 248 helper_->SimulateAddProcessToPattern(pattern,
209 helper_->mock_render_process_id()); 249 helper_->mock_render_process_id());
210 250
211 // Start should succeed. 251 // Start should succeed.
212 ServiceWorkerStatusCode status; 252 ServiceWorkerStatusCode status;
213 base::RunLoop run_loop; 253 base::RunLoop run_loop;
214 std::unique_ptr<EmbeddedWorkerStartParams> params = 254 std::unique_ptr<EmbeddedWorkerStartParams> params =
215 CreateStartParams(service_worker_version_id, pattern, url); 255 CreateStartParams(service_worker_version_id, pattern, url);
216 worker->Start( 256 worker->Start(
217 std::move(params), CreateEventDispatcher(), 257 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
218 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 258 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
219 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); 259 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
220 run_loop.Run(); 260 run_loop.Run();
221 EXPECT_EQ(SERVICE_WORKER_OK, status); 261 EXPECT_EQ(SERVICE_WORKER_OK, status);
222 262
223 // The 'WorkerStarted' message should have been sent by 263 // The 'WorkerStarted' message should have been sent by
224 // EmbeddedWorkerTestHelper. 264 // EmbeddedWorkerTestHelper.
225 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); 265 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
226 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); 266 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id());
227 267
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 helper_->SimulateAddProcessToPattern(pattern, 304 helper_->SimulateAddProcessToPattern(pattern,
265 helper_->new_render_process_id()); 305 helper_->new_render_process_id());
266 306
267 { 307 {
268 // Start once normally. 308 // Start once normally.
269 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 309 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
270 base::RunLoop run_loop; 310 base::RunLoop run_loop;
271 std::unique_ptr<EmbeddedWorkerStartParams> params = 311 std::unique_ptr<EmbeddedWorkerStartParams> params =
272 CreateStartParams(service_worker_version_id, pattern, url); 312 CreateStartParams(service_worker_version_id, pattern, url);
273 worker->Start( 313 worker->Start(
274 std::move(params), CreateEventDispatcher(), 314 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
275 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 315 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
276 run_loop.Run(); 316 run_loop.Run();
277 EXPECT_EQ(SERVICE_WORKER_OK, status); 317 EXPECT_EQ(SERVICE_WORKER_OK, status);
278 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); 318 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
279 // The worker should be using the default render process. 319 // The worker should be using the default render process.
280 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); 320 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id());
281 321
282 EXPECT_TRUE(worker->Stop()); 322 EXPECT_TRUE(worker->Stop());
283 base::RunLoop().RunUntilIdle(); 323 base::RunLoop().RunUntilIdle();
284 } 324 }
285 325
286 // Fail twice. 326 // Fail twice.
287 context()->UpdateVersionFailureCount(service_worker_version_id, 327 context()->UpdateVersionFailureCount(service_worker_version_id,
288 SERVICE_WORKER_ERROR_FAILED); 328 SERVICE_WORKER_ERROR_FAILED);
289 context()->UpdateVersionFailureCount(service_worker_version_id, 329 context()->UpdateVersionFailureCount(service_worker_version_id,
290 SERVICE_WORKER_ERROR_FAILED); 330 SERVICE_WORKER_ERROR_FAILED);
291 331
292 { 332 {
293 // Start again. 333 // Start again.
294 ServiceWorkerStatusCode status; 334 ServiceWorkerStatusCode status;
295 base::RunLoop run_loop; 335 base::RunLoop run_loop;
296 std::unique_ptr<EmbeddedWorkerStartParams> params = 336 std::unique_ptr<EmbeddedWorkerStartParams> params =
297 CreateStartParams(service_worker_version_id, pattern, url); 337 CreateStartParams(service_worker_version_id, pattern, url);
298 worker->Start( 338 worker->Start(
299 std::move(params), CreateEventDispatcher(), 339 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
300 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 340 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
301 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); 341 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
302 run_loop.Run(); 342 run_loop.Run();
303 EXPECT_EQ(SERVICE_WORKER_OK, status); 343 EXPECT_EQ(SERVICE_WORKER_OK, status);
304 344
305 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); 345 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
306 // The worker should be using the new render process. 346 // The worker should be using the new render process.
307 EXPECT_EQ(helper_->new_render_process_id(), worker->process_id()); 347 EXPECT_EQ(helper_->new_render_process_id(), worker->process_id());
308 EXPECT_TRUE(worker->Stop()); 348 EXPECT_TRUE(worker->Stop());
309 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 int process_id = helper_->mock_render_process_id(); 410 int process_id = helper_->mock_render_process_id();
371 411
372 helper_->SimulateAddProcessToPattern(pattern, process_id); 412 helper_->SimulateAddProcessToPattern(pattern, process_id);
373 { 413 {
374 // Start worker1. 414 // Start worker1.
375 ServiceWorkerStatusCode status; 415 ServiceWorkerStatusCode status;
376 base::RunLoop run_loop; 416 base::RunLoop run_loop;
377 std::unique_ptr<EmbeddedWorkerStartParams> params = 417 std::unique_ptr<EmbeddedWorkerStartParams> params =
378 CreateStartParams(version_id1, pattern, url); 418 CreateStartParams(version_id1, pattern, url);
379 worker1->Start( 419 worker1->Start(
380 std::move(params), CreateEventDispatcher(), 420 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
381 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 421 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
382 run_loop.Run(); 422 run_loop.Run();
383 EXPECT_EQ(SERVICE_WORKER_OK, status); 423 EXPECT_EQ(SERVICE_WORKER_OK, status);
384 } 424 }
385 425
386 { 426 {
387 // Start worker2. 427 // Start worker2.
388 ServiceWorkerStatusCode status; 428 ServiceWorkerStatusCode status;
389 base::RunLoop run_loop; 429 base::RunLoop run_loop;
390 std::unique_ptr<EmbeddedWorkerStartParams> params = 430 std::unique_ptr<EmbeddedWorkerStartParams> params =
391 CreateStartParams(version_id2, pattern, url); 431 CreateStartParams(version_id2, pattern, url);
392 worker2->Start( 432 worker2->Start(
393 std::move(params), CreateEventDispatcher(), 433 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
394 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 434 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
395 run_loop.Run(); 435 run_loop.Run();
396 EXPECT_EQ(SERVICE_WORKER_OK, status); 436 EXPECT_EQ(SERVICE_WORKER_OK, status);
397 } 437 }
398 438
399 // The two workers share the same process. 439 // The two workers share the same process.
400 EXPECT_EQ(worker1->process_id(), worker2->process_id()); 440 EXPECT_EQ(worker1->process_id(), worker2->process_id());
401 441
402 // Destroy worker1. It removes itself from the registry. 442 // Destroy worker1. It removes itself from the registry.
403 int worker1_id = worker1->embedded_worker_id(); 443 int worker1_id = worker1->embedded_worker_id();
(...skipping 17 matching lines...) Expand all
421 461
422 std::unique_ptr<EmbeddedWorkerInstance> worker = 462 std::unique_ptr<EmbeddedWorkerInstance> worker =
423 embedded_worker_registry()->CreateWorker(); 463 embedded_worker_registry()->CreateWorker();
424 worker->AddListener(this); 464 worker->AddListener(this);
425 465
426 // Run the start worker sequence and detach during process allocation. 466 // Run the start worker sequence and detach during process allocation.
427 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 467 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
428 std::unique_ptr<EmbeddedWorkerStartParams> params = 468 std::unique_ptr<EmbeddedWorkerStartParams> params =
429 CreateStartParams(version_id, scope, url); 469 CreateStartParams(version_id, scope, url);
430 worker->Start( 470 worker->Start(
431 std::move(params), CreateEventDispatcher(), 471 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
432 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); 472 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
433 worker->Detach(); 473 worker->Detach();
434 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle();
435 475
436 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 476 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
437 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id()); 477 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id());
438 478
439 // The start callback should not be aborted by detach (see a comment on the 479 // The start callback should not be aborted by detach (see a comment on the
440 // dtor of EmbeddedWorkerInstance::StartTask). 480 // dtor of EmbeddedWorkerInstance::StartTask).
441 EXPECT_EQ(SERVICE_WORKER_ERROR_MAX_VALUE, status); 481 EXPECT_EQ(SERVICE_WORKER_ERROR_MAX_VALUE, status);
(...skipping 12 matching lines...) Expand all
454 helper_.reset(new StalledInStartWorkerHelper()); 494 helper_.reset(new StalledInStartWorkerHelper());
455 std::unique_ptr<EmbeddedWorkerInstance> worker = 495 std::unique_ptr<EmbeddedWorkerInstance> worker =
456 embedded_worker_registry()->CreateWorker(); 496 embedded_worker_registry()->CreateWorker();
457 worker->AddListener(this); 497 worker->AddListener(this);
458 498
459 // Run the start worker sequence until a start worker message is sent. 499 // Run the start worker sequence until a start worker message is sent.
460 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 500 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
461 std::unique_ptr<EmbeddedWorkerStartParams> params = 501 std::unique_ptr<EmbeddedWorkerStartParams> params =
462 CreateStartParams(version_id, scope, url); 502 CreateStartParams(version_id, scope, url);
463 worker->Start( 503 worker->Start(
464 std::move(params), CreateEventDispatcher(), 504 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
465 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); 505 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
466 base::RunLoop().RunUntilIdle(); 506 base::RunLoop().RunUntilIdle();
467 507
468 ASSERT_EQ(2u, events_.size()); 508 ASSERT_EQ(2u, events_.size());
469 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 509 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
470 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 510 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
471 events_.clear(); 511 events_.clear();
472 512
473 worker->Detach(); 513 worker->Detach();
474 base::RunLoop().RunUntilIdle(); 514 base::RunLoop().RunUntilIdle();
(...skipping 19 matching lines...) Expand all
494 std::unique_ptr<EmbeddedWorkerInstance> worker = 534 std::unique_ptr<EmbeddedWorkerInstance> worker =
495 embedded_worker_registry()->CreateWorker(); 535 embedded_worker_registry()->CreateWorker();
496 worker->AddListener(this); 536 worker->AddListener(this);
497 537
498 // Stop the start worker sequence before a process is allocated. 538 // Stop the start worker sequence before a process is allocated.
499 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 539 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
500 540
501 std::unique_ptr<EmbeddedWorkerStartParams> params = 541 std::unique_ptr<EmbeddedWorkerStartParams> params =
502 CreateStartParams(version_id, scope, url); 542 CreateStartParams(version_id, scope, url);
503 worker->Start( 543 worker->Start(
504 std::move(params), CreateEventDispatcher(), 544 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
505 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); 545 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
506 worker->Stop(); 546 worker->Stop();
507 base::RunLoop().RunUntilIdle(); 547 base::RunLoop().RunUntilIdle();
508 548
509 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 549 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
510 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id()); 550 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id());
511 551
512 // The start callback should not be aborted by stop (see a comment on the dtor 552 // The start callback should not be aborted by stop (see a comment on the dtor
513 // of EmbeddedWorkerInstance::StartTask). 553 // of EmbeddedWorkerInstance::StartTask).
514 EXPECT_EQ(SERVICE_WORKER_ERROR_MAX_VALUE, status); 554 EXPECT_EQ(SERVICE_WORKER_ERROR_MAX_VALUE, status);
515 555
516 // "PROCESS_ALLOCATED" event should not be recorded. 556 // "PROCESS_ALLOCATED" event should not be recorded.
517 ASSERT_EQ(1u, events_.size()); 557 ASSERT_EQ(1u, events_.size());
518 EXPECT_EQ(DETACHED, events_[0].type); 558 EXPECT_EQ(DETACHED, events_[0].type);
519 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status); 559 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status);
520 events_.clear(); 560 events_.clear();
521 561
522 // Restart the worker. 562 // Restart the worker.
523 status = SERVICE_WORKER_ERROR_MAX_VALUE; 563 status = SERVICE_WORKER_ERROR_MAX_VALUE;
524 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop); 564 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop);
525 params = CreateStartParams(version_id, scope, url); 565 params = CreateStartParams(version_id, scope, url);
526 worker->Start( 566 worker->Start(
527 std::move(params), CreateEventDispatcher(), 567 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
528 base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure())); 568 base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure()));
529 run_loop->Run(); 569 run_loop->Run();
530 570
531 EXPECT_EQ(SERVICE_WORKER_OK, status); 571 EXPECT_EQ(SERVICE_WORKER_OK, status);
532 ASSERT_EQ(3u, events_.size()); 572 ASSERT_EQ(3u, events_.size());
533 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 573 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
534 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 574 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
535 EXPECT_EQ(STARTED, events_[2].type); 575 EXPECT_EQ(STARTED, events_[2].type);
536 576
537 // Tear down the worker. 577 // Tear down the worker.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 embedded_worker_registry()->CreateWorker(); 609 embedded_worker_registry()->CreateWorker();
570 worker->AddListener(this); 610 worker->AddListener(this);
571 611
572 // Run the start worker sequence until pause after download. 612 // Run the start worker sequence until pause after download.
573 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 613 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
574 614
575 std::unique_ptr<EmbeddedWorkerStartParams> params = 615 std::unique_ptr<EmbeddedWorkerStartParams> params =
576 CreateStartParams(version_id, scope, url); 616 CreateStartParams(version_id, scope, url);
577 params->pause_after_download = true; 617 params->pause_after_download = true;
578 worker->Start( 618 worker->Start(
579 std::move(params), CreateEventDispatcher(), 619 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
580 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); 620 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
581 base::RunLoop().RunUntilIdle(); 621 base::RunLoop().RunUntilIdle();
582 622
583 // Make the worker stopping and attempt to send a resume after download 623 // Make the worker stopping and attempt to send a resume after download
584 // message. 624 // message.
585 worker->Stop(); 625 worker->Stop();
586 worker->ResumeAfterDownload(); 626 worker->ResumeAfterDownload();
587 base::RunLoop().RunUntilIdle(); 627 base::RunLoop().RunUntilIdle();
588 628
589 // The resume after download message should not have been sent. 629 // The resume after download message should not have been sent.
590 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 630 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
591 EXPECT_FALSE(was_resume_after_download_called); 631 EXPECT_FALSE(was_resume_after_download_called);
592 } 632 }
593 633
594 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { 634 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
595 const int64_t version_id = 55L; 635 const int64_t version_id = 55L;
596 const GURL scope("http://example.com/"); 636 const GURL scope("http://example.com/");
597 const GURL url("http://example.com/worker.js"); 637 const GURL url("http://example.com/worker.js");
598 638
599 helper_.reset(new StalledInStartWorkerHelper); 639 helper_.reset(new StalledInStartWorkerHelper);
600 std::unique_ptr<EmbeddedWorkerInstance> worker = 640 std::unique_ptr<EmbeddedWorkerInstance> worker =
601 embedded_worker_registry()->CreateWorker(); 641 embedded_worker_registry()->CreateWorker();
602 worker->AddListener(this); 642 worker->AddListener(this);
603 643
604 // Run the start worker sequence until a start worker message is sent. 644 // Run the start worker sequence until a start worker message is sent.
605 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 645 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
606 std::unique_ptr<EmbeddedWorkerStartParams> params = 646 std::unique_ptr<EmbeddedWorkerStartParams> params =
607 CreateStartParams(version_id, scope, url); 647 CreateStartParams(version_id, scope, url);
608 worker->Start( 648 worker->Start(
609 std::move(params), CreateEventDispatcher(), 649 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
610 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); 650 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
611 base::RunLoop().RunUntilIdle(); 651 base::RunLoop().RunUntilIdle();
612 652
613 ASSERT_EQ(2u, events_.size()); 653 ASSERT_EQ(2u, events_.size());
614 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 654 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
615 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 655 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
616 events_.clear(); 656 events_.clear();
617 657
618 worker->Stop(); 658 worker->Stop();
619 base::RunLoop().RunUntilIdle(); 659 base::RunLoop().RunUntilIdle();
(...skipping 12 matching lines...) Expand all
632 events_.clear(); 672 events_.clear();
633 673
634 // Restart the worker. 674 // Restart the worker.
635 static_cast<StalledInStartWorkerHelper*>(helper_.get()) 675 static_cast<StalledInStartWorkerHelper*>(helper_.get())
636 ->set_force_stall_in_start(false); 676 ->set_force_stall_in_start(false);
637 status = SERVICE_WORKER_ERROR_MAX_VALUE; 677 status = SERVICE_WORKER_ERROR_MAX_VALUE;
638 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop); 678 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop);
639 679
640 params = CreateStartParams(version_id, scope, url); 680 params = CreateStartParams(version_id, scope, url);
641 worker->Start( 681 worker->Start(
642 std::move(params), CreateEventDispatcher(), 682 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
643 base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure())); 683 base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure()));
644 run_loop->Run(); 684 run_loop->Run();
645 685
646 // The worker should be started. 686 // The worker should be started.
647 EXPECT_EQ(SERVICE_WORKER_OK, status); 687 EXPECT_EQ(SERVICE_WORKER_OK, status);
648 ASSERT_EQ(3u, events_.size()); 688 ASSERT_EQ(3u, events_.size());
649 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 689 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
650 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 690 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
651 EXPECT_EQ(STARTED, events_[2].type); 691 EXPECT_EQ(STARTED, events_[2].type);
652 692
(...skipping 10 matching lines...) Expand all
663 helper_->SimulateAddProcessToPattern(pattern, 703 helper_->SimulateAddProcessToPattern(pattern,
664 helper_->mock_render_process_id()); 704 helper_->mock_render_process_id());
665 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 705 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
666 worker->AddListener(this); 706 worker->AddListener(this);
667 707
668 // Start the worker. 708 // Start the worker.
669 base::RunLoop run_loop; 709 base::RunLoop run_loop;
670 std::unique_ptr<EmbeddedWorkerStartParams> params = 710 std::unique_ptr<EmbeddedWorkerStartParams> params =
671 CreateStartParams(version_id, pattern, url); 711 CreateStartParams(version_id, pattern, url);
672 worker->Start( 712 worker->Start(
673 std::move(params), CreateEventDispatcher(), 713 std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
674 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); 714 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
675 run_loop.Run(); 715 run_loop.Run();
676 716
677 // Detach. 717 // Detach.
678 int process_id = worker->process_id(); 718 int process_id = worker->process_id();
679 worker->Detach(); 719 worker->Detach();
680 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 720 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
681 721
682 // Send the registry a message from the detached worker. Nothing should 722 // Send the registry a message from the detached worker. Nothing should
683 // happen. 723 // happen.
(...skipping 13 matching lines...) Expand all
697 737
698 std::unique_ptr<EmbeddedWorkerInstance> worker = 738 std::unique_ptr<EmbeddedWorkerInstance> worker =
699 embedded_worker_registry()->CreateWorker(); 739 embedded_worker_registry()->CreateWorker();
700 helper_->SimulateAddProcessToPattern(pattern, 740 helper_->SimulateAddProcessToPattern(pattern,
701 helper_->mock_render_process_id()); 741 helper_->mock_render_process_id());
702 worker->AddListener(this); 742 worker->AddListener(this);
703 743
704 // Attempt to start the worker. 744 // Attempt to start the worker.
705 std::unique_ptr<EmbeddedWorkerStartParams> params = 745 std::unique_ptr<EmbeddedWorkerStartParams> params =
706 CreateStartParams(version_id, pattern, url); 746 CreateStartParams(version_id, pattern, url);
707 worker->Start(std::move(params), CreateEventDispatcher(), 747 worker->Start(std::move(params), CreateProviderInfoGetter(),
748 CreateEventDispatcher(),
708 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 749 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
709 base::RunLoop().RunUntilIdle(); 750 base::RunLoop().RunUntilIdle();
710 751
711 // Worker should handle the failure of binding as detach. 752 // Worker should handle the failure of binding as detach.
712 ASSERT_EQ(2u, events_.size()); 753 ASSERT_EQ(2u, events_.size());
713 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 754 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
714 EXPECT_EQ(DETACHED, events_[1].type); 755 EXPECT_EQ(DETACHED, events_[1].type);
715 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[1].status); 756 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[1].status);
716 } 757 }
717 758
718 class FailEmbeddedWorkerInstanceClientImpl 759 class FailEmbeddedWorkerInstanceClientImpl
719 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { 760 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient {
720 public: 761 public:
721 explicit FailEmbeddedWorkerInstanceClientImpl( 762 explicit FailEmbeddedWorkerInstanceClientImpl(
722 base::WeakPtr<EmbeddedWorkerTestHelper> helper) 763 base::WeakPtr<EmbeddedWorkerTestHelper> helper)
723 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} 764 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {}
724 765
725 private: 766 private:
726 void StartWorker( 767 void StartWorker(const EmbeddedWorkerStartParams&,
727 const EmbeddedWorkerStartParams& /* unused */, 768 mojom::ServiceWorkerEventDispatcherRequest,
728 mojom::ServiceWorkerEventDispatcherRequest /* unused */, 769 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo,
729 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo /* unused */) 770 mojom::ServiceWorkerProviderInfoForStartWorkerPtr) override {
730 override {
731 helper_->mock_instance_clients()->clear(); 771 helper_->mock_instance_clients()->clear();
732 } 772 }
733 }; 773 };
734 774
735 TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) { 775 TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) {
736 const int64_t version_id = 55L; 776 const int64_t version_id = 55L;
737 const GURL pattern("http://example.com/"); 777 const GURL pattern("http://example.com/");
738 const GURL url("http://example.com/worker.js"); 778 const GURL url("http://example.com/worker.js");
739 779
740 // Let StartWorker fail; binding is discarded in the middle of IPC 780 // Let StartWorker fail; binding is discarded in the middle of IPC
741 helper_->RegisterMockInstanceClient( 781 helper_->RegisterMockInstanceClient(
742 base::MakeUnique<FailEmbeddedWorkerInstanceClientImpl>( 782 base::MakeUnique<FailEmbeddedWorkerInstanceClientImpl>(
743 helper_->AsWeakPtr())); 783 helper_->AsWeakPtr()));
744 ASSERT_EQ(mock_instance_clients()->size(), 1UL); 784 ASSERT_EQ(mock_instance_clients()->size(), 1UL);
745 785
746 std::unique_ptr<EmbeddedWorkerInstance> worker = 786 std::unique_ptr<EmbeddedWorkerInstance> worker =
747 embedded_worker_registry()->CreateWorker(); 787 embedded_worker_registry()->CreateWorker();
748 helper_->SimulateAddProcessToPattern(pattern, 788 helper_->SimulateAddProcessToPattern(pattern,
749 helper_->mock_render_process_id()); 789 helper_->mock_render_process_id());
750 worker->AddListener(this); 790 worker->AddListener(this);
751 791
752 // Attempt to start the worker. 792 // Attempt to start the worker.
753 std::unique_ptr<EmbeddedWorkerStartParams> params = 793 std::unique_ptr<EmbeddedWorkerStartParams> params =
754 CreateStartParams(version_id, pattern, url); 794 CreateStartParams(version_id, pattern, url);
755 worker->Start(std::move(params), CreateEventDispatcher(), 795 worker->Start(std::move(params), CreateProviderInfoGetter(),
796 CreateEventDispatcher(),
756 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 797 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
757 base::RunLoop().RunUntilIdle(); 798 base::RunLoop().RunUntilIdle();
758 799
759 // Worker should handle the sudden shutdown as detach. 800 // Worker should handle the sudden shutdown as detach.
760 ASSERT_EQ(3u, events_.size()); 801 ASSERT_EQ(3u, events_.size());
761 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 802 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
762 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 803 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
763 EXPECT_EQ(DETACHED, events_[2].type); 804 EXPECT_EQ(DETACHED, events_[2].type);
764 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status); 805 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status);
765 } 806 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 helper_->SimulateAddProcessToPattern(pattern, 842 helper_->SimulateAddProcessToPattern(pattern,
802 helper_->mock_render_process_id()); 843 helper_->mock_render_process_id());
803 worker->AddListener(this); 844 worker->AddListener(this);
804 845
805 // Attempt to start the worker and immediate AddMessageToConsole should not 846 // Attempt to start the worker and immediate AddMessageToConsole should not
806 // cause a crash. 847 // cause a crash.
807 std::pair<blink::WebConsoleMessage::Level, std::string> test_message = 848 std::pair<blink::WebConsoleMessage::Level, std::string> test_message =
808 std::make_pair(blink::WebConsoleMessage::kLevelVerbose, ""); 849 std::make_pair(blink::WebConsoleMessage::kLevelVerbose, "");
809 std::unique_ptr<EmbeddedWorkerStartParams> params = 850 std::unique_ptr<EmbeddedWorkerStartParams> params =
810 CreateStartParams(version_id, pattern, url); 851 CreateStartParams(version_id, pattern, url);
811 worker->Start(std::move(params), CreateEventDispatcher(), 852 worker->Start(std::move(params), CreateProviderInfoGetter(),
853 CreateEventDispatcher(),
812 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 854 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
813 worker->AddMessageToConsole(test_message.first, test_message.second); 855 worker->AddMessageToConsole(test_message.first, test_message.second);
814 base::RunLoop().RunUntilIdle(); 856 base::RunLoop().RunUntilIdle();
815 857
816 // Messages sent before sending StartWorker message won't be dispatched. 858 // Messages sent before sending StartWorker message won't be dispatched.
817 ASSERT_EQ(0UL, instance_client_rawptr->message().size()); 859 ASSERT_EQ(0UL, instance_client_rawptr->message().size());
818 ASSERT_EQ(3UL, events_.size()); 860 ASSERT_EQ(3UL, events_.size());
819 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 861 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
820 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 862 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
821 EXPECT_EQ(STARTED, events_[2].type); 863 EXPECT_EQ(STARTED, events_[2].type);
822 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); 864 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
823 865
824 worker->AddMessageToConsole(test_message.first, test_message.second); 866 worker->AddMessageToConsole(test_message.first, test_message.second);
825 base::RunLoop().RunUntilIdle(); 867 base::RunLoop().RunUntilIdle();
826 868
827 // Messages sent after sending StartWorker message should be reached to 869 // Messages sent after sending StartWorker message should be reached to
828 // the renderer. 870 // the renderer.
829 ASSERT_EQ(1UL, instance_client_rawptr->message().size()); 871 ASSERT_EQ(1UL, instance_client_rawptr->message().size());
830 EXPECT_EQ(test_message, instance_client_rawptr->message()[0]); 872 EXPECT_EQ(test_message, instance_client_rawptr->message()[0]);
831 873
832 // Ensure the worker is stopped. 874 // Ensure the worker is stopped.
833 worker->Stop(); 875 worker->Stop();
834 base::RunLoop().RunUntilIdle(); 876 base::RunLoop().RunUntilIdle();
835 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 877 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
836 } 878 }
837 879
838 } // namespace content 880 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698