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

Side by Side Diff: content/browser/service_worker/service_worker_context_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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_controllee_request_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/public/browser/service_worker_context.h" 5 #include "content/public/browser/service_worker_context.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 ServiceWorkerContextCore::UnregistrationCallback MakeUnregisteredCallback( 51 ServiceWorkerContextCore::UnregistrationCallback MakeUnregisteredCallback(
52 bool* called) { 52 bool* called) {
53 return base::Bind(&CallCompletedCallback, called); 53 return base::Bind(&CallCompletedCallback, called);
54 } 54 }
55 55
56 void ExpectRegisteredWorkers( 56 void ExpectRegisteredWorkers(
57 ServiceWorkerStatusCode expect_status, 57 ServiceWorkerStatusCode expect_status,
58 int64 expect_version_id, 58 int64 expect_version_id,
59 bool expect_pending, 59 bool expect_waiting,
60 bool expect_active, 60 bool expect_active,
61 ServiceWorkerStatusCode status, 61 ServiceWorkerStatusCode status,
62 const scoped_refptr<ServiceWorkerRegistration>& registration) { 62 const scoped_refptr<ServiceWorkerRegistration>& registration) {
63 ASSERT_EQ(expect_status, status); 63 ASSERT_EQ(expect_status, status);
64 if (status != SERVICE_WORKER_OK) { 64 if (status != SERVICE_WORKER_OK) {
65 EXPECT_FALSE(registration); 65 EXPECT_FALSE(registration);
66 return; 66 return;
67 } 67 }
68 68
69 if (expect_pending) { 69 if (expect_waiting) {
70 EXPECT_TRUE(registration->pending_version()); 70 EXPECT_TRUE(registration->waiting_version());
71 EXPECT_EQ(expect_version_id, 71 EXPECT_EQ(expect_version_id,
72 registration->pending_version()->version_id()); 72 registration->waiting_version()->version_id());
73 } else { 73 } else {
74 EXPECT_FALSE(registration->pending_version()); 74 EXPECT_FALSE(registration->waiting_version());
75 } 75 }
76 76
77 if (expect_active) { 77 if (expect_active) {
78 EXPECT_TRUE(registration->active_version()); 78 EXPECT_TRUE(registration->active_version());
79 EXPECT_EQ(expect_version_id, 79 EXPECT_EQ(expect_version_id,
80 registration->active_version()->version_id()); 80 registration->active_version()->version_id());
81 } else { 81 } else {
82 EXPECT_FALSE(registration->active_version()); 82 EXPECT_FALSE(registration->active_version());
83 } 83 }
84 } 84 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 EmbeddedWorkerMsg_StopWorker::ID)); 163 EmbeddedWorkerMsg_StopWorker::ID));
164 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 164 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
165 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); 165 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id);
166 166
167 context()->storage()->FindRegistrationForId( 167 context()->storage()->FindRegistrationForId(
168 registration_id, 168 registration_id,
169 GURL("http://www.example.com"), 169 GURL("http://www.example.com"),
170 base::Bind(&ExpectRegisteredWorkers, 170 base::Bind(&ExpectRegisteredWorkers,
171 SERVICE_WORKER_OK, 171 SERVICE_WORKER_OK,
172 version_id, 172 version_id,
173 false /* expect_pending */, 173 false /* expect_waiting */,
174 true /* expect_active */)); 174 true /* expect_active */));
175 base::RunLoop().RunUntilIdle(); 175 base::RunLoop().RunUntilIdle();
176 } 176 }
177 177
178 // Test registration when the service worker rejects the install event. The 178 // Test registration when the service worker rejects the install event. The
179 // registration callback should indicate success, but there should be no pending 179 // registration callback should indicate success, but there should be no waiting
180 // or active worker in the registration. 180 // or active worker in the registration.
181 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { 181 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
182 helper_.reset(); // Make sure the process lookups stay overridden. 182 helper_.reset(); // Make sure the process lookups stay overridden.
183 helper_.reset(new RejectInstallTestHelper(render_process_id_)); 183 helper_.reset(new RejectInstallTestHelper(render_process_id_));
184 int64 registration_id = kInvalidServiceWorkerRegistrationId; 184 int64 registration_id = kInvalidServiceWorkerRegistrationId;
185 int64 version_id = kInvalidServiceWorkerVersionId; 185 int64 version_id = kInvalidServiceWorkerVersionId;
186 bool called = false; 186 bool called = false;
187 context()->RegisterServiceWorker( 187 context()->RegisterServiceWorker(
188 GURL("http://www.example.com/*"), 188 GURL("http://www.example.com/*"),
189 GURL("http://www.example.com/service_worker.js"), 189 GURL("http://www.example.com/service_worker.js"),
(...skipping 16 matching lines...) Expand all
206 EmbeddedWorkerMsg_StopWorker::ID)); 206 EmbeddedWorkerMsg_StopWorker::ID));
207 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 207 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
208 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); 208 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id);
209 209
210 context()->storage()->FindRegistrationForId( 210 context()->storage()->FindRegistrationForId(
211 registration_id, 211 registration_id,
212 GURL("http://www.example.com"), 212 GURL("http://www.example.com"),
213 base::Bind(&ExpectRegisteredWorkers, 213 base::Bind(&ExpectRegisteredWorkers,
214 SERVICE_WORKER_ERROR_NOT_FOUND, 214 SERVICE_WORKER_ERROR_NOT_FOUND,
215 kInvalidServiceWorkerVersionId, 215 kInvalidServiceWorkerVersionId,
216 false /* expect_pending */, 216 false /* expect_waiting */,
217 false /* expect_active */)); 217 false /* expect_active */));
218 base::RunLoop().RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
219 } 219 }
220 220
221 // Test registration when the service worker rejects the activate event. The 221 // Test registration when the service worker rejects the activate event. The
222 // registration callback should indicate success, but there should be no pending 222 // registration callback should indicate success, but there should be no waiting
223 // or active worker in the registration. 223 // or active worker in the registration.
224 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { 224 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
225 helper_.reset(); // Make sure the process lookups stay overridden. 225 helper_.reset(); // Make sure the process lookups stay overridden.
226 helper_.reset(new RejectActivateTestHelper(render_process_id_)); 226 helper_.reset(new RejectActivateTestHelper(render_process_id_));
227 int64 registration_id = kInvalidServiceWorkerRegistrationId; 227 int64 registration_id = kInvalidServiceWorkerRegistrationId;
228 int64 version_id = kInvalidServiceWorkerVersionId; 228 int64 version_id = kInvalidServiceWorkerVersionId;
229 bool called = false; 229 bool called = false;
230 context()->RegisterServiceWorker( 230 context()->RegisterServiceWorker(
231 GURL("http://www.example.com/*"), 231 GURL("http://www.example.com/*"),
232 GURL("http://www.example.com/service_worker.js"), 232 GURL("http://www.example.com/service_worker.js"),
(...skipping 16 matching lines...) Expand all
249 EmbeddedWorkerMsg_StopWorker::ID)); 249 EmbeddedWorkerMsg_StopWorker::ID));
250 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 250 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
251 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); 251 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id);
252 252
253 context()->storage()->FindRegistrationForId( 253 context()->storage()->FindRegistrationForId(
254 registration_id, 254 registration_id,
255 GURL("http://www.example.com"), 255 GURL("http://www.example.com"),
256 base::Bind(&ExpectRegisteredWorkers, 256 base::Bind(&ExpectRegisteredWorkers,
257 SERVICE_WORKER_ERROR_NOT_FOUND, 257 SERVICE_WORKER_ERROR_NOT_FOUND,
258 kInvalidServiceWorkerVersionId, 258 kInvalidServiceWorkerVersionId,
259 false /* expect_pending */, 259 false /* expect_waiting */,
260 false /* expect_active */)); 260 false /* expect_active */));
261 base::RunLoop().RunUntilIdle(); 261 base::RunLoop().RunUntilIdle();
262 } 262 }
263 263
264 // Make sure registrations are cleaned up when they are unregistered. 264 // Make sure registrations are cleaned up when they are unregistered.
265 TEST_F(ServiceWorkerContextTest, Unregister) { 265 TEST_F(ServiceWorkerContextTest, Unregister) {
266 GURL pattern("http://www.example.com/*"); 266 GURL pattern("http://www.example.com/*");
267 267
268 bool called = false; 268 bool called = false;
269 int64 registration_id = kInvalidServiceWorkerRegistrationId; 269 int64 registration_id = kInvalidServiceWorkerRegistrationId;
(...skipping 18 matching lines...) Expand all
288 ASSERT_FALSE(called); 288 ASSERT_FALSE(called);
289 base::RunLoop().RunUntilIdle(); 289 base::RunLoop().RunUntilIdle();
290 ASSERT_TRUE(called); 290 ASSERT_TRUE(called);
291 291
292 context()->storage()->FindRegistrationForId( 292 context()->storage()->FindRegistrationForId(
293 registration_id, 293 registration_id,
294 pattern.GetOrigin(), 294 pattern.GetOrigin(),
295 base::Bind(&ExpectRegisteredWorkers, 295 base::Bind(&ExpectRegisteredWorkers,
296 SERVICE_WORKER_ERROR_NOT_FOUND, 296 SERVICE_WORKER_ERROR_NOT_FOUND,
297 kInvalidServiceWorkerVersionId, 297 kInvalidServiceWorkerVersionId,
298 false /* expect_pending */, 298 false /* expect_waiting */,
299 false /* expect_active */)); 299 false /* expect_active */));
300 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
301 } 301 }
302 302
303 // Make sure that when a new registration replaces an existing 303 // Make sure that when a new registration replaces an existing
304 // registration, that the old one is cleaned up. 304 // registration, that the old one is cleaned up.
305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
306 GURL pattern("http://www.example.com/*"); 306 GURL pattern("http://www.example.com/*");
307 307
308 bool called = false; 308 bool called = false;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id)); 376 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
377 377
378 ASSERT_FALSE(called); 378 ASSERT_FALSE(called);
379 base::RunLoop().RunUntilIdle(); 379 base::RunLoop().RunUntilIdle();
380 ASSERT_TRUE(called); 380 ASSERT_TRUE(called);
381 EXPECT_EQ(old_registration_id, new_registration_id); 381 EXPECT_EQ(old_registration_id, new_registration_id);
382 EXPECT_EQ(old_version_id, new_version_id); 382 EXPECT_EQ(old_version_id, new_version_id);
383 } 383 }
384 384
385 } // namespace content 385 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_controllee_request_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698