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

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

Issue 535753002: ServiceWorker: Implement navigator.serviceWorker.getRegistration [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch for review Created 6 years, 3 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 void CallCompletedCallback(bool* called, ServiceWorkerStatusCode) { 47 void CallCompletedCallback(bool* called, ServiceWorkerStatusCode) {
48 *called = true; 48 *called = true;
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 SaveRegistrationIdCallback(bool* called,
57 int64* store_registration_id,
58 ServiceWorkerStatusCode status,
59 int64 registration_id) {
60 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
61 *called = true;
62 *store_registration_id = registration_id;
63 }
64
65 ServiceWorkerContextCore::GetRegistrationCallback MakeGetRegistrationCallback(
66 bool* called,
67 int64* store_registration_id) {
68 return base::Bind(&SaveRegistrationIdCallback, called, store_registration_id);
nhiroki 2014/09/10 04:07:22 nit: This indirection doesn't seem very helpful, o
Kunihiko Sakamoto 2014/09/10 08:22:44 Agreed - inlined it.
69 }
70
56 void ExpectRegisteredWorkers( 71 void ExpectRegisteredWorkers(
57 ServiceWorkerStatusCode expect_status, 72 ServiceWorkerStatusCode expect_status,
58 int64 expect_version_id, 73 int64 expect_version_id,
59 bool expect_waiting, 74 bool expect_waiting,
60 bool expect_active, 75 bool expect_active,
61 ServiceWorkerStatusCode status, 76 ServiceWorkerStatusCode status,
62 const scoped_refptr<ServiceWorkerRegistration>& registration) { 77 const scoped_refptr<ServiceWorkerRegistration>& registration) {
63 ASSERT_EQ(expect_status, status); 78 ASSERT_EQ(expect_status, status);
64 if (status != SERVICE_WORKER_OK) { 79 if (status != SERVICE_WORKER_OK) {
65 EXPECT_FALSE(registration.get()); 80 EXPECT_FALSE(registration.get());
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 registration_id, 463 registration_id,
449 GURL("http://www.example.com"), 464 GURL("http://www.example.com"),
450 base::Bind(&ExpectRegisteredWorkers, 465 base::Bind(&ExpectRegisteredWorkers,
451 SERVICE_WORKER_OK, 466 SERVICE_WORKER_OK,
452 version_id, 467 version_id,
453 false /* expect_waiting */, 468 false /* expect_waiting */,
454 true /* expect_active */)); 469 true /* expect_active */));
455 base::RunLoop().RunUntilIdle(); 470 base::RunLoop().RunUntilIdle();
456 } 471 }
457 472
473 TEST_F(ServiceWorkerContextTest, GetRegistration) {
474 GURL pattern("http://www.example.com/");
475 GURL document_url("http://www.example.com/foo");
476
477 bool called = false;
478 int64 registration_id = kInvalidServiceWorkerRegistrationId;
479 int64 version_id = kInvalidServiceWorkerVersionId;
480 context()->RegisterServiceWorker(
481 pattern,
482 GURL("http://www.example.com/service_worker.js"),
483 render_process_id_,
484 NULL,
485 MakeRegisteredCallback(&called, &registration_id, &version_id));
486
487 ASSERT_FALSE(called);
488 base::RunLoop().RunUntilIdle();
489 ASSERT_TRUE(called);
490 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
491 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id);
492
493 called = false;
494 int64 result_registration_id;
495 context()->GetRegistration(
496 document_url,
497 MakeGetRegistrationCallback(&called, &result_registration_id));
498
499 ASSERT_FALSE(called);
500 base::RunLoop().RunUntilIdle();
501 ASSERT_TRUE(called);
502 EXPECT_EQ(registration_id, result_registration_id);
nhiroki 2014/09/10 04:07:22 Can you test a case that there is no registration
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
503 }
504
458 } // namespace content 505 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698