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

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

Issue 2627543002: ServiceWorker: Returns true for IsMojoForServiceWorkerEnabled (Closed)
Patch Set: Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h> 5 #include <stdint.h>
6 #include <tuple> 6 #include <tuple>
7 7
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK); 136 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK);
137 scoped_refptr<ServiceWorkerRegistration> FindRegistrationForPattern( 137 scoped_refptr<ServiceWorkerRegistration> FindRegistrationForPattern(
138 const GURL& pattern, 138 const GURL& pattern,
139 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK); 139 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK);
140 std::unique_ptr<ServiceWorkerProviderHost> CreateControllee(); 140 std::unique_ptr<ServiceWorkerProviderHost> CreateControllee();
141 141
142 TestBrowserThreadBundle browser_thread_bundle_; 142 TestBrowserThreadBundle browser_thread_bundle_;
143 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 143 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
144 }; 144 };
145 145
146 class ServiceWorkerJobTestP
147 : public MojoServiceWorkerTestP<ServiceWorkerJobTest> {};
148
149 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob( 146 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob(
150 const GURL& pattern, 147 const GURL& pattern,
151 const GURL& script_url, 148 const GURL& script_url,
152 ServiceWorkerStatusCode expected_status) { 149 ServiceWorkerStatusCode expected_status) {
153 scoped_refptr<ServiceWorkerRegistration> registration; 150 scoped_refptr<ServiceWorkerRegistration> registration;
154 bool called; 151 bool called;
155 job_coordinator()->Register( 152 job_coordinator()->Register(
156 pattern, script_url, NULL, 153 pattern, script_url, NULL,
157 SaveRegistration(expected_status, &called, &registration)); 154 SaveRegistration(expected_status, &called, &registration));
158 EXPECT_FALSE(called); 155 EXPECT_FALSE(called);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 ServiceWorkerJobTest::CreateControllee() { 189 ServiceWorkerJobTest::CreateControllee() {
193 return std::unique_ptr<ServiceWorkerProviderHost>( 190 return std::unique_ptr<ServiceWorkerProviderHost>(
194 new ServiceWorkerProviderHost( 191 new ServiceWorkerProviderHost(
195 33 /* dummy render_process id */, 192 33 /* dummy render_process id */,
196 MSG_ROUTING_NONE /* render_frame_id */, 1 /* dummy provider_id */, 193 MSG_ROUTING_NONE /* render_frame_id */, 1 /* dummy provider_id */,
197 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 194 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
198 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 195 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
199 helper_->context()->AsWeakPtr(), NULL)); 196 helper_->context()->AsWeakPtr(), NULL));
200 } 197 }
201 198
202 TEST_P(ServiceWorkerJobTestP, SameDocumentSameRegistration) { 199 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
203 scoped_refptr<ServiceWorkerRegistration> original_registration = 200 scoped_refptr<ServiceWorkerRegistration> original_registration =
204 RunRegisterJob(GURL("http://www.example.com/"), 201 RunRegisterJob(GURL("http://www.example.com/"),
205 GURL("http://www.example.com/service_worker.js")); 202 GURL("http://www.example.com/service_worker.js"));
206 bool called; 203 bool called;
207 scoped_refptr<ServiceWorkerRegistration> registration1; 204 scoped_refptr<ServiceWorkerRegistration> registration1;
208 storage()->FindRegistrationForDocument( 205 storage()->FindRegistrationForDocument(
209 GURL("http://www.example.com/"), 206 GURL("http://www.example.com/"),
210 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1)); 207 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1));
211 scoped_refptr<ServiceWorkerRegistration> registration2; 208 scoped_refptr<ServiceWorkerRegistration> registration2;
212 storage()->FindRegistrationForDocument( 209 storage()->FindRegistrationForDocument(
213 GURL("http://www.example.com/"), 210 GURL("http://www.example.com/"),
214 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2)); 211 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2));
215 base::RunLoop().RunUntilIdle(); 212 base::RunLoop().RunUntilIdle();
216 EXPECT_TRUE(called); 213 EXPECT_TRUE(called);
217 ASSERT_TRUE(registration1.get()); 214 ASSERT_TRUE(registration1.get());
218 ASSERT_EQ(registration1, original_registration); 215 ASSERT_EQ(registration1, original_registration);
219 ASSERT_EQ(registration1, registration2); 216 ASSERT_EQ(registration1, registration2);
220 } 217 }
221 218
222 TEST_P(ServiceWorkerJobTestP, SameMatchSameRegistration) { 219 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
223 bool called; 220 bool called;
224 scoped_refptr<ServiceWorkerRegistration> original_registration = 221 scoped_refptr<ServiceWorkerRegistration> original_registration =
225 RunRegisterJob(GURL("http://www.example.com/"), 222 RunRegisterJob(GURL("http://www.example.com/"),
226 GURL("http://www.example.com/service_worker.js")); 223 GURL("http://www.example.com/service_worker.js"));
227 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), 224 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL),
228 original_registration.get()); 225 original_registration.get());
229 226
230 scoped_refptr<ServiceWorkerRegistration> registration1; 227 scoped_refptr<ServiceWorkerRegistration> registration1;
231 storage()->FindRegistrationForDocument( 228 storage()->FindRegistrationForDocument(
232 GURL("http://www.example.com/one"), 229 GURL("http://www.example.com/one"),
233 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1)); 230 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1));
234 base::RunLoop().RunUntilIdle(); 231 base::RunLoop().RunUntilIdle();
235 EXPECT_TRUE(called); 232 EXPECT_TRUE(called);
236 233
237 scoped_refptr<ServiceWorkerRegistration> registration2; 234 scoped_refptr<ServiceWorkerRegistration> registration2;
238 storage()->FindRegistrationForDocument( 235 storage()->FindRegistrationForDocument(
239 GURL("http://www.example.com/two"), 236 GURL("http://www.example.com/two"),
240 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2)); 237 SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2));
241 base::RunLoop().RunUntilIdle(); 238 base::RunLoop().RunUntilIdle();
242 EXPECT_TRUE(called); 239 EXPECT_TRUE(called);
243 ASSERT_EQ(registration1, original_registration); 240 ASSERT_EQ(registration1, original_registration);
244 ASSERT_EQ(registration1, registration2); 241 ASSERT_EQ(registration1, registration2);
245 } 242 }
246 243
247 TEST_P(ServiceWorkerJobTestP, DifferentMatchDifferentRegistration) { 244 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
248 bool called1; 245 bool called1;
249 scoped_refptr<ServiceWorkerRegistration> original_registration1; 246 scoped_refptr<ServiceWorkerRegistration> original_registration1;
250 job_coordinator()->Register( 247 job_coordinator()->Register(
251 GURL("http://www.example.com/one/"), 248 GURL("http://www.example.com/one/"),
252 GURL("http://www.example.com/service_worker.js"), 249 GURL("http://www.example.com/service_worker.js"),
253 NULL, 250 NULL,
254 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); 251 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1));
255 252
256 bool called2; 253 bool called2;
257 scoped_refptr<ServiceWorkerRegistration> original_registration2; 254 scoped_refptr<ServiceWorkerRegistration> original_registration2;
(...skipping 18 matching lines...) Expand all
276 GURL("http://www.example.com/two/"), 273 GURL("http://www.example.com/two/"),
277 SaveFoundRegistration(SERVICE_WORKER_OK, &called2, &registration2)); 274 SaveFoundRegistration(SERVICE_WORKER_OK, &called2, &registration2));
278 275
279 base::RunLoop().RunUntilIdle(); 276 base::RunLoop().RunUntilIdle();
280 EXPECT_TRUE(called2); 277 EXPECT_TRUE(called2);
281 EXPECT_TRUE(called1); 278 EXPECT_TRUE(called1);
282 ASSERT_NE(registration1, registration2); 279 ASSERT_NE(registration1, registration2);
283 } 280 }
284 281
285 // Make sure basic registration is working. 282 // Make sure basic registration is working.
286 TEST_P(ServiceWorkerJobTestP, Register) { 283 TEST_F(ServiceWorkerJobTest, Register) {
287 scoped_refptr<ServiceWorkerRegistration> registration = 284 scoped_refptr<ServiceWorkerRegistration> registration =
288 RunRegisterJob(GURL("http://www.example.com/"), 285 RunRegisterJob(GURL("http://www.example.com/"),
289 GURL("http://www.example.com/service_worker.js")); 286 GURL("http://www.example.com/service_worker.js"));
290 287
291 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 288 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration);
292 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 289 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
293 ServiceWorkerMsg_InstallEvent::ID)); 290 ServiceWorkerMsg_InstallEvent::ID));
294 } 291 }
295 292
296 // Make sure registrations are cleaned up when they are unregistered. 293 // Make sure registrations are cleaned up when they are unregistered.
297 TEST_P(ServiceWorkerJobTestP, Unregister) { 294 TEST_F(ServiceWorkerJobTest, Unregister) {
298 GURL pattern("http://www.example.com/"); 295 GURL pattern("http://www.example.com/");
299 296
300 scoped_refptr<ServiceWorkerRegistration> registration = 297 scoped_refptr<ServiceWorkerRegistration> registration =
301 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); 298 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js"));
302 299
303 RunUnregisterJob(pattern); 300 RunUnregisterJob(pattern);
304 301
305 ASSERT_TRUE(registration->HasOneRef()); 302 ASSERT_TRUE(registration->HasOneRef());
306 303
307 registration = FindRegistrationForPattern(pattern, 304 registration = FindRegistrationForPattern(pattern,
308 SERVICE_WORKER_ERROR_NOT_FOUND); 305 SERVICE_WORKER_ERROR_NOT_FOUND);
309 306
310 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 307 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration);
311 } 308 }
312 309
313 TEST_P(ServiceWorkerJobTestP, Unregister_NothingRegistered) { 310 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) {
314 GURL pattern("http://www.example.com/"); 311 GURL pattern("http://www.example.com/");
315 312
316 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); 313 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND);
317 } 314 }
318 315
319 // Make sure registering a new script creates a new version and shares an 316 // Make sure registering a new script creates a new version and shares an
320 // existing registration. 317 // existing registration.
321 TEST_P(ServiceWorkerJobTestP, RegisterNewScript) { 318 TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
322 GURL pattern("http://www.example.com/"); 319 GURL pattern("http://www.example.com/");
323 320
324 scoped_refptr<ServiceWorkerRegistration> old_registration = 321 scoped_refptr<ServiceWorkerRegistration> old_registration =
325 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); 322 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js"));
326 323
327 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = 324 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern =
328 FindRegistrationForPattern(pattern); 325 FindRegistrationForPattern(pattern);
329 326
330 ASSERT_EQ(old_registration, old_registration_by_pattern); 327 ASSERT_EQ(old_registration, old_registration_by_pattern);
331 old_registration_by_pattern = NULL; 328 old_registration_by_pattern = NULL;
332 329
333 scoped_refptr<ServiceWorkerRegistration> new_registration = 330 scoped_refptr<ServiceWorkerRegistration> new_registration =
334 RunRegisterJob(pattern, 331 RunRegisterJob(pattern,
335 GURL("http://www.example.com/service_worker_new.js")); 332 GURL("http://www.example.com/service_worker_new.js"));
336 333
337 ASSERT_EQ(old_registration, new_registration); 334 ASSERT_EQ(old_registration, new_registration);
338 335
339 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = 336 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern =
340 FindRegistrationForPattern(pattern); 337 FindRegistrationForPattern(pattern);
341 338
342 ASSERT_EQ(new_registration, new_registration_by_pattern); 339 ASSERT_EQ(new_registration, new_registration_by_pattern);
343 } 340 }
344 341
345 // Make sure that when registering a duplicate pattern+script_url 342 // Make sure that when registering a duplicate pattern+script_url
346 // combination, that the same registration is used. 343 // combination, that the same registration is used.
347 TEST_P(ServiceWorkerJobTestP, RegisterDuplicateScript) { 344 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
348 GURL pattern("http://www.example.com/"); 345 GURL pattern("http://www.example.com/");
349 GURL script_url("http://www.example.com/service_worker.js"); 346 GURL script_url("http://www.example.com/service_worker.js");
350 347
351 scoped_refptr<ServiceWorkerRegistration> old_registration = 348 scoped_refptr<ServiceWorkerRegistration> old_registration =
352 RunRegisterJob(pattern, script_url); 349 RunRegisterJob(pattern, script_url);
353 350
354 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = 351 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern =
355 FindRegistrationForPattern(pattern); 352 FindRegistrationForPattern(pattern);
356 353
357 ASSERT_TRUE(old_registration_by_pattern.get()); 354 ASSERT_TRUE(old_registration_by_pattern.get());
(...skipping 18 matching lines...) Expand all
376 void OnStartWorker(int embedded_worker_id, 373 void OnStartWorker(int embedded_worker_id,
377 int64_t service_worker_version_id, 374 int64_t service_worker_version_id,
378 const GURL& scope, 375 const GURL& scope,
379 const GURL& script_url, 376 const GURL& script_url,
380 bool pause_after_download) override { 377 bool pause_after_download) override {
381 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 378 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
382 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); 379 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id);
383 } 380 }
384 }; 381 };
385 382
386 TEST_P(ServiceWorkerJobTestP, Register_FailToStartWorker) { 383 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
387 helper_.reset(new FailToStartWorkerTestHelper); 384 helper_.reset(new FailToStartWorkerTestHelper);
388 385
389 scoped_refptr<ServiceWorkerRegistration> registration = 386 scoped_refptr<ServiceWorkerRegistration> registration =
390 RunRegisterJob(GURL("http://www.example.com/"), 387 RunRegisterJob(GURL("http://www.example.com/"),
391 GURL("http://www.example.com/service_worker.js"), 388 GURL("http://www.example.com/service_worker.js"),
392 SERVICE_WORKER_ERROR_START_WORKER_FAILED); 389 SERVICE_WORKER_ERROR_START_WORKER_FAILED);
393 390
394 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 391 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration);
395 } 392 }
396 393
397 // Register and then unregister the pattern, in parallel. Job coordinator should 394 // Register and then unregister the pattern, in parallel. Job coordinator should
398 // process jobs until the last job. 395 // process jobs until the last job.
399 TEST_P(ServiceWorkerJobTestP, ParallelRegUnreg) { 396 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) {
400 GURL pattern("http://www.example.com/"); 397 GURL pattern("http://www.example.com/");
401 GURL script_url("http://www.example.com/service_worker.js"); 398 GURL script_url("http://www.example.com/service_worker.js");
402 399
403 bool registration_called = false; 400 bool registration_called = false;
404 scoped_refptr<ServiceWorkerRegistration> registration; 401 scoped_refptr<ServiceWorkerRegistration> registration;
405 job_coordinator()->Register( 402 job_coordinator()->Register(
406 pattern, 403 pattern,
407 script_url, 404 script_url,
408 NULL, 405 NULL,
409 SaveRegistration(SERVICE_WORKER_OK, &registration_called, &registration)); 406 SaveRegistration(SERVICE_WORKER_OK, &registration_called, &registration));
(...skipping 11 matching lines...) Expand all
421 418
422 registration = FindRegistrationForPattern(pattern, 419 registration = FindRegistrationForPattern(pattern,
423 SERVICE_WORKER_ERROR_NOT_FOUND); 420 SERVICE_WORKER_ERROR_NOT_FOUND);
424 421
425 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); 422 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
426 } 423 }
427 424
428 // Register conflicting scripts for the same pattern. The most recent 425 // Register conflicting scripts for the same pattern. The most recent
429 // registration should win, and the old registration should have been 426 // registration should win, and the old registration should have been
430 // shutdown. 427 // shutdown.
431 TEST_P(ServiceWorkerJobTestP, ParallelRegNewScript) { 428 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
432 GURL pattern("http://www.example.com/"); 429 GURL pattern("http://www.example.com/");
433 430
434 GURL script_url1("http://www.example.com/service_worker1.js"); 431 GURL script_url1("http://www.example.com/service_worker1.js");
435 bool registration1_called = false; 432 bool registration1_called = false;
436 scoped_refptr<ServiceWorkerRegistration> registration1; 433 scoped_refptr<ServiceWorkerRegistration> registration1;
437 job_coordinator()->Register( 434 job_coordinator()->Register(
438 pattern, 435 pattern,
439 script_url1, 436 script_url1,
440 NULL, 437 NULL,
441 SaveRegistration( 438 SaveRegistration(
(...skipping 17 matching lines...) Expand all
459 456
460 scoped_refptr<ServiceWorkerRegistration> registration = 457 scoped_refptr<ServiceWorkerRegistration> registration =
461 FindRegistrationForPattern(pattern); 458 FindRegistrationForPattern(pattern);
462 459
463 ASSERT_EQ(registration2, registration); 460 ASSERT_EQ(registration2, registration);
464 } 461 }
465 462
466 // Register the exact same pattern + script. Requests should be 463 // Register the exact same pattern + script. Requests should be
467 // coalesced such that both callers get the exact same registration 464 // coalesced such that both callers get the exact same registration
468 // object. 465 // object.
469 TEST_P(ServiceWorkerJobTestP, ParallelRegSameScript) { 466 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) {
470 GURL pattern("http://www.example.com/"); 467 GURL pattern("http://www.example.com/");
471 468
472 GURL script_url("http://www.example.com/service_worker1.js"); 469 GURL script_url("http://www.example.com/service_worker1.js");
473 bool registration1_called = false; 470 bool registration1_called = false;
474 scoped_refptr<ServiceWorkerRegistration> registration1; 471 scoped_refptr<ServiceWorkerRegistration> registration1;
475 job_coordinator()->Register( 472 job_coordinator()->Register(
476 pattern, 473 pattern,
477 script_url, 474 script_url,
478 NULL, 475 NULL,
479 SaveRegistration( 476 SaveRegistration(
(...skipping 16 matching lines...) Expand all
496 493
497 ASSERT_EQ(registration1, registration2); 494 ASSERT_EQ(registration1, registration2);
498 495
499 scoped_refptr<ServiceWorkerRegistration> registration = 496 scoped_refptr<ServiceWorkerRegistration> registration =
500 FindRegistrationForPattern(pattern); 497 FindRegistrationForPattern(pattern);
501 498
502 ASSERT_EQ(registration, registration1); 499 ASSERT_EQ(registration, registration1);
503 } 500 }
504 501
505 // Call simulataneous unregister calls. 502 // Call simulataneous unregister calls.
506 TEST_P(ServiceWorkerJobTestP, ParallelUnreg) { 503 TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
507 GURL pattern("http://www.example.com/"); 504 GURL pattern("http://www.example.com/");
508 505
509 GURL script_url("http://www.example.com/service_worker.js"); 506 GURL script_url("http://www.example.com/service_worker.js");
510 bool unregistration1_called = false; 507 bool unregistration1_called = false;
511 job_coordinator()->Unregister( 508 job_coordinator()->Unregister(
512 pattern, 509 pattern,
513 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, 510 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND,
514 &unregistration1_called)); 511 &unregistration1_called));
515 512
516 bool unregistration2_called = false; 513 bool unregistration2_called = false;
(...skipping 10 matching lines...) Expand all
527 524
528 // There isn't really a way to test that they are being coalesced, 525 // There isn't really a way to test that they are being coalesced,
529 // but we can make sure they can exist simultaneously without 526 // but we can make sure they can exist simultaneously without
530 // crashing. 527 // crashing.
531 scoped_refptr<ServiceWorkerRegistration> registration = 528 scoped_refptr<ServiceWorkerRegistration> registration =
532 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); 529 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND);
533 530
534 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); 531 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
535 } 532 }
536 533
537 TEST_P(ServiceWorkerJobTestP, AbortAll_Register) { 534 TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
538 GURL pattern1("http://www1.example.com/"); 535 GURL pattern1("http://www1.example.com/");
539 GURL pattern2("http://www2.example.com/"); 536 GURL pattern2("http://www2.example.com/");
540 GURL script_url1("http://www1.example.com/service_worker.js"); 537 GURL script_url1("http://www1.example.com/service_worker.js");
541 GURL script_url2("http://www2.example.com/service_worker.js"); 538 GURL script_url2("http://www2.example.com/service_worker.js");
542 539
543 bool registration_called1 = false; 540 bool registration_called1 = false;
544 scoped_refptr<ServiceWorkerRegistration> registration1; 541 scoped_refptr<ServiceWorkerRegistration> registration1;
545 job_coordinator()->Register( 542 job_coordinator()->Register(
546 pattern1, 543 pattern1,
547 script_url1, 544 script_url1,
(...skipping 30 matching lines...) Expand all
578 SaveFoundRegistration( 575 SaveFoundRegistration(
579 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called2, &registration2)); 576 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called2, &registration2));
580 577
581 base::RunLoop().RunUntilIdle(); 578 base::RunLoop().RunUntilIdle();
582 ASSERT_TRUE(find_called1); 579 ASSERT_TRUE(find_called1);
583 ASSERT_TRUE(find_called2); 580 ASSERT_TRUE(find_called2);
584 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1); 581 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1);
585 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2); 582 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2);
586 } 583 }
587 584
588 TEST_P(ServiceWorkerJobTestP, AbortAll_Unregister) { 585 TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
589 GURL pattern1("http://www1.example.com/"); 586 GURL pattern1("http://www1.example.com/");
590 GURL pattern2("http://www2.example.com/"); 587 GURL pattern2("http://www2.example.com/");
591 588
592 bool unregistration_called1 = false; 589 bool unregistration_called1 = false;
593 scoped_refptr<ServiceWorkerRegistration> registration1; 590 scoped_refptr<ServiceWorkerRegistration> registration1;
594 job_coordinator()->Unregister( 591 job_coordinator()->Unregister(
595 pattern1, 592 pattern1,
596 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, 593 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT,
597 &unregistration_called1)); 594 &unregistration_called1));
598 595
599 bool unregistration_called2 = false; 596 bool unregistration_called2 = false;
600 job_coordinator()->Unregister( 597 job_coordinator()->Unregister(
601 pattern2, 598 pattern2,
602 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, 599 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT,
603 &unregistration_called2)); 600 &unregistration_called2));
604 601
605 ASSERT_FALSE(unregistration_called1); 602 ASSERT_FALSE(unregistration_called1);
606 ASSERT_FALSE(unregistration_called2); 603 ASSERT_FALSE(unregistration_called2);
607 job_coordinator()->AbortAll(); 604 job_coordinator()->AbortAll();
608 605
609 base::RunLoop().RunUntilIdle(); 606 base::RunLoop().RunUntilIdle();
610 ASSERT_TRUE(unregistration_called1); 607 ASSERT_TRUE(unregistration_called1);
611 ASSERT_TRUE(unregistration_called2); 608 ASSERT_TRUE(unregistration_called2);
612 } 609 }
613 610
614 TEST_P(ServiceWorkerJobTestP, AbortAll_RegUnreg) { 611 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
615 GURL pattern("http://www.example.com/"); 612 GURL pattern("http://www.example.com/");
616 GURL script_url("http://www.example.com/service_worker.js"); 613 GURL script_url("http://www.example.com/service_worker.js");
617 614
618 bool registration_called = false; 615 bool registration_called = false;
619 scoped_refptr<ServiceWorkerRegistration> registration; 616 scoped_refptr<ServiceWorkerRegistration> registration;
620 job_coordinator()->Register( 617 job_coordinator()->Register(
621 pattern, 618 pattern,
622 script_url, 619 script_url,
623 NULL, 620 NULL,
624 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, 621 SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
(...skipping 14 matching lines...) Expand all
639 ASSERT_TRUE(unregistration_called); 636 ASSERT_TRUE(unregistration_called);
640 637
641 registration = FindRegistrationForPattern(pattern, 638 registration = FindRegistrationForPattern(pattern,
642 SERVICE_WORKER_ERROR_NOT_FOUND); 639 SERVICE_WORKER_ERROR_NOT_FOUND);
643 640
644 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); 641 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
645 } 642 }
646 643
647 // Tests that the waiting worker enters the 'redundant' state upon 644 // Tests that the waiting worker enters the 'redundant' state upon
648 // unregistration. 645 // unregistration.
649 TEST_P(ServiceWorkerJobTestP, UnregisterWaitingSetsRedundant) { 646 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
650 GURL script_url("http://www.example.com/service_worker.js"); 647 GURL script_url("http://www.example.com/service_worker.js");
651 scoped_refptr<ServiceWorkerRegistration> registration = 648 scoped_refptr<ServiceWorkerRegistration> registration =
652 RunRegisterJob(GURL("http://www.example.com/"), script_url); 649 RunRegisterJob(GURL("http://www.example.com/"), script_url);
653 ASSERT_TRUE(registration.get()); 650 ASSERT_TRUE(registration.get());
654 651
655 // Manually create the waiting worker since there is no way to become a 652 // Manually create the waiting worker since there is no way to become a
656 // waiting worker until Update is implemented. 653 // waiting worker until Update is implemented.
657 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 654 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
658 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); 655 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr());
659 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 656 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
(...skipping 12 matching lines...) Expand all
672 RunUnregisterJob(GURL("http://www.example.com/")); 669 RunUnregisterJob(GURL("http://www.example.com/"));
673 670
674 // The version should be stopped since there is no controllee after 671 // The version should be stopped since there is no controllee after
675 // unregistration. 672 // unregistration.
676 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); 673 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status());
677 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); 674 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
678 } 675 }
679 676
680 // Tests that the active worker enters the 'redundant' state upon 677 // Tests that the active worker enters the 'redundant' state upon
681 // unregistration. 678 // unregistration.
682 TEST_P(ServiceWorkerJobTestP, UnregisterActiveSetsRedundant) { 679 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
683 scoped_refptr<ServiceWorkerRegistration> registration = 680 scoped_refptr<ServiceWorkerRegistration> registration =
684 RunRegisterJob(GURL("http://www.example.com/"), 681 RunRegisterJob(GURL("http://www.example.com/"),
685 GURL("http://www.example.com/service_worker.js")); 682 GURL("http://www.example.com/service_worker.js"));
686 ASSERT_TRUE(registration.get()); 683 ASSERT_TRUE(registration.get());
687 684
688 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); 685 scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
689 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); 686 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status());
690 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); 687 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
691 688
692 RunUnregisterJob(GURL("http://www.example.com/")); 689 RunUnregisterJob(GURL("http://www.example.com/"));
693 690
694 // The version should be stopped since there is no controllee after 691 // The version should be stopped since there is no controllee after
695 // unregistration. 692 // unregistration.
696 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); 693 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status());
697 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); 694 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
698 } 695 }
699 696
700 // Tests that the active worker enters the 'redundant' state upon 697 // Tests that the active worker enters the 'redundant' state upon
701 // unregistration. 698 // unregistration.
702 TEST_P(ServiceWorkerJobTestP, 699 TEST_F(ServiceWorkerJobTest,
703 UnregisterActiveSetsRedundant_WaitForNoControllee) { 700 UnregisterActiveSetsRedundant_WaitForNoControllee) {
704 scoped_refptr<ServiceWorkerRegistration> registration = 701 scoped_refptr<ServiceWorkerRegistration> registration =
705 RunRegisterJob(GURL("http://www.example.com/"), 702 RunRegisterJob(GURL("http://www.example.com/"),
706 GURL("http://www.example.com/service_worker.js")); 703 GURL("http://www.example.com/service_worker.js"));
707 ASSERT_TRUE(registration.get()); 704 ASSERT_TRUE(registration.get());
708 705
709 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); 706 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
710 registration->active_version()->AddControllee(host.get()); 707 registration->active_version()->AddControllee(host.get());
711 708
712 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); 709 scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 961
965 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { 962 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override {
966 registration_failed_ = true; 963 registration_failed_ = true;
967 } 964 }
968 965
969 bool registration_failed_ = false; 966 bool registration_failed_ = false;
970 }; 967 };
971 968
972 } // namespace 969 } // namespace
973 970
974 TEST_P(ServiceWorkerJobTestP, Update_NoChange) { 971 TEST_F(ServiceWorkerJobTest, Update_NoChange) {
975 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; 972 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
976 helper_.reset(update_helper); 973 helper_.reset(update_helper);
977 scoped_refptr<ServiceWorkerRegistration> registration = 974 scoped_refptr<ServiceWorkerRegistration> registration =
978 update_helper->SetupInitialRegistration(kNoChangeOrigin); 975 update_helper->SetupInitialRegistration(kNoChangeOrigin);
979 ASSERT_TRUE(registration.get()); 976 ASSERT_TRUE(registration.get());
980 ASSERT_EQ(4u, update_helper->state_change_log_.size()); 977 ASSERT_EQ(4u, update_helper->state_change_log_.size());
981 EXPECT_EQ(ServiceWorkerVersion::INSTALLING, 978 EXPECT_EQ(ServiceWorkerVersion::INSTALLING,
982 update_helper->state_change_log_[0].status); 979 update_helper->state_change_log_[0].status);
983 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, 980 EXPECT_EQ(ServiceWorkerVersion::INSTALLED,
984 update_helper->state_change_log_[1].status); 981 update_helper->state_change_log_[1].status);
(...skipping 17 matching lines...) Expand all
1002 EXPECT_FALSE(registration->waiting_version()); 999 EXPECT_FALSE(registration->waiting_version());
1003 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); 1000 EXPECT_TRUE(update_helper->attribute_change_log_.empty());
1004 ASSERT_EQ(1u, update_helper->state_change_log_.size()); 1001 ASSERT_EQ(1u, update_helper->state_change_log_.size());
1005 EXPECT_NE(registration->active_version()->version_id(), 1002 EXPECT_NE(registration->active_version()->version_id(),
1006 update_helper->state_change_log_[0].version_id); 1003 update_helper->state_change_log_[0].version_id);
1007 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, 1004 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT,
1008 update_helper->state_change_log_[0].status); 1005 update_helper->state_change_log_[0].status);
1009 EXPECT_FALSE(update_helper->update_found_); 1006 EXPECT_FALSE(update_helper->update_found_);
1010 } 1007 }
1011 1008
1012 TEST_P(ServiceWorkerJobTestP, Update_BumpLastUpdateCheckTime) { 1009 TEST_F(ServiceWorkerJobTest, Update_BumpLastUpdateCheckTime) {
1013 const base::Time kToday = base::Time::Now(); 1010 const base::Time kToday = base::Time::Now();
1014 const base::Time kYesterday = 1011 const base::Time kYesterday =
1015 kToday - base::TimeDelta::FromDays(1) - base::TimeDelta::FromHours(1); 1012 kToday - base::TimeDelta::FromDays(1) - base::TimeDelta::FromHours(1);
1016 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; 1013 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
1017 helper_.reset(update_helper); 1014 helper_.reset(update_helper);
1018 scoped_refptr<ServiceWorkerRegistration> registration = 1015 scoped_refptr<ServiceWorkerRegistration> registration =
1019 update_helper->SetupInitialRegistration(kNoChangeOrigin); 1016 update_helper->SetupInitialRegistration(kNoChangeOrigin);
1020 ASSERT_TRUE(registration.get()); 1017 ASSERT_TRUE(registration.get());
1021 1018
1022 registration->AddListener(update_helper); 1019 registration->AddListener(update_helper);
(...skipping 28 matching lines...) Expand all
1051 1048
1052 // Run an update to a worker that loads successfully but fails to start up 1049 // Run an update to a worker that loads successfully but fails to start up
1053 // (script evaluation failure). The check time should be updated. 1050 // (script evaluation failure). The check time should be updated.
1054 update_helper->set_force_start_worker_failure(true); 1051 update_helper->set_force_start_worker_failure(true);
1055 registration->set_last_update_check(kYesterday); 1052 registration->set_last_update_check(kYesterday);
1056 registration->active_version()->StartUpdate(); 1053 registration->active_version()->StartUpdate();
1057 base::RunLoop().RunUntilIdle(); 1054 base::RunLoop().RunUntilIdle();
1058 EXPECT_LT(kYesterday, registration->last_update_check()); 1055 EXPECT_LT(kYesterday, registration->last_update_check());
1059 } 1056 }
1060 1057
1061 TEST_P(ServiceWorkerJobTestP, Update_NewVersion) { 1058 TEST_F(ServiceWorkerJobTest, Update_NewVersion) {
1062 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; 1059 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
1063 helper_.reset(update_helper); 1060 helper_.reset(update_helper);
1064 scoped_refptr<ServiceWorkerRegistration> registration = 1061 scoped_refptr<ServiceWorkerRegistration> registration =
1065 update_helper->SetupInitialRegistration(kNewVersionOrigin); 1062 update_helper->SetupInitialRegistration(kNewVersionOrigin);
1066 ASSERT_TRUE(registration.get()); 1063 ASSERT_TRUE(registration.get());
1067 update_helper->state_change_log_.clear(); 1064 update_helper->state_change_log_.clear();
1068 1065
1069 // Run the update job. 1066 // Run the update job.
1070 registration->AddListener(update_helper); 1067 registration->AddListener(update_helper);
1071 scoped_refptr<ServiceWorkerVersion> first_version = 1068 scoped_refptr<ServiceWorkerVersion> first_version =
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 EXPECT_EQ(registration->active_version()->version_id(), 1140 EXPECT_EQ(registration->active_version()->version_id(),
1144 update_helper->state_change_log_[4].version_id); 1141 update_helper->state_change_log_[4].version_id);
1145 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, 1142 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED,
1146 update_helper->state_change_log_[4].status); 1143 update_helper->state_change_log_[4].status);
1147 1144
1148 EXPECT_TRUE(update_helper->update_found_); 1145 EXPECT_TRUE(update_helper->update_found_);
1149 } 1146 }
1150 1147
1151 // Test that the update job uses the script URL of the newest worker when the 1148 // Test that the update job uses the script URL of the newest worker when the
1152 // job starts, rather than when it is scheduled. 1149 // job starts, rather than when it is scheduled.
1153 TEST_P(ServiceWorkerJobTestP, Update_ScriptUrlChanged) { 1150 TEST_F(ServiceWorkerJobTest, Update_ScriptUrlChanged) {
1154 // Create a registration with an active version. 1151 // Create a registration with an active version.
1155 scoped_refptr<ServiceWorkerRegistration> registration = 1152 scoped_refptr<ServiceWorkerRegistration> registration =
1156 RunRegisterJob(GURL("http://www.example.com/one/"), 1153 RunRegisterJob(GURL("http://www.example.com/one/"),
1157 GURL("http://www.example.com/service_worker.js")); 1154 GURL("http://www.example.com/service_worker.js"));
1158 1155
1159 // Queue an Update. When this runs, it will use the waiting version's script. 1156 // Queue an Update. When this runs, it will use the waiting version's script.
1160 job_coordinator()->Update(registration.get(), false); 1157 job_coordinator()->Update(registration.get(), false);
1161 1158
1162 // Add a waiting version with a new script. 1159 // Add a waiting version with a new script.
1163 GURL new_script("http://www.example.com/new_worker.js"); 1160 GURL new_script("http://www.example.com/new_worker.js");
1164 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 1161 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
1165 registration.get(), new_script, 2L /* dummy version id */, 1162 registration.get(), new_script, 2L /* dummy version id */,
1166 helper_->context()->AsWeakPtr()); 1163 helper_->context()->AsWeakPtr());
1167 registration->SetWaitingVersion(version); 1164 registration->SetWaitingVersion(version);
1168 1165
1169 // Run the update job. 1166 // Run the update job.
1170 base::RunLoop().RunUntilIdle(); 1167 base::RunLoop().RunUntilIdle();
1171 1168
1172 // The update job should have created a new version with the new script, 1169 // The update job should have created a new version with the new script,
1173 // and promoted it to the active version. 1170 // and promoted it to the active version.
1174 EXPECT_EQ(new_script, registration->active_version()->script_url()); 1171 EXPECT_EQ(new_script, registration->active_version()->script_url());
1175 EXPECT_EQ(nullptr, registration->waiting_version()); 1172 EXPECT_EQ(nullptr, registration->waiting_version());
1176 EXPECT_EQ(nullptr, registration->installing_version()); 1173 EXPECT_EQ(nullptr, registration->installing_version());
1177 } 1174 }
1178 1175
1179 // Test that update succeeds if the incumbent worker was evicted 1176 // Test that update succeeds if the incumbent worker was evicted
1180 // during the update job (this can happen on disk cache failure). 1177 // during the update job (this can happen on disk cache failure).
1181 TEST_P(ServiceWorkerJobTestP, Update_EvictedIncumbent) { 1178 TEST_F(ServiceWorkerJobTest, Update_EvictedIncumbent) {
1182 EvictIncumbentVersionHelper* update_helper = new EvictIncumbentVersionHelper; 1179 EvictIncumbentVersionHelper* update_helper = new EvictIncumbentVersionHelper;
1183 helper_.reset(update_helper); 1180 helper_.reset(update_helper);
1184 scoped_refptr<ServiceWorkerRegistration> registration = 1181 scoped_refptr<ServiceWorkerRegistration> registration =
1185 update_helper->SetupInitialRegistration(kNewVersionOrigin); 1182 update_helper->SetupInitialRegistration(kNewVersionOrigin);
1186 ASSERT_TRUE(registration.get()); 1183 ASSERT_TRUE(registration.get());
1187 update_helper->state_change_log_.clear(); 1184 update_helper->state_change_log_.clear();
1188 1185
1189 // Run the update job. 1186 // Run the update job.
1190 registration->AddListener(update_helper); 1187 registration->AddListener(update_helper);
1191 scoped_refptr<ServiceWorkerVersion> first_version = 1188 scoped_refptr<ServiceWorkerVersion> first_version =
1192 registration->active_version(); 1189 registration->active_version();
1193 first_version->StartUpdate(); 1190 first_version->StartUpdate();
1194 base::RunLoop().RunUntilIdle(); 1191 base::RunLoop().RunUntilIdle();
1195 1192
1196 // Verify results. 1193 // Verify results.
1197 ASSERT_TRUE(registration->active_version()); 1194 ASSERT_TRUE(registration->active_version());
1198 EXPECT_NE(first_version.get(), registration->active_version()); 1195 EXPECT_NE(first_version.get(), registration->active_version());
1199 EXPECT_FALSE(registration->installing_version()); 1196 EXPECT_FALSE(registration->installing_version());
1200 EXPECT_FALSE(registration->waiting_version()); 1197 EXPECT_FALSE(registration->waiting_version());
1201 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, first_version->status()); 1198 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, first_version->status());
1202 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, 1199 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED,
1203 registration->active_version()->status()); 1200 registration->active_version()->status());
1204 ASSERT_EQ(4u, update_helper->attribute_change_log_.size()); 1201 ASSERT_EQ(4u, update_helper->attribute_change_log_.size());
1205 EXPECT_TRUE(update_helper->update_found_); 1202 EXPECT_TRUE(update_helper->update_found_);
1206 EXPECT_TRUE(update_helper->registration_failed_); 1203 EXPECT_TRUE(update_helper->registration_failed_);
1207 EXPECT_FALSE(registration->is_uninstalled()); 1204 EXPECT_FALSE(registration->is_uninstalled());
1208 } 1205 }
1209 1206
1210 TEST_P(ServiceWorkerJobTestP, Update_UninstallingRegistration) { 1207 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) {
1211 bool called; 1208 bool called;
1212 scoped_refptr<ServiceWorkerRegistration> registration = 1209 scoped_refptr<ServiceWorkerRegistration> registration =
1213 RunRegisterJob(GURL("http://www.example.com/one/"), 1210 RunRegisterJob(GURL("http://www.example.com/one/"),
1214 GURL("http://www.example.com/service_worker.js")); 1211 GURL("http://www.example.com/service_worker.js"));
1215 1212
1216 // Add a controllee and queue an unregister to force the uninstalling state. 1213 // Add a controllee and queue an unregister to force the uninstalling state.
1217 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); 1214 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
1218 ServiceWorkerVersion* active_version = registration->active_version(); 1215 ServiceWorkerVersion* active_version = registration->active_version();
1219 active_version->AddControllee(host.get()); 1216 active_version->AddControllee(host.get());
1220 job_coordinator()->Unregister(GURL("http://www.example.com/one/"), 1217 job_coordinator()->Unregister(GURL("http://www.example.com/one/"),
1221 SaveUnregistration(SERVICE_WORKER_OK, &called)); 1218 SaveUnregistration(SERVICE_WORKER_OK, &called));
1222 1219
1223 // Update should abort after it starts and sees uninstalling. 1220 // Update should abort after it starts and sees uninstalling.
1224 job_coordinator()->Update(registration.get(), false); 1221 job_coordinator()->Update(registration.get(), false);
1225 1222
1226 EXPECT_FALSE(called); 1223 EXPECT_FALSE(called);
1227 base::RunLoop().RunUntilIdle(); 1224 base::RunLoop().RunUntilIdle();
1228 EXPECT_TRUE(called); 1225 EXPECT_TRUE(called);
1229 1226
1230 // Verify the registration was not modified by the Update. 1227 // Verify the registration was not modified by the Update.
1231 EXPECT_TRUE(registration->is_uninstalling()); 1228 EXPECT_TRUE(registration->is_uninstalling());
1232 EXPECT_EQ(active_version, registration->active_version()); 1229 EXPECT_EQ(active_version, registration->active_version());
1233 EXPECT_EQ(NULL, registration->waiting_version()); 1230 EXPECT_EQ(NULL, registration->waiting_version());
1234 EXPECT_EQ(NULL, registration->installing_version()); 1231 EXPECT_EQ(NULL, registration->installing_version());
1235 } 1232 }
1236 1233
1237 TEST_P(ServiceWorkerJobTestP, RegisterWhileUninstalling) { 1234 TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) {
1238 GURL pattern("http://www.example.com/one/"); 1235 GURL pattern("http://www.example.com/one/");
1239 GURL script1("http://www.example.com/service_worker.js"); 1236 GURL script1("http://www.example.com/service_worker.js");
1240 GURL script2("http://www.example.com/service_worker.js?new"); 1237 GURL script2("http://www.example.com/service_worker.js?new");
1241 1238
1242 scoped_refptr<ServiceWorkerRegistration> registration = 1239 scoped_refptr<ServiceWorkerRegistration> registration =
1243 RunRegisterJob(pattern, script1); 1240 RunRegisterJob(pattern, script1);
1244 scoped_refptr<base::TestSimpleTaskRunner> runner( 1241 scoped_refptr<base::TestSimpleTaskRunner> runner(
1245 new base::TestSimpleTaskRunner()); 1242 new base::TestSimpleTaskRunner());
1246 registration->SetTaskRunnerForTest(runner); 1243 registration->SetTaskRunnerForTest(runner);
1247 1244
(...skipping 30 matching lines...) Expand all
1278 EXPECT_EQ(NULL, registration->waiting_version()); 1275 EXPECT_EQ(NULL, registration->waiting_version());
1279 EXPECT_EQ(new_version, registration->active_version()); 1276 EXPECT_EQ(new_version, registration->active_version());
1280 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); 1277 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1281 1278
1282 runner->RunUntilIdle(); 1279 runner->RunUntilIdle();
1283 base::RunLoop().RunUntilIdle(); 1280 base::RunLoop().RunUntilIdle();
1284 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); 1281 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status());
1285 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); 1282 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status());
1286 } 1283 }
1287 1284
1288 TEST_P(ServiceWorkerJobTestP, RegisterAndUnregisterWhileUninstalling) { 1285 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
1289 GURL pattern("http://www.example.com/one/"); 1286 GURL pattern("http://www.example.com/one/");
1290 GURL script1("http://www.example.com/service_worker.js"); 1287 GURL script1("http://www.example.com/service_worker.js");
1291 GURL script2("http://www.example.com/service_worker.js?new"); 1288 GURL script2("http://www.example.com/service_worker.js?new");
1292 1289
1293 scoped_refptr<ServiceWorkerRegistration> registration = 1290 scoped_refptr<ServiceWorkerRegistration> registration =
1294 RunRegisterJob(pattern, script1); 1291 RunRegisterJob(pattern, script1);
1295 1292
1296 // Add a controllee and queue an unregister to force the uninstalling state. 1293 // Add a controllee and queue an unregister to force the uninstalling state.
1297 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); 1294 std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
1298 scoped_refptr<ServiceWorkerVersion> old_version = 1295 scoped_refptr<ServiceWorkerVersion> old_version =
(...skipping 27 matching lines...) Expand all
1326 1323
1327 EXPECT_FALSE(registration->is_uninstalling()); 1324 EXPECT_FALSE(registration->is_uninstalling());
1328 EXPECT_TRUE(registration->is_uninstalled()); 1325 EXPECT_TRUE(registration->is_uninstalled());
1329 1326
1330 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status()); 1327 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status());
1331 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); 1328 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status());
1332 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, new_version->running_status()); 1329 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, new_version->running_status());
1333 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, new_version->status()); 1330 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, new_version->status());
1334 } 1331 }
1335 1332
1336 TEST_P(ServiceWorkerJobTestP, 1333 TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) {
1337 RegisterSameScriptMultipleTimesWhileUninstalling) {
1338 GURL pattern("http://www.example.com/one/"); 1334 GURL pattern("http://www.example.com/one/");
1339 GURL script1("http://www.example.com/service_worker.js"); 1335 GURL script1("http://www.example.com/service_worker.js");
1340 GURL script2("http://www.example.com/service_worker.js?new"); 1336 GURL script2("http://www.example.com/service_worker.js?new");
1341 1337
1342 scoped_refptr<ServiceWorkerRegistration> registration = 1338 scoped_refptr<ServiceWorkerRegistration> registration =
1343 RunRegisterJob(pattern, script1); 1339 RunRegisterJob(pattern, script1);
1344 scoped_refptr<base::TestSimpleTaskRunner> runner( 1340 scoped_refptr<base::TestSimpleTaskRunner> runner(
1345 new base::TestSimpleTaskRunner()); 1341 new base::TestSimpleTaskRunner());
1346 registration->SetTaskRunnerForTest(runner); 1342 registration->SetTaskRunnerForTest(runner);
1347 1343
(...skipping 30 matching lines...) Expand all
1378 EXPECT_EQ(NULL, registration->waiting_version()); 1374 EXPECT_EQ(NULL, registration->waiting_version());
1379 EXPECT_EQ(new_version, registration->active_version()); 1375 EXPECT_EQ(new_version, registration->active_version());
1380 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); 1376 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1381 1377
1382 runner->RunUntilIdle(); 1378 runner->RunUntilIdle();
1383 base::RunLoop().RunUntilIdle(); 1379 base::RunLoop().RunUntilIdle();
1384 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); 1380 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status());
1385 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); 1381 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status());
1386 } 1382 }
1387 1383
1388 TEST_P(ServiceWorkerJobTestP, RegisterMultipleTimesWhileUninstalling) { 1384 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) {
1389 GURL pattern("http://www.example.com/one/"); 1385 GURL pattern("http://www.example.com/one/");
1390 GURL script1("http://www.example.com/service_worker.js?first"); 1386 GURL script1("http://www.example.com/service_worker.js?first");
1391 GURL script2("http://www.example.com/service_worker.js?second"); 1387 GURL script2("http://www.example.com/service_worker.js?second");
1392 GURL script3("http://www.example.com/service_worker.js?third"); 1388 GURL script3("http://www.example.com/service_worker.js?third");
1393 1389
1394 scoped_refptr<ServiceWorkerRegistration> registration = 1390 scoped_refptr<ServiceWorkerRegistration> registration =
1395 RunRegisterJob(pattern, script1); 1391 RunRegisterJob(pattern, script1);
1396 scoped_refptr<base::TestSimpleTaskRunner> runner( 1392 scoped_refptr<base::TestSimpleTaskRunner> runner(
1397 new base::TestSimpleTaskRunner()); 1393 new base::TestSimpleTaskRunner());
1398 registration->SetTaskRunnerForTest(runner); 1394 registration->SetTaskRunnerForTest(runner);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 has_fetch_handler_ = has_fetch_handler; 1471 has_fetch_handler_ = has_fetch_handler;
1476 } 1472 }
1477 1473
1478 private: 1474 private:
1479 base::Closure install_callback_; 1475 base::Closure install_callback_;
1480 blink::WebServiceWorkerEventResult install_event_result_; 1476 blink::WebServiceWorkerEventResult install_event_result_;
1481 blink::WebServiceWorkerEventResult activate_event_result_; 1477 blink::WebServiceWorkerEventResult activate_event_result_;
1482 bool has_fetch_handler_ = true; 1478 bool has_fetch_handler_ = true;
1483 }; 1479 };
1484 1480
1485 TEST_P(ServiceWorkerJobTestP, RemoveControlleeDuringInstall) { 1481 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall) {
1486 EventCallbackHelper* helper = new EventCallbackHelper; 1482 EventCallbackHelper* helper = new EventCallbackHelper;
1487 helper_.reset(helper); 1483 helper_.reset(helper);
1488 1484
1489 GURL pattern("http://www.example.com/one/"); 1485 GURL pattern("http://www.example.com/one/");
1490 GURL script1("http://www.example.com/service_worker.js"); 1486 GURL script1("http://www.example.com/service_worker.js");
1491 GURL script2("http://www.example.com/service_worker.js?new"); 1487 GURL script2("http://www.example.com/service_worker.js?new");
1492 1488
1493 scoped_refptr<ServiceWorkerRegistration> registration = 1489 scoped_refptr<ServiceWorkerRegistration> registration =
1494 RunRegisterJob(pattern, script1); 1490 RunRegisterJob(pattern, script1);
1495 1491
(...skipping 19 matching lines...) Expand all
1515 EXPECT_NE(old_version, new_version); 1511 EXPECT_NE(old_version, new_version);
1516 EXPECT_EQ(NULL, registration->installing_version()); 1512 EXPECT_EQ(NULL, registration->installing_version());
1517 EXPECT_EQ(NULL, registration->waiting_version()); 1513 EXPECT_EQ(NULL, registration->waiting_version());
1518 EXPECT_EQ(new_version, registration->active_version()); 1514 EXPECT_EQ(new_version, registration->active_version());
1519 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); 1515 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status());
1520 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); 1516 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status());
1521 1517
1522 EXPECT_EQ(registration, FindRegistrationForPattern(pattern)); 1518 EXPECT_EQ(registration, FindRegistrationForPattern(pattern));
1523 } 1519 }
1524 1520
1525 TEST_P(ServiceWorkerJobTestP, RemoveControlleeDuringRejectedInstall) { 1521 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) {
1526 EventCallbackHelper* helper = new EventCallbackHelper; 1522 EventCallbackHelper* helper = new EventCallbackHelper;
1527 helper_.reset(helper); 1523 helper_.reset(helper);
1528 1524
1529 GURL pattern("http://www.example.com/one/"); 1525 GURL pattern("http://www.example.com/one/");
1530 GURL script1("http://www.example.com/service_worker.js"); 1526 GURL script1("http://www.example.com/service_worker.js");
1531 GURL script2("http://www.example.com/service_worker.js?new"); 1527 GURL script2("http://www.example.com/service_worker.js?new");
1532 1528
1533 scoped_refptr<ServiceWorkerRegistration> registration = 1529 scoped_refptr<ServiceWorkerRegistration> registration =
1534 RunRegisterJob(pattern, script1); 1530 RunRegisterJob(pattern, script1);
1535 1531
(...skipping 15 matching lines...) Expand all
1551 // Verify the registration was uninstalled. 1547 // Verify the registration was uninstalled.
1552 EXPECT_FALSE(registration->is_uninstalling()); 1548 EXPECT_FALSE(registration->is_uninstalling());
1553 EXPECT_TRUE(registration->is_uninstalled()); 1549 EXPECT_TRUE(registration->is_uninstalled());
1554 1550
1555 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status()); 1551 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status());
1556 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); 1552 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status());
1557 1553
1558 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); 1554 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND);
1559 } 1555 }
1560 1556
1561 TEST_P(ServiceWorkerJobTestP, RemoveControlleeDuringInstall_RejectActivate) { 1557 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall_RejectActivate) {
1562 EventCallbackHelper* helper = new EventCallbackHelper; 1558 EventCallbackHelper* helper = new EventCallbackHelper;
1563 helper_.reset(helper); 1559 helper_.reset(helper);
1564 1560
1565 GURL pattern("http://www.example.com/one/"); 1561 GURL pattern("http://www.example.com/one/");
1566 GURL script1("http://www.example.com/service_worker.js"); 1562 GURL script1("http://www.example.com/service_worker.js");
1567 GURL script2("http://www.example.com/service_worker.js?new"); 1563 GURL script2("http://www.example.com/service_worker.js?new");
1568 1564
1569 scoped_refptr<ServiceWorkerRegistration> registration = 1565 scoped_refptr<ServiceWorkerRegistration> registration =
1570 RunRegisterJob(pattern, script1); 1566 RunRegisterJob(pattern, script1);
1571 1567
(...skipping 15 matching lines...) Expand all
1587 // Verify the registration remains. 1583 // Verify the registration remains.
1588 EXPECT_FALSE(registration->is_uninstalling()); 1584 EXPECT_FALSE(registration->is_uninstalling());
1589 EXPECT_FALSE(registration->is_uninstalled()); 1585 EXPECT_FALSE(registration->is_uninstalled());
1590 1586
1591 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status()); 1587 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, old_version->running_status());
1592 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); 1588 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status());
1593 1589
1594 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); 1590 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK);
1595 } 1591 }
1596 1592
1597 TEST_P(ServiceWorkerJobTestP, HasFetchHandler) { 1593 TEST_F(ServiceWorkerJobTest, HasFetchHandler) {
1598 EventCallbackHelper* helper = new EventCallbackHelper; 1594 EventCallbackHelper* helper = new EventCallbackHelper;
1599 helper_.reset(helper); 1595 helper_.reset(helper);
1600 1596
1601 GURL pattern("http://www.example.com/"); 1597 GURL pattern("http://www.example.com/");
1602 GURL script("http://www.example.com/service_worker.js"); 1598 GURL script("http://www.example.com/service_worker.js");
1603 scoped_refptr<ServiceWorkerRegistration> registration; 1599 scoped_refptr<ServiceWorkerRegistration> registration;
1604 1600
1605 helper->set_has_fetch_handler(true); 1601 helper->set_has_fetch_handler(true);
1606 RunRegisterJob(pattern, script); 1602 RunRegisterJob(pattern, script);
1607 registration = FindRegistrationForPattern(pattern); 1603 registration = FindRegistrationForPattern(pattern);
(...skipping 30 matching lines...) Expand all
1638 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( 1634 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker(
1639 params, std::move(request)); 1635 params, std::move(request));
1640 } 1636 }
1641 1637
1642 private: 1638 private:
1643 base::Optional<bool> next_pause_after_download_; 1639 base::Optional<bool> next_pause_after_download_;
1644 int num_of_startworker_ = 0; 1640 int num_of_startworker_ = 0;
1645 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient); 1641 DISALLOW_COPY_AND_ASSIGN(CheckPauseAfterDownloadEmbeddedWorkerInstanceClient);
1646 }; 1642 };
1647 1643
1648 TEST_P(ServiceWorkerJobTestP, Update_PauseAfterDownload) { 1644 TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) {
1649 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; 1645 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
1650 helper_.reset(update_helper); 1646 helper_.reset(update_helper);
1651 IPC::TestSink* sink = update_helper->ipc_sink();
1652 1647
1653 std::vector<CheckPauseAfterDownloadEmbeddedWorkerInstanceClient*> clients; 1648 std::vector<CheckPauseAfterDownloadEmbeddedWorkerInstanceClient*> clients;
1654 if (is_mojo_enabled()) { 1649 clients.push_back(helper_->CreateAndRegisterMockInstanceClient<
1655 clients.push_back(helper_->CreateAndRegisterMockInstanceClient< 1650 CheckPauseAfterDownloadEmbeddedWorkerInstanceClient>(
1656 CheckPauseAfterDownloadEmbeddedWorkerInstanceClient>( 1651 helper_->AsWeakPtr()));
1657 helper_->AsWeakPtr())); 1652 clients.push_back(helper_->CreateAndRegisterMockInstanceClient<
1658 clients.push_back(helper_->CreateAndRegisterMockInstanceClient< 1653 CheckPauseAfterDownloadEmbeddedWorkerInstanceClient>(
1659 CheckPauseAfterDownloadEmbeddedWorkerInstanceClient>( 1654 helper_->AsWeakPtr()));
1660 helper_->AsWeakPtr()));
1661 }
1662 1655
1663 // The initial version should not pause after download. 1656 // The initial version should not pause after download.
1664 if (is_mojo_enabled()) 1657 clients[0]->set_next_pause_after_download(false);
1665 clients[0]->set_next_pause_after_download(false);
1666 scoped_refptr<ServiceWorkerRegistration> registration = 1658 scoped_refptr<ServiceWorkerRegistration> registration =
1667 update_helper->SetupInitialRegistration(kNewVersionOrigin); 1659 update_helper->SetupInitialRegistration(kNewVersionOrigin);
1668 if (is_mojo_enabled()) { 1660 ASSERT_EQ(1, clients[0]->num_of_startworker());
1669 ASSERT_EQ(1, clients[0]->num_of_startworker());
1670 } else {
1671 const IPC::Message* start_msg =
1672 sink->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID);
1673 ASSERT_TRUE(start_msg);
1674 EmbeddedWorkerMsg_StartWorker::Param param;
1675 EmbeddedWorkerMsg_StartWorker::Read(start_msg, &param);
1676 const EmbeddedWorkerStartParams& start_params = std::get<0>(param);
1677 EXPECT_FALSE(start_params.pause_after_download);
1678 sink->ClearMessages();
1679 }
1680 1661
1681 // The updated version should pause after download. 1662 // The updated version should pause after download.
1682 if (is_mojo_enabled()) 1663 clients[1]->set_next_pause_after_download(true);
1683 clients[1]->set_next_pause_after_download(true);
1684 registration->AddListener(update_helper); 1664 registration->AddListener(update_helper);
1685 registration->active_version()->StartUpdate(); 1665 registration->active_version()->StartUpdate();
1686 base::RunLoop().RunUntilIdle(); 1666 base::RunLoop().RunUntilIdle();
1687 if (is_mojo_enabled()) { 1667 ASSERT_EQ(1, clients[1]->num_of_startworker());
1688 ASSERT_EQ(1, clients[1]->num_of_startworker());
1689 } else {
1690 const IPC::Message* start_msg =
1691 sink->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID);
1692 ASSERT_TRUE(start_msg);
1693 EmbeddedWorkerMsg_StartWorker::Param param;
1694 EmbeddedWorkerMsg_StartWorker::Read(start_msg, &param);
1695 const EmbeddedWorkerStartParams& start_params = std::get<0>(param);
1696 EXPECT_TRUE(start_params.pause_after_download);
1697 sink->ClearMessages();
1698 }
1699 } 1668 }
1700 1669
1701 // Test that activation doesn't complete if it's triggered by removing a 1670 // Test that activation doesn't complete if it's triggered by removing a
1702 // controllee and starting the worker failed due to shutdown. 1671 // controllee and starting the worker failed due to shutdown.
1703 TEST_P(ServiceWorkerJobTestP, ActivateCancelsOnShutdown) { 1672 TEST_F(ServiceWorkerJobTest, ActivateCancelsOnShutdown) {
1704 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; 1673 UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
1705 helper_.reset(update_helper); 1674 helper_.reset(update_helper);
1706 GURL pattern("http://www.example.com/"); 1675 GURL pattern("http://www.example.com/");
1707 GURL script("http://www.example.com/service_worker.js"); 1676 GURL script("http://www.example.com/service_worker.js");
1708 1677
1709 scoped_refptr<ServiceWorkerRegistration> registration = 1678 scoped_refptr<ServiceWorkerRegistration> registration =
1710 RunRegisterJob(pattern, script); 1679 RunRegisterJob(pattern, script);
1711 scoped_refptr<base::TestSimpleTaskRunner> runner( 1680 scoped_refptr<base::TestSimpleTaskRunner> runner(
1712 new base::TestSimpleTaskRunner()); 1681 new base::TestSimpleTaskRunner());
1713 registration->SetTaskRunnerForTest(runner); 1682 registration->SetTaskRunnerForTest(runner);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 // Allow the activation to continue. It will fail, and the worker 1717 // Allow the activation to continue. It will fail, and the worker
1749 // should not be promoted to ACTIVATED because failure occur 1718 // should not be promoted to ACTIVATED because failure occur
1750 // during shutdown. 1719 // during shutdown.
1751 runner->RunUntilIdle(); 1720 runner->RunUntilIdle();
1752 base::RunLoop().RunUntilIdle(); 1721 base::RunLoop().RunUntilIdle();
1753 EXPECT_EQ(new_version.get(), registration->active_version()); 1722 EXPECT_EQ(new_version.get(), registration->active_version());
1754 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); 1723 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1755 registration->RemoveListener(update_helper); 1724 registration->RemoveListener(update_helper);
1756 } 1725 }
1757 1726
1758 INSTANTIATE_TEST_CASE_P(ServiceWorkerJobTest,
1759 ServiceWorkerJobTestP,
1760 ::testing::Values(false, true));
1761
1762 } // namespace content 1727 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698