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

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

Issue 1022363002: ServiceWorker: Run ServiceWorkerContextTest.DeleteAndStartOver on disk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 9 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if (expect_active) { 72 if (expect_active) {
73 EXPECT_TRUE(registration->active_version()); 73 EXPECT_TRUE(registration->active_version());
74 } else { 74 } else {
75 EXPECT_FALSE(registration->active_version()); 75 EXPECT_FALSE(registration->active_version());
76 } 76 }
77 } 77 }
78 78
79 class RejectInstallTestHelper : public EmbeddedWorkerTestHelper { 79 class RejectInstallTestHelper : public EmbeddedWorkerTestHelper {
80 public: 80 public:
81 explicit RejectInstallTestHelper(int mock_render_process_id) 81 explicit RejectInstallTestHelper(int mock_render_process_id)
82 : EmbeddedWorkerTestHelper(mock_render_process_id) {} 82 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {}
83 83
84 void OnInstallEvent(int embedded_worker_id, 84 void OnInstallEvent(int embedded_worker_id,
85 int request_id) override { 85 int request_id) override {
86 SimulateSend( 86 SimulateSend(
87 new ServiceWorkerHostMsg_InstallEventFinished( 87 new ServiceWorkerHostMsg_InstallEventFinished(
88 embedded_worker_id, request_id, 88 embedded_worker_id, request_id,
89 blink::WebServiceWorkerEventResultRejected)); 89 blink::WebServiceWorkerEventResultRejected));
90 } 90 }
91 }; 91 };
92 92
93 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { 93 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper {
94 public: 94 public:
95 explicit RejectActivateTestHelper(int mock_render_process_id) 95 explicit RejectActivateTestHelper(int mock_render_process_id)
96 : EmbeddedWorkerTestHelper(mock_render_process_id) {} 96 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {}
97 97
98 void OnActivateEvent(int embedded_worker_id, int request_id) override { 98 void OnActivateEvent(int embedded_worker_id, int request_id) override {
99 SimulateSend( 99 SimulateSend(
100 new ServiceWorkerHostMsg_ActivateEventFinished( 100 new ServiceWorkerHostMsg_ActivateEventFinished(
101 embedded_worker_id, request_id, 101 embedded_worker_id, request_id,
102 blink::WebServiceWorkerEventResultRejected)); 102 blink::WebServiceWorkerEventResultRejected));
103 } 103 }
104 }; 104 };
105 105
106 enum NotificationType { 106 enum NotificationType {
(...skipping 11 matching lines...) Expand all
118 } // namespace 118 } // namespace
119 119
120 class ServiceWorkerContextTest : public ServiceWorkerContextObserver, 120 class ServiceWorkerContextTest : public ServiceWorkerContextObserver,
121 public testing::Test { 121 public testing::Test {
122 public: 122 public:
123 ServiceWorkerContextTest() 123 ServiceWorkerContextTest()
124 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 124 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
125 render_process_id_(99) {} 125 render_process_id_(99) {}
126 126
127 void SetUp() override { 127 void SetUp() override {
128 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_)); 128 helper_.reset(
129 new EmbeddedWorkerTestHelper(base::FilePath(), render_process_id_));
129 helper_->context_wrapper()->AddObserver(this); 130 helper_->context_wrapper()->AddObserver(this);
130 } 131 }
131 132
132 void TearDown() override { helper_.reset(); } 133 void TearDown() override { helper_.reset(); }
133 134
134 // ServiceWorkerContextObserver overrides. 135 // ServiceWorkerContextObserver overrides.
135 void OnRegistrationStored(int64 registration_id, 136 void OnRegistrationStored(int64 registration_id,
136 const GURL& pattern) override { 137 const GURL& pattern) override {
137 NotificationLog log; 138 NotificationLog log;
138 log.type = REGISTRATION_STORED; 139 log.type = REGISTRATION_STORED;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 513
513 ASSERT_EQ(2u, notifications_.size()); 514 ASSERT_EQ(2u, notifications_.size());
514 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 515 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
515 EXPECT_EQ(pattern, notifications_[0].pattern); 516 EXPECT_EQ(pattern, notifications_[0].pattern);
516 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); 517 EXPECT_EQ(old_registration_id, notifications_[0].registration_id);
517 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); 518 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type);
518 EXPECT_EQ(pattern, notifications_[1].pattern); 519 EXPECT_EQ(pattern, notifications_[1].pattern);
519 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); 520 EXPECT_EQ(old_registration_id, notifications_[1].registration_id);
520 } 521 }
521 522
522 // TODO(nhiroki): Test this for on-disk storage.
523 TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) { 523 TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) {
524 GURL pattern("http://www.example.com/"); 524 GURL pattern("http://www.example.com/");
525 GURL script_url("http://www.example.com/service_worker.js"); 525 GURL script_url("http://www.example.com/service_worker.js");
526 526
527 // Reinitialize the helper to test on-disk storage.
528 base::ScopedTempDir user_data_directory;
529 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir());
530 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.path(),
531 render_process_id_));
532 helper_->context_wrapper()->AddObserver(this);
533
527 int64 registration_id = kInvalidServiceWorkerRegistrationId; 534 int64 registration_id = kInvalidServiceWorkerRegistrationId;
528 bool called = false; 535 bool called = false;
529 context()->RegisterServiceWorker( 536 context()->RegisterServiceWorker(
530 pattern, 537 pattern,
531 script_url, 538 script_url,
532 NULL, 539 NULL,
533 MakeRegisteredCallback(&called, &registration_id)); 540 MakeRegisteredCallback(&called, &registration_id));
534 541
535 ASSERT_FALSE(called); 542 ASSERT_FALSE(called);
536 base::RunLoop().RunUntilIdle(); 543 base::RunLoop().RunUntilIdle();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 EXPECT_EQ(1u, results.size()); 682 EXPECT_EQ(1u, results.size());
676 EXPECT_TRUE(ContainsKey(results, host2)); 683 EXPECT_TRUE(ContainsKey(results, host2));
677 684
678 context()->RemoveProviderHost(kRenderProcessId1, 1); 685 context()->RemoveProviderHost(kRenderProcessId1, 1);
679 context()->RemoveProviderHost(kRenderProcessId2, 2); 686 context()->RemoveProviderHost(kRenderProcessId2, 2);
680 context()->RemoveProviderHost(kRenderProcessId2, 3); 687 context()->RemoveProviderHost(kRenderProcessId2, 3);
681 context()->RemoveProviderHost(kRenderProcessId2, 4); 688 context()->RemoveProviderHost(kRenderProcessId2, 4);
682 } 689 }
683 690
684 } // namespace content 691 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698