OLD | NEW |
---|---|
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/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 void TearDown() override { helper_.reset(); } | 111 void TearDown() override { helper_.reset(); } |
112 | 112 |
113 ServiceWorkerContextCore* context() const { return helper_->context(); } | 113 ServiceWorkerContextCore* context() const { return helper_->context(); } |
114 | 114 |
115 ServiceWorkerJobCoordinator* job_coordinator() const { | 115 ServiceWorkerJobCoordinator* job_coordinator() const { |
116 return context()->job_coordinator(); | 116 return context()->job_coordinator(); |
117 } | 117 } |
118 ServiceWorkerStorage* storage() const { return context()->storage(); } | 118 ServiceWorkerStorage* storage() const { return context()->storage(); } |
119 | 119 |
120 protected: | 120 protected: |
121 scoped_refptr<ServiceWorkerRegistration> RunRegisterJob( | |
122 const GURL& pattern, | |
123 const GURL& script_url, | |
124 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK); | |
125 void RunUnregisterJob( | |
126 const GURL& pattern, | |
127 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK); | |
128 scoped_refptr<ServiceWorkerRegistration> FindRegistrationForPattern( | |
129 const GURL& pattern, | |
130 ServiceWorkerStatusCode expected_status = SERVICE_WORKER_OK); | |
131 | |
121 TestBrowserThreadBundle browser_thread_bundle_; | 132 TestBrowserThreadBundle browser_thread_bundle_; |
122 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 133 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
123 int render_process_id_; | 134 int render_process_id_; |
124 }; | 135 }; |
125 | 136 |
126 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { | 137 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob( |
127 scoped_refptr<ServiceWorkerRegistration> original_registration; | 138 const GURL& pattern, |
139 const GURL& script_url, | |
140 ServiceWorkerStatusCode expected_status) { | |
141 scoped_refptr<ServiceWorkerRegistration> registration; | |
128 bool called; | 142 bool called; |
129 job_coordinator()->Register( | 143 job_coordinator()->Register( |
130 GURL("http://www.example.com/"), | 144 pattern, script_url, NULL, |
131 GURL("http://www.example.com/service_worker.js"), | 145 SaveRegistration(expected_status, &called, ®istration)); |
132 NULL, | |
133 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | |
134 EXPECT_FALSE(called); | 146 EXPECT_FALSE(called); |
135 base::RunLoop().RunUntilIdle(); | 147 base::RunLoop().RunUntilIdle(); |
136 EXPECT_TRUE(called); | 148 EXPECT_TRUE(called); |
149 return registration; | |
150 } | |
137 | 151 |
152 void ServiceWorkerJobTest::RunUnregisterJob( | |
153 const GURL& pattern, | |
154 ServiceWorkerStatusCode expected_status) { | |
155 bool called; | |
156 job_coordinator()->Unregister(pattern, | |
157 SaveUnregistration(expected_status, &called)); | |
158 EXPECT_FALSE(called); | |
159 base::RunLoop().RunUntilIdle(); | |
160 EXPECT_TRUE(called); | |
161 } | |
162 | |
163 scoped_refptr<ServiceWorkerRegistration> | |
164 ServiceWorkerJobTest::FindRegistrationForPattern( | |
165 const GURL& pattern, | |
166 ServiceWorkerStatusCode expected_status) { | |
167 bool called; | |
168 scoped_refptr<ServiceWorkerRegistration> registration; | |
169 storage()->FindRegistrationForPattern( | |
170 pattern, | |
171 SaveFoundRegistration(expected_status, &called, ®istration)); | |
172 | |
173 EXPECT_FALSE(called); | |
174 base::RunLoop().RunUntilIdle(); | |
175 EXPECT_TRUE(called); | |
176 return registration; | |
177 } | |
178 | |
179 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { | |
180 scoped_refptr<ServiceWorkerRegistration> original_registration = | |
181 RunRegisterJob(GURL("http://www.example.com/"), | |
182 GURL("http://www.example.com/service_worker.js")); | |
183 bool called; | |
138 scoped_refptr<ServiceWorkerRegistration> registration1; | 184 scoped_refptr<ServiceWorkerRegistration> registration1; |
139 storage()->FindRegistrationForDocument( | 185 storage()->FindRegistrationForDocument( |
140 GURL("http://www.example.com/"), | 186 GURL("http://www.example.com/"), |
141 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); | 187 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); |
142 scoped_refptr<ServiceWorkerRegistration> registration2; | 188 scoped_refptr<ServiceWorkerRegistration> registration2; |
143 storage()->FindRegistrationForDocument( | 189 storage()->FindRegistrationForDocument( |
144 GURL("http://www.example.com/"), | 190 GURL("http://www.example.com/"), |
145 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); | 191 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); |
146 base::RunLoop().RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
147 EXPECT_TRUE(called); | 193 EXPECT_TRUE(called); |
148 ASSERT_TRUE(registration1.get()); | 194 ASSERT_TRUE(registration1.get()); |
149 ASSERT_EQ(registration1, original_registration); | 195 ASSERT_EQ(registration1, original_registration); |
150 ASSERT_EQ(registration1, registration2); | 196 ASSERT_EQ(registration1, registration2); |
151 } | 197 } |
152 | 198 |
153 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { | 199 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { |
154 bool called; | 200 bool called; |
155 scoped_refptr<ServiceWorkerRegistration> original_registration; | 201 scoped_refptr<ServiceWorkerRegistration> original_registration = |
156 job_coordinator()->Register( | 202 RunRegisterJob(GURL("http://www.example.com/"), |
157 GURL("http://www.example.com/"), | 203 GURL("http://www.example.com/service_worker.js")); |
158 GURL("http://www.example.com/service_worker.js"), | |
159 NULL, | |
160 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | |
161 EXPECT_FALSE(called); | |
162 base::RunLoop().RunUntilIdle(); | |
163 EXPECT_TRUE(called); | |
164 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), | 204 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), |
165 original_registration.get()); | 205 original_registration.get()); |
166 | 206 |
167 scoped_refptr<ServiceWorkerRegistration> registration1; | 207 scoped_refptr<ServiceWorkerRegistration> registration1; |
168 storage()->FindRegistrationForDocument( | 208 storage()->FindRegistrationForDocument( |
169 GURL("http://www.example.com/one"), | 209 GURL("http://www.example.com/one"), |
170 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); | 210 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); |
171 base::RunLoop().RunUntilIdle(); | 211 base::RunLoop().RunUntilIdle(); |
172 EXPECT_TRUE(called); | 212 EXPECT_TRUE(called); |
173 | 213 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 SaveFoundRegistration(SERVICE_WORKER_OK, &called2, ®istration2)); | 254 SaveFoundRegistration(SERVICE_WORKER_OK, &called2, ®istration2)); |
215 | 255 |
216 base::RunLoop().RunUntilIdle(); | 256 base::RunLoop().RunUntilIdle(); |
217 EXPECT_TRUE(called2); | 257 EXPECT_TRUE(called2); |
218 EXPECT_TRUE(called1); | 258 EXPECT_TRUE(called1); |
219 ASSERT_NE(registration1, registration2); | 259 ASSERT_NE(registration1, registration2); |
220 } | 260 } |
221 | 261 |
222 // Make sure basic registration is working. | 262 // Make sure basic registration is working. |
223 TEST_F(ServiceWorkerJobTest, Register) { | 263 TEST_F(ServiceWorkerJobTest, Register) { |
224 bool called = false; | 264 scoped_refptr<ServiceWorkerRegistration> registration = |
225 scoped_refptr<ServiceWorkerRegistration> registration; | 265 RunRegisterJob(GURL("http://www.example.com/"), |
226 job_coordinator()->Register( | 266 GURL("http://www.example.com/service_worker.js")); |
227 GURL("http://www.example.com/"), | |
228 GURL("http://www.example.com/service_worker.js"), | |
229 NULL, | |
230 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
231 | |
232 ASSERT_FALSE(called); | |
233 base::RunLoop().RunUntilIdle(); | |
234 ASSERT_TRUE(called); | |
235 | 267 |
236 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 268 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
237 } | 269 } |
238 | 270 |
239 // Make sure registrations are cleaned up when they are unregistered. | 271 // Make sure registrations are cleaned up when they are unregistered. |
240 TEST_F(ServiceWorkerJobTest, Unregister) { | 272 TEST_F(ServiceWorkerJobTest, Unregister) { |
241 GURL pattern("http://www.example.com/"); | 273 GURL pattern("http://www.example.com/"); |
242 | 274 |
243 bool called; | 275 scoped_refptr<ServiceWorkerRegistration> registration = |
244 scoped_refptr<ServiceWorkerRegistration> registration; | 276 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); |
245 job_coordinator()->Register( | |
246 pattern, | |
247 GURL("http://www.example.com/service_worker.js"), | |
248 NULL, | |
249 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
250 | 277 |
251 ASSERT_FALSE(called); | 278 RunUnregisterJob(pattern); |
252 base::RunLoop().RunUntilIdle(); | |
253 ASSERT_TRUE(called); | |
254 | |
255 job_coordinator()->Unregister(pattern, | |
256 SaveUnregistration(SERVICE_WORKER_OK, &called)); | |
257 | |
258 ASSERT_FALSE(called); | |
259 base::RunLoop().RunUntilIdle(); | |
260 ASSERT_TRUE(called); | |
261 | 279 |
262 ASSERT_TRUE(registration->HasOneRef()); | 280 ASSERT_TRUE(registration->HasOneRef()); |
263 | 281 |
264 storage()->FindRegistrationForPattern( | 282 registration = FindRegistrationForPattern(pattern, |
265 pattern, | 283 SERVICE_WORKER_ERROR_NOT_FOUND); |
266 SaveFoundRegistration(SERVICE_WORKER_ERROR_NOT_FOUND, | |
267 &called, ®istration)); | |
268 | |
269 ASSERT_FALSE(called); | |
270 base::RunLoop().RunUntilIdle(); | |
271 ASSERT_TRUE(called); | |
272 | 284 |
273 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 285 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
274 } | 286 } |
275 | 287 |
276 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { | 288 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { |
277 GURL pattern("http://www.example.com/"); | 289 GURL pattern("http://www.example.com/"); |
278 | 290 |
279 bool called; | 291 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
280 job_coordinator()->Unregister( | |
281 pattern, | |
282 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, &called)); | |
283 | |
284 ASSERT_FALSE(called); | |
285 base::RunLoop().RunUntilIdle(); | |
286 ASSERT_TRUE(called); | |
287 } | 292 } |
288 | 293 |
289 // Make sure registering a new script creates a new version and shares an | 294 // Make sure registering a new script creates a new version and shares an |
290 // existing registration. | 295 // existing registration. |
291 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { | 296 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
292 GURL pattern("http://www.example.com/"); | 297 GURL pattern("http://www.example.com/"); |
293 | 298 |
294 bool called; | 299 scoped_refptr<ServiceWorkerRegistration> old_registration = |
295 scoped_refptr<ServiceWorkerRegistration> old_registration; | 300 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); |
296 job_coordinator()->Register( | |
297 pattern, | |
298 GURL("http://www.example.com/service_worker.js"), | |
299 NULL, | |
300 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | |
301 | 301 |
302 ASSERT_FALSE(called); | 302 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = |
303 base::RunLoop().RunUntilIdle(); | 303 FindRegistrationForPattern(pattern); |
304 ASSERT_TRUE(called); | |
305 | |
306 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; | |
307 storage()->FindRegistrationForPattern( | |
308 pattern, | |
309 SaveFoundRegistration( | |
310 SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); | |
311 | |
312 ASSERT_FALSE(called); | |
313 base::RunLoop().RunUntilIdle(); | |
314 ASSERT_TRUE(called); | |
315 | 304 |
316 ASSERT_EQ(old_registration, old_registration_by_pattern); | 305 ASSERT_EQ(old_registration, old_registration_by_pattern); |
317 old_registration_by_pattern = NULL; | 306 old_registration_by_pattern = NULL; |
318 | 307 |
319 scoped_refptr<ServiceWorkerRegistration> new_registration; | 308 scoped_refptr<ServiceWorkerRegistration> new_registration = |
320 job_coordinator()->Register( | 309 RunRegisterJob(pattern, |
321 pattern, | 310 GURL("http://www.example.com/service_worker_new.js")); |
322 GURL("http://www.example.com/service_worker_new.js"), | |
323 NULL, | |
324 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); | |
325 | |
326 ASSERT_FALSE(called); | |
327 base::RunLoop().RunUntilIdle(); | |
328 ASSERT_TRUE(called); | |
329 | 311 |
330 ASSERT_EQ(old_registration, new_registration); | 312 ASSERT_EQ(old_registration, new_registration); |
331 | 313 |
332 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; | 314 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = |
333 storage()->FindRegistrationForPattern( | 315 FindRegistrationForPattern(pattern); |
334 pattern, | |
335 SaveFoundRegistration( | |
336 SERVICE_WORKER_OK, &called, &new_registration)); | |
Kunihiko Sakamoto
2015/02/02 11:01:32
I think there was a bug here; |new_registration| s
| |
337 | 316 |
338 ASSERT_FALSE(called); | 317 ASSERT_EQ(new_registration, new_registration_by_pattern); |
339 base::RunLoop().RunUntilIdle(); | |
340 ASSERT_TRUE(called); | |
341 | |
342 ASSERT_NE(new_registration_by_pattern, old_registration); | |
343 } | 318 } |
344 | 319 |
345 // Make sure that when registering a duplicate pattern+script_url | 320 // Make sure that when registering a duplicate pattern+script_url |
346 // combination, that the same registration is used. | 321 // combination, that the same registration is used. |
347 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { | 322 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { |
348 GURL pattern("http://www.example.com/"); | 323 GURL pattern("http://www.example.com/"); |
349 GURL script_url("http://www.example.com/service_worker.js"); | 324 GURL script_url("http://www.example.com/service_worker.js"); |
350 | 325 |
351 bool called; | 326 scoped_refptr<ServiceWorkerRegistration> old_registration = |
352 scoped_refptr<ServiceWorkerRegistration> old_registration; | 327 RunRegisterJob(pattern, script_url); |
353 job_coordinator()->Register( | |
354 pattern, | |
355 script_url, | |
356 NULL, | |
357 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | |
358 | 328 |
359 ASSERT_FALSE(called); | 329 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = |
360 base::RunLoop().RunUntilIdle(); | 330 FindRegistrationForPattern(pattern); |
361 ASSERT_TRUE(called); | |
362 | |
363 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern; | |
364 storage()->FindRegistrationForPattern( | |
365 pattern, | |
366 SaveFoundRegistration( | |
367 SERVICE_WORKER_OK, &called, &old_registration_by_pattern)); | |
368 ASSERT_FALSE(called); | |
369 base::RunLoop().RunUntilIdle(); | |
370 ASSERT_TRUE(called); | |
371 | 331 |
372 ASSERT_TRUE(old_registration_by_pattern.get()); | 332 ASSERT_TRUE(old_registration_by_pattern.get()); |
373 | 333 |
374 scoped_refptr<ServiceWorkerRegistration> new_registration; | 334 scoped_refptr<ServiceWorkerRegistration> new_registration = |
375 job_coordinator()->Register( | 335 RunRegisterJob(pattern, script_url); |
376 pattern, | |
377 script_url, | |
378 NULL, | |
379 SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); | |
380 | |
381 ASSERT_FALSE(called); | |
382 base::RunLoop().RunUntilIdle(); | |
383 ASSERT_TRUE(called); | |
384 | 336 |
385 ASSERT_EQ(old_registration, new_registration); | 337 ASSERT_EQ(old_registration, new_registration); |
386 | 338 |
387 ASSERT_FALSE(old_registration->HasOneRef()); | 339 ASSERT_FALSE(old_registration->HasOneRef()); |
388 | 340 |
389 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern; | 341 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = |
390 storage()->FindRegistrationForPattern( | 342 FindRegistrationForPattern(pattern); |
391 pattern, | |
392 SaveFoundRegistration( | |
393 SERVICE_WORKER_OK, &called, &new_registration_by_pattern)); | |
394 | |
395 ASSERT_FALSE(called); | |
396 base::RunLoop().RunUntilIdle(); | |
397 ASSERT_TRUE(called); | |
398 | 343 |
399 ASSERT_EQ(new_registration, old_registration); | 344 ASSERT_EQ(new_registration, old_registration); |
400 } | 345 } |
401 | 346 |
402 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { | 347 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { |
403 public: | 348 public: |
404 explicit FailToStartWorkerTestHelper(int mock_render_process_id) | 349 explicit FailToStartWorkerTestHelper(int mock_render_process_id) |
405 : EmbeddedWorkerTestHelper(mock_render_process_id) {} | 350 : EmbeddedWorkerTestHelper(mock_render_process_id) {} |
406 | 351 |
407 void OnStartWorker(int embedded_worker_id, | 352 void OnStartWorker(int embedded_worker_id, |
408 int64 service_worker_version_id, | 353 int64 service_worker_version_id, |
409 const GURL& scope, | 354 const GURL& scope, |
410 const GURL& script_url, | 355 const GURL& script_url, |
411 bool pause_after_download) override { | 356 bool pause_after_download) override { |
412 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 357 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
413 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 358 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
414 } | 359 } |
415 }; | 360 }; |
416 | 361 |
417 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 362 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
418 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); | 363 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); |
419 | 364 |
420 bool called = false; | 365 scoped_refptr<ServiceWorkerRegistration> registration = |
421 scoped_refptr<ServiceWorkerRegistration> registration; | 366 RunRegisterJob(GURL("http://www.example.com/"), |
422 job_coordinator()->Register( | 367 GURL("http://www.example.com/service_worker.js"), |
423 GURL("http://www.example.com/"), | 368 SERVICE_WORKER_ERROR_START_WORKER_FAILED); |
424 GURL("http://www.example.com/service_worker.js"), | |
425 NULL, | |
426 SaveRegistration( | |
427 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, ®istration)); | |
428 | 369 |
429 ASSERT_FALSE(called); | |
430 base::RunLoop().RunUntilIdle(); | |
431 | |
432 ASSERT_TRUE(called); | |
433 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 370 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
434 } | 371 } |
435 | 372 |
436 // Register and then unregister the pattern, in parallel. Job coordinator should | 373 // Register and then unregister the pattern, in parallel. Job coordinator should |
437 // process jobs until the last job. | 374 // process jobs until the last job. |
438 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { | 375 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { |
439 GURL pattern("http://www.example.com/"); | 376 GURL pattern("http://www.example.com/"); |
440 GURL script_url("http://www.example.com/service_worker.js"); | 377 GURL script_url("http://www.example.com/service_worker.js"); |
441 | 378 |
442 bool registration_called = false; | 379 bool registration_called = false; |
443 scoped_refptr<ServiceWorkerRegistration> registration; | 380 scoped_refptr<ServiceWorkerRegistration> registration; |
444 job_coordinator()->Register( | 381 job_coordinator()->Register( |
445 pattern, | 382 pattern, |
446 script_url, | 383 script_url, |
447 NULL, | 384 NULL, |
448 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); | 385 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
449 | 386 |
450 bool unregistration_called = false; | 387 bool unregistration_called = false; |
451 job_coordinator()->Unregister( | 388 job_coordinator()->Unregister( |
452 pattern, | 389 pattern, |
453 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | 390 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
454 | 391 |
455 ASSERT_FALSE(registration_called); | 392 ASSERT_FALSE(registration_called); |
456 ASSERT_FALSE(unregistration_called); | 393 ASSERT_FALSE(unregistration_called); |
457 base::RunLoop().RunUntilIdle(); | 394 base::RunLoop().RunUntilIdle(); |
458 ASSERT_TRUE(registration_called); | 395 ASSERT_TRUE(registration_called); |
459 ASSERT_TRUE(unregistration_called); | 396 ASSERT_TRUE(unregistration_called); |
460 | 397 |
461 bool find_called = false; | 398 registration = FindRegistrationForPattern(pattern, |
462 storage()->FindRegistrationForPattern( | 399 SERVICE_WORKER_ERROR_NOT_FOUND); |
463 pattern, | |
464 SaveFoundRegistration( | |
465 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | |
466 | |
467 base::RunLoop().RunUntilIdle(); | |
468 | 400 |
469 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 401 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
470 } | 402 } |
471 | 403 |
472 // Register conflicting scripts for the same pattern. The most recent | 404 // Register conflicting scripts for the same pattern. The most recent |
473 // registration should win, and the old registration should have been | 405 // registration should win, and the old registration should have been |
474 // shutdown. | 406 // shutdown. |
475 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { | 407 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
476 GURL pattern("http://www.example.com/"); | 408 GURL pattern("http://www.example.com/"); |
477 | 409 |
(...skipping 16 matching lines...) Expand all Loading... | |
494 NULL, | 426 NULL, |
495 SaveRegistration( | 427 SaveRegistration( |
496 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | 428 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); |
497 | 429 |
498 ASSERT_FALSE(registration1_called); | 430 ASSERT_FALSE(registration1_called); |
499 ASSERT_FALSE(registration2_called); | 431 ASSERT_FALSE(registration2_called); |
500 base::RunLoop().RunUntilIdle(); | 432 base::RunLoop().RunUntilIdle(); |
501 ASSERT_TRUE(registration1_called); | 433 ASSERT_TRUE(registration1_called); |
502 ASSERT_TRUE(registration2_called); | 434 ASSERT_TRUE(registration2_called); |
503 | 435 |
504 scoped_refptr<ServiceWorkerRegistration> registration; | 436 scoped_refptr<ServiceWorkerRegistration> registration = |
505 bool find_called = false; | 437 FindRegistrationForPattern(pattern); |
506 storage()->FindRegistrationForPattern( | |
507 pattern, | |
508 SaveFoundRegistration( | |
509 SERVICE_WORKER_OK, &find_called, ®istration)); | |
510 | |
511 base::RunLoop().RunUntilIdle(); | |
512 | 438 |
513 ASSERT_EQ(registration2, registration); | 439 ASSERT_EQ(registration2, registration); |
514 } | 440 } |
515 | 441 |
516 // Register the exact same pattern + script. Requests should be | 442 // Register the exact same pattern + script. Requests should be |
517 // coalesced such that both callers get the exact same registration | 443 // coalesced such that both callers get the exact same registration |
518 // object. | 444 // object. |
519 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { | 445 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
520 GURL pattern("http://www.example.com/"); | 446 GURL pattern("http://www.example.com/"); |
521 | 447 |
(...skipping 17 matching lines...) Expand all Loading... | |
539 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | 465 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); |
540 | 466 |
541 ASSERT_FALSE(registration1_called); | 467 ASSERT_FALSE(registration1_called); |
542 ASSERT_FALSE(registration2_called); | 468 ASSERT_FALSE(registration2_called); |
543 base::RunLoop().RunUntilIdle(); | 469 base::RunLoop().RunUntilIdle(); |
544 ASSERT_TRUE(registration1_called); | 470 ASSERT_TRUE(registration1_called); |
545 ASSERT_TRUE(registration2_called); | 471 ASSERT_TRUE(registration2_called); |
546 | 472 |
547 ASSERT_EQ(registration1, registration2); | 473 ASSERT_EQ(registration1, registration2); |
548 | 474 |
549 scoped_refptr<ServiceWorkerRegistration> registration; | 475 scoped_refptr<ServiceWorkerRegistration> registration = |
550 bool find_called = false; | 476 FindRegistrationForPattern(pattern); |
551 storage()->FindRegistrationForPattern( | |
552 pattern, | |
553 SaveFoundRegistration( | |
554 SERVICE_WORKER_OK, &find_called, ®istration)); | |
555 | 477 |
556 base::RunLoop().RunUntilIdle(); | |
557 ASSERT_EQ(registration, registration1); | 478 ASSERT_EQ(registration, registration1); |
558 } | 479 } |
559 | 480 |
560 // Call simulataneous unregister calls. | 481 // Call simulataneous unregister calls. |
561 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { | 482 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { |
562 GURL pattern("http://www.example.com/"); | 483 GURL pattern("http://www.example.com/"); |
563 | 484 |
564 GURL script_url("http://www.example.com/service_worker.js"); | 485 GURL script_url("http://www.example.com/service_worker.js"); |
565 bool unregistration1_called = false; | 486 bool unregistration1_called = false; |
566 job_coordinator()->Unregister( | 487 job_coordinator()->Unregister( |
567 pattern, | 488 pattern, |
568 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, | 489 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, |
569 &unregistration1_called)); | 490 &unregistration1_called)); |
570 | 491 |
571 bool unregistration2_called = false; | 492 bool unregistration2_called = false; |
572 job_coordinator()->Unregister( | 493 job_coordinator()->Unregister( |
573 pattern, | 494 pattern, |
574 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, | 495 SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, |
575 &unregistration2_called)); | 496 &unregistration2_called)); |
576 | 497 |
577 ASSERT_FALSE(unregistration1_called); | 498 ASSERT_FALSE(unregistration1_called); |
578 ASSERT_FALSE(unregistration2_called); | 499 ASSERT_FALSE(unregistration2_called); |
579 base::RunLoop().RunUntilIdle(); | 500 base::RunLoop().RunUntilIdle(); |
580 ASSERT_TRUE(unregistration1_called); | 501 ASSERT_TRUE(unregistration1_called); |
581 ASSERT_TRUE(unregistration2_called); | 502 ASSERT_TRUE(unregistration2_called); |
582 | 503 |
583 // There isn't really a way to test that they are being coalesced, | 504 // There isn't really a way to test that they are being coalesced, |
584 // but we can make sure they can exist simultaneously without | 505 // but we can make sure they can exist simultaneously without |
585 // crashing. | 506 // crashing. |
586 scoped_refptr<ServiceWorkerRegistration> registration; | 507 scoped_refptr<ServiceWorkerRegistration> registration = |
587 bool find_called = false; | 508 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
588 storage()->FindRegistrationForPattern( | |
589 pattern, | |
590 SaveFoundRegistration( | |
591 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | |
592 | 509 |
593 base::RunLoop().RunUntilIdle(); | |
594 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 510 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
595 } | 511 } |
596 | 512 |
597 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { | 513 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { |
598 GURL pattern1("http://www1.example.com/"); | 514 GURL pattern1("http://www1.example.com/"); |
599 GURL pattern2("http://www2.example.com/"); | 515 GURL pattern2("http://www2.example.com/"); |
600 GURL script_url1("http://www1.example.com/service_worker.js"); | 516 GURL script_url1("http://www1.example.com/service_worker.js"); |
601 GURL script_url2("http://www2.example.com/service_worker.js"); | 517 GURL script_url2("http://www2.example.com/service_worker.js"); |
602 | 518 |
603 bool registration_called1 = false; | 519 bool registration_called1 = false; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 &unregistration_called)); | 607 &unregistration_called)); |
692 | 608 |
693 ASSERT_FALSE(registration_called); | 609 ASSERT_FALSE(registration_called); |
694 ASSERT_FALSE(unregistration_called); | 610 ASSERT_FALSE(unregistration_called); |
695 job_coordinator()->AbortAll(); | 611 job_coordinator()->AbortAll(); |
696 | 612 |
697 base::RunLoop().RunUntilIdle(); | 613 base::RunLoop().RunUntilIdle(); |
698 ASSERT_TRUE(registration_called); | 614 ASSERT_TRUE(registration_called); |
699 ASSERT_TRUE(unregistration_called); | 615 ASSERT_TRUE(unregistration_called); |
700 | 616 |
701 bool find_called = false; | 617 registration = FindRegistrationForPattern(pattern, |
702 storage()->FindRegistrationForPattern( | 618 SERVICE_WORKER_ERROR_NOT_FOUND); |
703 pattern, | |
704 SaveFoundRegistration( | |
705 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | |
706 | 619 |
707 base::RunLoop().RunUntilIdle(); | |
708 ASSERT_TRUE(find_called); | |
709 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 620 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
710 } | 621 } |
711 | 622 |
712 // Tests that the waiting worker enters the 'redundant' state upon | 623 // Tests that the waiting worker enters the 'redundant' state upon |
713 // unregistration. | 624 // unregistration. |
714 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { | 625 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { |
715 scoped_refptr<ServiceWorkerRegistration> registration; | |
716 bool called = false; | |
717 GURL script_url("http://www.example.com/service_worker.js"); | 626 GURL script_url("http://www.example.com/service_worker.js"); |
718 job_coordinator()->Register( | 627 scoped_refptr<ServiceWorkerRegistration> registration = |
719 GURL("http://www.example.com/"), | 628 RunRegisterJob(GURL("http://www.example.com/"), script_url); |
720 script_url, | |
721 NULL, | |
722 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
723 base::RunLoop().RunUntilIdle(); | |
724 ASSERT_TRUE(called); | |
725 ASSERT_TRUE(registration.get()); | 629 ASSERT_TRUE(registration.get()); |
726 | 630 |
727 // Manually create the waiting worker since there is no way to become a | 631 // Manually create the waiting worker since there is no way to become a |
728 // waiting worker until Update is implemented. | 632 // waiting worker until Update is implemented. |
729 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 633 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
730 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); | 634 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); |
731 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 635 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
732 version->StartWorker(CreateReceiverOnCurrentThread(&status)); | 636 version->StartWorker(CreateReceiverOnCurrentThread(&status)); |
733 base::RunLoop().RunUntilIdle(); | 637 base::RunLoop().RunUntilIdle(); |
734 ASSERT_EQ(SERVICE_WORKER_OK, status); | 638 ASSERT_EQ(SERVICE_WORKER_OK, status); |
735 | 639 |
736 version->SetStatus(ServiceWorkerVersion::INSTALLED); | 640 version->SetStatus(ServiceWorkerVersion::INSTALLED); |
737 registration->SetWaitingVersion(version.get()); | 641 registration->SetWaitingVersion(version.get()); |
738 EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 642 EXPECT_EQ(ServiceWorkerVersion::RUNNING, |
739 version->running_status()); | 643 version->running_status()); |
740 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 644 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); |
741 | 645 |
742 called = false; | 646 RunUnregisterJob(GURL("http://www.example.com/")); |
743 job_coordinator()->Unregister(GURL("http://www.example.com/"), | |
744 SaveUnregistration(SERVICE_WORKER_OK, &called)); | |
745 base::RunLoop().RunUntilIdle(); | |
746 ASSERT_TRUE(called); | |
747 | 647 |
748 // The version should be stopped since there is no controllee after | 648 // The version should be stopped since there is no controllee after |
749 // unregistration. | 649 // unregistration. |
750 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 650 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); |
751 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 651 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
752 } | 652 } |
753 | 653 |
754 // Tests that the active worker enters the 'redundant' state upon | 654 // Tests that the active worker enters the 'redundant' state upon |
755 // unregistration. | 655 // unregistration. |
756 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { | 656 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { |
757 scoped_refptr<ServiceWorkerRegistration> registration; | 657 scoped_refptr<ServiceWorkerRegistration> registration = |
758 bool called = false; | 658 RunRegisterJob(GURL("http://www.example.com/"), |
759 job_coordinator()->Register( | 659 GURL("http://www.example.com/service_worker.js")); |
760 GURL("http://www.example.com/"), | |
761 GURL("http://www.example.com/service_worker.js"), | |
762 NULL, | |
763 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
764 base::RunLoop().RunUntilIdle(); | |
765 ASSERT_TRUE(called); | |
766 ASSERT_TRUE(registration.get()); | 660 ASSERT_TRUE(registration.get()); |
767 | 661 |
768 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 662 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
769 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 663 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
770 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 664 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
771 | 665 |
772 called = false; | 666 RunUnregisterJob(GURL("http://www.example.com/")); |
773 job_coordinator()->Unregister(GURL("http://www.example.com/"), | |
774 SaveUnregistration(SERVICE_WORKER_OK, &called)); | |
775 base::RunLoop().RunUntilIdle(); | |
776 ASSERT_TRUE(called); | |
777 | 667 |
778 // The version should be stopped since there is no controllee after | 668 // The version should be stopped since there is no controllee after |
779 // unregistration. | 669 // unregistration. |
780 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 670 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); |
781 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 671 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
782 } | 672 } |
783 | 673 |
784 // Tests that the active worker enters the 'redundant' state upon | 674 // Tests that the active worker enters the 'redundant' state upon |
785 // unregistration. | 675 // unregistration. |
786 TEST_F(ServiceWorkerJobTest, | 676 TEST_F(ServiceWorkerJobTest, |
787 UnregisterActiveSetsRedundant_WaitForNoControllee) { | 677 UnregisterActiveSetsRedundant_WaitForNoControllee) { |
788 scoped_refptr<ServiceWorkerRegistration> registration; | 678 scoped_refptr<ServiceWorkerRegistration> registration = |
789 bool called = false; | 679 RunRegisterJob(GURL("http://www.example.com/"), |
790 job_coordinator()->Register( | 680 GURL("http://www.example.com/service_worker.js")); |
791 GURL("http://www.example.com/"), | |
792 GURL("http://www.example.com/service_worker.js"), | |
793 NULL, | |
794 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
795 base::RunLoop().RunUntilIdle(); | |
796 ASSERT_TRUE(called); | |
797 ASSERT_TRUE(registration.get()); | 681 ASSERT_TRUE(registration.get()); |
798 | 682 |
799 scoped_ptr<ServiceWorkerProviderHost> host( | 683 scoped_ptr<ServiceWorkerProviderHost> host( |
800 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 684 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
801 MSG_ROUTING_NONE /* render_frame_id */, | 685 MSG_ROUTING_NONE /* render_frame_id */, |
802 1 /* dummy provider_id */, | 686 1 /* dummy provider_id */, |
803 context()->AsWeakPtr(), | 687 context()->AsWeakPtr(), |
804 NULL)); | 688 NULL)); |
805 registration->active_version()->AddControllee(host.get()); | 689 registration->active_version()->AddControllee(host.get()); |
806 | 690 |
807 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 691 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
808 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 692 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
809 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 693 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
810 | 694 |
811 called = false; | 695 RunUnregisterJob(GURL("http://www.example.com/")); |
812 job_coordinator()->Unregister(GURL("http://www.example.com/"), | |
813 SaveUnregistration(SERVICE_WORKER_OK, &called)); | |
814 base::RunLoop().RunUntilIdle(); | |
815 ASSERT_TRUE(called); | |
816 | 696 |
817 // The version should be running since there is still a controllee. | 697 // The version should be running since there is still a controllee. |
818 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 698 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
819 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 699 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
820 | 700 |
821 registration->active_version()->RemoveControllee(host.get()); | 701 registration->active_version()->RemoveControllee(host.get()); |
822 base::RunLoop().RunUntilIdle(); | 702 base::RunLoop().RunUntilIdle(); |
823 | 703 |
824 // The version should be stopped since there is no controllee. | 704 // The version should be stopped since there is no controllee. |
825 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 705 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1128 | 1008 |
1129 EXPECT_EQ(registration->active_version()->version_id(), | 1009 EXPECT_EQ(registration->active_version()->version_id(), |
1130 update_helper->state_change_log_[4].version_id); | 1010 update_helper->state_change_log_[4].version_id); |
1131 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1011 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
1132 update_helper->state_change_log_[4].status); | 1012 update_helper->state_change_log_[4].status); |
1133 | 1013 |
1134 EXPECT_TRUE(update_helper->update_found_); | 1014 EXPECT_TRUE(update_helper->update_found_); |
1135 } | 1015 } |
1136 | 1016 |
1137 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { | 1017 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { |
1138 bool called; | 1018 scoped_refptr<ServiceWorkerRegistration> registration = |
1139 scoped_refptr<ServiceWorkerRegistration> registration; | 1019 RunRegisterJob(GURL("http://www.example.com/one/"), |
1140 job_coordinator()->Register( | 1020 GURL("http://www.example.com/service_worker.js")); |
1141 GURL("http://www.example.com/one/"), | |
1142 GURL("http://www.example.com/service_worker.js"), | |
1143 NULL, | |
1144 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
1145 | 1021 |
1146 EXPECT_FALSE(called); | |
1147 base::RunLoop().RunUntilIdle(); | |
1148 EXPECT_TRUE(called); | |
1149 ServiceWorkerVersion* active_version = registration->active_version(); | 1022 ServiceWorkerVersion* active_version = registration->active_version(); |
1150 | 1023 |
1151 // Queue an Update, it should abort when it starts and sees the new version. | 1024 // Queue an Update, it should abort when it starts and sees the new version. |
1152 job_coordinator()->Update(registration.get()); | 1025 job_coordinator()->Update(registration.get()); |
1153 | 1026 |
1154 // Add a waiting version with new script. | 1027 // Add a waiting version with new script. |
1155 scoped_refptr<ServiceWorkerVersion> version = | 1028 scoped_refptr<ServiceWorkerVersion> version = |
1156 new ServiceWorkerVersion(registration.get(), | 1029 new ServiceWorkerVersion(registration.get(), |
1157 GURL("http://www.example.com/new_worker.js"), | 1030 GURL("http://www.example.com/new_worker.js"), |
1158 2L /* dummy version id */, | 1031 2L /* dummy version id */, |
1159 helper_->context()->AsWeakPtr()); | 1032 helper_->context()->AsWeakPtr()); |
1160 registration->SetWaitingVersion(version.get()); | 1033 registration->SetWaitingVersion(version.get()); |
1161 | 1034 |
1162 base::RunLoop().RunUntilIdle(); | 1035 base::RunLoop().RunUntilIdle(); |
1163 | 1036 |
1164 // Verify the registration was not modified by the Update. | 1037 // Verify the registration was not modified by the Update. |
1165 EXPECT_EQ(active_version, registration->active_version()); | 1038 EXPECT_EQ(active_version, registration->active_version()); |
1166 EXPECT_EQ(version.get(), registration->waiting_version()); | 1039 EXPECT_EQ(version.get(), registration->waiting_version()); |
1167 EXPECT_EQ(NULL, registration->installing_version()); | 1040 EXPECT_EQ(NULL, registration->installing_version()); |
1168 } | 1041 } |
1169 | 1042 |
1170 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { | 1043 TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { |
1171 bool called; | 1044 bool called; |
1172 scoped_refptr<ServiceWorkerRegistration> registration; | 1045 scoped_refptr<ServiceWorkerRegistration> registration = |
1173 job_coordinator()->Register( | 1046 RunRegisterJob(GURL("http://www.example.com/one/"), |
1174 GURL("http://www.example.com/one/"), | 1047 GURL("http://www.example.com/service_worker.js")); |
1175 GURL("http://www.example.com/service_worker.js"), | |
1176 NULL, | |
1177 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | |
1178 | |
1179 EXPECT_FALSE(called); | |
1180 base::RunLoop().RunUntilIdle(); | |
1181 EXPECT_TRUE(called); | |
1182 | 1048 |
1183 // Add a controllee and queue an unregister to force the uninstalling state. | 1049 // Add a controllee and queue an unregister to force the uninstalling state. |
1184 scoped_ptr<ServiceWorkerProviderHost> host( | 1050 scoped_ptr<ServiceWorkerProviderHost> host( |
1185 new ServiceWorkerProviderHost(33 /* dummy render_process id */, | 1051 new ServiceWorkerProviderHost(33 /* dummy render_process id */, |
1186 MSG_ROUTING_NONE /* render_frame_id */, | 1052 MSG_ROUTING_NONE /* render_frame_id */, |
1187 1 /* dummy provider_id */, | 1053 1 /* dummy provider_id */, |
1188 helper_->context()->AsWeakPtr(), | 1054 helper_->context()->AsWeakPtr(), |
1189 NULL)); | 1055 NULL)); |
1190 ServiceWorkerVersion* active_version = registration->active_version(); | 1056 ServiceWorkerVersion* active_version = registration->active_version(); |
1191 active_version->AddControllee(host.get()); | 1057 active_version->AddControllee(host.get()); |
1192 job_coordinator()->Unregister(GURL("http://www.example.com/one/"), | 1058 job_coordinator()->Unregister(GURL("http://www.example.com/one/"), |
1193 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 1059 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
1194 | 1060 |
1195 // Update should abort after it starts and sees uninstalling. | 1061 // Update should abort after it starts and sees uninstalling. |
1196 job_coordinator()->Update(registration.get()); | 1062 job_coordinator()->Update(registration.get()); |
1197 | 1063 |
1198 EXPECT_FALSE(called); | 1064 EXPECT_FALSE(called); |
1199 base::RunLoop().RunUntilIdle(); | 1065 base::RunLoop().RunUntilIdle(); |
1200 EXPECT_TRUE(called); | 1066 EXPECT_TRUE(called); |
1201 | 1067 |
1202 // Verify the registration was not modified by the Update. | 1068 // Verify the registration was not modified by the Update. |
1203 EXPECT_TRUE(registration->is_uninstalling()); | 1069 EXPECT_TRUE(registration->is_uninstalling()); |
1204 EXPECT_EQ(active_version, registration->active_version()); | 1070 EXPECT_EQ(active_version, registration->active_version()); |
1205 EXPECT_EQ(NULL, registration->waiting_version()); | 1071 EXPECT_EQ(NULL, registration->waiting_version()); |
1206 EXPECT_EQ(NULL, registration->installing_version()); | 1072 EXPECT_EQ(NULL, registration->installing_version()); |
1207 } | 1073 } |
1208 | 1074 |
1209 } // namespace content | 1075 } // namespace content |
OLD | NEW |