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

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

Issue 501453002: Decouple script_url from ServiceWorkerRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments and add unittests Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_provider_host.h" 9 #include "content/browser/service_worker/service_worker_provider_host.h"
10 #include "content/browser/service_worker/service_worker_register_job.h" 10 #include "content/browser/service_worker/service_worker_register_job.h"
(...skipping 18 matching lines...) Expand all
29 base::ThreadTaskRunnerHandle::Get(), 29 base::ThreadTaskRunnerHandle::Get(),
30 base::ThreadTaskRunnerHandle::Get(), 30 base::ThreadTaskRunnerHandle::Get(),
31 base::ThreadTaskRunnerHandle::Get(), 31 base::ThreadTaskRunnerHandle::Get(),
32 NULL, 32 NULL,
33 NULL, 33 NULL,
34 NULL)); 34 NULL));
35 35
36 scope_ = GURL("http://www.example.com/"); 36 scope_ = GURL("http://www.example.com/");
37 script_url_ = GURL("http://www.example.com/service_worker.js"); 37 script_url_ = GURL("http://www.example.com/service_worker.js");
38 registration_ = new ServiceWorkerRegistration( 38 registration_ = new ServiceWorkerRegistration(
39 scope_, script_url_, 1L, context_->AsWeakPtr()); 39 scope_, 1L, context_->AsWeakPtr());
40 version_ = new ServiceWorkerVersion( 40 version_ = new ServiceWorkerVersion(
41 registration_, 41 registration_, script_url_, 1L, context_->AsWeakPtr());
42 1L, context_->AsWeakPtr());
43 42
44 // Prepare provider hosts (for the same process). 43 // Prepare provider hosts (for the same process).
45 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( 44 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost(
46 kRenderProcessId, 1 /* provider_id */, 45 kRenderProcessId, 1 /* provider_id */,
47 context_->AsWeakPtr(), NULL)); 46 context_->AsWeakPtr(), NULL));
48 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( 47 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost(
49 kRenderProcessId, 2 /* provider_id */, 48 kRenderProcessId, 2 /* provider_id */,
50 context_->AsWeakPtr(), NULL)); 49 context_->AsWeakPtr(), NULL));
51 provider_host1_ = host1->AsWeakPtr(); 50 provider_host1_ = host1->AsWeakPtr();
52 provider_host2_ = host2->AsWeakPtr(); 51 provider_host2_ = host2->AsWeakPtr();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 187 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
189 } 188 }
190 189
191 TEST_F(ServiceWorkerProviderHostTest, 190 TEST_F(ServiceWorkerProviderHostTest,
192 ObserveVersionAttributesChanged_MultipleVersions) { 191 ObserveVersionAttributesChanged_MultipleVersions) {
193 provider_host1_->AssociateRegistration(registration_); 192 provider_host1_->AssociateRegistration(registration_);
194 provider_host2_->AssociateRegistration(registration_); 193 provider_host2_->AssociateRegistration(registration_);
195 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL); 194 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL);
196 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 195 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
197 196
198 scoped_refptr<ServiceWorkerVersion> version1 = 197 scoped_refptr<ServiceWorkerVersion> version1 = new ServiceWorkerVersion(
199 new ServiceWorkerVersion(registration_, 10L, context_->AsWeakPtr()); 198 registration_, script_url_, 10L, context_->AsWeakPtr());
200 scoped_refptr<ServiceWorkerVersion> version2 = 199 scoped_refptr<ServiceWorkerVersion> version2 = new ServiceWorkerVersion(
201 new ServiceWorkerVersion(registration_, 20L, context_->AsWeakPtr()); 200 registration_, script_url_, 20L, context_->AsWeakPtr());
202 201
203 registration_->SetInstallingVersion(version1); 202 registration_->SetInstallingVersion(version1);
204 VerifyVersionAttributes(provider_host1_, version1, NULL, NULL); 203 VerifyVersionAttributes(provider_host1_, version1, NULL, NULL);
205 VerifyVersionAttributes(provider_host2_, version1, NULL, NULL); 204 VerifyVersionAttributes(provider_host2_, version1, NULL, NULL);
206 205
207 registration_->SetWaitingVersion(version1); 206 registration_->SetWaitingVersion(version1);
208 VerifyVersionAttributes(provider_host1_, NULL, version1, NULL); 207 VerifyVersionAttributes(provider_host1_, NULL, version1, NULL);
209 VerifyVersionAttributes(provider_host2_, NULL, version1, NULL); 208 VerifyVersionAttributes(provider_host2_, NULL, version1, NULL);
210 209
211 registration_->SetInstallingVersion(version2); 210 registration_->SetInstallingVersion(version2);
212 VerifyVersionAttributes(provider_host1_, version2, version1, NULL); 211 VerifyVersionAttributes(provider_host1_, version2, version1, NULL);
213 VerifyVersionAttributes(provider_host2_, version2, version1, NULL); 212 VerifyVersionAttributes(provider_host2_, version2, version1, NULL);
214 213
215 // Disassociating the registration should clear all version attributes. 214 // Disassociating the registration should clear all version attributes.
216 provider_host2_->UnassociateRegistration(); 215 provider_host2_->UnassociateRegistration();
217 VerifyVersionAttributes(provider_host1_, version2, version1, NULL); 216 VerifyVersionAttributes(provider_host1_, version2, version1, NULL);
218 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 217 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
219 218
220 // Shouldn't notify the disassociated provider of the change. 219 // Shouldn't notify the disassociated provider of the change.
221 registration_->SetActiveVersion(version1); 220 registration_->SetActiveVersion(version1);
222 VerifyVersionAttributes(provider_host1_, version2, NULL, version1); 221 VerifyVersionAttributes(provider_host1_, version2, NULL, version1);
223 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 222 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
224 223
225 registration_->SetActiveVersion(version2); 224 registration_->SetActiveVersion(version2);
226 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2); 225 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2);
227 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 226 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
228 } 227 }
229 228
230 } // namespace content 229 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698