| 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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 125 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
| 126 int render_process_id_; | 126 int render_process_id_; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { | 129 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { |
| 130 scoped_refptr<ServiceWorkerRegistration> original_registration; | 130 scoped_refptr<ServiceWorkerRegistration> original_registration; |
| 131 bool called; | 131 bool called; |
| 132 job_coordinator()->Register( | 132 job_coordinator()->Register( |
| 133 GURL("http://www.example.com/"), | 133 GURL("http://www.example.com/"), |
| 134 GURL("http://www.example.com/service_worker.js"), | 134 GURL("http://www.example.com/service_worker.js"), |
| 135 render_process_id_, | 135 NULL, |
| 136 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | 136 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
| 137 EXPECT_FALSE(called); | 137 EXPECT_FALSE(called); |
| 138 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
| 139 EXPECT_TRUE(called); | 139 EXPECT_TRUE(called); |
| 140 | 140 |
| 141 scoped_refptr<ServiceWorkerRegistration> registration1; | 141 scoped_refptr<ServiceWorkerRegistration> registration1; |
| 142 storage()->FindRegistrationForDocument( | 142 storage()->FindRegistrationForDocument( |
| 143 GURL("http://www.example.com/"), | 143 GURL("http://www.example.com/"), |
| 144 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); | 144 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); |
| 145 scoped_refptr<ServiceWorkerRegistration> registration2; | 145 scoped_refptr<ServiceWorkerRegistration> registration2; |
| 146 storage()->FindRegistrationForDocument( | 146 storage()->FindRegistrationForDocument( |
| 147 GURL("http://www.example.com/"), | 147 GURL("http://www.example.com/"), |
| 148 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); | 148 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); |
| 149 base::RunLoop().RunUntilIdle(); | 149 base::RunLoop().RunUntilIdle(); |
| 150 EXPECT_TRUE(called); | 150 EXPECT_TRUE(called); |
| 151 ASSERT_TRUE(registration1.get()); | 151 ASSERT_TRUE(registration1.get()); |
| 152 ASSERT_EQ(registration1, original_registration); | 152 ASSERT_EQ(registration1, original_registration); |
| 153 ASSERT_EQ(registration1, registration2); | 153 ASSERT_EQ(registration1, registration2); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { | 156 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { |
| 157 bool called; | 157 bool called; |
| 158 scoped_refptr<ServiceWorkerRegistration> original_registration; | 158 scoped_refptr<ServiceWorkerRegistration> original_registration; |
| 159 job_coordinator()->Register( | 159 job_coordinator()->Register( |
| 160 GURL("http://www.example.com/"), | 160 GURL("http://www.example.com/"), |
| 161 GURL("http://www.example.com/service_worker.js"), | 161 GURL("http://www.example.com/service_worker.js"), |
| 162 render_process_id_, | 162 NULL, |
| 163 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | 163 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
| 164 EXPECT_FALSE(called); | 164 EXPECT_FALSE(called); |
| 165 base::RunLoop().RunUntilIdle(); | 165 base::RunLoop().RunUntilIdle(); |
| 166 EXPECT_TRUE(called); | 166 EXPECT_TRUE(called); |
| 167 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), | 167 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), |
| 168 original_registration.get()); | 168 original_registration.get()); |
| 169 | 169 |
| 170 scoped_refptr<ServiceWorkerRegistration> registration1; | 170 scoped_refptr<ServiceWorkerRegistration> registration1; |
| 171 storage()->FindRegistrationForDocument( | 171 storage()->FindRegistrationForDocument( |
| 172 GURL("http://www.example.com/one"), | 172 GURL("http://www.example.com/one"), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 183 ASSERT_EQ(registration1, original_registration); | 183 ASSERT_EQ(registration1, original_registration); |
| 184 ASSERT_EQ(registration1, registration2); | 184 ASSERT_EQ(registration1, registration2); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { | 187 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { |
| 188 bool called1; | 188 bool called1; |
| 189 scoped_refptr<ServiceWorkerRegistration> original_registration1; | 189 scoped_refptr<ServiceWorkerRegistration> original_registration1; |
| 190 job_coordinator()->Register( | 190 job_coordinator()->Register( |
| 191 GURL("http://www.example.com/one/"), | 191 GURL("http://www.example.com/one/"), |
| 192 GURL("http://www.example.com/service_worker.js"), | 192 GURL("http://www.example.com/service_worker.js"), |
| 193 render_process_id_, | 193 NULL, |
| 194 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); | 194 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); |
| 195 | 195 |
| 196 bool called2; | 196 bool called2; |
| 197 scoped_refptr<ServiceWorkerRegistration> original_registration2; | 197 scoped_refptr<ServiceWorkerRegistration> original_registration2; |
| 198 job_coordinator()->Register( | 198 job_coordinator()->Register( |
| 199 GURL("http://www.example.com/two/"), | 199 GURL("http://www.example.com/two/"), |
| 200 GURL("http://www.example.com/service_worker.js"), | 200 GURL("http://www.example.com/service_worker.js"), |
| 201 render_process_id_, | 201 NULL, |
| 202 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); | 202 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); |
| 203 | 203 |
| 204 EXPECT_FALSE(called1); | 204 EXPECT_FALSE(called1); |
| 205 EXPECT_FALSE(called2); | 205 EXPECT_FALSE(called2); |
| 206 base::RunLoop().RunUntilIdle(); | 206 base::RunLoop().RunUntilIdle(); |
| 207 EXPECT_TRUE(called2); | 207 EXPECT_TRUE(called2); |
| 208 EXPECT_TRUE(called1); | 208 EXPECT_TRUE(called1); |
| 209 | 209 |
| 210 scoped_refptr<ServiceWorkerRegistration> registration1; | 210 scoped_refptr<ServiceWorkerRegistration> registration1; |
| 211 storage()->FindRegistrationForDocument( | 211 storage()->FindRegistrationForDocument( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 222 ASSERT_NE(registration1, registration2); | 222 ASSERT_NE(registration1, registration2); |
| 223 } | 223 } |
| 224 | 224 |
| 225 // Make sure basic registration is working. | 225 // Make sure basic registration is working. |
| 226 TEST_F(ServiceWorkerJobTest, Register) { | 226 TEST_F(ServiceWorkerJobTest, Register) { |
| 227 bool called = false; | 227 bool called = false; |
| 228 scoped_refptr<ServiceWorkerRegistration> registration; | 228 scoped_refptr<ServiceWorkerRegistration> registration; |
| 229 job_coordinator()->Register( | 229 job_coordinator()->Register( |
| 230 GURL("http://www.example.com/"), | 230 GURL("http://www.example.com/"), |
| 231 GURL("http://www.example.com/service_worker.js"), | 231 GURL("http://www.example.com/service_worker.js"), |
| 232 render_process_id_, | 232 NULL, |
| 233 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 233 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 234 | 234 |
| 235 ASSERT_FALSE(called); | 235 ASSERT_FALSE(called); |
| 236 base::RunLoop().RunUntilIdle(); | 236 base::RunLoop().RunUntilIdle(); |
| 237 ASSERT_TRUE(called); | 237 ASSERT_TRUE(called); |
| 238 | 238 |
| 239 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 239 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Make sure registrations are cleaned up when they are unregistered. | 242 // Make sure registrations are cleaned up when they are unregistered. |
| 243 TEST_F(ServiceWorkerJobTest, Unregister) { | 243 TEST_F(ServiceWorkerJobTest, Unregister) { |
| 244 GURL pattern("http://www.example.com/"); | 244 GURL pattern("http://www.example.com/"); |
| 245 | 245 |
| 246 bool called; | 246 bool called; |
| 247 scoped_refptr<ServiceWorkerRegistration> registration; | 247 scoped_refptr<ServiceWorkerRegistration> registration; |
| 248 job_coordinator()->Register( | 248 job_coordinator()->Register( |
| 249 pattern, | 249 pattern, |
| 250 GURL("http://www.example.com/service_worker.js"), | 250 GURL("http://www.example.com/service_worker.js"), |
| 251 render_process_id_, | 251 NULL, |
| 252 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 252 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 253 | 253 |
| 254 ASSERT_FALSE(called); | 254 ASSERT_FALSE(called); |
| 255 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
| 256 ASSERT_TRUE(called); | 256 ASSERT_TRUE(called); |
| 257 | 257 |
| 258 job_coordinator()->Unregister(pattern, | 258 job_coordinator()->Unregister(pattern, |
| 259 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 259 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| 260 | 260 |
| 261 ASSERT_FALSE(called); | 261 ASSERT_FALSE(called); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 291 // Make sure registering a new script creates a new version and shares an | 291 // Make sure registering a new script creates a new version and shares an |
| 292 // existing registration. | 292 // existing registration. |
| 293 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { | 293 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
| 294 GURL pattern("http://www.example.com/"); | 294 GURL pattern("http://www.example.com/"); |
| 295 | 295 |
| 296 bool called; | 296 bool called; |
| 297 scoped_refptr<ServiceWorkerRegistration> old_registration; | 297 scoped_refptr<ServiceWorkerRegistration> old_registration; |
| 298 job_coordinator()->Register( | 298 job_coordinator()->Register( |
| 299 pattern, | 299 pattern, |
| 300 GURL("http://www.example.com/service_worker.js"), | 300 GURL("http://www.example.com/service_worker.js"), |
| 301 render_process_id_, | 301 NULL, |
| 302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
| 303 | 303 |
| 304 ASSERT_FALSE(called); | 304 ASSERT_FALSE(called); |
| 305 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
| 306 ASSERT_TRUE(called); | 306 ASSERT_TRUE(called); |
| 307 | 307 |
| 308 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; | 308 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; |
| 309 storage()->FindRegistrationForPattern( | 309 storage()->FindRegistrationForPattern( |
| 310 pattern, | 310 pattern, |
| 311 SaveFoundRegistration( | 311 SaveFoundRegistration( |
| 312 SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); | 312 SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); |
| 313 | 313 |
| 314 ASSERT_FALSE(called); | 314 ASSERT_FALSE(called); |
| 315 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
| 316 ASSERT_TRUE(called); | 316 ASSERT_TRUE(called); |
| 317 | 317 |
| 318 ASSERT_EQ(old_registration, old_registration_by_pattern); | 318 ASSERT_EQ(old_registration, old_registration_by_pattern); |
| 319 old_registration_by_pattern = NULL; | 319 old_registration_by_pattern = NULL; |
| 320 | 320 |
| 321 scoped_refptr<ServiceWorkerRegistration> new_registration; | 321 scoped_refptr<ServiceWorkerRegistration> new_registration; |
| 322 job_coordinator()->Register( | 322 job_coordinator()->Register( |
| 323 pattern, | 323 pattern, |
| 324 GURL("http://www.example.com/service_worker_new.js"), | 324 GURL("http://www.example.com/service_worker_new.js"), |
| 325 render_process_id_, | 325 NULL, |
| 326 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); | 326 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); |
| 327 | 327 |
| 328 ASSERT_FALSE(called); | 328 ASSERT_FALSE(called); |
| 329 base::RunLoop().RunUntilIdle(); | 329 base::RunLoop().RunUntilIdle(); |
| 330 ASSERT_TRUE(called); | 330 ASSERT_TRUE(called); |
| 331 | 331 |
| 332 ASSERT_EQ(old_registration, new_registration); | 332 ASSERT_EQ(old_registration, new_registration); |
| 333 | 333 |
| 334 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; | 334 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; |
| 335 storage()->FindRegistrationForPattern( | 335 storage()->FindRegistrationForPattern( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 348 // combination, that the same registration is used. | 348 // combination, that the same registration is used. |
| 349 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { | 349 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { |
| 350 GURL pattern("http://www.example.com/"); | 350 GURL pattern("http://www.example.com/"); |
| 351 GURL script_url("http://www.example.com/service_worker.js"); | 351 GURL script_url("http://www.example.com/service_worker.js"); |
| 352 | 352 |
| 353 bool called; | 353 bool called; |
| 354 scoped_refptr<ServiceWorkerRegistration> old_registration; | 354 scoped_refptr<ServiceWorkerRegistration> old_registration; |
| 355 job_coordinator()->Register( | 355 job_coordinator()->Register( |
| 356 pattern, | 356 pattern, |
| 357 script_url, | 357 script_url, |
| 358 render_process_id_, | 358 NULL, |
| 359 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 359 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
| 360 | 360 |
| 361 ASSERT_FALSE(called); | 361 ASSERT_FALSE(called); |
| 362 base::RunLoop().RunUntilIdle(); | 362 base::RunLoop().RunUntilIdle(); |
| 363 ASSERT_TRUE(called); | 363 ASSERT_TRUE(called); |
| 364 | 364 |
| 365 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; | 365 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; |
| 366 storage()->FindRegistrationForPattern( | 366 storage()->FindRegistrationForPattern( |
| 367 pattern, | 367 pattern, |
| 368 SaveFoundRegistration( | 368 SaveFoundRegistration( |
| 369 SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); | 369 SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); |
| 370 ASSERT_FALSE(called); | 370 ASSERT_FALSE(called); |
| 371 base::RunLoop().RunUntilIdle(); | 371 base::RunLoop().RunUntilIdle(); |
| 372 ASSERT_TRUE(called); | 372 ASSERT_TRUE(called); |
| 373 | 373 |
| 374 ASSERT_TRUE(old_registration_by_pattern.get()); | 374 ASSERT_TRUE(old_registration_by_pattern.get()); |
| 375 | 375 |
| 376 scoped_refptr<ServiceWorkerRegistration> new_registration; | 376 scoped_refptr<ServiceWorkerRegistration> new_registration; |
| 377 job_coordinator()->Register( | 377 job_coordinator()->Register( |
| 378 pattern, | 378 pattern, |
| 379 script_url, | 379 script_url, |
| 380 render_process_id_, | 380 NULL, |
| 381 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); | 381 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); |
| 382 | 382 |
| 383 ASSERT_FALSE(called); | 383 ASSERT_FALSE(called); |
| 384 base::RunLoop().RunUntilIdle(); | 384 base::RunLoop().RunUntilIdle(); |
| 385 ASSERT_TRUE(called); | 385 ASSERT_TRUE(called); |
| 386 | 386 |
| 387 ASSERT_EQ(old_registration, new_registration); | 387 ASSERT_EQ(old_registration, new_registration); |
| 388 | 388 |
| 389 ASSERT_FALSE(old_registration->HasOneRef()); | 389 ASSERT_FALSE(old_registration->HasOneRef()); |
| 390 | 390 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 419 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
| 420 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); | 420 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); |
| 421 | 421 |
| 422 bool called = false; | 422 bool called = false; |
| 423 scoped_refptr<ServiceWorkerRegistration> registration; | 423 scoped_refptr<ServiceWorkerRegistration> registration; |
| 424 job_coordinator()->Register( | 424 job_coordinator()->Register( |
| 425 GURL("http://www.example.com/"), | 425 GURL("http://www.example.com/"), |
| 426 GURL("http://www.example.com/service_worker.js"), | 426 GURL("http://www.example.com/service_worker.js"), |
| 427 render_process_id_, | 427 NULL, |
| 428 SaveRegistration( | 428 SaveRegistration( |
| 429 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, ®istration)); | 429 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, ®istration)); |
| 430 | 430 |
| 431 ASSERT_FALSE(called); | 431 ASSERT_FALSE(called); |
| 432 base::RunLoop().RunUntilIdle(); | 432 base::RunLoop().RunUntilIdle(); |
| 433 | 433 |
| 434 ASSERT_TRUE(called); | 434 ASSERT_TRUE(called); |
| 435 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 435 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
| 436 } | 436 } |
| 437 | 437 |
| 438 // Register and then unregister the pattern, in parallel. Job coordinator should | 438 // Register and then unregister the pattern, in parallel. Job coordinator should |
| 439 // process jobs until the last job. | 439 // process jobs until the last job. |
| 440 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { | 440 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { |
| 441 GURL pattern("http://www.example.com/"); | 441 GURL pattern("http://www.example.com/"); |
| 442 GURL script_url("http://www.example.com/service_worker.js"); | 442 GURL script_url("http://www.example.com/service_worker.js"); |
| 443 | 443 |
| 444 bool registration_called = false; | 444 bool registration_called = false; |
| 445 scoped_refptr<ServiceWorkerRegistration> registration; | 445 scoped_refptr<ServiceWorkerRegistration> registration; |
| 446 job_coordinator()->Register( | 446 job_coordinator()->Register( |
| 447 pattern, | 447 pattern, |
| 448 script_url, | 448 script_url, |
| 449 render_process_id_, | 449 NULL, |
| 450 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); | 450 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
| 451 | 451 |
| 452 bool unregistration_called = false; | 452 bool unregistration_called = false; |
| 453 job_coordinator()->Unregister( | 453 job_coordinator()->Unregister( |
| 454 pattern, | 454 pattern, |
| 455 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | 455 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
| 456 | 456 |
| 457 ASSERT_FALSE(registration_called); | 457 ASSERT_FALSE(registration_called); |
| 458 ASSERT_FALSE(unregistration_called); | 458 ASSERT_FALSE(unregistration_called); |
| 459 base::RunLoop().RunUntilIdle(); | 459 base::RunLoop().RunUntilIdle(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 476 // shutdown. | 476 // shutdown. |
| 477 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { | 477 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
| 478 GURL pattern("http://www.example.com/"); | 478 GURL pattern("http://www.example.com/"); |
| 479 | 479 |
| 480 GURL script_url1("http://www.example.com/service_worker1.js"); | 480 GURL script_url1("http://www.example.com/service_worker1.js"); |
| 481 bool registration1_called = false; | 481 bool registration1_called = false; |
| 482 scoped_refptr<ServiceWorkerRegistration> registration1; | 482 scoped_refptr<ServiceWorkerRegistration> registration1; |
| 483 job_coordinator()->Register( | 483 job_coordinator()->Register( |
| 484 pattern, | 484 pattern, |
| 485 script_url1, | 485 script_url1, |
| 486 render_process_id_, | 486 NULL, |
| 487 SaveRegistration( | 487 SaveRegistration( |
| 488 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | 488 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); |
| 489 | 489 |
| 490 GURL script_url2("http://www.example.com/service_worker2.js"); | 490 GURL script_url2("http://www.example.com/service_worker2.js"); |
| 491 bool registration2_called = false; | 491 bool registration2_called = false; |
| 492 scoped_refptr<ServiceWorkerRegistration> registration2; | 492 scoped_refptr<ServiceWorkerRegistration> registration2; |
| 493 job_coordinator()->Register( | 493 job_coordinator()->Register( |
| 494 pattern, | 494 pattern, |
| 495 script_url2, | 495 script_url2, |
| 496 render_process_id_, | 496 NULL, |
| 497 SaveRegistration( | 497 SaveRegistration( |
| 498 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | 498 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); |
| 499 | 499 |
| 500 ASSERT_FALSE(registration1_called); | 500 ASSERT_FALSE(registration1_called); |
| 501 ASSERT_FALSE(registration2_called); | 501 ASSERT_FALSE(registration2_called); |
| 502 base::RunLoop().RunUntilIdle(); | 502 base::RunLoop().RunUntilIdle(); |
| 503 ASSERT_TRUE(registration1_called); | 503 ASSERT_TRUE(registration1_called); |
| 504 ASSERT_TRUE(registration2_called); | 504 ASSERT_TRUE(registration2_called); |
| 505 | 505 |
| 506 scoped_refptr<ServiceWorkerRegistration> registration; | 506 scoped_refptr<ServiceWorkerRegistration> registration; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 520 // object. | 520 // object. |
| 521 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { | 521 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
| 522 GURL pattern("http://www.example.com/"); | 522 GURL pattern("http://www.example.com/"); |
| 523 | 523 |
| 524 GURL script_url("http://www.example.com/service_worker1.js"); | 524 GURL script_url("http://www.example.com/service_worker1.js"); |
| 525 bool registration1_called = false; | 525 bool registration1_called = false; |
| 526 scoped_refptr<ServiceWorkerRegistration> registration1; | 526 scoped_refptr<ServiceWorkerRegistration> registration1; |
| 527 job_coordinator()->Register( | 527 job_coordinator()->Register( |
| 528 pattern, | 528 pattern, |
| 529 script_url, | 529 script_url, |
| 530 render_process_id_, | 530 NULL, |
| 531 SaveRegistration( | 531 SaveRegistration( |
| 532 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | 532 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); |
| 533 | 533 |
| 534 bool registration2_called = false; | 534 bool registration2_called = false; |
| 535 scoped_refptr<ServiceWorkerRegistration> registration2; | 535 scoped_refptr<ServiceWorkerRegistration> registration2; |
| 536 job_coordinator()->Register( | 536 job_coordinator()->Register( |
| 537 pattern, | 537 pattern, |
| 538 script_url, | 538 script_url, |
| 539 render_process_id_, | 539 NULL, |
| 540 SaveRegistration( | 540 SaveRegistration( |
| 541 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | 541 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); |
| 542 | 542 |
| 543 ASSERT_FALSE(registration1_called); | 543 ASSERT_FALSE(registration1_called); |
| 544 ASSERT_FALSE(registration2_called); | 544 ASSERT_FALSE(registration2_called); |
| 545 base::RunLoop().RunUntilIdle(); | 545 base::RunLoop().RunUntilIdle(); |
| 546 ASSERT_TRUE(registration1_called); | 546 ASSERT_TRUE(registration1_called); |
| 547 ASSERT_TRUE(registration2_called); | 547 ASSERT_TRUE(registration2_called); |
| 548 | 548 |
| 549 ASSERT_EQ(registration1, registration2); | 549 ASSERT_EQ(registration1, registration2); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 GURL pattern1("http://www1.example.com/"); | 597 GURL pattern1("http://www1.example.com/"); |
| 598 GURL pattern2("http://www2.example.com/"); | 598 GURL pattern2("http://www2.example.com/"); |
| 599 GURL script_url1("http://www1.example.com/service_worker.js"); | 599 GURL script_url1("http://www1.example.com/service_worker.js"); |
| 600 GURL script_url2("http://www2.example.com/service_worker.js"); | 600 GURL script_url2("http://www2.example.com/service_worker.js"); |
| 601 | 601 |
| 602 bool registration_called1 = false; | 602 bool registration_called1 = false; |
| 603 scoped_refptr<ServiceWorkerRegistration> registration1; | 603 scoped_refptr<ServiceWorkerRegistration> registration1; |
| 604 job_coordinator()->Register( | 604 job_coordinator()->Register( |
| 605 pattern1, | 605 pattern1, |
| 606 script_url1, | 606 script_url1, |
| 607 render_process_id_, | 607 NULL, |
| 608 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | 608 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, |
| 609 ®istration_called1, ®istration1)); | 609 ®istration_called1, ®istration1)); |
| 610 | 610 |
| 611 bool registration_called2 = false; | 611 bool registration_called2 = false; |
| 612 scoped_refptr<ServiceWorkerRegistration> registration2; | 612 scoped_refptr<ServiceWorkerRegistration> registration2; |
| 613 job_coordinator()->Register( | 613 job_coordinator()->Register( |
| 614 pattern2, | 614 pattern2, |
| 615 script_url2, | 615 script_url2, |
| 616 render_process_id_, | 616 NULL, |
| 617 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | 617 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, |
| 618 ®istration_called2, ®istration2)); | 618 ®istration_called2, ®istration2)); |
| 619 | 619 |
| 620 ASSERT_FALSE(registration_called1); | 620 ASSERT_FALSE(registration_called1); |
| 621 ASSERT_FALSE(registration_called2); | 621 ASSERT_FALSE(registration_called2); |
| 622 job_coordinator()->AbortAll(); | 622 job_coordinator()->AbortAll(); |
| 623 | 623 |
| 624 base::RunLoop().RunUntilIdle(); | 624 base::RunLoop().RunUntilIdle(); |
| 625 ASSERT_TRUE(registration_called1); | 625 ASSERT_TRUE(registration_called1); |
| 626 ASSERT_TRUE(registration_called2); | 626 ASSERT_TRUE(registration_called2); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 672 |
| 673 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { | 673 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { |
| 674 GURL pattern("http://www.example.com/"); | 674 GURL pattern("http://www.example.com/"); |
| 675 GURL script_url("http://www.example.com/service_worker.js"); | 675 GURL script_url("http://www.example.com/service_worker.js"); |
| 676 | 676 |
| 677 bool registration_called = false; | 677 bool registration_called = false; |
| 678 scoped_refptr<ServiceWorkerRegistration> registration; | 678 scoped_refptr<ServiceWorkerRegistration> registration; |
| 679 job_coordinator()->Register( | 679 job_coordinator()->Register( |
| 680 pattern, | 680 pattern, |
| 681 script_url, | 681 script_url, |
| 682 render_process_id_, | 682 NULL, |
| 683 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | 683 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, |
| 684 ®istration_called, ®istration)); | 684 ®istration_called, ®istration)); |
| 685 | 685 |
| 686 bool unregistration_called = false; | 686 bool unregistration_called = false; |
| 687 job_coordinator()->Unregister( | 687 job_coordinator()->Unregister( |
| 688 pattern, | 688 pattern, |
| 689 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | 689 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, |
| 690 &unregistration_called)); | 690 &unregistration_called)); |
| 691 | 691 |
| 692 ASSERT_FALSE(registration_called); | 692 ASSERT_FALSE(registration_called); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 710 | 710 |
| 711 // Tests that the waiting worker enters the 'redundant' state upon | 711 // Tests that the waiting worker enters the 'redundant' state upon |
| 712 // unregistration. | 712 // unregistration. |
| 713 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { | 713 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { |
| 714 scoped_refptr<ServiceWorkerRegistration> registration; | 714 scoped_refptr<ServiceWorkerRegistration> registration; |
| 715 bool called = false; | 715 bool called = false; |
| 716 GURL script_url("http://www.example.com/service_worker.js"); | 716 GURL script_url("http://www.example.com/service_worker.js"); |
| 717 job_coordinator()->Register( | 717 job_coordinator()->Register( |
| 718 GURL("http://www.example.com/"), | 718 GURL("http://www.example.com/"), |
| 719 script_url, | 719 script_url, |
| 720 render_process_id_, | 720 NULL, |
| 721 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 721 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 722 base::RunLoop().RunUntilIdle(); | 722 base::RunLoop().RunUntilIdle(); |
| 723 ASSERT_TRUE(called); | 723 ASSERT_TRUE(called); |
| 724 ASSERT_TRUE(registration.get()); | 724 ASSERT_TRUE(registration.get()); |
| 725 | 725 |
| 726 // Manually create the waiting worker since there is no way to become a | 726 // Manually create the waiting worker since there is no way to become a |
| 727 // waiting worker until Update is implemented. | 727 // waiting worker until Update is implemented. |
| 728 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 728 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
| 729 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); | 729 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); |
| 730 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 730 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 751 } | 751 } |
| 752 | 752 |
| 753 // Tests that the active worker enters the 'redundant' state upon | 753 // Tests that the active worker enters the 'redundant' state upon |
| 754 // unregistration. | 754 // unregistration. |
| 755 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { | 755 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { |
| 756 scoped_refptr<ServiceWorkerRegistration> registration; | 756 scoped_refptr<ServiceWorkerRegistration> registration; |
| 757 bool called = false; | 757 bool called = false; |
| 758 job_coordinator()->Register( | 758 job_coordinator()->Register( |
| 759 GURL("http://www.example.com/"), | 759 GURL("http://www.example.com/"), |
| 760 GURL("http://www.example.com/service_worker.js"), | 760 GURL("http://www.example.com/service_worker.js"), |
| 761 render_process_id_, | 761 NULL, |
| 762 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 762 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 763 base::RunLoop().RunUntilIdle(); | 763 base::RunLoop().RunUntilIdle(); |
| 764 ASSERT_TRUE(called); | 764 ASSERT_TRUE(called); |
| 765 ASSERT_TRUE(registration.get()); | 765 ASSERT_TRUE(registration.get()); |
| 766 | 766 |
| 767 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 767 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
| 768 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 768 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
| 769 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 769 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
| 770 | 770 |
| 771 called = false; | 771 called = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 782 | 782 |
| 783 // Tests that the active worker enters the 'redundant' state upon | 783 // Tests that the active worker enters the 'redundant' state upon |
| 784 // unregistration. | 784 // unregistration. |
| 785 TEST_F(ServiceWorkerJobTest, | 785 TEST_F(ServiceWorkerJobTest, |
| 786 UnregisterActiveSetsRedundant_WaitForNoControllee) { | 786 UnregisterActiveSetsRedundant_WaitForNoControllee) { |
| 787 scoped_refptr<ServiceWorkerRegistration> registration; | 787 scoped_refptr<ServiceWorkerRegistration> registration; |
| 788 bool called = false; | 788 bool called = false; |
| 789 job_coordinator()->Register( | 789 job_coordinator()->Register( |
| 790 GURL("http://www.example.com/"), | 790 GURL("http://www.example.com/"), |
| 791 GURL("http://www.example.com/service_worker.js"), | 791 GURL("http://www.example.com/service_worker.js"), |
| 792 render_process_id_, | 792 NULL, |
| 793 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 793 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 794 base::RunLoop().RunUntilIdle(); | 794 base::RunLoop().RunUntilIdle(); |
| 795 ASSERT_TRUE(called); | 795 ASSERT_TRUE(called); |
| 796 ASSERT_TRUE(registration.get()); | 796 ASSERT_TRUE(registration.get()); |
| 797 | 797 |
| 798 scoped_ptr<ServiceWorkerProviderHost> host( | 798 scoped_ptr<ServiceWorkerProviderHost> host( |
| 799 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 799 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
| 800 1 /* dummy provider_id */, | 800 1 /* dummy provider_id */, |
| 801 context()->AsWeakPtr(), | 801 context()->AsWeakPtr(), |
| 802 NULL)); | 802 NULL)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 return context()->job_coordinator(); | 906 return context()->job_coordinator(); |
| 907 } | 907 } |
| 908 | 908 |
| 909 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( | 909 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( |
| 910 const GURL& test_origin) { | 910 const GURL& test_origin) { |
| 911 scoped_refptr<ServiceWorkerRegistration> registration; | 911 scoped_refptr<ServiceWorkerRegistration> registration; |
| 912 bool called = false; | 912 bool called = false; |
| 913 job_coordinator()->Register( | 913 job_coordinator()->Register( |
| 914 test_origin.Resolve(kScope), | 914 test_origin.Resolve(kScope), |
| 915 test_origin.Resolve(kScript), | 915 test_origin.Resolve(kScript), |
| 916 mock_render_process_id(), | 916 NULL, |
| 917 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 917 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 918 base::RunLoop().RunUntilIdle(); | 918 base::RunLoop().RunUntilIdle(); |
| 919 EXPECT_TRUE(called); | 919 EXPECT_TRUE(called); |
| 920 EXPECT_TRUE(registration.get()); | 920 EXPECT_TRUE(registration.get()); |
| 921 EXPECT_TRUE(registration->active_version()); | 921 EXPECT_TRUE(registration->active_version()); |
| 922 EXPECT_FALSE(registration->installing_version()); | 922 EXPECT_FALSE(registration->installing_version()); |
| 923 EXPECT_FALSE(registration->waiting_version()); | 923 EXPECT_FALSE(registration->waiting_version()); |
| 924 registration_ = registration; | 924 registration_ = registration; |
| 925 return registration; | 925 return registration; |
| 926 } | 926 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 | 1121 |
| 1122 EXPECT_TRUE(update_helper->update_found_); | 1122 EXPECT_TRUE(update_helper->update_found_); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { | 1125 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { |
| 1126 bool called; | 1126 bool called; |
| 1127 scoped_refptr<ServiceWorkerRegistration> registration; | 1127 scoped_refptr<ServiceWorkerRegistration> registration; |
| 1128 job_coordinator()->Register( | 1128 job_coordinator()->Register( |
| 1129 GURL("http://www.example.com/one/"), | 1129 GURL("http://www.example.com/one/"), |
| 1130 GURL("http://www.example.com/service_worker.js"), | 1130 GURL("http://www.example.com/service_worker.js"), |
| 1131 render_process_id_, | 1131 NULL, |
| 1132 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 1132 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 1133 | 1133 |
| 1134 EXPECT_FALSE(called); | 1134 EXPECT_FALSE(called); |
| 1135 base::RunLoop().RunUntilIdle(); | 1135 base::RunLoop().RunUntilIdle(); |
| 1136 EXPECT_TRUE(called); | 1136 EXPECT_TRUE(called); |
| 1137 ServiceWorkerVersion* active_version = registration->active_version(); | 1137 ServiceWorkerVersion* active_version = registration->active_version(); |
| 1138 | 1138 |
| 1139 // Queue an Update, it should abort when it starts and sees the new version. | 1139 // Queue an Update, it should abort when it starts and sees the new version. |
| 1140 job_coordinator()->Update(registration.get()); | 1140 job_coordinator()->Update(registration.get()); |
| 1141 | 1141 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1154 EXPECT_EQ(version.get(), registration->waiting_version()); | 1154 EXPECT_EQ(version.get(), registration->waiting_version()); |
| 1155 EXPECT_EQ(NULL, registration->installing_version()); | 1155 EXPECT_EQ(NULL, registration->installing_version()); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { | 1158 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { |
| 1159 bool called; | 1159 bool called; |
| 1160 scoped_refptr<ServiceWorkerRegistration> registration; | 1160 scoped_refptr<ServiceWorkerRegistration> registration; |
| 1161 job_coordinator()->Register( | 1161 job_coordinator()->Register( |
| 1162 GURL("http://www.example.com/one/"), | 1162 GURL("http://www.example.com/one/"), |
| 1163 GURL("http://www.example.com/service_worker.js"), | 1163 GURL("http://www.example.com/service_worker.js"), |
| 1164 render_process_id_, | 1164 NULL, |
| 1165 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 1165 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 1166 | 1166 |
| 1167 EXPECT_FALSE(called); | 1167 EXPECT_FALSE(called); |
| 1168 base::RunLoop().RunUntilIdle(); | 1168 base::RunLoop().RunUntilIdle(); |
| 1169 EXPECT_TRUE(called); | 1169 EXPECT_TRUE(called); |
| 1170 | 1170 |
| 1171 // Add a controllee and queue an unregister to force the uninstalling state. | 1171 // Add a controllee and queue an unregister to force the uninstalling state. |
| 1172 scoped_ptr<ServiceWorkerProviderHost> host( | 1172 scoped_ptr<ServiceWorkerProviderHost> host( |
| 1173 new ServiceWorkerProviderHost(33 /* dummy render_process id */, | 1173 new ServiceWorkerProviderHost(33 /* dummy render_process id */, |
| 1174 1 /* dummy provider_id */, | 1174 1 /* dummy provider_id */, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1187 EXPECT_TRUE(called); | 1187 EXPECT_TRUE(called); |
| 1188 | 1188 |
| 1189 // Verify the registration was not modified by the Update. | 1189 // Verify the registration was not modified by the Update. |
| 1190 EXPECT_TRUE(registration->is_uninstalling()); | 1190 EXPECT_TRUE(registration->is_uninstalling()); |
| 1191 EXPECT_EQ(active_version, registration->active_version()); | 1191 EXPECT_EQ(active_version, registration->active_version()); |
| 1192 EXPECT_EQ(NULL, registration->waiting_version()); | 1192 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1193 EXPECT_EQ(NULL, registration->installing_version()); | 1193 EXPECT_EQ(NULL, registration->installing_version()); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 } // namespace content | 1196 } // namespace content |
| OLD | NEW |