| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/service_worker/service_worker_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 private: | 290 private: |
| 291 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); | 291 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 class ServiceWorkerVersionTestP | 294 class ServiceWorkerVersionTestP |
| 295 : public MojoServiceWorkerTestP<ServiceWorkerVersionTest> {}; | 295 : public MojoServiceWorkerTestP<ServiceWorkerVersionTest> {}; |
| 296 | 296 |
| 297 class MessageReceiverDisallowStart : public MessageReceiver { | 297 class MessageReceiverDisallowStart : public MessageReceiver { |
| 298 public: | 298 public: |
| 299 MessageReceiverDisallowStart() | 299 MessageReceiverDisallowStart(bool is_mojo_enabled) |
| 300 : MessageReceiver() {} | 300 : MessageReceiver(), is_mojo_enabled_(is_mojo_enabled) {} |
| 301 ~MessageReceiverDisallowStart() override {} | 301 ~MessageReceiverDisallowStart() override {} |
| 302 | 302 |
| 303 enum class StartMode { STALL, FAIL, SUCCEED }; | 303 enum class StartMode { STALL, FAIL, SUCCEED }; |
| 304 | 304 |
| 305 void OnStartWorker(int embedded_worker_id, | 305 void OnStartWorker(int embedded_worker_id, |
| 306 int64_t service_worker_version_id, | 306 int64_t service_worker_version_id, |
| 307 const GURL& scope, | 307 const GURL& scope, |
| 308 const GURL& script_url, | 308 const GURL& script_url, |
| 309 bool pause_after_download) override { | 309 bool pause_after_download) override { |
| 310 switch (mode_) { | 310 switch (mode_) { |
| 311 case StartMode::STALL: | 311 case StartMode::STALL: |
| 312 break; // Do nothing. | 312 break; // Do nothing. |
| 313 case StartMode::FAIL: | 313 case StartMode::FAIL: |
| 314 OnStopWorker(embedded_worker_id); | 314 if (is_mojo_enabled_) { |
| 315 ASSERT_EQ(current_mock_instance_index_ + 1, |
| 316 mock_instance_clients()->size()); |
| 317 // Remove the connection by peer |
| 318 mock_instance_clients()->at(current_mock_instance_index_).reset(); |
| 319 } else { |
| 320 OnStopWorker(embedded_worker_id); |
| 321 } |
| 315 break; | 322 break; |
| 316 case StartMode::SUCCEED: | 323 case StartMode::SUCCEED: |
| 317 MessageReceiver::OnStartWorker(embedded_worker_id, | 324 MessageReceiver::OnStartWorker(embedded_worker_id, |
| 318 service_worker_version_id, scope, | 325 service_worker_version_id, scope, |
| 319 script_url, pause_after_download); | 326 script_url, pause_after_download); |
| 320 break; | 327 break; |
| 321 } | 328 } |
| 329 current_mock_instance_index_++; |
| 322 } | 330 } |
| 323 | 331 |
| 324 void set_start_mode(StartMode mode) { mode_ = mode; } | 332 void set_start_mode(StartMode mode) { mode_ = mode; } |
| 325 | 333 |
| 326 private: | 334 private: |
| 335 const bool is_mojo_enabled_; |
| 336 uint32_t current_mock_instance_index_ = 0; |
| 327 StartMode mode_ = StartMode::STALL; | 337 StartMode mode_ = StartMode::STALL; |
| 328 DISALLOW_COPY_AND_ASSIGN(MessageReceiverDisallowStart); | 338 DISALLOW_COPY_AND_ASSIGN(MessageReceiverDisallowStart); |
| 329 }; | 339 }; |
| 330 | 340 |
| 331 class ServiceWorkerFailToStartTest : public ServiceWorkerVersionTestP { | 341 class ServiceWorkerFailToStartTest : public ServiceWorkerVersionTestP { |
| 332 protected: | 342 protected: |
| 333 ServiceWorkerFailToStartTest() : ServiceWorkerVersionTestP() {} | 343 ServiceWorkerFailToStartTest() : ServiceWorkerVersionTestP() {} |
| 334 | 344 |
| 335 void set_start_mode(MessageReceiverDisallowStart::StartMode mode) { | 345 void set_start_mode(MessageReceiverDisallowStart::StartMode mode) { |
| 336 MessageReceiverDisallowStart* helper = | 346 MessageReceiverDisallowStart* helper = |
| 337 static_cast<MessageReceiverDisallowStart*>(helper_.get()); | 347 static_cast<MessageReceiverDisallowStart*>(helper_.get()); |
| 338 helper->set_start_mode(mode); | 348 helper->set_start_mode(mode); |
| 339 } | 349 } |
| 340 | 350 |
| 341 std::unique_ptr<MessageReceiver> GetMessageReceiver() override { | 351 std::unique_ptr<MessageReceiver> GetMessageReceiver() override { |
| 342 return base::MakeUnique<MessageReceiverDisallowStart>(); | 352 return base::MakeUnique<MessageReceiverDisallowStart>(is_mojo_enabled()); |
| 343 } | 353 } |
| 344 | 354 |
| 345 private: | 355 private: |
| 346 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFailToStartTest); | 356 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerFailToStartTest); |
| 347 }; | 357 }; |
| 348 | 358 |
| 349 class NoOpStopWorkerEmbeddedWorkerInstanceClient | 359 class NoOpStopWorkerEmbeddedWorkerInstanceClient |
| 350 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { | 360 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { |
| 351 public: | 361 public: |
| 352 explicit NoOpStopWorkerEmbeddedWorkerInstanceClient( | 362 explicit NoOpStopWorkerEmbeddedWorkerInstanceClient( |
| (...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 ServiceWorkerNavigationHintUMATest, | 1795 ServiceWorkerNavigationHintUMATest, |
| 1786 testing::Bool()); | 1796 testing::Bool()); |
| 1787 INSTANTIATE_TEST_CASE_P(ServiceWorkerStallInStoppingTest, | 1797 INSTANTIATE_TEST_CASE_P(ServiceWorkerStallInStoppingTest, |
| 1788 ServiceWorkerStallInStoppingTest, | 1798 ServiceWorkerStallInStoppingTest, |
| 1789 testing::Bool()); | 1799 testing::Bool()); |
| 1790 INSTANTIATE_TEST_CASE_P(ServiceWorkerVersionWithMojoTest, | 1800 INSTANTIATE_TEST_CASE_P(ServiceWorkerVersionWithMojoTest, |
| 1791 ServiceWorkerVersionWithMojoTest, | 1801 ServiceWorkerVersionWithMojoTest, |
| 1792 testing::Bool()); | 1802 testing::Bool()); |
| 1793 | 1803 |
| 1794 } // namespace content | 1804 } // namespace content |
| OLD | NEW |