OLD | NEW |
---|---|
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( | 90 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( |
91 embedded_worker_id, request_id, | 91 embedded_worker_id, request_id, |
92 blink::WebServiceWorkerEventResultRejected, true, base::Time::Now())); | 92 blink::WebServiceWorkerEventResultRejected, true, base::Time::Now())); |
93 } | 93 } |
94 }; | 94 }; |
95 | 95 |
96 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { | 96 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { |
97 public: | 97 public: |
98 RejectActivateTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 98 RejectActivateTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
99 | 99 |
100 void OnActivateEvent(int embedded_worker_id, int request_id) override { | 100 void OnActivateEvent( |
101 SimulateSend(new ServiceWorkerHostMsg_ActivateEventFinished( | 101 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& |
102 embedded_worker_id, request_id, | 102 callback) override { |
103 blink::WebServiceWorkerEventResultRejected, base::Time::Now())); | 103 events_.push_back(Event::Activate); |
104 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | |
105 base::Time::Now()); | |
104 } | 106 } |
105 }; | 107 }; |
106 | 108 |
107 enum NotificationType { | 109 enum NotificationType { |
108 REGISTRATION_STORED, | 110 REGISTRATION_STORED, |
109 REGISTRATION_DELETED, | 111 REGISTRATION_DELETED, |
110 STORAGE_RECOVERED, | 112 STORAGE_RECOVERED, |
111 }; | 113 }; |
112 | 114 |
113 struct NotificationLog { | 115 struct NotificationLog { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 context()->RegisterServiceWorker( | 210 context()->RegisterServiceWorker( |
209 pattern, | 211 pattern, |
210 script_url, | 212 script_url, |
211 NULL, | 213 NULL, |
212 MakeRegisteredCallback(&called, ®istration_id)); | 214 MakeRegisteredCallback(&called, ®istration_id)); |
213 | 215 |
214 ASSERT_FALSE(called); | 216 ASSERT_FALSE(called); |
215 base::RunLoop().RunUntilIdle(); | 217 base::RunLoop().RunUntilIdle(); |
216 EXPECT_TRUE(called); | 218 EXPECT_TRUE(called); |
217 | 219 |
218 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); | 220 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
219 ASSERT_EQ(2UL, client->events().size()); | 221 ASSERT_EQ(2UL, client->events().size()); |
220 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 222 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
221 client->events()[0]); | 223 client->events()[0]); |
222 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 224 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
223 ServiceWorkerMsg_InstallEvent::ID)); | 225 ServiceWorkerMsg_InstallEvent::ID)); |
224 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 226 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
Peter Beverloo
2017/02/14 15:48:13
Add:
ASSERT_EQ(1UL, helper_->dispatched_events()
xiaofengzhang
2017/02/15 01:59:45
Acknowledged.
xiaofengzhang
2017/02/15 06:14:44
Done.
| |
225 ServiceWorkerMsg_ActivateEvent::ID)); | 227 helper_->dispatched_events()[0]); |
226 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 228 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
227 client->events()[1]); | 229 client->events()[1]); |
228 | 230 |
229 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 231 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
230 | 232 |
231 ASSERT_EQ(1u, notifications_.size()); | 233 ASSERT_EQ(1u, notifications_.size()); |
232 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 234 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
233 EXPECT_EQ(pattern, notifications_[0].pattern); | 235 EXPECT_EQ(pattern, notifications_[0].pattern); |
234 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 236 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
235 | 237 |
(...skipping 27 matching lines...) Expand all Loading... | |
263 context()->RegisterServiceWorker( | 265 context()->RegisterServiceWorker( |
264 pattern, | 266 pattern, |
265 script_url, | 267 script_url, |
266 NULL, | 268 NULL, |
267 MakeRegisteredCallback(&called, ®istration_id)); | 269 MakeRegisteredCallback(&called, ®istration_id)); |
268 | 270 |
269 ASSERT_FALSE(called); | 271 ASSERT_FALSE(called); |
270 base::RunLoop().RunUntilIdle(); | 272 base::RunLoop().RunUntilIdle(); |
271 EXPECT_TRUE(called); | 273 EXPECT_TRUE(called); |
272 | 274 |
273 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 275 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
shimazu
2017/02/15 01:29:02
Could you add a check if ActivateEvent didn't disp
xiaofengzhang
2017/02/15 01:59:45
Acknowledged.
xiaofengzhang
2017/02/15 06:14:44
Done.
| |
274 ASSERT_EQ(2UL, client->events().size()); | 276 ASSERT_EQ(2UL, client->events().size()); |
275 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 277 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
276 client->events()[0]); | 278 client->events()[0]); |
277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 279 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
278 ServiceWorkerMsg_InstallEvent::ID)); | 280 ServiceWorkerMsg_InstallEvent::ID)); |
279 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
280 ServiceWorkerMsg_ActivateEvent::ID)); | |
281 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 281 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
282 client->events()[1]); | 282 client->events()[1]); |
283 | 283 |
284 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 284 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
285 | 285 |
286 ASSERT_EQ(1u, notifications_.size()); | 286 ASSERT_EQ(1u, notifications_.size()); |
287 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 287 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
288 EXPECT_EQ(pattern, notifications_[0].pattern); | 288 EXPECT_EQ(pattern, notifications_[0].pattern); |
289 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 289 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
290 | 290 |
(...skipping 24 matching lines...) Expand all Loading... | |
315 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 315 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
316 bool called = false; | 316 bool called = false; |
317 context()->RegisterServiceWorker( | 317 context()->RegisterServiceWorker( |
318 pattern, script_url, NULL, | 318 pattern, script_url, NULL, |
319 MakeRegisteredCallback(&called, ®istration_id)); | 319 MakeRegisteredCallback(&called, ®istration_id)); |
320 | 320 |
321 ASSERT_FALSE(called); | 321 ASSERT_FALSE(called); |
322 base::RunLoop().RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
323 EXPECT_TRUE(called); | 323 EXPECT_TRUE(called); |
324 | 324 |
325 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); | 325 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
326 ASSERT_EQ(2UL, client->events().size()); | 326 ASSERT_EQ(2UL, client->events().size()); |
327 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 327 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
328 client->events()[0]); | 328 client->events()[0]); |
329 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 329 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
330 ServiceWorkerMsg_InstallEvent::ID)); | 330 ServiceWorkerMsg_InstallEvent::ID)); |
331 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 331 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
Peter Beverloo
2017/02/14 15:48:13
dito re: the ASSERT_EQ
xiaofengzhang
2017/02/15 06:14:44
Done.
| |
332 ServiceWorkerMsg_ActivateEvent::ID)); | 332 helper_->dispatched_events()[0]); |
333 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 333 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
334 client->events()[1]); | 334 client->events()[1]); |
335 | 335 |
336 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 336 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
337 | 337 |
338 ASSERT_EQ(1u, notifications_.size()); | 338 ASSERT_EQ(1u, notifications_.size()); |
339 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 339 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
340 EXPECT_EQ(pattern, notifications_[0].pattern); | 340 EXPECT_EQ(pattern, notifications_[0].pattern); |
341 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 341 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
342 | 342 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
759 EXPECT_EQ(pattern, notifications_[2].pattern); | 759 EXPECT_EQ(pattern, notifications_[2].pattern); |
760 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 760 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
761 } | 761 } |
762 | 762 |
763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | 763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, |
764 ServiceWorkerContextRecoveryTest, | 764 ServiceWorkerContextRecoveryTest, |
765 testing::Bool()); | 765 testing::Bool()); |
766 | 766 |
767 } // namespace content | 767 } // namespace content |
OLD | NEW |