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 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 GURL("http://www.example.com/service_worker.js"), | 1116 GURL("http://www.example.com/service_worker.js"), |
1117 render_process_id_, | 1117 render_process_id_, |
1118 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 1118 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
1119 | 1119 |
1120 EXPECT_FALSE(called); | 1120 EXPECT_FALSE(called); |
1121 base::RunLoop().RunUntilIdle(); | 1121 base::RunLoop().RunUntilIdle(); |
1122 EXPECT_TRUE(called); | 1122 EXPECT_TRUE(called); |
1123 ServiceWorkerVersion* active_version = registration->active_version(); | 1123 ServiceWorkerVersion* active_version = registration->active_version(); |
1124 | 1124 |
1125 // Queue an Update, it should abort when it starts and sees the new version. | 1125 // Queue an Update, it should abort when it starts and sees the new version. |
1126 job_coordinator()->Update(registration); | 1126 job_coordinator()->Update(registration.get()); |
1127 | 1127 |
1128 // Add a waiting version with new script. | 1128 // Add a waiting version with new script. |
1129 scoped_refptr<ServiceWorkerVersion> version = | 1129 scoped_refptr<ServiceWorkerVersion> version = |
1130 new ServiceWorkerVersion(registration, | 1130 new ServiceWorkerVersion(registration.get(), |
1131 GURL("http://www.example.com/new_worker.js"), | 1131 GURL("http://www.example.com/new_worker.js"), |
1132 2L /* dummy version id */, | 1132 2L /* dummy version id */, |
1133 helper_->context()->AsWeakPtr()); | 1133 helper_->context()->AsWeakPtr()); |
1134 registration->SetWaitingVersion(version); | 1134 registration->SetWaitingVersion(version.get()); |
1135 | 1135 |
1136 base::RunLoop().RunUntilIdle(); | 1136 base::RunLoop().RunUntilIdle(); |
1137 | 1137 |
1138 // Verify the registration was not modified by the Update. | 1138 // Verify the registration was not modified by the Update. |
1139 EXPECT_EQ(active_version, registration->active_version()); | 1139 EXPECT_EQ(active_version, registration->active_version()); |
1140 EXPECT_EQ(version, registration->waiting_version()); | 1140 EXPECT_EQ(version.get(), registration->waiting_version()); |
1141 EXPECT_EQ(NULL, registration->installing_version()); | 1141 EXPECT_EQ(NULL, registration->installing_version()); |
1142 } | 1142 } |
1143 | 1143 |
1144 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { | 1144 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { |
1145 bool called; | 1145 bool called; |
1146 scoped_refptr<ServiceWorkerRegistration> registration; | 1146 scoped_refptr<ServiceWorkerRegistration> registration; |
1147 job_coordinator()->Register( | 1147 job_coordinator()->Register( |
1148 GURL("http://www.example.com/one/"), | 1148 GURL("http://www.example.com/one/"), |
1149 GURL("http://www.example.com/service_worker.js"), | 1149 GURL("http://www.example.com/service_worker.js"), |
1150 render_process_id_, | 1150 render_process_id_, |
1151 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 1151 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
1152 | 1152 |
1153 EXPECT_FALSE(called); | 1153 EXPECT_FALSE(called); |
1154 base::RunLoop().RunUntilIdle(); | 1154 base::RunLoop().RunUntilIdle(); |
1155 EXPECT_TRUE(called); | 1155 EXPECT_TRUE(called); |
1156 | 1156 |
1157 // Add a controllee and queue an unregister to force the uninstalling state. | 1157 // Add a controllee and queue an unregister to force the uninstalling state. |
1158 scoped_ptr<ServiceWorkerProviderHost> host( | 1158 scoped_ptr<ServiceWorkerProviderHost> host( |
1159 new ServiceWorkerProviderHost(33 /* dummy render_process id */, | 1159 new ServiceWorkerProviderHost(33 /* dummy render_process id */, |
1160 1 /* dummy provider_id */, | 1160 1 /* dummy provider_id */, |
1161 helper_->context()->AsWeakPtr(), | 1161 helper_->context()->AsWeakPtr(), |
1162 NULL)); | 1162 NULL)); |
1163 ServiceWorkerVersion* active_version = registration->active_version(); | 1163 ServiceWorkerVersion* active_version = registration->active_version(); |
1164 active_version->AddControllee(host.get()); | 1164 active_version->AddControllee(host.get()); |
1165 job_coordinator()->Unregister(GURL("http://www.example.com/one/"), | 1165 job_coordinator()->Unregister(GURL("http://www.example.com/one/"), |
1166 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 1166 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
1167 | 1167 |
1168 // Update should abort after it starts and sees uninstalling. | 1168 // Update should abort after it starts and sees uninstalling. |
1169 job_coordinator()->Update(registration); | 1169 job_coordinator()->Update(registration.get()); |
1170 | 1170 |
1171 EXPECT_FALSE(called); | 1171 EXPECT_FALSE(called); |
1172 base::RunLoop().RunUntilIdle(); | 1172 base::RunLoop().RunUntilIdle(); |
1173 EXPECT_TRUE(called); | 1173 EXPECT_TRUE(called); |
1174 | 1174 |
1175 // Verify the registration was not modified by the Update. | 1175 // Verify the registration was not modified by the Update. |
1176 EXPECT_TRUE(registration->is_uninstalling()); | 1176 EXPECT_TRUE(registration->is_uninstalling()); |
1177 EXPECT_EQ(active_version, registration->active_version()); | 1177 EXPECT_EQ(active_version, registration->active_version()); |
1178 EXPECT_EQ(NULL, registration->waiting_version()); | 1178 EXPECT_EQ(NULL, registration->waiting_version()); |
1179 EXPECT_EQ(NULL, registration->installing_version()); | 1179 EXPECT_EQ(NULL, registration->installing_version()); |
1180 } | 1180 } |
1181 | 1181 |
1182 } // namespace content | 1182 } // namespace content |
OLD | NEW |