OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 protected: | 101 protected: |
102 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 102 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
103 TestBrowserThreadBundle thread_bundle_; | 103 TestBrowserThreadBundle thread_bundle_; |
104 }; | 104 }; |
105 | 105 |
106 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { | 106 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { |
107 const GURL kScope("http://www.example.not/"); | 107 const GURL kScope("http://www.example.not/"); |
108 const GURL kScript("http://www.example.not/service_worker.js"); | 108 const GURL kScript("http://www.example.not/service_worker.js"); |
109 int64_t kRegistrationId = 1L; | 109 int64_t kRegistrationId = 1L; |
110 scoped_refptr<ServiceWorkerRegistration> registration = | 110 scoped_refptr<ServiceWorkerRegistration> registration = |
111 new ServiceWorkerRegistration(kScope, kRegistrationId, | 111 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope), |
112 context()->AsWeakPtr()); | 112 kRegistrationId, context()->AsWeakPtr()); |
113 | 113 |
114 const int64_t version_1_id = 1L; | 114 const int64_t version_1_id = 1L; |
115 const int64_t version_2_id = 2L; | 115 const int64_t version_2_id = 2L; |
116 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( | 116 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
117 registration.get(), kScript, version_1_id, context()->AsWeakPtr()); | 117 registration.get(), kScript, version_1_id, context()->AsWeakPtr()); |
118 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( | 118 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
119 registration.get(), kScript, version_2_id, context()->AsWeakPtr()); | 119 registration.get(), kScript, version_2_id, context()->AsWeakPtr()); |
120 | 120 |
121 RegistrationListener listener; | 121 RegistrationListener listener; |
122 registration->AddListener(&listener); | 122 registration->AddListener(&listener); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, | 168 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, |
169 kInvalidServiceWorkerVersionId); | 169 kInvalidServiceWorkerVersionId); |
170 EXPECT_EQ(listener.observed_info_.installing_version.version_id, | 170 EXPECT_EQ(listener.observed_info_.installing_version.version_id, |
171 kInvalidServiceWorkerVersionId); | 171 kInvalidServiceWorkerVersionId); |
172 } | 172 } |
173 | 173 |
174 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { | 174 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { |
175 const GURL kScope("http://www.example.not/"); | 175 const GURL kScope("http://www.example.not/"); |
176 int64_t kRegistrationId = 1L; | 176 int64_t kRegistrationId = 1L; |
177 scoped_refptr<ServiceWorkerRegistration> registration = | 177 scoped_refptr<ServiceWorkerRegistration> registration = |
178 new ServiceWorkerRegistration(kScope, kRegistrationId, | 178 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope), |
179 context()->AsWeakPtr()); | 179 kRegistrationId, context()->AsWeakPtr()); |
180 std::unique_ptr<ServiceWorkerRegistrationHandle> handle( | 180 std::unique_ptr<ServiceWorkerRegistrationHandle> handle( |
181 new ServiceWorkerRegistrationHandle( | 181 new ServiceWorkerRegistrationHandle( |
182 context()->AsWeakPtr(), base::WeakPtr<ServiceWorkerProviderHost>(), | 182 context()->AsWeakPtr(), base::WeakPtr<ServiceWorkerProviderHost>(), |
183 registration.get())); | 183 registration.get())); |
184 registration->NotifyRegistrationFailed(); | 184 registration->NotifyRegistrationFailed(); |
185 // Don't crash when handle gets destructed. | 185 // Don't crash when handle gets destructed. |
186 } | 186 } |
187 | 187 |
188 TEST_F(ServiceWorkerRegistrationTest, NavigationPreload) { | 188 TEST_F(ServiceWorkerRegistrationTest, NavigationPreload) { |
189 const GURL kScope("http://www.example.not/"); | 189 const GURL kScope("http://www.example.not/"); |
190 const GURL kScript("https://www.example.not/service_worker.js"); | 190 const GURL kScript("https://www.example.not/service_worker.js"); |
191 // Setup. | 191 // Setup. |
192 scoped_refptr<ServiceWorkerRegistration> registration = | 192 scoped_refptr<ServiceWorkerRegistration> registration = |
193 new ServiceWorkerRegistration(kScope, storage()->NewRegistrationId(), | 193 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope), |
| 194 storage()->NewRegistrationId(), |
194 context()->AsWeakPtr()); | 195 context()->AsWeakPtr()); |
195 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( | 196 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
196 registration.get(), kScript, storage()->NewVersionId(), | 197 registration.get(), kScript, storage()->NewVersionId(), |
197 context()->AsWeakPtr()); | 198 context()->AsWeakPtr()); |
198 version_1->set_fetch_handler_existence( | 199 version_1->set_fetch_handler_existence( |
199 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 200 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
200 registration->SetActiveVersion(version_1); | 201 registration->SetActiveVersion(version_1); |
201 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); | 202 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); |
202 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( | 203 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
203 registration.get(), kScript, storage()->NewVersionId(), | 204 registration.get(), kScript, storage()->NewVersionId(), |
(...skipping 23 matching lines...) Expand all Loading... |
227 public: | 228 public: |
228 ServiceWorkerActivationTest() : ServiceWorkerRegistrationTest() {} | 229 ServiceWorkerActivationTest() : ServiceWorkerRegistrationTest() {} |
229 | 230 |
230 void SetUp() override { | 231 void SetUp() override { |
231 ServiceWorkerRegistrationTest::SetUp(); | 232 ServiceWorkerRegistrationTest::SetUp(); |
232 | 233 |
233 const GURL kScope("https://www.example.not/"); | 234 const GURL kScope("https://www.example.not/"); |
234 const GURL kScript("https://www.example.not/service_worker.js"); | 235 const GURL kScript("https://www.example.not/service_worker.js"); |
235 | 236 |
236 registration_ = new ServiceWorkerRegistration( | 237 registration_ = new ServiceWorkerRegistration( |
237 kScope, storage()->NewRegistrationId(), context()->AsWeakPtr()); | 238 ServiceWorkerRegistrationOptions(kScope), |
| 239 storage()->NewRegistrationId(), context()->AsWeakPtr()); |
238 | 240 |
239 // Create an active version. | 241 // Create an active version. |
240 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( | 242 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
241 registration_.get(), kScript, storage()->NewVersionId(), | 243 registration_.get(), kScript, storage()->NewVersionId(), |
242 context()->AsWeakPtr()); | 244 context()->AsWeakPtr()); |
243 version_1->set_fetch_handler_existence( | 245 version_1->set_fetch_handler_existence( |
244 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 246 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
245 registration_->SetActiveVersion(version_1); | 247 registration_->SetActiveVersion(version_1); |
246 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); | 248 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); |
247 | 249 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 clock_1->Advance(kMaxLameDuckTime + base::TimeDelta::FromSeconds(1)); | 499 clock_1->Advance(kMaxLameDuckTime + base::TimeDelta::FromSeconds(1)); |
498 | 500 |
499 // Activation should happen by the lame duck timer. | 501 // Activation should happen by the lame duck timer. |
500 RunLameDuckTimer(); | 502 RunLameDuckTimer(); |
501 base::RunLoop().RunUntilIdle(); | 503 base::RunLoop().RunUntilIdle(); |
502 EXPECT_EQ(version_2.get(), reg->active_version()); | 504 EXPECT_EQ(version_2.get(), reg->active_version()); |
503 EXPECT_FALSE(IsLameDuckTimerRunning()); | 505 EXPECT_FALSE(IsLameDuckTimerRunning()); |
504 } | 506 } |
505 | 507 |
506 } // namespace content | 508 } // namespace content |
OLD | NEW |