| 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 <tuple> | 5 #include <tuple> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 ASSERT_TRUE(ServiceWorkerMsg_ServiceWorkerStateChanged::Read( | 39 ASSERT_TRUE(ServiceWorkerMsg_ServiceWorkerStateChanged::Read( |
| 40 message, ¶m)); | 40 message, ¶m)); |
| 41 EXPECT_EQ(expected_handle_id, std::get<1>(param)); | 41 EXPECT_EQ(expected_handle_id, std::get<1>(param)); |
| 42 EXPECT_EQ(expected_state, std::get<2>(param)); | 42 EXPECT_EQ(expected_state, std::get<2>(param)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { | 47 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { |
| 48 public: | 48 public: |
| 49 TestingServiceWorkerDispatcherHost( | 49 TestingServiceWorkerDispatcherHost(int process_id, |
| 50 int process_id, | 50 ResourceContext* resource_context, |
| 51 ServiceWorkerContextWrapper* context_wrapper, | 51 EmbeddedWorkerTestHelper* helper) |
| 52 ResourceContext* resource_context, | |
| 53 EmbeddedWorkerTestHelper* helper) | |
| 54 : ServiceWorkerDispatcherHost(process_id, resource_context), | 52 : ServiceWorkerDispatcherHost(process_id, resource_context), |
| 55 bad_message_received_count_(0), | 53 bad_message_received_count_(0), |
| 56 helper_(helper) { | 54 helper_(helper) {} |
| 57 Init(context_wrapper); | |
| 58 } | |
| 59 | 55 |
| 60 bool Send(IPC::Message* message) override { return helper_->Send(message); } | 56 bool Send(IPC::Message* message) override { return helper_->Send(message); } |
| 61 | 57 |
| 62 void ShutdownForBadMessage() override { ++bad_message_received_count_; } | 58 void ShutdownForBadMessage() override { ++bad_message_received_count_; } |
| 63 | 59 |
| 64 int bad_message_received_count_; | 60 int bad_message_received_count_; |
| 65 | 61 |
| 66 protected: | 62 protected: |
| 67 EmbeddedWorkerTestHelper* helper_; | 63 EmbeddedWorkerTestHelper* helper_; |
| 68 ~TestingServiceWorkerDispatcherHost() override {} | 64 ~TestingServiceWorkerDispatcherHost() override {} |
| 69 }; | 65 }; |
| 70 | 66 |
| 71 class ServiceWorkerHandleTest : public testing::Test { | 67 class ServiceWorkerHandleTest : public testing::Test { |
| 72 public: | 68 public: |
| 73 ServiceWorkerHandleTest() | 69 ServiceWorkerHandleTest() |
| 74 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 70 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 75 | 71 |
| 76 void SetUp() override { | 72 void SetUp() override { |
| 77 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 73 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 78 | 74 |
| 79 helper_->context()->RemoveDispatcherHost(helper_->mock_render_process_id()); | |
| 80 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( | 75 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( |
| 81 helper_->mock_render_process_id(), helper_->context_wrapper(), | 76 helper_->mock_render_process_id(), &resource_context_, helper_.get()); |
| 82 &resource_context_, helper_.get()); | 77 helper_->RegisterMockDispatcherHost(helper_->mock_render_process_id(), |
| 78 dispatcher_host_); |
| 79 dispatcher_host_->Init(helper_->context_wrapper()); |
| 83 | 80 |
| 84 const GURL pattern("http://www.example.com/"); | 81 const GURL pattern("http://www.example.com/"); |
| 85 registration_ = new ServiceWorkerRegistration( | 82 registration_ = new ServiceWorkerRegistration( |
| 86 pattern, | 83 pattern, |
| 87 1L, | 84 1L, |
| 88 helper_->context()->AsWeakPtr()); | 85 helper_->context()->AsWeakPtr()); |
| 89 version_ = new ServiceWorkerVersion( | 86 version_ = new ServiceWorkerVersion( |
| 90 registration_.get(), | 87 registration_.get(), |
| 91 GURL("http://www.example.com/service_worker.js"), | 88 GURL("http://www.example.com/service_worker.js"), |
| 92 1L, | 89 1L, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // StartWorker shouldn't be recorded here. | 161 // StartWorker shouldn't be recorded here. |
| 165 ASSERT_EQ(1UL, ipc_sink()->message_count()); | 162 ASSERT_EQ(1UL, ipc_sink()->message_count()); |
| 166 message = ipc_sink()->GetMessageAt(0); | 163 message = ipc_sink()->GetMessageAt(0); |
| 167 | 164 |
| 168 // StateChanged (state == Installed). | 165 // StateChanged (state == Installed). |
| 169 VerifyStateChangedMessage(handle->handle_id(), | 166 VerifyStateChangedMessage(handle->handle_id(), |
| 170 blink::kWebServiceWorkerStateInstalled, message); | 167 blink::kWebServiceWorkerStateInstalled, message); |
| 171 } | 168 } |
| 172 | 169 |
| 173 } // namespace content | 170 } // namespace content |
| OLD | NEW |