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

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

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

Powered by Google App Engine
This is Rietveld 408576698