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