| 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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 EXPECT_TRUE(called); | 1171 EXPECT_TRUE(called); |
| 1174 | 1172 |
| 1175 // Verify the registration was not modified by the Update. | 1173 // Verify the registration was not modified by the Update. |
| 1176 EXPECT_TRUE(registration->is_uninstalling()); | 1174 EXPECT_TRUE(registration->is_uninstalling()); |
| 1177 EXPECT_EQ(active_version, registration->active_version()); | 1175 EXPECT_EQ(active_version, registration->active_version()); |
| 1178 EXPECT_EQ(NULL, registration->waiting_version()); | 1176 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1179 EXPECT_EQ(NULL, registration->installing_version()); | 1177 EXPECT_EQ(NULL, registration->installing_version()); |
| 1180 } | 1178 } |
| 1181 | 1179 |
| 1182 } // namespace content | 1180 } // namespace content |
| OLD | NEW |