| 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 SaveFoundRegistration( | 695 SaveFoundRegistration( |
| 696 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | 696 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); |
| 697 | 697 |
| 698 base::RunLoop().RunUntilIdle(); | 698 base::RunLoop().RunUntilIdle(); |
| 699 ASSERT_TRUE(find_called); | 699 ASSERT_TRUE(find_called); |
| 700 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 700 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
| 701 } | 701 } |
| 702 | 702 |
| 703 // Tests that the waiting worker enters the 'redundant' state upon | 703 // Tests that the waiting worker enters the 'redundant' state upon |
| 704 // unregistration. | 704 // unregistration. |
| 705 TEST_F(ServiceWorkerJobTest, UnregisterSetsRedundant) { | 705 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { |
| 706 scoped_refptr<ServiceWorkerRegistration> registration; | 706 scoped_refptr<ServiceWorkerRegistration> registration; |
| 707 bool called = false; | 707 bool called = false; |
| 708 job_coordinator()->Register( | 708 job_coordinator()->Register( |
| 709 GURL("http://www.example.com/*"), | 709 GURL("http://www.example.com/*"), |
| 710 GURL("http://www.example.com/service_worker.js"), | 710 GURL("http://www.example.com/service_worker.js"), |
| 711 render_process_id_, | 711 render_process_id_, |
| 712 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 712 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 713 base::RunLoop().RunUntilIdle(); | 713 base::RunLoop().RunUntilIdle(); |
| 714 ASSERT_TRUE(called); | 714 ASSERT_TRUE(called); |
| 715 ASSERT_TRUE(registration); | 715 ASSERT_TRUE(registration); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 733 job_coordinator()->Unregister(GURL("http://www.example.com/*"), | 733 job_coordinator()->Unregister(GURL("http://www.example.com/*"), |
| 734 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 734 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| 735 base::RunLoop().RunUntilIdle(); | 735 base::RunLoop().RunUntilIdle(); |
| 736 ASSERT_TRUE(called); | 736 ASSERT_TRUE(called); |
| 737 | 737 |
| 738 EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 738 EXPECT_EQ(ServiceWorkerVersion::RUNNING, |
| 739 version->running_status()); | 739 version->running_status()); |
| 740 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 740 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
| 741 } | 741 } |
| 742 | 742 |
| 743 // Tests that the active worker enters the 'redundant' state upon |
| 744 // unregistration. |
| 745 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { |
| 746 scoped_refptr<ServiceWorkerRegistration> registration; |
| 747 bool called = false; |
| 748 job_coordinator()->Register( |
| 749 GURL("http://www.example.com/*"), |
| 750 GURL("http://www.example.com/service_worker.js"), |
| 751 render_process_id_, |
| 752 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 753 base::RunLoop().RunUntilIdle(); |
| 754 ASSERT_TRUE(called); |
| 755 ASSERT_TRUE(registration); |
| 756 ASSERT_TRUE(registration->active_version()); |
| 757 |
| 758 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
| 759 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
| 760 EXPECT_EQ(ServiceWorkerVersion::ACTIVE, version->status()); |
| 761 |
| 762 called = false; |
| 763 job_coordinator()->Unregister(GURL("http://www.example.com/*"), |
| 764 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| 765 base::RunLoop().RunUntilIdle(); |
| 766 ASSERT_TRUE(called); |
| 767 |
| 768 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
| 769 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
| 770 } |
| 771 |
| 743 } // namespace content | 772 } // namespace content |
| OLD | NEW |