| 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/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
| 16 #include "content/browser/message_port_service.h" | 16 #include "content/browser/message_port_service.h" |
| 17 #include "content/browser/service_worker/embedded_worker_instance.h" | 17 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 18 #include "content/browser/service_worker/embedded_worker_registry.h" | 18 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 19 #include "content/browser/service_worker/embedded_worker_status.h" | 19 #include "content/browser/service_worker/embedded_worker_status.h" |
| 20 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 20 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 21 #include "content/browser/service_worker/service_worker_context_core.h" | 21 #include "content/browser/service_worker/service_worker_context_core.h" |
| 22 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 22 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 23 #include "content/browser/service_worker/service_worker_handle.h" | 23 #include "content/browser/service_worker/service_worker_handle.h" |
| 24 #include "content/common/service_worker/embedded_worker_messages.h" | 24 #include "content/common/service_worker/embedded_worker_messages.h" |
| 25 #include "content/common/service_worker/service_worker_messages.h" | 25 #include "content/common/service_worker/service_worker_messages.h" |
| 26 #include "content/common/service_worker/service_worker_utils.h" |
| 26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/test/mock_resource_context.h" | 28 #include "content/public/test/mock_resource_context.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "content/test/test_content_browser_client.h" | 30 #include "content/test/test_content_browser_client.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 EXPECT_NE(version_->embedded_worker()->process_id(), | 763 EXPECT_NE(version_->embedded_worker()->process_id(), |
| 763 provider_host_->process_id()); | 764 provider_host_->process_id()); |
| 764 // SendSetHostedVersionId should reject because the provider host process id | 765 // SendSetHostedVersionId should reject because the provider host process id |
| 765 // is different. | 766 // is different. |
| 766 SendSetHostedVersionId(kProviderId, version_->version_id()); | 767 SendSetHostedVersionId(kProviderId, version_->version_id()); |
| 767 base::RunLoop().RunUntilIdle(); | 768 base::RunLoop().RunUntilIdle(); |
| 768 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 769 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 769 ServiceWorkerMsg_AssociateRegistration::ID)); | 770 ServiceWorkerMsg_AssociateRegistration::ID)); |
| 770 } | 771 } |
| 771 | 772 |
| 773 TEST_F(ServiceWorkerDispatcherHostTest, ReceivedTimedOutRequestResponse) { |
| 774 GURL pattern = GURL("https://www.example.com/"); |
| 775 GURL script_url = GURL("https://www.example.com/service_worker.js"); |
| 776 |
| 777 SendProviderCreated(SERVICE_WORKER_PROVIDER_FOR_WINDOW, pattern); |
| 778 SetUpRegistration(pattern, script_url); |
| 779 |
| 780 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 781 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 782 base::RunLoop().RunUntilIdle(); |
| 783 |
| 784 // Set the worker status to STOPPING. |
| 785 version_->embedded_worker()->Stop(); |
| 786 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, version_->running_status()); |
| 787 |
| 788 // Receive a response for a timed out request. The bad message count should |
| 789 // not increase. |
| 790 const int kRequestId = 91; // Dummy value |
| 791 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( |
| 792 version_->embedded_worker()->embedded_worker_id(), kRequestId, |
| 793 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse())); |
| 794 |
| 795 base::RunLoop().RunUntilIdle(); |
| 796 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
| 797 } |
| 798 |
| 772 } // namespace content | 799 } // namespace content |
| OLD | NEW |