| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; | 251 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; |
| 252 context()->storage()->StoreRegistration( | 252 context()->storage()->StoreRegistration( |
| 253 registration_.get(), version_1.get(), | 253 registration_.get(), version_1.get(), |
| 254 CreateReceiverOnCurrentThread(&status)); | 254 CreateReceiverOnCurrentThread(&status)); |
| 255 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
| 256 ASSERT_EQ(SERVICE_WORKER_OK, status); | 256 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 257 | 257 |
| 258 // Give the active version a controllee. | 258 // Give the active version a controllee. |
| 259 host_ = CreateProviderHostForWindow( | 259 host_ = CreateProviderHostForWindow( |
| 260 33 /* dummy render process id */, 1 /* dummy provider_id */, | 260 33 /* dummy render process id */, 1 /* dummy provider_id */, |
| 261 true /* is_parent_frame_secure */, context()->AsWeakPtr()); | 261 true /* is_parent_frame_secure */, context()->AsWeakPtr(), |
| 262 &remote_endpoint_); |
| 262 version_1->AddControllee(host_.get()); | 263 version_1->AddControllee(host_.get()); |
| 263 | 264 |
| 264 // Give the active version an in-flight request. | 265 // Give the active version an in-flight request. |
| 265 inflight_request_id_ = CreateInflightRequest(version_1.get()); | 266 inflight_request_id_ = CreateInflightRequest(version_1.get()); |
| 266 | 267 |
| 267 // Create a waiting version. | 268 // Create a waiting version. |
| 268 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( | 269 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
| 269 registration_.get(), kScript, storage()->NewVersionId(), | 270 registration_.get(), kScript, storage()->NewVersionId(), |
| 270 context()->AsWeakPtr()); | 271 context()->AsWeakPtr()); |
| 271 version_2->set_fetch_handler_existence( | 272 version_2->set_fetch_handler_existence( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 285 ServiceWorkerRegistrationTest::TearDown(); | 286 ServiceWorkerRegistrationTest::TearDown(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 ServiceWorkerRegistration* registration() { return registration_.get(); } | 289 ServiceWorkerRegistration* registration() { return registration_.get(); } |
| 289 ServiceWorkerProviderHost* controllee() { return host_.get(); } | 290 ServiceWorkerProviderHost* controllee() { return host_.get(); } |
| 290 int inflight_request_id() const { return inflight_request_id_; } | 291 int inflight_request_id() const { return inflight_request_id_; } |
| 291 | 292 |
| 292 private: | 293 private: |
| 293 scoped_refptr<ServiceWorkerRegistration> registration_; | 294 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 294 std::unique_ptr<ServiceWorkerProviderHost> host_; | 295 std::unique_ptr<ServiceWorkerProviderHost> host_; |
| 296 ServiceWorkerRemoteProviderEndpoint remote_endpoint_; |
| 295 int inflight_request_id_ = -1; | 297 int inflight_request_id_ = -1; |
| 296 }; | 298 }; |
| 297 | 299 |
| 298 // Test activation triggered by finishing all requests. | 300 // Test activation triggered by finishing all requests. |
| 299 TEST_F(ServiceWorkerActivationTest, NoInflightRequest) { | 301 TEST_F(ServiceWorkerActivationTest, NoInflightRequest) { |
| 300 scoped_refptr<ServiceWorkerRegistration> reg = registration(); | 302 scoped_refptr<ServiceWorkerRegistration> reg = registration(); |
| 301 scoped_refptr<ServiceWorkerVersion> version_1 = reg->active_version(); | 303 scoped_refptr<ServiceWorkerVersion> version_1 = reg->active_version(); |
| 302 scoped_refptr<ServiceWorkerVersion> version_2 = reg->waiting_version(); | 304 scoped_refptr<ServiceWorkerVersion> version_2 = reg->waiting_version(); |
| 303 | 305 |
| 304 // Remove the controllee. Since there is an in-flight request, | 306 // Remove the controllee. Since there is an in-flight request, |
| (...skipping 60 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 |