| 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 dispatched_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()); |
| 221 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); |
| 219 ASSERT_EQ(2UL, client->events().size()); | 222 ASSERT_EQ(2UL, client->events().size()); |
| 220 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 223 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
| 221 client->events()[0]); | 224 client->events()[0]); |
| 222 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 225 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 223 ServiceWorkerMsg_InstallEvent::ID)); | 226 ServiceWorkerMsg_InstallEvent::ID)); |
| 224 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 227 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
| 225 ServiceWorkerMsg_ActivateEvent::ID)); | 228 helper_->dispatched_events()->at(0)); |
| 226 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 229 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 227 client->events()[1]); | 230 client->events()[1]); |
| 228 | 231 |
| 229 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 232 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 230 | 233 |
| 231 ASSERT_EQ(1u, notifications_.size()); | 234 ASSERT_EQ(1u, notifications_.size()); |
| 232 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 235 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 233 EXPECT_EQ(pattern, notifications_[0].pattern); | 236 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 234 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 237 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 235 | 238 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 264 pattern, | 267 pattern, |
| 265 script_url, | 268 script_url, |
| 266 NULL, | 269 NULL, |
| 267 MakeRegisteredCallback(&called, ®istration_id)); | 270 MakeRegisteredCallback(&called, ®istration_id)); |
| 268 | 271 |
| 269 ASSERT_FALSE(called); | 272 ASSERT_FALSE(called); |
| 270 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
| 271 EXPECT_TRUE(called); | 274 EXPECT_TRUE(called); |
| 272 | 275 |
| 273 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 276 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
| 277 EXPECT_EQ(0UL, helper_->dispatched_events()->size()); |
| 274 ASSERT_EQ(2UL, client->events().size()); | 278 ASSERT_EQ(2UL, client->events().size()); |
| 275 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 279 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
| 276 client->events()[0]); | 280 client->events()[0]); |
| 277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 281 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 278 ServiceWorkerMsg_InstallEvent::ID)); | 282 ServiceWorkerMsg_InstallEvent::ID)); |
| 279 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 280 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 281 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 283 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 282 client->events()[1]); | 284 client->events()[1]); |
| 283 | 285 |
| 284 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 286 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 285 | 287 |
| 286 ASSERT_EQ(1u, notifications_.size()); | 288 ASSERT_EQ(1u, notifications_.size()); |
| 287 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 289 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 288 EXPECT_EQ(pattern, notifications_[0].pattern); | 290 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 289 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 291 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 290 | 292 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 315 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 317 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 316 bool called = false; | 318 bool called = false; |
| 317 context()->RegisterServiceWorker( | 319 context()->RegisterServiceWorker( |
| 318 pattern, script_url, NULL, | 320 pattern, script_url, NULL, |
| 319 MakeRegisteredCallback(&called, ®istration_id)); | 321 MakeRegisteredCallback(&called, ®istration_id)); |
| 320 | 322 |
| 321 ASSERT_FALSE(called); | 323 ASSERT_FALSE(called); |
| 322 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
| 323 EXPECT_TRUE(called); | 325 EXPECT_TRUE(called); |
| 324 | 326 |
| 325 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); | 327 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
| 328 ASSERT_EQ(1UL, helper_->dispatched_events()->size()); |
| 326 ASSERT_EQ(2UL, client->events().size()); | 329 ASSERT_EQ(2UL, client->events().size()); |
| 327 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 330 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
| 328 client->events()[0]); | 331 client->events()[0]); |
| 329 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 332 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 330 ServiceWorkerMsg_InstallEvent::ID)); | 333 ServiceWorkerMsg_InstallEvent::ID)); |
| 331 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 334 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
| 332 ServiceWorkerMsg_ActivateEvent::ID)); | 335 helper_->dispatched_events()->at(0)); |
| 333 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 336 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 334 client->events()[1]); | 337 client->events()[1]); |
| 335 | 338 |
| 336 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 339 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 337 | 340 |
| 338 ASSERT_EQ(1u, notifications_.size()); | 341 ASSERT_EQ(1u, notifications_.size()); |
| 339 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 342 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 340 EXPECT_EQ(pattern, notifications_[0].pattern); | 343 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 341 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 344 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 342 | 345 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 761 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
| 759 EXPECT_EQ(pattern, notifications_[2].pattern); | 762 EXPECT_EQ(pattern, notifications_[2].pattern); |
| 760 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 763 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
| 761 } | 764 } |
| 762 | 765 |
| 763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | 766 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, |
| 764 ServiceWorkerContextRecoveryTest, | 767 ServiceWorkerContextRecoveryTest, |
| 765 testing::Bool()); | 768 testing::Bool()); |
| 766 | 769 |
| 767 } // namespace content | 770 } // namespace content |
| OLD | NEW |