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

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

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent of Service Worker (Closed)
Patch Set: Created 3 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 EXPECT_TRUE(registration->active_version()); 78 EXPECT_TRUE(registration->active_version());
79 } else { 79 } else {
80 EXPECT_FALSE(registration->active_version()); 80 EXPECT_FALSE(registration->active_version());
81 } 81 }
82 } 82 }
83 83
84 class RejectInstallTestHelper : public EmbeddedWorkerTestHelper { 84 class RejectInstallTestHelper : public EmbeddedWorkerTestHelper {
85 public: 85 public:
86 RejectInstallTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} 86 RejectInstallTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
87 87
88 void OnInstallEvent(int embedded_worker_id, 88 void OnInstallEvent(
89 int request_id) override { 89 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
90 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( 90 callback) override {
91 embedded_worker_id, request_id, 91 dispatched_events()->push_back(Event::Install);
92 blink::WebServiceWorkerEventResultRejected, true, base::Time::Now())); 92 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, true,
falken 2017/03/14 08:49:26 true /* has_fetch_handler */
xiaofengzhang 2017/04/01 02:27:21 Done.
93 base::Time::Now());
93 } 94 }
94 }; 95 };
95 96
96 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { 97 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper {
97 public: 98 public:
98 RejectActivateTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} 99 RejectActivateTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
99 100
100 void OnActivateEvent( 101 void OnActivateEvent(
101 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& 102 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback&
102 callback) override { 103 callback) override {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 context()->RegisterServiceWorker( 211 context()->RegisterServiceWorker(
211 pattern, 212 pattern,
212 script_url, 213 script_url,
213 NULL, 214 NULL,
214 MakeRegisteredCallback(&called, &registration_id)); 215 MakeRegisteredCallback(&called, &registration_id));
215 216
216 ASSERT_FALSE(called); 217 ASSERT_FALSE(called);
217 base::RunLoop().RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
218 EXPECT_TRUE(called); 219 EXPECT_TRUE(called);
219 220
220 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); 221 ASSERT_EQ(2UL, helper_->dispatched_events()->size());
221 ASSERT_EQ(1UL, helper_->dispatched_events()->size());
222 ASSERT_EQ(2UL, client->events().size()); 222 ASSERT_EQ(2UL, client->events().size());
223 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, 223 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker,
224 client->events()[0]); 224 client->events()[0]);
225 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 225 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install,
226 ServiceWorkerMsg_InstallEvent::ID)); 226 helper_->dispatched_events()->at(0));
227 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, 227 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate,
228 helper_->dispatched_events()->at(0)); 228 helper_->dispatched_events()->at(1));
229 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, 229 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker,
230 client->events()[1]); 230 client->events()[1]);
231 231
232 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 232 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
233 233
234 ASSERT_EQ(1u, notifications_.size()); 234 ASSERT_EQ(1u, notifications_.size());
235 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 235 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
236 EXPECT_EQ(pattern, notifications_[0].pattern); 236 EXPECT_EQ(pattern, notifications_[0].pattern);
237 EXPECT_EQ(registration_id, notifications_[0].registration_id); 237 EXPECT_EQ(registration_id, notifications_[0].registration_id);
238 238
(...skipping 27 matching lines...) Expand all
266 context()->RegisterServiceWorker( 266 context()->RegisterServiceWorker(
267 pattern, 267 pattern,
268 script_url, 268 script_url,
269 NULL, 269 NULL,
270 MakeRegisteredCallback(&called, &registration_id)); 270 MakeRegisteredCallback(&called, &registration_id));
271 271
272 ASSERT_FALSE(called); 272 ASSERT_FALSE(called);
273 base::RunLoop().RunUntilIdle(); 273 base::RunLoop().RunUntilIdle();
274 EXPECT_TRUE(called); 274 EXPECT_TRUE(called);
275 275
276 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); 276 EXPECT_EQ(1UL, helper_->dispatched_events()->size());
277 EXPECT_EQ(0UL, helper_->dispatched_events()->size());
278 ASSERT_EQ(2UL, client->events().size()); 277 ASSERT_EQ(2UL, client->events().size());
279 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, 278 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker,
280 client->events()[0]); 279 client->events()[0]);
281 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 280 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install,
282 ServiceWorkerMsg_InstallEvent::ID)); 281 helper_->dispatched_events()->at(0));
283 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, 282 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker,
284 client->events()[1]); 283 client->events()[1]);
285 284
286 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 285 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
287 286
288 ASSERT_EQ(1u, notifications_.size()); 287 ASSERT_EQ(1u, notifications_.size());
289 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 288 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
290 EXPECT_EQ(pattern, notifications_[0].pattern); 289 EXPECT_EQ(pattern, notifications_[0].pattern);
291 EXPECT_EQ(registration_id, notifications_[0].registration_id); 290 EXPECT_EQ(registration_id, notifications_[0].registration_id);
292 291
(...skipping 24 matching lines...) Expand all
317 int64_t registration_id = kInvalidServiceWorkerRegistrationId; 316 int64_t registration_id = kInvalidServiceWorkerRegistrationId;
318 bool called = false; 317 bool called = false;
319 context()->RegisterServiceWorker( 318 context()->RegisterServiceWorker(
320 pattern, script_url, NULL, 319 pattern, script_url, NULL,
321 MakeRegisteredCallback(&called, &registration_id)); 320 MakeRegisteredCallback(&called, &registration_id));
322 321
323 ASSERT_FALSE(called); 322 ASSERT_FALSE(called);
324 base::RunLoop().RunUntilIdle(); 323 base::RunLoop().RunUntilIdle();
325 EXPECT_TRUE(called); 324 EXPECT_TRUE(called);
326 325
327 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); 326 ASSERT_EQ(2UL, helper_->dispatched_events()->size());
328 ASSERT_EQ(1UL, helper_->dispatched_events()->size());
329 ASSERT_EQ(2UL, client->events().size()); 327 ASSERT_EQ(2UL, client->events().size());
330 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, 328 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker,
331 client->events()[0]); 329 client->events()[0]);
332 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 330 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install,
333 ServiceWorkerMsg_InstallEvent::ID)); 331 helper_->dispatched_events()->at(0));
334 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, 332 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate,
335 helper_->dispatched_events()->at(0)); 333 helper_->dispatched_events()->at(1));
336 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, 334 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker,
337 client->events()[1]); 335 client->events()[1]);
338 336
339 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 337 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
340 338
341 ASSERT_EQ(1u, notifications_.size()); 339 ASSERT_EQ(1u, notifications_.size());
342 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 340 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
343 EXPECT_EQ(pattern, notifications_[0].pattern); 341 EXPECT_EQ(pattern, notifications_[0].pattern);
344 EXPECT_EQ(registration_id, notifications_[0].registration_id); 342 EXPECT_EQ(registration_id, notifications_[0].registration_id);
345 343
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); 759 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type);
762 EXPECT_EQ(pattern, notifications_[2].pattern); 760 EXPECT_EQ(pattern, notifications_[2].pattern);
763 EXPECT_EQ(registration_id, notifications_[2].registration_id); 761 EXPECT_EQ(registration_id, notifications_[2].registration_id);
764 } 762 }
765 763
766 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, 764 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest,
767 ServiceWorkerContextRecoveryTest, 765 ServiceWorkerContextRecoveryTest,
768 testing::Bool()); 766 testing::Bool());
769 767
770 } // namespace content 768 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698