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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 mojom::ServiceWorkerInstallEventMethodsAssociatedPtrInfo client, |
90 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( | 90 mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback |
91 embedded_worker_id, request_id, | 91 callback) override { |
92 blink::kWebServiceWorkerEventResultRejected, true, base::Time::Now())); | 92 dispatched_events()->push_back(Event::Install); |
| 93 std::move(callback).Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
| 94 true /* has_fetch_handler */, base::Time::Now()); |
93 } | 95 } |
94 }; | 96 }; |
95 | 97 |
96 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { | 98 class RejectActivateTestHelper : public EmbeddedWorkerTestHelper { |
97 public: | 99 public: |
98 RejectActivateTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 100 RejectActivateTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
99 | 101 |
100 void OnActivateEvent( | 102 void OnActivateEvent( |
101 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback | 103 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
102 callback) override { | 104 callback) override { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 context()->RegisterServiceWorker( | 212 context()->RegisterServiceWorker( |
211 pattern, | 213 pattern, |
212 script_url, | 214 script_url, |
213 NULL, | 215 NULL, |
214 MakeRegisteredCallback(&called, ®istration_id)); | 216 MakeRegisteredCallback(&called, ®istration_id)); |
215 | 217 |
216 ASSERT_FALSE(called); | 218 ASSERT_FALSE(called); |
217 base::RunLoop().RunUntilIdle(); | 219 base::RunLoop().RunUntilIdle(); |
218 EXPECT_TRUE(called); | 220 EXPECT_TRUE(called); |
219 | 221 |
220 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 222 ASSERT_EQ(2UL, helper_->dispatched_events()->size()); |
221 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); | |
222 ASSERT_EQ(2UL, client->events().size()); | 223 ASSERT_EQ(2UL, client->events().size()); |
223 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 224 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
224 client->events()[0]); | 225 client->events()[0]); |
225 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 226 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, |
226 ServiceWorkerMsg_InstallEvent::ID)); | 227 helper_->dispatched_events()->at(0)); |
227 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, | 228 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
228 helper_->dispatched_events()->at(0)); | 229 helper_->dispatched_events()->at(1)); |
229 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 230 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
230 client->events()[1]); | 231 client->events()[1]); |
231 | 232 |
232 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 233 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
233 | 234 |
234 ASSERT_EQ(1u, notifications_.size()); | 235 ASSERT_EQ(1u, notifications_.size()); |
235 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 236 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
236 EXPECT_EQ(pattern, notifications_[0].pattern); | 237 EXPECT_EQ(pattern, notifications_[0].pattern); |
237 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 238 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
238 | 239 |
(...skipping 27 matching lines...) Expand all Loading... |
266 context()->RegisterServiceWorker( | 267 context()->RegisterServiceWorker( |
267 pattern, | 268 pattern, |
268 script_url, | 269 script_url, |
269 NULL, | 270 NULL, |
270 MakeRegisteredCallback(&called, ®istration_id)); | 271 MakeRegisteredCallback(&called, ®istration_id)); |
271 | 272 |
272 ASSERT_FALSE(called); | 273 ASSERT_FALSE(called); |
273 base::RunLoop().RunUntilIdle(); | 274 base::RunLoop().RunUntilIdle(); |
274 EXPECT_TRUE(called); | 275 EXPECT_TRUE(called); |
275 | 276 |
276 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 277 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); |
277 EXPECT_EQ(0UL, helper_->dispatched_events()->size()); | |
278 ASSERT_EQ(2UL, client->events().size()); | 278 ASSERT_EQ(2UL, client->events().size()); |
279 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 279 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
280 client->events()[0]); | 280 client->events()[0]); |
281 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 281 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, |
282 ServiceWorkerMsg_InstallEvent::ID)); | 282 helper_->dispatched_events()->at(0)); |
283 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 283 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
284 client->events()[1]); | 284 client->events()[1]); |
285 | 285 |
286 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 286 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
287 | 287 |
288 ASSERT_EQ(1u, notifications_.size()); | 288 ASSERT_EQ(1u, notifications_.size()); |
289 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 289 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
290 EXPECT_EQ(pattern, notifications_[0].pattern); | 290 EXPECT_EQ(pattern, notifications_[0].pattern); |
291 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 291 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
292 | 292 |
(...skipping 24 matching lines...) Expand all Loading... |
317 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 317 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
318 bool called = false; | 318 bool called = false; |
319 context()->RegisterServiceWorker( | 319 context()->RegisterServiceWorker( |
320 pattern, script_url, NULL, | 320 pattern, script_url, NULL, |
321 MakeRegisteredCallback(&called, ®istration_id)); | 321 MakeRegisteredCallback(&called, ®istration_id)); |
322 | 322 |
323 ASSERT_FALSE(called); | 323 ASSERT_FALSE(called); |
324 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
325 EXPECT_TRUE(called); | 325 EXPECT_TRUE(called); |
326 | 326 |
327 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 327 ASSERT_EQ(2UL, helper_->dispatched_events()->size()); |
328 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); | |
329 ASSERT_EQ(2UL, client->events().size()); | 328 ASSERT_EQ(2UL, client->events().size()); |
330 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 329 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
331 client->events()[0]); | 330 client->events()[0]); |
332 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 331 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, |
333 ServiceWorkerMsg_InstallEvent::ID)); | 332 helper_->dispatched_events()->at(0)); |
334 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, | 333 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
335 helper_->dispatched_events()->at(0)); | 334 helper_->dispatched_events()->at(1)); |
336 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 335 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
337 client->events()[1]); | 336 client->events()[1]); |
338 | 337 |
339 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 338 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
340 | 339 |
341 ASSERT_EQ(1u, notifications_.size()); | 340 ASSERT_EQ(1u, notifications_.size()); |
342 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 341 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
343 EXPECT_EQ(pattern, notifications_[0].pattern); | 342 EXPECT_EQ(pattern, notifications_[0].pattern); |
344 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 343 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
345 | 344 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 760 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
762 EXPECT_EQ(pattern, notifications_[2].pattern); | 761 EXPECT_EQ(pattern, notifications_[2].pattern); |
763 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 762 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
764 } | 763 } |
765 | 764 |
766 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | 765 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, |
767 ServiceWorkerContextRecoveryTest, | 766 ServiceWorkerContextRecoveryTest, |
768 testing::Bool()); | 767 testing::Bool()); |
769 | 768 |
770 } // namespace content | 769 } // namespace content |
OLD | NEW |