| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 private: | 97 private: |
| 98 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 98 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 99 TestBrowserThreadBundle thread_bundle_; | 99 TestBrowserThreadBundle thread_bundle_; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { | 102 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { |
| 103 const GURL kScope("http://www.example.not/"); | 103 const GURL kScope("http://www.example.not/"); |
| 104 const GURL kScript("http://www.example.not/service_worker.js"); | 104 const GURL kScript("http://www.example.not/service_worker.js"); |
| 105 int64_t kRegistrationId = 1L; | 105 int64_t kRegistrationId = 1L; |
| 106 scoped_refptr<ServiceWorkerRegistration> registration = | 106 scoped_refptr<ServiceWorkerRegistration> registration = |
| 107 new ServiceWorkerRegistration(kScope, kRegistrationId, | 107 new ServiceWorkerRegistration(kScope, false /* use_cache */, |
| 108 context()->AsWeakPtr()); | 108 kRegistrationId, context()->AsWeakPtr()); |
| 109 | 109 |
| 110 const int64_t version_1_id = 1L; | 110 const int64_t version_1_id = 1L; |
| 111 const int64_t version_2_id = 2L; | 111 const int64_t version_2_id = 2L; |
| 112 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( | 112 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
| 113 registration.get(), kScript, version_1_id, context()->AsWeakPtr()); | 113 registration.get(), kScript, version_1_id, context()->AsWeakPtr()); |
| 114 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( | 114 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
| 115 registration.get(), kScript, version_2_id, context()->AsWeakPtr()); | 115 registration.get(), kScript, version_2_id, context()->AsWeakPtr()); |
| 116 | 116 |
| 117 RegistrationListener listener; | 117 RegistrationListener listener; |
| 118 registration->AddListener(&listener); | 118 registration->AddListener(&listener); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, | 164 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, |
| 165 kInvalidServiceWorkerVersionId); | 165 kInvalidServiceWorkerVersionId); |
| 166 EXPECT_EQ(listener.observed_info_.installing_version.version_id, | 166 EXPECT_EQ(listener.observed_info_.installing_version.version_id, |
| 167 kInvalidServiceWorkerVersionId); | 167 kInvalidServiceWorkerVersionId); |
| 168 } | 168 } |
| 169 | 169 |
| 170 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { | 170 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { |
| 171 const GURL kScope("http://www.example.not/"); | 171 const GURL kScope("http://www.example.not/"); |
| 172 int64_t kRegistrationId = 1L; | 172 int64_t kRegistrationId = 1L; |
| 173 scoped_refptr<ServiceWorkerRegistration> registration = | 173 scoped_refptr<ServiceWorkerRegistration> registration = |
| 174 new ServiceWorkerRegistration(kScope, kRegistrationId, | 174 new ServiceWorkerRegistration(kScope, false /* use_cache */, |
| 175 context()->AsWeakPtr()); | 175 kRegistrationId, context()->AsWeakPtr()); |
| 176 std::unique_ptr<ServiceWorkerRegistrationHandle> handle( | 176 std::unique_ptr<ServiceWorkerRegistrationHandle> handle( |
| 177 new ServiceWorkerRegistrationHandle( | 177 new ServiceWorkerRegistrationHandle( |
| 178 context()->AsWeakPtr(), base::WeakPtr<ServiceWorkerProviderHost>(), | 178 context()->AsWeakPtr(), base::WeakPtr<ServiceWorkerProviderHost>(), |
| 179 registration.get())); | 179 registration.get())); |
| 180 registration->NotifyRegistrationFailed(); | 180 registration->NotifyRegistrationFailed(); |
| 181 // Don't crash when handle gets destructed. | 181 // Don't crash when handle gets destructed. |
| 182 } | 182 } |
| 183 | 183 |
| 184 TEST_F(ServiceWorkerRegistrationTest, NavigationPreload) { | 184 TEST_F(ServiceWorkerRegistrationTest, NavigationPreload) { |
| 185 const GURL kScope("http://www.example.not/"); | 185 const GURL kScope("http://www.example.not/"); |
| 186 const GURL kScript("https://www.example.not/service_worker.js"); | 186 const GURL kScript("https://www.example.not/service_worker.js"); |
| 187 // Setup. | 187 // Setup. |
| 188 scoped_refptr<ServiceWorkerRegistration> registration = | 188 scoped_refptr<ServiceWorkerRegistration> registration = |
| 189 new ServiceWorkerRegistration(kScope, storage()->NewRegistrationId(), | 189 new ServiceWorkerRegistration(kScope, false /* use_cache */, |
| 190 storage()->NewRegistrationId(), |
| 190 context()->AsWeakPtr()); | 191 context()->AsWeakPtr()); |
| 191 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( | 192 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
| 192 registration.get(), kScript, storage()->NewVersionId(), | 193 registration.get(), kScript, storage()->NewVersionId(), |
| 193 context()->AsWeakPtr()); | 194 context()->AsWeakPtr()); |
| 194 version_1->set_fetch_handler_existence( | 195 version_1->set_fetch_handler_existence( |
| 195 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 196 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| 196 registration->SetActiveVersion(version_1); | 197 registration->SetActiveVersion(version_1); |
| 197 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); | 198 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 198 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( | 199 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
| 199 registration.get(), kScript, storage()->NewVersionId(), | 200 registration.get(), kScript, storage()->NewVersionId(), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 223 public: | 224 public: |
| 224 ServiceWorkerActivationTest() : ServiceWorkerRegistrationTest() {} | 225 ServiceWorkerActivationTest() : ServiceWorkerRegistrationTest() {} |
| 225 | 226 |
| 226 void SetUp() override { | 227 void SetUp() override { |
| 227 ServiceWorkerRegistrationTest::SetUp(); | 228 ServiceWorkerRegistrationTest::SetUp(); |
| 228 | 229 |
| 229 const GURL kScope("https://www.example.not/"); | 230 const GURL kScope("https://www.example.not/"); |
| 230 const GURL kScript("https://www.example.not/service_worker.js"); | 231 const GURL kScript("https://www.example.not/service_worker.js"); |
| 231 | 232 |
| 232 registration_ = new ServiceWorkerRegistration( | 233 registration_ = new ServiceWorkerRegistration( |
| 233 kScope, storage()->NewRegistrationId(), context()->AsWeakPtr()); | 234 kScope, false /* use_cache */, storage()->NewRegistrationId(), |
| 235 context()->AsWeakPtr()); |
| 234 | 236 |
| 235 // Create an active version. | 237 // Create an active version. |
| 236 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( | 238 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
| 237 registration_.get(), kScript, storage()->NewVersionId(), | 239 registration_.get(), kScript, storage()->NewVersionId(), |
| 238 context()->AsWeakPtr()); | 240 context()->AsWeakPtr()); |
| 239 version_1->set_fetch_handler_existence( | 241 version_1->set_fetch_handler_existence( |
| 240 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 242 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| 241 registration_->SetActiveVersion(version_1); | 243 registration_->SetActiveVersion(version_1); |
| 242 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); | 244 version_1->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 243 | 245 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 EXPECT_EQ(version_1.get(), reg->active_version()); | 367 EXPECT_EQ(version_1.get(), reg->active_version()); |
| 366 | 368 |
| 367 // Finish the request. Activation should happen. | 369 // Finish the request. Activation should happen. |
| 368 version_1->FinishRequest(inflight_request_id(), true /* was_handled */, | 370 version_1->FinishRequest(inflight_request_id(), true /* was_handled */, |
| 369 base::Time::Now()); | 371 base::Time::Now()); |
| 370 base::RunLoop().RunUntilIdle(); | 372 base::RunLoop().RunUntilIdle(); |
| 371 EXPECT_EQ(version_2.get(), reg->active_version()); | 373 EXPECT_EQ(version_2.get(), reg->active_version()); |
| 372 } | 374 } |
| 373 | 375 |
| 374 } // namespace content | 376 } // namespace content |
| OLD | NEW |