| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 6 #include "content/child/service_worker/service_worker_provider_context.h" | 7 #include "content/child/service_worker/service_worker_provider_context.h" |
| 7 #include "content/child/service_worker/web_service_worker_impl.h" | 8 #include "content/child/service_worker/web_service_worker_impl.h" |
| 8 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 9 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 9 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
| 10 #include "content/common/service_worker/service_worker_messages.h" | 11 #include "content/common/service_worker/service_worker_messages.h" |
| 11 #include "content/common/service_worker/service_worker_types.h" | 12 #include "content/common/service_worker/service_worker_types.h" |
| 12 #include "ipc/ipc_sync_message_filter.h" | 13 #include "ipc/ipc_sync_message_filter.h" |
| 13 #include "ipc/ipc_test_sink.h" | 14 #include "ipc/ipc_test_sink.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProviderClient.h" | 16 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProviderClient.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 78 } |
| 78 | 79 |
| 79 void OnSetControllerServiceWorker(int thread_id, | 80 void OnSetControllerServiceWorker(int thread_id, |
| 80 int provider_id, | 81 int provider_id, |
| 81 const ServiceWorkerObjectInfo& info, | 82 const ServiceWorkerObjectInfo& info, |
| 82 bool should_notify_controllerchange) { | 83 bool should_notify_controllerchange) { |
| 83 dispatcher_->OnSetControllerServiceWorker(thread_id, provider_id, info, | 84 dispatcher_->OnSetControllerServiceWorker(thread_id, provider_id, info, |
| 84 should_notify_controllerchange); | 85 should_notify_controllerchange); |
| 85 } | 86 } |
| 86 | 87 |
| 88 void OnPostMessage(const ServiceWorkerMsg_MessageToDocument_Params& params) { |
| 89 dispatcher_->OnPostMessage(params); |
| 90 } |
| 91 |
| 92 scoped_ptr<ServiceWorkerHandleReference> Adopt( |
| 93 const ServiceWorkerObjectInfo& info) { |
| 94 return dispatcher_->Adopt(info); |
| 95 } |
| 96 |
| 87 ServiceWorkerDispatcher* dispatcher() { return dispatcher_.get(); } | 97 ServiceWorkerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 88 ThreadSafeSender* thread_safe_sender() { return sender_.get(); } | 98 ThreadSafeSender* thread_safe_sender() { return sender_.get(); } |
| 89 IPC::TestSink* ipc_sink() { return &ipc_sink_; } | 99 IPC::TestSink* ipc_sink() { return &ipc_sink_; } |
| 90 | 100 |
| 91 private: | 101 private: |
| 92 base::MessageLoop message_loop_; | 102 base::MessageLoop message_loop_; |
| 93 IPC::TestSink ipc_sink_; | 103 IPC::TestSink ipc_sink_; |
| 94 scoped_ptr<ServiceWorkerDispatcher> dispatcher_; | 104 scoped_ptr<ServiceWorkerDispatcher> dispatcher_; |
| 95 scoped_refptr<ServiceWorkerTestSender> sender_; | 105 scoped_refptr<ServiceWorkerTestSender> sender_; |
| 96 | 106 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 108 | 118 |
| 109 ~MockWebServiceWorkerProviderClientImpl() { | 119 ~MockWebServiceWorkerProviderClientImpl() { |
| 110 dispatcher_->RemoveProviderClient(provider_id_); | 120 dispatcher_->RemoveProviderClient(provider_id_); |
| 111 } | 121 } |
| 112 | 122 |
| 113 void setController( | 123 void setController( |
| 114 blink::WebPassOwnPtr<blink::WebServiceWorker::Handle> handle, | 124 blink::WebPassOwnPtr<blink::WebServiceWorker::Handle> handle, |
| 115 bool shouldNotifyControllerChange) { | 125 bool shouldNotifyControllerChange) { |
| 116 // WebPassOwnPtr cannot be owned in Chromium, so drop the handle here. | 126 // WebPassOwnPtr cannot be owned in Chromium, so drop the handle here. |
| 117 // The destruction releases ServiceWorkerHandleReference. | 127 // The destruction releases ServiceWorkerHandleReference. |
| 128 is_set_controlled_called_ = true; |
| 118 } | 129 } |
| 119 | 130 |
| 120 void dispatchMessageEvent( | 131 void dispatchMessageEvent( |
| 121 blink::WebPassOwnPtr<blink::WebServiceWorker::Handle> handle, | 132 blink::WebPassOwnPtr<blink::WebServiceWorker::Handle> handle, |
| 122 const blink::WebString& message, | 133 const blink::WebString& message, |
| 123 const blink::WebMessagePortChannelArray& channels) override { | 134 const blink::WebMessagePortChannelArray& channels) override { |
| 124 NOTREACHED(); | 135 // WebPassOwnPtr cannot be owned in Chromium, so drop the handle here. |
| 136 // The destruction releases ServiceWorkerHandleReference. |
| 137 is_dispatch_message_event_called_ = true; |
| 138 } |
| 139 |
| 140 bool is_set_controlled_called() const { return is_set_controlled_called_; } |
| 141 |
| 142 bool is_dispatch_message_event_called() const { |
| 143 return is_dispatch_message_event_called_; |
| 125 } | 144 } |
| 126 | 145 |
| 127 private: | 146 private: |
| 128 const int provider_id_; | 147 const int provider_id_; |
| 148 bool is_set_controlled_called_ = false; |
| 149 bool is_dispatch_message_event_called_ = false; |
| 129 ServiceWorkerDispatcher* dispatcher_; | 150 ServiceWorkerDispatcher* dispatcher_; |
| 130 }; | 151 }; |
| 131 | 152 |
| 132 // TODO(nhiroki): Add tests for message handlers especially to receive reference | 153 // TODO(nhiroki): Add tests for message handlers especially to receive reference |
| 133 // counts. | 154 // counts. |
| 134 | 155 |
| 135 TEST_F(ServiceWorkerDispatcherTest, OnAssociateRegistration_NoProviderContext) { | 156 TEST_F(ServiceWorkerDispatcherTest, OnAssociateRegistration_NoProviderContext) { |
| 136 // Assume that these objects are passed from the browser process and own | 157 // Assume that these objects are passed from the browser process and own |
| 137 // references to browser-side registration/worker representations. | 158 // references to browser-side registration/worker representations. |
| 138 ServiceWorkerRegistrationObjectInfo info; | 159 ServiceWorkerRegistrationObjectInfo info; |
| 139 ServiceWorkerVersionAttributes attrs; | 160 ServiceWorkerVersionAttributes attrs; |
| 140 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 161 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 141 | 162 |
| 142 // The passed references should be adopted but immediately destroyed because | 163 // The passed references should be adopted but immediately released because |
| 143 // there is no provider context to own the references. | 164 // there is no provider context to own the references. |
| 144 const int kProviderId = 10; | 165 const int kProviderId = 10; |
| 145 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 166 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
| 146 ASSERT_EQ(4UL, ipc_sink()->message_count()); | 167 ASSERT_EQ(4UL, ipc_sink()->message_count()); |
| 147 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 168 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 148 ipc_sink()->GetMessageAt(0)->type()); | 169 ipc_sink()->GetMessageAt(0)->type()); |
| 149 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 170 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 150 ipc_sink()->GetMessageAt(1)->type()); | 171 ipc_sink()->GetMessageAt(1)->type()); |
| 151 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 172 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 152 ipc_sink()->GetMessageAt(2)->type()); | 173 ipc_sink()->GetMessageAt(2)->type()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 bool should_notify_controllerchange = true; | 248 bool should_notify_controllerchange = true; |
| 228 | 249 |
| 229 // Assume that these objects are passed from the browser process and own | 250 // Assume that these objects are passed from the browser process and own |
| 230 // references to browser-side registration/worker representations. | 251 // references to browser-side registration/worker representations. |
| 231 ServiceWorkerRegistrationObjectInfo info; | 252 ServiceWorkerRegistrationObjectInfo info; |
| 232 ServiceWorkerVersionAttributes attrs; | 253 ServiceWorkerVersionAttributes attrs; |
| 233 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 254 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 234 | 255 |
| 235 // (1) In the case there are no SWProviderContext and WebSWProviderClient for | 256 // (1) In the case there are no SWProviderContext and WebSWProviderClient for |
| 236 // the provider, the passed reference to the active worker should be adopted | 257 // the provider, the passed reference to the active worker should be adopted |
| 237 // but immediately destroyed because there is no provider context to own it. | 258 // but immediately released because there is no provider context to own it. |
| 238 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, | 259 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, |
| 239 should_notify_controllerchange); | 260 should_notify_controllerchange); |
| 240 ASSERT_EQ(1UL, ipc_sink()->message_count()); | 261 ASSERT_EQ(1UL, ipc_sink()->message_count()); |
| 241 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 262 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 242 ipc_sink()->GetMessageAt(0)->type()); | 263 ipc_sink()->GetMessageAt(0)->type()); |
| 243 ipc_sink()->ClearMessages(); | 264 ipc_sink()->ClearMessages(); |
| 244 | 265 |
| 245 // (2) In the case there is no WebSWProviderClient but SWProviderContext for | 266 // (2) In the case there is no WebSWProviderClient but SWProviderContext for |
| 246 // the provider, the passed referecence should be adopted and owned by the | 267 // the provider, the passed referecence should be adopted and owned by the |
| 247 // provider context. | 268 // provider context. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 provider_context = nullptr; | 281 provider_context = nullptr; |
| 261 ASSERT_EQ(2UL, ipc_sink()->message_count()); | 282 ASSERT_EQ(2UL, ipc_sink()->message_count()); |
| 262 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 283 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 263 ipc_sink()->GetMessageAt(0)->type()); | 284 ipc_sink()->GetMessageAt(0)->type()); |
| 264 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, | 285 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, |
| 265 ipc_sink()->GetMessageAt(1)->type()); | 286 ipc_sink()->GetMessageAt(1)->type()); |
| 266 ipc_sink()->ClearMessages(); | 287 ipc_sink()->ClearMessages(); |
| 267 | 288 |
| 268 // (3) In the case there is no SWProviderContext but WebSWProviderClient for | 289 // (3) In the case there is no SWProviderContext but WebSWProviderClient for |
| 269 // the provider, the new reference should be created and owned by the provider | 290 // the provider, the new reference should be created and owned by the provider |
| 270 // client (but the reference is immediately destroyed due to limitation of the | 291 // client (but the reference is immediately released due to limitation of the |
| 271 // mock provider client. See the comment on setController() of the mock). | 292 // mock provider client. See the comment on setController() of the mock). |
| 272 // In addition, the passed reference should be adopted but immediately | 293 // In addition, the passed reference should be adopted but immediately |
| 273 // destroyed because there is no provider context to own it. | 294 // released because there is no provider context to own it. |
| 274 scoped_ptr<MockWebServiceWorkerProviderClientImpl> provider_client( | 295 scoped_ptr<MockWebServiceWorkerProviderClientImpl> provider_client( |
| 275 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); | 296 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); |
| 297 ASSERT_FALSE(provider_client->is_set_controlled_called()); |
| 276 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, | 298 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, |
| 277 should_notify_controllerchange); | 299 should_notify_controllerchange); |
| 300 EXPECT_TRUE(provider_client->is_set_controlled_called()); |
| 278 ASSERT_EQ(3UL, ipc_sink()->message_count()); | 301 ASSERT_EQ(3UL, ipc_sink()->message_count()); |
| 279 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, | 302 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, |
| 280 ipc_sink()->GetMessageAt(0)->type()); | 303 ipc_sink()->GetMessageAt(0)->type()); |
| 281 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 304 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 282 ipc_sink()->GetMessageAt(1)->type()); | 305 ipc_sink()->GetMessageAt(1)->type()); |
| 283 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 306 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 284 ipc_sink()->GetMessageAt(2)->type()); | 307 ipc_sink()->GetMessageAt(2)->type()); |
| 285 provider_client.reset(); | 308 provider_client.reset(); |
| 286 ipc_sink()->ClearMessages(); | 309 ipc_sink()->ClearMessages(); |
| 287 | 310 |
| 288 // (4) In the case there are both SWProviderContext and SWProviderClient for | 311 // (4) In the case there are both SWProviderContext and SWProviderClient for |
| 289 // the provider, the passed referecence should be adopted and owned by the | 312 // the provider, the passed referecence should be adopted and owned by the |
| 290 // provider context. In addition, the new reference should be created for the | 313 // provider context. In addition, the new reference should be created for the |
| 291 // provider client and immediately destroyed due to limitation of the mock | 314 // provider client and immediately released due to limitation of the mock |
| 292 // implementation. | 315 // implementation. |
| 293 provider_context = new ServiceWorkerProviderContext( | 316 provider_context = new ServiceWorkerProviderContext( |
| 294 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, thread_safe_sender()); | 317 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, thread_safe_sender()); |
| 295 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 318 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
| 296 provider_client.reset( | 319 provider_client.reset( |
| 297 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); | 320 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); |
| 321 ASSERT_FALSE(provider_client->is_set_controlled_called()); |
| 298 ipc_sink()->ClearMessages(); | 322 ipc_sink()->ClearMessages(); |
| 299 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, | 323 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, |
| 300 should_notify_controllerchange); | 324 should_notify_controllerchange); |
| 325 EXPECT_TRUE(provider_client->is_set_controlled_called()); |
| 301 ASSERT_EQ(2UL, ipc_sink()->message_count()); | 326 ASSERT_EQ(2UL, ipc_sink()->message_count()); |
| 302 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, | 327 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, |
| 303 ipc_sink()->GetMessageAt(0)->type()); | 328 ipc_sink()->GetMessageAt(0)->type()); |
| 304 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 329 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 305 ipc_sink()->GetMessageAt(1)->type()); | 330 ipc_sink()->GetMessageAt(1)->type()); |
| 306 } | 331 } |
| 307 | 332 |
| 333 TEST_F(ServiceWorkerDispatcherTest, OnPostMessage) { |
| 334 const int kProviderId = 10; |
| 335 |
| 336 // Assume that these objects are passed from the browser process and own |
| 337 // references to browser-side registration/worker representations. |
| 338 ServiceWorkerRegistrationObjectInfo info; |
| 339 ServiceWorkerVersionAttributes attrs; |
| 340 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 341 |
| 342 ServiceWorkerMsg_MessageToDocument_Params params; |
| 343 params.thread_id = kDocumentMainThreadId; |
| 344 params.provider_id = kProviderId; |
| 345 params.service_worker_info = attrs.active; |
| 346 |
| 347 // The passed reference should be adopted but immediately released because |
| 348 // there is no provider client. |
| 349 OnPostMessage(params); |
| 350 ASSERT_EQ(1UL, ipc_sink()->message_count()); |
| 351 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 352 ipc_sink()->GetMessageAt(0)->type()); |
| 353 ipc_sink()->ClearMessages(); |
| 354 |
| 355 scoped_ptr<MockWebServiceWorkerProviderClientImpl> provider_client( |
| 356 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); |
| 357 ASSERT_FALSE(provider_client->is_dispatch_message_event_called()); |
| 358 |
| 359 // The passed reference should be owned by the provider client (but the |
| 360 // reference is immediately released due to limitation of the mock provider |
| 361 // client. See the comment on dispatchMessageEvent() of the mock). |
| 362 OnPostMessage(params); |
| 363 EXPECT_TRUE(provider_client->is_dispatch_message_event_called()); |
| 364 ASSERT_EQ(1UL, ipc_sink()->message_count()); |
| 365 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 366 ipc_sink()->GetMessageAt(0)->type()); |
| 367 } |
| 368 |
| 308 TEST_F(ServiceWorkerDispatcherTest, GetServiceWorker) { | 369 TEST_F(ServiceWorkerDispatcherTest, GetServiceWorker) { |
| 309 ServiceWorkerRegistrationObjectInfo info; | 370 ServiceWorkerRegistrationObjectInfo info; |
| 310 ServiceWorkerVersionAttributes attrs; | 371 ServiceWorkerVersionAttributes attrs; |
| 311 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 372 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 312 | 373 |
| 313 // Should return a worker object newly created with incrementing refcount. | 374 // Should return a worker object newly created with the given reference. |
| 314 scoped_refptr<WebServiceWorkerImpl> worker( | 375 scoped_refptr<WebServiceWorkerImpl> worker( |
| 315 dispatcher()->GetOrCreateServiceWorker(attrs.installing)); | 376 dispatcher()->GetOrCreateServiceWorker(Adopt(attrs.installing))); |
| 316 EXPECT_TRUE(worker); | 377 EXPECT_TRUE(worker); |
| 317 EXPECT_TRUE(ContainsServiceWorker(attrs.installing.handle_id)); | 378 EXPECT_TRUE(ContainsServiceWorker(attrs.installing.handle_id)); |
| 318 EXPECT_EQ(1UL, ipc_sink()->message_count()); | |
| 319 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, | |
| 320 ipc_sink()->GetMessageAt(0)->type()); | |
| 321 | |
| 322 ipc_sink()->ClearMessages(); | |
| 323 | |
| 324 // Should return the existing worker object. | |
| 325 scoped_refptr<WebServiceWorkerImpl> existing_worker = | |
| 326 dispatcher()->GetOrCreateServiceWorker(attrs.installing); | |
| 327 EXPECT_EQ(worker, existing_worker); | |
| 328 EXPECT_EQ(0UL, ipc_sink()->message_count()); | 379 EXPECT_EQ(0UL, ipc_sink()->message_count()); |
| 329 | 380 |
| 330 // Should return the existing worker object with adopting refcount. | 381 // Should return the same worker object and release the given reference. |
| 331 existing_worker = dispatcher()->GetOrAdoptServiceWorker(attrs.installing); | 382 scoped_refptr<WebServiceWorkerImpl> existing_worker = |
| 383 dispatcher()->GetOrCreateServiceWorker(Adopt(attrs.installing)); |
| 332 EXPECT_EQ(worker, existing_worker); | 384 EXPECT_EQ(worker, existing_worker); |
| 333 ASSERT_EQ(1UL, ipc_sink()->message_count()); | 385 ASSERT_EQ(1UL, ipc_sink()->message_count()); |
| 334 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 386 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 335 ipc_sink()->GetMessageAt(0)->type()); | 387 ipc_sink()->GetMessageAt(0)->type()); |
| 336 | |
| 337 ipc_sink()->ClearMessages(); | 388 ipc_sink()->ClearMessages(); |
| 338 | 389 |
| 339 // Should return another worker object newly created with adopting refcount. | |
| 340 scoped_refptr<WebServiceWorkerImpl> another_worker( | |
| 341 dispatcher()->GetOrAdoptServiceWorker(attrs.waiting)); | |
| 342 EXPECT_NE(worker.get(), another_worker.get()); | |
| 343 EXPECT_TRUE(ContainsServiceWorker(attrs.waiting.handle_id)); | |
| 344 EXPECT_EQ(0UL, ipc_sink()->message_count()); | |
| 345 | |
| 346 // Should return nullptr when a given object is invalid. | 390 // Should return nullptr when a given object is invalid. |
| 347 scoped_refptr<WebServiceWorkerImpl> invalid_worker = | 391 scoped_refptr<WebServiceWorkerImpl> invalid_worker = |
| 348 dispatcher()->GetOrCreateServiceWorker(ServiceWorkerObjectInfo()); | 392 dispatcher()->GetOrCreateServiceWorker(Adopt(ServiceWorkerObjectInfo())); |
| 349 EXPECT_FALSE(invalid_worker); | |
| 350 EXPECT_EQ(0UL, ipc_sink()->message_count()); | |
| 351 | |
| 352 invalid_worker = | |
| 353 dispatcher()->GetOrAdoptServiceWorker(ServiceWorkerObjectInfo()); | |
| 354 EXPECT_FALSE(invalid_worker); | 393 EXPECT_FALSE(invalid_worker); |
| 355 EXPECT_EQ(0UL, ipc_sink()->message_count()); | 394 EXPECT_EQ(0UL, ipc_sink()->message_count()); |
| 356 } | 395 } |
| 357 | 396 |
| 358 TEST_F(ServiceWorkerDispatcherTest, GetOrCreateRegistration) { | 397 TEST_F(ServiceWorkerDispatcherTest, GetOrCreateRegistration) { |
| 359 ServiceWorkerRegistrationObjectInfo info; | 398 ServiceWorkerRegistrationObjectInfo info; |
| 360 ServiceWorkerVersionAttributes attrs; | 399 ServiceWorkerVersionAttributes attrs; |
| 361 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 400 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 362 | 401 |
| 363 // Should return a registration object newly created with incrementing | 402 // Should return a registration object newly created with incrementing |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 ipc_sink()->GetMessageAt(0)->type()); | 484 ipc_sink()->GetMessageAt(0)->type()); |
| 446 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 485 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 447 ipc_sink()->GetMessageAt(1)->type()); | 486 ipc_sink()->GetMessageAt(1)->type()); |
| 448 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 487 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 449 ipc_sink()->GetMessageAt(2)->type()); | 488 ipc_sink()->GetMessageAt(2)->type()); |
| 450 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, | 489 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, |
| 451 ipc_sink()->GetMessageAt(3)->type()); | 490 ipc_sink()->GetMessageAt(3)->type()); |
| 452 } | 491 } |
| 453 | 492 |
| 454 } // namespace content | 493 } // namespace content |
| OLD | NEW |