Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: content/browser/service_worker/service_worker_registration_unittest.cc

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Rebased Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 observed_registration_ = NULL; 87 observed_registration_ = NULL;
88 observed_changed_mask_ = ChangedVersionAttributesMask(); 88 observed_changed_mask_ = ChangedVersionAttributesMask();
89 observed_info_ = ServiceWorkerRegistrationInfo(); 89 observed_info_ = ServiceWorkerRegistrationInfo();
90 } 90 }
91 91
92 scoped_refptr<ServiceWorkerRegistration> observed_registration_; 92 scoped_refptr<ServiceWorkerRegistration> observed_registration_;
93 ChangedVersionAttributesMask observed_changed_mask_; 93 ChangedVersionAttributesMask observed_changed_mask_;
94 ServiceWorkerRegistrationInfo observed_info_; 94 ServiceWorkerRegistrationInfo observed_info_;
95 }; 95 };
96 96
97 private: 97 protected:
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, kRegistrationId,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); 250 EmbeddedWorkerTestHelper::CreateHttpResponseInfo());
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 helper_->mock_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 &remote_endpoint_);
263 DCHECK(remote_endpoint_.client_request()->is_pending());
264 DCHECK(remote_endpoint_.host_ptr()->is_bound());
263 version_1->AddControllee(host_.get()); 265 version_1->AddControllee(host_.get());
264 266
265 // Give the active version an in-flight request. 267 // Give the active version an in-flight request.
266 inflight_request_id_ = CreateInflightRequest(version_1.get()); 268 inflight_request_id_ = CreateInflightRequest(version_1.get());
267 269
268 // Create a waiting version. 270 // Create a waiting version.
269 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( 271 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion(
270 registration_.get(), kScript, storage()->NewVersionId(), 272 registration_.get(), kScript, storage()->NewVersionId(),
271 context()->AsWeakPtr()); 273 context()->AsWeakPtr());
272 version_2->set_fetch_handler_existence( 274 version_2->set_fetch_handler_existence(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_EQ(version_1.get(), reg->active_version()); 369 EXPECT_EQ(version_1.get(), reg->active_version());
368 370
369 // Finish the request. Activation should happen. 371 // Finish the request. Activation should happen.
370 version_1->FinishRequest(inflight_request_id(), true /* was_handled */, 372 version_1->FinishRequest(inflight_request_id(), true /* was_handled */,
371 base::Time::Now()); 373 base::Time::Now());
372 base::RunLoop().RunUntilIdle(); 374 base::RunLoop().RunUntilIdle();
373 EXPECT_EQ(version_2.get(), reg->active_version()); 375 EXPECT_EQ(version_2.get(), reg->active_version());
374 } 376 }
375 377
376 } // namespace content 378 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698