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

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

Issue 633273002: Added quota client for serviceworker. Enables 'clear past <time> data'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, &registration_id1));
293 context()->RegisterServiceWorker(
294 origin1_p2,
295 GURL("http://www.example.com/service_worker2.js"),
296 NULL,
297 MakeRegisteredCallback(&called, &registration_id2));
298 context()->RegisterServiceWorker(
299 origin2_p1,
300 GURL("http://www.example.com:8080/service_worker3.js"),
301 NULL,
302 MakeRegisteredCallback(&called, &registration_id3));
303 context()->RegisterServiceWorker(
304 origin3_p1,
305 GURL("http://www.other.com/service_worker4.js"),
306 NULL,
307 MakeRegisteredCallback(&called, &registration_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
276 // Make sure registering a new script shares an existing registration. 359 // Make sure registering a new script shares an existing registration.
277 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 360 TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
278 GURL pattern("http://www.example.com/"); 361 GURL pattern("http://www.example.com/");
279 362
280 bool called = false; 363 bool called = false;
281 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 364 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
282 context()->RegisterServiceWorker( 365 context()->RegisterServiceWorker(
283 pattern, 366 pattern,
284 GURL("http://www.example.com/service_worker.js"), 367 GURL("http://www.example.com/service_worker.js"),
285 NULL, 368 NULL,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 false /* expect_waiting */, 492 false /* expect_waiting */,
410 true /* expect_active */)); 493 true /* expect_active */));
411 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
412 495
413 // The new context should take over next handle ids. 496 // The new context should take over next handle ids.
414 EXPECT_EQ(1, context()->GetNewServiceWorkerHandleId()); 497 EXPECT_EQ(1, context()->GetNewServiceWorkerHandleId());
415 EXPECT_EQ(1, context()->GetNewRegistrationHandleId()); 498 EXPECT_EQ(1, context()->GetNewRegistrationHandleId());
416 } 499 }
417 500
418 } // namespace content 501 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698