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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 int process_id, | 31 int process_id, |
32 ServiceWorkerContextWrapper* context_wrapper, | 32 ServiceWorkerContextWrapper* context_wrapper, |
33 ResourceContext* resource_context, | 33 ResourceContext* resource_context, |
34 EmbeddedWorkerTestHelper* helper) | 34 EmbeddedWorkerTestHelper* helper) |
35 : ServiceWorkerDispatcherHost(process_id, NULL, resource_context), | 35 : ServiceWorkerDispatcherHost(process_id, NULL, resource_context), |
36 bad_messages_received_count_(0), | 36 bad_messages_received_count_(0), |
37 helper_(helper) { | 37 helper_(helper) { |
38 Init(context_wrapper); | 38 Init(context_wrapper); |
39 } | 39 } |
40 | 40 |
41 virtual bool Send(IPC::Message* message) override { | 41 bool Send(IPC::Message* message) override { return helper_->Send(message); } |
42 return helper_->Send(message); | |
43 } | |
44 | 42 |
45 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } | 43 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } |
46 | 44 |
47 virtual void BadMessageReceived() override { | 45 void BadMessageReceived() override { ++bad_messages_received_count_; } |
48 ++bad_messages_received_count_; | |
49 } | |
50 | 46 |
51 int bad_messages_received_count_; | 47 int bad_messages_received_count_; |
52 | 48 |
53 protected: | 49 protected: |
54 EmbeddedWorkerTestHelper* helper_; | 50 EmbeddedWorkerTestHelper* helper_; |
55 virtual ~TestingServiceWorkerDispatcherHost() {} | 51 ~TestingServiceWorkerDispatcherHost() override {} |
56 }; | 52 }; |
57 | 53 |
58 class ServiceWorkerDispatcherHostTest : public testing::Test { | 54 class ServiceWorkerDispatcherHostTest : public testing::Test { |
59 protected: | 55 protected: |
60 ServiceWorkerDispatcherHostTest() | 56 ServiceWorkerDispatcherHostTest() |
61 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 57 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
62 | 58 |
63 virtual void SetUp() { | 59 virtual void SetUp() { |
64 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); | 60 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); |
65 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( | 61 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 120 |
125 TestBrowserThreadBundle browser_thread_bundle_; | 121 TestBrowserThreadBundle browser_thread_bundle_; |
126 content::MockResourceContext resource_context_; | 122 content::MockResourceContext resource_context_; |
127 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 123 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
128 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; | 124 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; |
129 }; | 125 }; |
130 | 126 |
131 class ServiceWorkerTestContentBrowserClient : public TestContentBrowserClient { | 127 class ServiceWorkerTestContentBrowserClient : public TestContentBrowserClient { |
132 public: | 128 public: |
133 ServiceWorkerTestContentBrowserClient() {} | 129 ServiceWorkerTestContentBrowserClient() {} |
134 virtual bool AllowServiceWorker(const GURL& scope, | 130 bool AllowServiceWorker(const GURL& scope, |
135 const GURL& first_party, | 131 const GURL& first_party, |
136 content::ResourceContext* context) override { | 132 content::ResourceContext* context) override { |
137 return false; | 133 return false; |
138 } | 134 } |
139 }; | 135 }; |
140 | 136 |
141 TEST_F(ServiceWorkerDispatcherHostTest, | 137 TEST_F(ServiceWorkerDispatcherHostTest, |
142 Register_ContentSettingsDisallowsServiceWorker) { | 138 Register_ContentSettingsDisallowsServiceWorker) { |
143 ServiceWorkerTestContentBrowserClient test_browser_client; | 139 ServiceWorkerTestContentBrowserClient test_browser_client; |
144 ContentBrowserClient* old_browser_client = | 140 ContentBrowserClient* old_browser_client = |
145 SetBrowserClientForTesting(&test_browser_client); | 141 SetBrowserClientForTesting(&test_browser_client); |
146 | 142 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 373 |
378 // Let the shutdown reach the simulated IO thread. | 374 // Let the shutdown reach the simulated IO thread. |
379 base::RunLoop().RunUntilIdle(); | 375 base::RunLoop().RunUntilIdle(); |
380 | 376 |
381 GetRegistration(-1, | 377 GetRegistration(-1, |
382 GURL(), | 378 GURL(), |
383 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 379 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
384 } | 380 } |
385 | 381 |
386 } // namespace content | 382 } // namespace content |
OLD | NEW |