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

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

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

Powered by Google App Engine
This is Rietveld 408576698