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