| 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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 708   base::RunLoop().RunUntilIdle(); | 708   base::RunLoop().RunUntilIdle(); | 
| 709   ASSERT_TRUE(find_called); | 709   ASSERT_TRUE(find_called); | 
| 710   EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 710   EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 
| 711 } | 711 } | 
| 712 | 712 | 
| 713 // Tests that the waiting worker enters the 'redundant' state upon | 713 // Tests that the waiting worker enters the 'redundant' state upon | 
| 714 // unregistration. | 714 // unregistration. | 
| 715 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { | 715 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { | 
| 716   scoped_refptr<ServiceWorkerRegistration> registration; | 716   scoped_refptr<ServiceWorkerRegistration> registration; | 
| 717   bool called = false; | 717   bool called = false; | 
|  | 718   GURL script_url("http://www.example.com/service_worker.js"); | 
| 718   job_coordinator()->Register( | 719   job_coordinator()->Register( | 
| 719       GURL("http://www.example.com/"), | 720       GURL("http://www.example.com/"), | 
| 720       GURL("http://www.example.com/service_worker.js"), | 721       script_url, | 
| 721       render_process_id_, | 722       render_process_id_, | 
| 722       SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 723       SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 
| 723   base::RunLoop().RunUntilIdle(); | 724   base::RunLoop().RunUntilIdle(); | 
| 724   ASSERT_TRUE(called); | 725   ASSERT_TRUE(called); | 
| 725   ASSERT_TRUE(registration.get()); | 726   ASSERT_TRUE(registration.get()); | 
| 726 | 727 | 
| 727   // Manually create the waiting worker since there is no way to become a | 728   // Manually create the waiting worker since there is no way to become a | 
| 728   // waiting worker until Update is implemented. | 729   // waiting worker until Update is implemented. | 
| 729   scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 730   scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 
| 730       registration.get(), 1L, helper_->context()->AsWeakPtr()); | 731       registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); | 
| 731   ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 732   ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 
| 732   version->StartWorker(CreateReceiverOnCurrentThread(&status)); | 733   version->StartWorker(CreateReceiverOnCurrentThread(&status)); | 
| 733   base::RunLoop().RunUntilIdle(); | 734   base::RunLoop().RunUntilIdle(); | 
| 734   ASSERT_EQ(SERVICE_WORKER_OK, status); | 735   ASSERT_EQ(SERVICE_WORKER_OK, status); | 
| 735 | 736 | 
| 736   version->SetStatus(ServiceWorkerVersion::INSTALLED); | 737   version->SetStatus(ServiceWorkerVersion::INSTALLED); | 
| 737   registration->SetWaitingVersion(version.get()); | 738   registration->SetWaitingVersion(version.get()); | 
| 738   EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 739   EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 
| 739             version->running_status()); | 740             version->running_status()); | 
| 740   EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 741   EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1100             update_helper->state_change_log_[3].version_id); | 1101             update_helper->state_change_log_[3].version_id); | 
| 1101   EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 1102   EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 
| 1102             update_helper->state_change_log_[3].status); | 1103             update_helper->state_change_log_[3].status); | 
| 1103 | 1104 | 
| 1104   EXPECT_EQ(registration->active_version()->version_id(), | 1105   EXPECT_EQ(registration->active_version()->version_id(), | 
| 1105             update_helper->state_change_log_[4].version_id); | 1106             update_helper->state_change_log_[4].version_id); | 
| 1106   EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1107   EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 
| 1107             update_helper->state_change_log_[4].status); | 1108             update_helper->state_change_log_[4].status); | 
| 1108 } | 1109 } | 
| 1109 | 1110 | 
|  | 1111 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { | 
|  | 1112   bool called; | 
|  | 1113   scoped_refptr<ServiceWorkerRegistration> registration; | 
|  | 1114   job_coordinator()->Register( | 
|  | 1115       GURL("http://www.example.com/one/"), | 
|  | 1116       GURL("http://www.example.com/service_worker.js"), | 
|  | 1117       render_process_id_, | 
|  | 1118       SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 
|  | 1119 | 
|  | 1120   EXPECT_FALSE(called); | 
|  | 1121   base::RunLoop().RunUntilIdle(); | 
|  | 1122   EXPECT_TRUE(called); | 
|  | 1123   ServiceWorkerVersion* active_version = registration->active_version(); | 
|  | 1124 | 
|  | 1125   // Queue an Update, it should abort when it starts and sees the new version. | 
|  | 1126   job_coordinator()->Update(registration); | 
|  | 1127 | 
|  | 1128   // Add a waiting version with new script. | 
|  | 1129   scoped_refptr<ServiceWorkerVersion> version = | 
|  | 1130       new ServiceWorkerVersion(registration, | 
|  | 1131                                GURL("http://www.example.com/new_worker.js"), | 
|  | 1132                                2L /* dummy version id */, | 
|  | 1133                                helper_->context()->AsWeakPtr()); | 
|  | 1134   registration->SetWaitingVersion(version); | 
|  | 1135 | 
|  | 1136   base::RunLoop().RunUntilIdle(); | 
|  | 1137 | 
|  | 1138   // Verify the registration was not modified by the Update. | 
|  | 1139   EXPECT_EQ(active_version, registration->active_version()); | 
|  | 1140   EXPECT_EQ(version, registration->waiting_version()); | 
|  | 1141   EXPECT_EQ(NULL, registration->installing_version()); | 
|  | 1142 } | 
|  | 1143 | 
|  | 1144 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { | 
|  | 1145   bool called; | 
|  | 1146   scoped_refptr<ServiceWorkerRegistration> registration; | 
|  | 1147   job_coordinator()->Register( | 
|  | 1148       GURL("http://www.example.com/one/"), | 
|  | 1149       GURL("http://www.example.com/service_worker.js"), | 
|  | 1150       render_process_id_, | 
|  | 1151       SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 
|  | 1152 | 
|  | 1153   EXPECT_FALSE(called); | 
|  | 1154   base::RunLoop().RunUntilIdle(); | 
|  | 1155   EXPECT_TRUE(called); | 
|  | 1156 | 
|  | 1157   // Add a controllee and queue an unregister to force the uninstalling state. | 
|  | 1158   scoped_ptr<ServiceWorkerProviderHost> host( | 
|  | 1159       new ServiceWorkerProviderHost(33 /* dummy render_process id */, | 
|  | 1160                                     1 /* dummy provider_id */, | 
|  | 1161                                     helper_->context()->AsWeakPtr(), | 
|  | 1162                                     NULL)); | 
|  | 1163   ServiceWorkerVersion* active_version = registration->active_version(); | 
|  | 1164   active_version->AddControllee(host.get()); | 
|  | 1165   job_coordinator()->Unregister(GURL("http://www.example.com/one/"), | 
|  | 1166                                 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 
|  | 1167 | 
|  | 1168   // Update should abort after it starts and sees uninstalling. | 
|  | 1169   job_coordinator()->Update(registration); | 
|  | 1170 | 
|  | 1171   EXPECT_FALSE(called); | 
|  | 1172   base::RunLoop().RunUntilIdle(); | 
|  | 1173   EXPECT_TRUE(called); | 
|  | 1174 | 
|  | 1175   // Verify the registration was not modified by the Update. | 
|  | 1176   EXPECT_TRUE(registration->is_uninstalling()); | 
|  | 1177   EXPECT_EQ(active_version, registration->active_version()); | 
|  | 1178   EXPECT_EQ(NULL, registration->waiting_version()); | 
|  | 1179   EXPECT_EQ(NULL, registration->installing_version()); | 
|  | 1180 } | 
|  | 1181 | 
| 1110 }  // namespace content | 1182 }  // namespace content | 
| OLD | NEW | 
|---|