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

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: Logic to Core 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 origin1_p3("http://www.example.com:8080/again");
jsbell 2014/10/13 20:54:25 http://example.com and http://example.com:8080 are
dmurph 2014/10/14 00:16:31 Done.
281 GURL origin2_p1("http://www.other.com/");
282 GURL origin1 = origin1_p1.GetOrigin();
283 GURL origin2 = origin2_p1.GetOrigin();
284
285 bool called = false;
286 int64 registration_id1 = kInvalidServiceWorkerRegistrationId;
287 int64 registration_id2 = kInvalidServiceWorkerRegistrationId;
288 int64 registration_id3 = kInvalidServiceWorkerRegistrationId;
289 int64 registration_id4 = kInvalidServiceWorkerRegistrationId;
290 context()->RegisterServiceWorker(
291 origin1_p1,
292 GURL("http://www.example.com/service_worker.js"),
293 NULL,
294 MakeRegisteredCallback(&called, &registration_id1));
295 context()->RegisterServiceWorker(
296 origin1_p2,
297 GURL("http://www.example.com/service_worker2.js"),
298 NULL,
299 MakeRegisteredCallback(&called, &registration_id2));
300 context()->RegisterServiceWorker(
301 origin1_p3,
302 GURL("http://www.example.com:8080/service_worker3.js"),
303 NULL,
304 MakeRegisteredCallback(&called, &registration_id3));
305 context()->RegisterServiceWorker(
306 origin2_p1,
307 GURL("http://www.other.com/service_worker4.js"),
308 NULL,
309 MakeRegisteredCallback(&called, &registration_id4));
310
311 ASSERT_FALSE(called);
312 base::RunLoop().RunUntilIdle();
313 ASSERT_TRUE(called);
314
315 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id1);
316 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id2);
317 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id3);
318 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id4);
319
320 called = false;
321 context()->UnregisterServiceWorkers(origin1,
322 MakeUnregisteredCallback(&called));
323
324 ASSERT_FALSE(called);
325 base::RunLoop().RunUntilIdle();
326 ASSERT_TRUE(called);
327
328 context()->storage()->FindRegistrationForId(
329 registration_id1,
330 origin1,
331 base::Bind(&ExpectRegisteredWorkers,
332 SERVICE_WORKER_ERROR_NOT_FOUND,
333 false /* expect_waiting */,
334 false /* expect_active */));
335 context()->storage()->FindRegistrationForId(
336 registration_id2,
337 origin1,
338 base::Bind(&ExpectRegisteredWorkers,
339 SERVICE_WORKER_ERROR_NOT_FOUND,
340 false /* expect_waiting */,
341 false /* expect_active */));
342 context()->storage()->FindRegistrationForId(
343 registration_id3,
344 origin1,
jsbell 2014/10/13 20:54:25 I believe this is only succeeding because registra
dmurph 2014/10/14 00:16:31 Done.
345 base::Bind(&ExpectRegisteredWorkers,
346 SERVICE_WORKER_ERROR_NOT_FOUND,
347 false /* expect_waiting */,
348 false /* expect_active */));
349
350 context()->storage()->FindRegistrationForId(
351 registration_id4,
352 origin2,
353 base::Bind(&ExpectRegisteredWorkers,
354 SERVICE_WORKER_OK,
355 false /* expect_waiting */,
356 true /* expect_active */));
357
358 base::RunLoop().RunUntilIdle();
359 }
360
276 // Make sure registering a new script shares an existing registration. 361 // Make sure registering a new script shares an existing registration.
277 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 362 TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
278 GURL pattern("http://www.example.com/"); 363 GURL pattern("http://www.example.com/");
279 364
280 bool called = false; 365 bool called = false;
281 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 366 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
282 context()->RegisterServiceWorker( 367 context()->RegisterServiceWorker(
283 pattern, 368 pattern,
284 GURL("http://www.example.com/service_worker.js"), 369 GURL("http://www.example.com/service_worker.js"),
285 NULL, 370 NULL,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 registration_id, 493 registration_id,
409 GURL("http://www.example.com"), 494 GURL("http://www.example.com"),
410 base::Bind(&ExpectRegisteredWorkers, 495 base::Bind(&ExpectRegisteredWorkers,
411 SERVICE_WORKER_OK, 496 SERVICE_WORKER_OK,
412 false /* expect_waiting */, 497 false /* expect_waiting */,
413 true /* expect_active */)); 498 true /* expect_active */));
414 base::RunLoop().RunUntilIdle(); 499 base::RunLoop().RunUntilIdle();
415 } 500 }
416 501
417 } // namespace content 502 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698