| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 281 |
| 282 bool called; | 282 bool called; |
| 283 job_coordinator()->Unregister(pattern, | 283 job_coordinator()->Unregister(pattern, |
| 284 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 284 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| 285 | 285 |
| 286 ASSERT_FALSE(called); | 286 ASSERT_FALSE(called); |
| 287 base::RunLoop().RunUntilIdle(); | 287 base::RunLoop().RunUntilIdle(); |
| 288 ASSERT_TRUE(called); | 288 ASSERT_TRUE(called); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Make sure that when a new registration replaces an existing | 291 // Make sure registering a new script creates a new version and shares an |
| 292 // registration, that the old one is cleaned up. | 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 render_process_id_, |
| 302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 render_process_id_, |
| 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_TRUE(old_registration->HasOneRef()); | 332 ASSERT_EQ(old_registration, new_registration); |
| 333 | |
| 334 ASSERT_NE(old_registration, new_registration); | |
| 335 | 333 |
| 336 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; | 334 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; |
| 337 storage()->FindRegistrationForPattern( | 335 storage()->FindRegistrationForPattern( |
| 338 pattern, | 336 pattern, |
| 339 SaveFoundRegistration( | 337 SaveFoundRegistration( |
| 340 SERVICE_WORKER_OK, &called, &new_registration)); | 338 SERVICE_WORKER_OK, &called, &new_registration)); |
| 341 | 339 |
| 342 ASSERT_FALSE(called); | 340 ASSERT_FALSE(called); |
| 343 base::RunLoop().RunUntilIdle(); | 341 base::RunLoop().RunUntilIdle(); |
| 344 ASSERT_TRUE(called); | 342 ASSERT_TRUE(called); |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 1099 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, |
| 1102 update_helper->state_change_log_[3].status); | 1100 update_helper->state_change_log_[3].status); |
| 1103 | 1101 |
| 1104 EXPECT_EQ(registration->active_version()->version_id(), | 1102 EXPECT_EQ(registration->active_version()->version_id(), |
| 1105 update_helper->state_change_log_[4].version_id); | 1103 update_helper->state_change_log_[4].version_id); |
| 1106 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1104 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
| 1107 update_helper->state_change_log_[4].status); | 1105 update_helper->state_change_log_[4].status); |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 } // namespace content | 1108 } // namespace content |
| OLD | NEW |