Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc

Issue 625533002: Respect content settings for Service Worker registration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testing
Patch Set: better diff Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/browser/service_worker/embedded_worker_instance.h" 11 #include "content/browser/service_worker/embedded_worker_instance.h"
12 #include "content/browser/service_worker/embedded_worker_registry.h" 12 #include "content/browser/service_worker/embedded_worker_registry.h"
13 #include "content/browser/service_worker/embedded_worker_test_helper.h" 13 #include "content/browser/service_worker/embedded_worker_test_helper.h"
14 #include "content/browser/service_worker/service_worker_context_core.h" 14 #include "content/browser/service_worker/service_worker_context_core.h"
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" 15 #include "content/browser/service_worker/service_worker_context_wrapper.h"
16 #include "content/common/service_worker/embedded_worker_messages.h" 16 #include "content/common/service_worker/embedded_worker_messages.h"
17 #include "content/common/service_worker/service_worker_messages.h" 17 #include "content/common/service_worker/service_worker_messages.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "content/public/test/mock_resource_context.h"
19 #include "content/public/test/test_browser_thread_bundle.h" 20 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 static const int kRenderProcessId = 1; 25 static const int kRenderProcessId = 1;
25 26
26 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { 27 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
27 public: 28 public:
28 TestingServiceWorkerDispatcherHost( 29 TestingServiceWorkerDispatcherHost(
29 int process_id, 30 int process_id,
30 ServiceWorkerContextWrapper* context_wrapper, 31 ServiceWorkerContextWrapper* context_wrapper,
32 ResourceContext* resource_context,
31 EmbeddedWorkerTestHelper* helper) 33 EmbeddedWorkerTestHelper* helper)
32 : ServiceWorkerDispatcherHost(process_id, NULL), 34 : ServiceWorkerDispatcherHost(process_id, NULL, resource_context),
33 bad_messages_received_count_(0), 35 bad_messages_received_count_(0),
34 helper_(helper) { 36 helper_(helper) {
35 Init(context_wrapper); 37 Init(context_wrapper);
36 } 38 }
37 39
38 virtual bool Send(IPC::Message* message) OVERRIDE { 40 virtual bool Send(IPC::Message* message) OVERRIDE {
39 return helper_->Send(message); 41 return helper_->Send(message);
40 } 42 }
41 43
42 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } 44 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); }
(...skipping 10 matching lines...) Expand all
53 }; 55 };
54 56
55 class ServiceWorkerDispatcherHostTest : public testing::Test { 57 class ServiceWorkerDispatcherHostTest : public testing::Test {
56 protected: 58 protected:
57 ServiceWorkerDispatcherHostTest() 59 ServiceWorkerDispatcherHostTest()
58 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} 60 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
59 61
60 virtual void SetUp() { 62 virtual void SetUp() {
61 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); 63 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId));
62 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( 64 dispatcher_host_ = new TestingServiceWorkerDispatcherHost(
63 kRenderProcessId, context_wrapper(), helper_.get()); 65 kRenderProcessId, context_wrapper(), &resource_context_, helper_.get());
64 } 66 }
65 67
66 virtual void TearDown() { 68 virtual void TearDown() {
67 helper_.reset(); 69 helper_.reset();
68 } 70 }
69 71
70 ServiceWorkerContextCore* context() { return helper_->context(); } 72 ServiceWorkerContextCore* context() { return helper_->context(); }
71 ServiceWorkerContextWrapper* context_wrapper() { 73 ServiceWorkerContextWrapper* context_wrapper() {
72 return helper_->context_wrapper(); 74 return helper_->context_wrapper();
73 } 75 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void GetRegistration(int64 provider_id, 115 void GetRegistration(int64 provider_id,
114 GURL document_url, 116 GURL document_url,
115 uint32 expected_message) { 117 uint32 expected_message) {
116 SendGetRegistration(provider_id, document_url); 118 SendGetRegistration(provider_id, document_url);
117 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( 119 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching(
118 expected_message)); 120 expected_message));
119 dispatcher_host_->ipc_sink()->ClearMessages(); 121 dispatcher_host_->ipc_sink()->ClearMessages();
120 } 122 }
121 123
122 TestBrowserThreadBundle browser_thread_bundle_; 124 TestBrowserThreadBundle browser_thread_bundle_;
125 content::MockResourceContext resource_context_;
123 scoped_ptr<EmbeddedWorkerTestHelper> helper_; 126 scoped_ptr<EmbeddedWorkerTestHelper> helper_;
124 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; 127 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
125 }; 128 };
126 129
127 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { 130 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) {
128 const int64 kProviderId = 99; // Dummy value 131 const int64 kProviderId = 99; // Dummy value
129 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 132 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
130 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); 133 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
131 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 134 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
132 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); 135 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 284
282 // Let the shutdown reach the simulated IO thread. 285 // Let the shutdown reach the simulated IO thread.
283 base::RunLoop().RunUntilIdle(); 286 base::RunLoop().RunUntilIdle();
284 287
285 GetRegistration(-1, 288 GetRegistration(-1,
286 GURL(), 289 GURL(),
287 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); 290 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID);
288 } 291 }
289 292
290 } // namespace content 293 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698