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

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

Issue 445883003: ServiceWorker: Consolidate version change messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 "content/browser/service_worker/service_worker_context_core.h" 7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_provider_host.h" 8 #include "content/browser/service_worker/service_worker_provider_host.h"
9 #include "content/browser/service_worker/service_worker_register_job.h" 9 #include "content/browser/service_worker/service_worker_register_job.h"
10 #include "content/browser/service_worker/service_worker_registration.h" 10 #include "content/browser/service_worker/service_worker_registration.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 context_->AddProviderHost(make_scoped_ptr(host1.release())); 52 context_->AddProviderHost(make_scoped_ptr(host1.release()));
53 context_->AddProviderHost(make_scoped_ptr(host2.release())); 53 context_->AddProviderHost(make_scoped_ptr(host2.release()));
54 } 54 }
55 55
56 virtual void TearDown() OVERRIDE { 56 virtual void TearDown() OVERRIDE {
57 version_ = 0; 57 version_ = 0;
58 registration_ = 0; 58 registration_ = 0;
59 context_.reset(); 59 context_.reset();
60 } 60 }
61 61
62 void SetActiveVersion( 62 void VerifyVersionAttributes(
63 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 63 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
64 ServiceWorkerVersion* version) { 64 ServiceWorkerVersion* installing,
65 provider_host->SetActiveVersion(version); 65 ServiceWorkerVersion* waiting,
66 } 66 ServiceWorkerVersion* active) {
67 67 EXPECT_EQ(installing, provider_host->installing_version_);
68 void SetWaitingVersion( 68 EXPECT_EQ(waiting, provider_host->waiting_version_);
69 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 69 EXPECT_EQ(active, provider_host->active_version_);
70 ServiceWorkerVersion* version) { 70 EXPECT_FALSE(provider_host->controlling_version_);
71 provider_host->SetWaitingVersion(version);
72 } 71 }
73 72
74 content::TestBrowserThreadBundle thread_bundle_; 73 content::TestBrowserThreadBundle thread_bundle_;
75 scoped_ptr<ServiceWorkerContextCore> context_; 74 scoped_ptr<ServiceWorkerContextCore> context_;
76 scoped_refptr<ServiceWorkerRegistration> registration_; 75 scoped_refptr<ServiceWorkerRegistration> registration_;
77 scoped_refptr<ServiceWorkerVersion> version_; 76 scoped_refptr<ServiceWorkerVersion> version_;
78 base::WeakPtr<ServiceWorkerProviderHost> provider_host1_; 77 base::WeakPtr<ServiceWorkerProviderHost> provider_host1_;
79 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; 78 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_;
80 GURL scope_; 79 GURL scope_;
81 GURL script_url_; 80 GURL script_url_;
82 81
83 private: 82 private:
84 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostTest); 83 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostTest);
85 }; 84 };
86 85
87 TEST_F(ServiceWorkerProviderHostTest, SetActiveVersion_ProcessStatus) { 86 TEST_F(ServiceWorkerProviderHostTest, SetActiveVersion_ProcessStatus) {
87 provider_host1_->AssociateRegistration(registration_);
88 ASSERT_FALSE(version_->HasProcessToRun()); 88 ASSERT_FALSE(version_->HasProcessToRun());
89 89
90 // Associating version_ to a provider_host's active version will internally 90 // Associating version_ to a provider_host's active version will internally
91 // add the provider_host's process ref to the version. 91 // add the provider_host's process ref to the version.
92 SetActiveVersion(provider_host1_, version_); 92 registration_->SetActiveVersion(version_);
93 ASSERT_TRUE(version_->HasProcessToRun()); 93 ASSERT_TRUE(version_->HasProcessToRun());
94 94
95 // Re-associating the same version and provider_host should just work too. 95 // Re-associating the same version and provider_host should just work too.
96 SetActiveVersion(provider_host1_, version_); 96 registration_->SetActiveVersion(version_);
97 ASSERT_TRUE(version_->HasProcessToRun()); 97 ASSERT_TRUE(version_->HasProcessToRun());
98 98
99 // Resetting the provider_host's active version should remove process refs 99 // Resetting the provider_host's active version should remove process refs
100 // from the version. 100 // from the version.
101 SetActiveVersion(provider_host1_, NULL); 101 provider_host1_->UnassociateRegistration();
102 ASSERT_FALSE(version_->HasProcessToRun()); 102 ASSERT_FALSE(version_->HasProcessToRun());
103 } 103 }
104 104
105 TEST_F(ServiceWorkerProviderHostTest, 105 TEST_F(ServiceWorkerProviderHostTest,
106 SetActiveVersion_MultipleHostsForSameProcess) { 106 SetActiveVersion_MultipleHostsForSameProcess) {
107 provider_host1_->AssociateRegistration(registration_);
108 provider_host2_->AssociateRegistration(registration_);
107 ASSERT_FALSE(version_->HasProcessToRun()); 109 ASSERT_FALSE(version_->HasProcessToRun());
108 110
109 // Associating version_ to two providers as active version. 111 // Associating version_ to two providers as active version.
110 SetActiveVersion(provider_host1_, version_); 112 registration_->SetActiveVersion(version_);
111 SetActiveVersion(provider_host2_, version_);
112 ASSERT_TRUE(version_->HasProcessToRun()); 113 ASSERT_TRUE(version_->HasProcessToRun());
113 114
114 // Disassociating one provider_host shouldn't remove all process refs 115 // Disassociating one provider_host shouldn't remove all process refs
115 // from the version yet. 116 // from the version yet.
116 SetActiveVersion(provider_host1_, NULL); 117 provider_host1_->UnassociateRegistration();
117 ASSERT_TRUE(version_->HasProcessToRun()); 118 ASSERT_TRUE(version_->HasProcessToRun());
118 119
119 // Disassociating the other provider_host will remove all process refs. 120 // Disassociating the other provider_host will remove all process refs.
120 SetActiveVersion(provider_host2_, NULL); 121 provider_host2_->UnassociateRegistration();
121 ASSERT_FALSE(version_->HasProcessToRun()); 122 ASSERT_FALSE(version_->HasProcessToRun());
122 } 123 }
123 124
124 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) { 125 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) {
126 provider_host1_->AssociateRegistration(registration_);
125 ASSERT_FALSE(version_->HasProcessToRun()); 127 ASSERT_FALSE(version_->HasProcessToRun());
126 128
127 // Associating version_ to a provider_host's waiting version will internally 129 // Associating version_ to a provider_host's waiting version will internally
128 // add the provider_host's process ref to the version. 130 // add the provider_host's process ref to the version.
129 SetWaitingVersion(provider_host1_, version_); 131 registration_->SetWaitingVersion(version_);
130 ASSERT_TRUE(version_->HasProcessToRun()); 132 ASSERT_TRUE(version_->HasProcessToRun());
131 133
132 // Re-associating the same version and provider_host should just work too. 134 // Re-associating the same version and provider_host should just work too.
133 SetWaitingVersion(provider_host1_, version_); 135 registration_->SetWaitingVersion(version_);
134 ASSERT_TRUE(version_->HasProcessToRun()); 136 ASSERT_TRUE(version_->HasProcessToRun());
135 137
136 // Resetting the provider_host's waiting version should remove process refs 138 // Resetting the provider_host's waiting version should remove process refs
137 // from the version. 139 // from the version.
138 SetWaitingVersion(provider_host1_, NULL); 140 provider_host1_->UnassociateRegistration();
139 ASSERT_FALSE(version_->HasProcessToRun()); 141 ASSERT_FALSE(version_->HasProcessToRun());
140 } 142 }
141 143
142 TEST_F(ServiceWorkerProviderHostTest, 144 TEST_F(ServiceWorkerProviderHostTest,
143 SetWaitingVersion_MultipleHostsForSameProcess) { 145 SetWaitingVersion_MultipleHostsForSameProcess) {
146 provider_host1_->AssociateRegistration(registration_);
147 provider_host2_->AssociateRegistration(registration_);
144 ASSERT_FALSE(version_->HasProcessToRun()); 148 ASSERT_FALSE(version_->HasProcessToRun());
145 149
146 // Associating version_ to two providers as active version. 150 // Associating version_ to two providers as waiting version.
147 SetWaitingVersion(provider_host1_, version_); 151 registration_->SetWaitingVersion(version_);
148 SetWaitingVersion(provider_host2_, version_);
149 ASSERT_TRUE(version_->HasProcessToRun()); 152 ASSERT_TRUE(version_->HasProcessToRun());
150 153
151 // Disassociating one provider_host shouldn't remove all process refs 154 // Disassociating one provider_host shouldn't remove all process refs
152 // from the version yet. 155 // from the version yet.
153 SetWaitingVersion(provider_host1_, NULL); 156 provider_host1_->UnassociateRegistration();
154 ASSERT_TRUE(version_->HasProcessToRun()); 157 ASSERT_TRUE(version_->HasProcessToRun());
155 158
156 // Disassociating the other provider_host will remove all process refs. 159 // Disassociating the other provider_host will remove all process refs.
157 SetWaitingVersion(provider_host2_, NULL); 160 provider_host2_->UnassociateRegistration();
158 ASSERT_FALSE(version_->HasProcessToRun()); 161 ASSERT_FALSE(version_->HasProcessToRun());
159 } 162 }
160 163
164 TEST_F(ServiceWorkerProviderHostTest,
165 ObserveVersionAttributesChanged_Basic) {
166 provider_host1_->AssociateRegistration(registration_);
167 provider_host2_->AssociateRegistration(registration_);
168 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL);
169 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
170
171 registration_->SetInstallingVersion(version_);
172 VerifyVersionAttributes(provider_host1_, version_, NULL, NULL);
173 VerifyVersionAttributes(provider_host2_, version_, NULL, NULL);
174
175 registration_->SetWaitingVersion(version_);
176 VerifyVersionAttributes(provider_host1_, NULL, version_, NULL);
177 VerifyVersionAttributes(provider_host2_, NULL, version_, NULL);
178
179 // Disassociating the registration should clear all version attributes.
180 provider_host2_->UnassociateRegistration();
181 VerifyVersionAttributes(provider_host1_, NULL, version_, NULL);
182 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
183
184 // Shouldn't notify the disassociated provider of the change.
185 registration_->SetActiveVersion(version_);
186 VerifyVersionAttributes(provider_host1_, NULL, NULL, version_);
187 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
188 }
189
190 TEST_F(ServiceWorkerProviderHostTest,
191 ObserveVersionAttributesChanged_MultipleVersions) {
192 provider_host1_->AssociateRegistration(registration_);
193 provider_host2_->AssociateRegistration(registration_);
194 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL);
195 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
196
197 scoped_refptr<ServiceWorkerVersion> version1 =
198 new ServiceWorkerVersion(registration_, 10L, context_->AsWeakPtr());
199 scoped_refptr<ServiceWorkerVersion> version2 =
200 new ServiceWorkerVersion(registration_, 20L, context_->AsWeakPtr());
201
202 registration_->SetInstallingVersion(version1);
203 VerifyVersionAttributes(provider_host1_, version1, NULL, NULL);
204 VerifyVersionAttributes(provider_host2_, version1, NULL, NULL);
205
206 registration_->SetWaitingVersion(version1);
207 VerifyVersionAttributes(provider_host1_, NULL, version1, NULL);
208 VerifyVersionAttributes(provider_host2_, NULL, version1, NULL);
209
210 registration_->SetInstallingVersion(version2);
211 VerifyVersionAttributes(provider_host1_, version2, version1, NULL);
212 VerifyVersionAttributes(provider_host2_, version2, version1, NULL);
213
214 // Disassociating the registration should clear all version attributes.
215 provider_host2_->UnassociateRegistration();
216 VerifyVersionAttributes(provider_host1_, version2, version1, NULL);
217 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
218
219 // Shouldn't notify the disassociated provider of the change.
220 registration_->SetActiveVersion(version1);
221 VerifyVersionAttributes(provider_host1_, version2, NULL, version1);
222 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
223
224 registration_->SetActiveVersion(version2);
225 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2);
226 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
227 }
228
161 } // namespace content 229 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698