OLD | NEW |
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 context()->storage()->FindRegistrationForId( | 266 context()->storage()->FindRegistrationForId( |
267 registration_id, | 267 registration_id, |
268 pattern.GetOrigin(), | 268 pattern.GetOrigin(), |
269 base::Bind(&ExpectRegisteredWorkers, | 269 base::Bind(&ExpectRegisteredWorkers, |
270 SERVICE_WORKER_ERROR_NOT_FOUND, | 270 SERVICE_WORKER_ERROR_NOT_FOUND, |
271 false /* expect_waiting */, | 271 false /* expect_waiting */, |
272 false /* expect_active */)); | 272 false /* expect_active */)); |
273 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
274 } | 274 } |
275 | 275 |
276 // Make sure registrations are cleaned up when they are unregistered in bulk. | |
277 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { | |
278 GURL origin1_p1("http://www.example.com/test"); | |
279 GURL origin1_p2("http://www.example.com/hello"); | |
280 GURL origin2_p1("http://www.example.com:8080/again"); | |
281 GURL origin3_p1("http://www.other.com/"); | |
282 | |
283 bool called = false; | |
284 int64 registration_id1 = kInvalidServiceWorkerRegistrationId; | |
285 int64 registration_id2 = kInvalidServiceWorkerRegistrationId; | |
286 int64 registration_id3 = kInvalidServiceWorkerRegistrationId; | |
287 int64 registration_id4 = kInvalidServiceWorkerRegistrationId; | |
288 context()->RegisterServiceWorker( | |
289 origin1_p1, | |
290 GURL("http://www.example.com/service_worker.js"), | |
291 NULL, | |
292 MakeRegisteredCallback(&called, ®istration_id1)); | |
293 context()->RegisterServiceWorker( | |
294 origin1_p2, | |
295 GURL("http://www.example.com/service_worker2.js"), | |
296 NULL, | |
297 MakeRegisteredCallback(&called, ®istration_id2)); | |
298 context()->RegisterServiceWorker( | |
299 origin2_p1, | |
300 GURL("http://www.example.com:8080/service_worker3.js"), | |
301 NULL, | |
302 MakeRegisteredCallback(&called, ®istration_id3)); | |
303 context()->RegisterServiceWorker( | |
304 origin3_p1, | |
305 GURL("http://www.other.com/service_worker4.js"), | |
306 NULL, | |
307 MakeRegisteredCallback(&called, ®istration_id4)); | |
308 | |
309 ASSERT_FALSE(called); | |
310 base::RunLoop().RunUntilIdle(); | |
311 ASSERT_TRUE(called); | |
312 | |
313 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id1); | |
314 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id2); | |
315 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id3); | |
316 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id4); | |
317 | |
318 called = false; | |
319 context()->UnregisterServiceWorkers(origin1_p1.GetOrigin(), | |
320 MakeUnregisteredCallback(&called)); | |
321 | |
322 ASSERT_FALSE(called); | |
323 base::RunLoop().RunUntilIdle(); | |
324 ASSERT_TRUE(called); | |
325 | |
326 context()->storage()->FindRegistrationForId( | |
327 registration_id1, | |
328 origin1_p1.GetOrigin(), | |
329 base::Bind(&ExpectRegisteredWorkers, | |
330 SERVICE_WORKER_ERROR_NOT_FOUND, | |
331 false /* expect_waiting */, | |
332 false /* expect_active */)); | |
333 context()->storage()->FindRegistrationForId( | |
334 registration_id2, | |
335 origin1_p2.GetOrigin(), | |
336 base::Bind(&ExpectRegisteredWorkers, | |
337 SERVICE_WORKER_ERROR_NOT_FOUND, | |
338 false /* expect_waiting */, | |
339 false /* expect_active */)); | |
340 context()->storage()->FindRegistrationForId( | |
341 registration_id3, | |
342 origin2_p1.GetOrigin(), | |
343 base::Bind(&ExpectRegisteredWorkers, | |
344 SERVICE_WORKER_OK, | |
345 false /* expect_waiting */, | |
346 true /* expect_active */)); | |
347 | |
348 context()->storage()->FindRegistrationForId( | |
349 registration_id4, | |
350 origin3_p1.GetOrigin(), | |
351 base::Bind(&ExpectRegisteredWorkers, | |
352 SERVICE_WORKER_OK, | |
353 false /* expect_waiting */, | |
354 true /* expect_active */)); | |
355 | |
356 base::RunLoop().RunUntilIdle(); | |
357 } | |
358 | |
359 // Make sure registering a new script shares an existing registration. | 276 // Make sure registering a new script shares an existing registration. |
360 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { | 277 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { |
361 GURL pattern("http://www.example.com/"); | 278 GURL pattern("http://www.example.com/"); |
362 | 279 |
363 bool called = false; | 280 bool called = false; |
364 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; | 281 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; |
365 context()->RegisterServiceWorker( | 282 context()->RegisterServiceWorker( |
366 pattern, | 283 pattern, |
367 GURL("http://www.example.com/service_worker.js"), | 284 GURL("http://www.example.com/service_worker.js"), |
368 NULL, | 285 NULL, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 false /* expect_waiting */, | 416 false /* expect_waiting */, |
500 true /* expect_active */)); | 417 true /* expect_active */)); |
501 base::RunLoop().RunUntilIdle(); | 418 base::RunLoop().RunUntilIdle(); |
502 | 419 |
503 // The new context should take over next handle ids. | 420 // The new context should take over next handle ids. |
504 EXPECT_EQ(1, context()->GetNewServiceWorkerHandleId()); | 421 EXPECT_EQ(1, context()->GetNewServiceWorkerHandleId()); |
505 EXPECT_EQ(1, context()->GetNewRegistrationHandleId()); | 422 EXPECT_EQ(1, context()->GetNewRegistrationHandleId()); |
506 } | 423 } |
507 | 424 |
508 } // namespace content | 425 } // namespace content |
OLD | NEW |