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( | 100 void OnActivateEvent(int embedded_worker_id, int request_id) override { |
101 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | 101 SimulateSend(new ServiceWorkerHostMsg_ActivateEventFinished( |
102 callback) override { | 102 embedded_worker_id, request_id, |
103 dispatched_events()->push_back(Event::Activate); | 103 blink::WebServiceWorkerEventResultRejected, base::Time::Now())); |
104 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | |
105 base::Time::Now()); | |
106 } | 104 } |
107 }; | 105 }; |
108 | 106 |
109 enum NotificationType { | 107 enum NotificationType { |
110 REGISTRATION_STORED, | 108 REGISTRATION_STORED, |
111 REGISTRATION_DELETED, | 109 REGISTRATION_DELETED, |
112 STORAGE_RECOVERED, | 110 STORAGE_RECOVERED, |
113 }; | 111 }; |
114 | 112 |
115 struct NotificationLog { | 113 struct NotificationLog { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 context()->RegisterServiceWorker( | 208 context()->RegisterServiceWorker( |
211 pattern, | 209 pattern, |
212 script_url, | 210 script_url, |
213 NULL, | 211 NULL, |
214 MakeRegisteredCallback(&called, ®istration_id)); | 212 MakeRegisteredCallback(&called, ®istration_id)); |
215 | 213 |
216 ASSERT_FALSE(called); | 214 ASSERT_FALSE(called); |
217 base::RunLoop().RunUntilIdle(); | 215 base::RunLoop().RunUntilIdle(); |
218 EXPECT_TRUE(called); | 216 EXPECT_TRUE(called); |
219 | 217 |
220 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 218 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
221 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); | |
222 ASSERT_EQ(2UL, client->events().size()); | 219 ASSERT_EQ(2UL, client->events().size()); |
223 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 220 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
224 client->events()[0]); | 221 client->events()[0]); |
225 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 222 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
226 ServiceWorkerMsg_InstallEvent::ID)); | 223 ServiceWorkerMsg_InstallEvent::ID)); |
227 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, | 224 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
228 helper_->dispatched_events()->at(0)); | 225 ServiceWorkerMsg_ActivateEvent::ID)); |
229 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 226 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
230 client->events()[1]); | 227 client->events()[1]); |
231 | 228 |
232 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 229 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
233 | 230 |
234 ASSERT_EQ(1u, notifications_.size()); | 231 ASSERT_EQ(1u, notifications_.size()); |
235 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 232 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
236 EXPECT_EQ(pattern, notifications_[0].pattern); | 233 EXPECT_EQ(pattern, notifications_[0].pattern); |
237 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 234 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
238 | 235 |
(...skipping 28 matching lines...) Expand all Loading... |
267 pattern, | 264 pattern, |
268 script_url, | 265 script_url, |
269 NULL, | 266 NULL, |
270 MakeRegisteredCallback(&called, ®istration_id)); | 267 MakeRegisteredCallback(&called, ®istration_id)); |
271 | 268 |
272 ASSERT_FALSE(called); | 269 ASSERT_FALSE(called); |
273 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
274 EXPECT_TRUE(called); | 271 EXPECT_TRUE(called); |
275 | 272 |
276 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 273 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
277 EXPECT_EQ(0UL, helper_->dispatched_events()->size()); | |
278 ASSERT_EQ(2UL, client->events().size()); | 274 ASSERT_EQ(2UL, client->events().size()); |
279 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 275 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
280 client->events()[0]); | 276 client->events()[0]); |
281 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
282 ServiceWorkerMsg_InstallEvent::ID)); | 278 ServiceWorkerMsg_InstallEvent::ID)); |
| 279 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 280 ServiceWorkerMsg_ActivateEvent::ID)); |
283 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 281 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
284 client->events()[1]); | 282 client->events()[1]); |
285 | 283 |
286 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 284 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
287 | 285 |
288 ASSERT_EQ(1u, notifications_.size()); | 286 ASSERT_EQ(1u, notifications_.size()); |
289 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 287 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
290 EXPECT_EQ(pattern, notifications_[0].pattern); | 288 EXPECT_EQ(pattern, notifications_[0].pattern); |
291 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 289 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
292 | 290 |
(...skipping 24 matching lines...) Expand all Loading... |
317 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 315 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
318 bool called = false; | 316 bool called = false; |
319 context()->RegisterServiceWorker( | 317 context()->RegisterServiceWorker( |
320 pattern, script_url, NULL, | 318 pattern, script_url, NULL, |
321 MakeRegisteredCallback(&called, ®istration_id)); | 319 MakeRegisteredCallback(&called, ®istration_id)); |
322 | 320 |
323 ASSERT_FALSE(called); | 321 ASSERT_FALSE(called); |
324 base::RunLoop().RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
325 EXPECT_TRUE(called); | 323 EXPECT_TRUE(called); |
326 | 324 |
327 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 325 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
328 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); | |
329 ASSERT_EQ(2UL, client->events().size()); | 326 ASSERT_EQ(2UL, client->events().size()); |
330 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 327 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
331 client->events()[0]); | 328 client->events()[0]); |
332 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 329 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
333 ServiceWorkerMsg_InstallEvent::ID)); | 330 ServiceWorkerMsg_InstallEvent::ID)); |
334 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, | 331 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
335 helper_->dispatched_events()->at(0)); | 332 ServiceWorkerMsg_ActivateEvent::ID)); |
336 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 333 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
337 client->events()[1]); | 334 client->events()[1]); |
338 | 335 |
339 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 336 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
340 | 337 |
341 ASSERT_EQ(1u, notifications_.size()); | 338 ASSERT_EQ(1u, notifications_.size()); |
342 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 339 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
343 EXPECT_EQ(pattern, notifications_[0].pattern); | 340 EXPECT_EQ(pattern, notifications_[0].pattern); |
344 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 341 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
345 | 342 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
762 EXPECT_EQ(pattern, notifications_[2].pattern); | 759 EXPECT_EQ(pattern, notifications_[2].pattern); |
763 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 760 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
764 } | 761 } |
765 | 762 |
766 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | 763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, |
767 ServiceWorkerContextRecoveryTest, | 764 ServiceWorkerContextRecoveryTest, |
768 testing::Bool()); | 765 testing::Bool()); |
769 | 766 |
770 } // namespace content | 767 } // namespace content |
OLD | NEW |