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

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

Issue 309453002: ServiceWorker: Rename 'pending version' to 'installing' or 'waiting' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 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 | 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Disassociating one provider_host shouldn't remove all process refs 107 // Disassociating one provider_host shouldn't remove all process refs
108 // from the version yet. 108 // from the version yet.
109 provider_host1_->SetActiveVersion(NULL); 109 provider_host1_->SetActiveVersion(NULL);
110 ASSERT_TRUE(version_->HasProcessToRun()); 110 ASSERT_TRUE(version_->HasProcessToRun());
111 111
112 // Disassociating the other provider_host will remove all process refs. 112 // Disassociating the other provider_host will remove all process refs.
113 provider_host2_->SetActiveVersion(NULL); 113 provider_host2_->SetActiveVersion(NULL);
114 ASSERT_FALSE(version_->HasProcessToRun()); 114 ASSERT_FALSE(version_->HasProcessToRun());
115 } 115 }
116 116
117 TEST_F(ServiceWorkerProviderHostTest, SetPendingVersion_ProcessStatus) { 117 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) {
118 ASSERT_FALSE(version_->HasProcessToRun()); 118 ASSERT_FALSE(version_->HasProcessToRun());
119 119
120 // Associating version_ to a provider_host's pending version will internally 120 // Associating version_ to a provider_host's waiting version will internally
121 // add the provider_host's process ref to the version. 121 // add the provider_host's process ref to the version.
122 provider_host1_->SetPendingVersion(version_); 122 provider_host1_->SetWaitingVersion(version_);
123 ASSERT_TRUE(version_->HasProcessToRun()); 123 ASSERT_TRUE(version_->HasProcessToRun());
124 124
125 // Re-associating the same version and provider_host should just work too. 125 // Re-associating the same version and provider_host should just work too.
126 provider_host1_->SetPendingVersion(version_); 126 provider_host1_->SetWaitingVersion(version_);
127 ASSERT_TRUE(version_->HasProcessToRun()); 127 ASSERT_TRUE(version_->HasProcessToRun());
128 128
129 // Resetting the provider_host's pending version should remove process refs 129 // Resetting the provider_host's waiting version should remove process refs
130 // from the version. 130 // from the version.
131 provider_host1_->SetPendingVersion(NULL); 131 provider_host1_->SetWaitingVersion(NULL);
132 ASSERT_FALSE(version_->HasProcessToRun()); 132 ASSERT_FALSE(version_->HasProcessToRun());
133 } 133 }
134 134
135 TEST_F(ServiceWorkerProviderHostTest, 135 TEST_F(ServiceWorkerProviderHostTest,
136 SetPendingVersion_MultipleHostsForSameProcess) { 136 SetWaitingVersion_MultipleHostsForSameProcess) {
137 ASSERT_FALSE(version_->HasProcessToRun()); 137 ASSERT_FALSE(version_->HasProcessToRun());
138 138
139 // Associating version_ to two providers as active version. 139 // Associating version_ to two providers as active version.
140 provider_host1_->SetPendingVersion(version_); 140 provider_host1_->SetWaitingVersion(version_);
141 provider_host2_->SetPendingVersion(version_); 141 provider_host2_->SetWaitingVersion(version_);
142 ASSERT_TRUE(version_->HasProcessToRun()); 142 ASSERT_TRUE(version_->HasProcessToRun());
143 143
144 // Disassociating one provider_host shouldn't remove all process refs 144 // Disassociating one provider_host shouldn't remove all process refs
145 // from the version yet. 145 // from the version yet.
146 provider_host1_->SetPendingVersion(NULL); 146 provider_host1_->SetWaitingVersion(NULL);
147 ASSERT_TRUE(version_->HasProcessToRun()); 147 ASSERT_TRUE(version_->HasProcessToRun());
148 148
149 // Disassociating the other provider_host will remove all process refs. 149 // Disassociating the other provider_host will remove all process refs.
150 provider_host2_->SetPendingVersion(NULL); 150 provider_host2_->SetWaitingVersion(NULL);
151 ASSERT_FALSE(version_->HasProcessToRun()); 151 ASSERT_FALSE(version_->HasProcessToRun());
152 } 152 }
153 153
154 class ServiceWorkerProviderHostPendingVersionTest : public testing::Test { 154 class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test {
155 protected: 155 protected:
156 ServiceWorkerProviderHostPendingVersionTest() 156 ServiceWorkerProviderHostWaitingVersionTest()
157 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 157 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
158 next_provider_id_(1L) {} 158 next_provider_id_(1L) {}
159 virtual ~ServiceWorkerProviderHostPendingVersionTest() {} 159 virtual ~ServiceWorkerProviderHostWaitingVersionTest() {}
160 160
161 virtual void SetUp() OVERRIDE { 161 virtual void SetUp() OVERRIDE {
162 context_.reset( 162 context_.reset(
163 new ServiceWorkerContextCore(base::FilePath(), 163 new ServiceWorkerContextCore(base::FilePath(),
164 base::MessageLoopProxy::current(), 164 base::MessageLoopProxy::current(),
165 base::MessageLoopProxy::current(), 165 base::MessageLoopProxy::current(),
166 NULL, 166 NULL,
167 NULL, 167 NULL,
168 NULL)); 168 NULL));
169 169
(...skipping 19 matching lines...) Expand all
189 189
190 content::TestBrowserThreadBundle thread_bundle_; 190 content::TestBrowserThreadBundle thread_bundle_;
191 scoped_ptr<ServiceWorkerContextCore> context_; 191 scoped_ptr<ServiceWorkerContextCore> context_;
192 base::WeakPtr<ServiceWorkerProviderHost> provider_host1_; 192 base::WeakPtr<ServiceWorkerProviderHost> provider_host1_;
193 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; 193 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_;
194 base::WeakPtr<ServiceWorkerProviderHost> provider_host3_; 194 base::WeakPtr<ServiceWorkerProviderHost> provider_host3_;
195 195
196 private: 196 private:
197 int64 next_provider_id_; 197 int64 next_provider_id_;
198 198
199 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostPendingVersionTest); 199 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostWaitingVersionTest);
200 }; 200 };
201 201
202 TEST_F(ServiceWorkerProviderHostPendingVersionTest, 202 TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
203 AssociatePendingVersionToDocuments) { 203 AssociateWaitingVersionToDocuments) {
204 const GURL scope("http://www.example.com/*"); 204 const GURL scope("http://www.example.com/*");
205 const GURL script_url("http://www.example.com/service_worker.js"); 205 const GURL script_url("http://www.example.com/service_worker.js");
206 206
207 scoped_refptr<ServiceWorkerRegistration> registration( 207 scoped_refptr<ServiceWorkerRegistration> registration(
208 new ServiceWorkerRegistration( 208 new ServiceWorkerRegistration(
209 scope, script_url, 1L, context_->AsWeakPtr())); 209 scope, script_url, 1L, context_->AsWeakPtr()));
210 scoped_refptr<ServiceWorkerVersion> version( 210 scoped_refptr<ServiceWorkerVersion> version(
211 new ServiceWorkerVersion(registration, 1L, context_->AsWeakPtr())); 211 new ServiceWorkerVersion(registration, 1L, context_->AsWeakPtr()));
212 212
213 ServiceWorkerRegisterJob::AssociatePendingVersionToDocuments( 213 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
214 context_->AsWeakPtr(), version.get()); 214 context_->AsWeakPtr(), version.get());
215 EXPECT_EQ(version.get(), provider_host1_->pending_version()); 215 EXPECT_EQ(version.get(), provider_host1_->waiting_version());
216 EXPECT_EQ(version.get(), provider_host2_->pending_version()); 216 EXPECT_EQ(version.get(), provider_host2_->waiting_version());
217 EXPECT_EQ(NULL, provider_host3_->pending_version()); 217 EXPECT_EQ(NULL, provider_host3_->waiting_version());
218 } 218 }
219 219
220 TEST_F(ServiceWorkerProviderHostPendingVersionTest, 220 TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
221 DisassociatePendingVersionFromDocuments) { 221 DisassociateWaitingVersionFromDocuments) {
222 const GURL scope1("http://www.example.com/*"); 222 const GURL scope1("http://www.example.com/*");
223 const GURL script_url1("http://www.example.com/service_worker.js"); 223 const GURL script_url1("http://www.example.com/service_worker.js");
224 scoped_refptr<ServiceWorkerRegistration> registration1( 224 scoped_refptr<ServiceWorkerRegistration> registration1(
225 new ServiceWorkerRegistration( 225 new ServiceWorkerRegistration(
226 scope1, script_url1, 1L, context_->AsWeakPtr())); 226 scope1, script_url1, 1L, context_->AsWeakPtr()));
227 scoped_refptr<ServiceWorkerVersion> version1( 227 scoped_refptr<ServiceWorkerVersion> version1(
228 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); 228 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr()));
229 229
230 const GURL scope2("http://www.example.ca/*"); 230 const GURL scope2("http://www.example.ca/*");
231 const GURL script_url2("http://www.example.ca/service_worker.js"); 231 const GURL script_url2("http://www.example.ca/service_worker.js");
232 scoped_refptr<ServiceWorkerRegistration> registration2( 232 scoped_refptr<ServiceWorkerRegistration> registration2(
233 new ServiceWorkerRegistration( 233 new ServiceWorkerRegistration(
234 scope2, script_url2, 2L, context_->AsWeakPtr())); 234 scope2, script_url2, 2L, context_->AsWeakPtr()));
235 scoped_refptr<ServiceWorkerVersion> version2( 235 scoped_refptr<ServiceWorkerVersion> version2(
236 new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr())); 236 new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr()));
237 237
238 ServiceWorkerRegisterJob::AssociatePendingVersionToDocuments( 238 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
239 context_->AsWeakPtr(), version1.get()); 239 context_->AsWeakPtr(), version1.get());
240 ServiceWorkerRegisterJob::AssociatePendingVersionToDocuments( 240 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
241 context_->AsWeakPtr(), version2.get()); 241 context_->AsWeakPtr(), version2.get());
242 242
243 // Host1 and host2 are associated with version1 as a pending version, whereas 243 // Host1 and host2 are associated with version1 as a waiting version, whereas
244 // host3 is associated with version2. 244 // host3 is associated with version2.
245 EXPECT_EQ(version1.get(), provider_host1_->pending_version()); 245 EXPECT_EQ(version1.get(), provider_host1_->waiting_version());
246 EXPECT_EQ(version1.get(), provider_host2_->pending_version()); 246 EXPECT_EQ(version1.get(), provider_host2_->waiting_version());
247 EXPECT_EQ(version2.get(), provider_host3_->pending_version()); 247 EXPECT_EQ(version2.get(), provider_host3_->waiting_version());
248 248
249 // Disassociate version1 from host1 and host2. 249 // Disassociate version1 from host1 and host2.
250 ServiceWorkerRegisterJob::DisassociatePendingVersionFromDocuments( 250 ServiceWorkerRegisterJob::DisassociateWaitingVersionFromDocuments(
251 context_->AsWeakPtr(), version1->version_id()); 251 context_->AsWeakPtr(), version1->version_id());
252 EXPECT_EQ(NULL, provider_host1_->pending_version()); 252 EXPECT_EQ(NULL, provider_host1_->waiting_version());
253 EXPECT_EQ(NULL, provider_host2_->pending_version()); 253 EXPECT_EQ(NULL, provider_host2_->waiting_version());
254 EXPECT_EQ(version2.get(), provider_host3_->pending_version()); 254 EXPECT_EQ(version2.get(), provider_host3_->waiting_version());
255 } 255 }
256 256
257 } // namespace content 257 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698