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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 93 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
94 expected_message)); | 94 expected_message)); |
95 dispatcher_host_->ipc_sink()->ClearMessages(); | 95 dispatcher_host_->ipc_sink()->ClearMessages(); |
96 } | 96 } |
97 | 97 |
98 TestBrowserThreadBundle browser_thread_bundle_; | 98 TestBrowserThreadBundle browser_thread_bundle_; |
99 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 99 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
100 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; | 100 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; |
101 }; | 101 }; |
102 | 102 |
103 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) { | 103 TEST_F(ServiceWorkerDispatcherHostTest, RegisterSameOrigin) { |
104 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | |
105 switches::kEnableServiceWorker)); | |
106 | |
107 dispatcher_host_->OnMessageReceived( | |
108 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL())); | |
109 | |
110 // TODO(alecflett): Pump the message loop when this becomes async. | |
111 ASSERT_EQ(1UL, dispatcher_host_->ipc_sink()->message_count()); | |
112 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | |
113 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); | |
114 } | |
115 | |
116 // TODO(falken): Enable this test when we remove the | |
117 // --enable-service-worker-flag (see crbug.com/352581) | |
118 TEST_F(ServiceWorkerDispatcherHostTest, DISABLED_RegisterSameOrigin) { | |
119 const int64 kProviderId = 99; // Dummy value | 104 const int64 kProviderId = 99; // Dummy value |
120 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 105 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
121 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 106 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
122 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 107 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
123 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | 108 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
124 context()->AddProviderHost(host.Pass()); | 109 context()->AddProviderHost(host.Pass()); |
125 | 110 |
126 Register(kProviderId, | 111 Register(kProviderId, |
127 GURL("http://www.example.com/*"), | 112 GURL("http://www.example.com/*"), |
128 GURL("http://foo.example.com/bar"), | 113 GURL("http://foo.example.com/bar"), |
129 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 114 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
130 Register(kProviderId, | 115 Register(kProviderId, |
131 GURL("http://foo.example.com/*"), | 116 GURL("http://foo.example.com/*"), |
132 GURL("http://www.example.com/bar"), | 117 GURL("http://www.example.com/bar"), |
133 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 118 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
134 Register(kProviderId, | 119 Register(kProviderId, |
135 GURL("http://foo.example.com/*"), | 120 GURL("http://foo.example.com/*"), |
136 GURL("http://foo.example.com/bar"), | 121 GURL("http://foo.example.com/bar"), |
137 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 122 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
138 Register(kProviderId, | 123 Register(kProviderId, |
139 GURL("http://www.example.com/*"), | 124 GURL("http://www.example.com/*"), |
140 GURL("http://www.example.com/bar"), | 125 GURL("http://www.example.com/bar"), |
141 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 126 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
142 } | 127 } |
143 | 128 |
144 // TODO(falken): Enable this test when we remove the | 129 TEST_F(ServiceWorkerDispatcherHostTest, UnregisterSameOrigin) { |
145 // --enable-service-worker-flag (see crbug.com/352581) | |
146 TEST_F(ServiceWorkerDispatcherHostTest, DISABLED_UnregisterSameOrigin) { | |
147 const int64 kProviderId = 99; // Dummy value | 130 const int64 kProviderId = 99; // Dummy value |
148 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 131 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
149 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 132 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
150 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 133 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
151 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | 134 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
152 context()->AddProviderHost(host.Pass()); | 135 context()->AddProviderHost(host.Pass()); |
153 | 136 |
154 Unregister(kProviderId, | 137 Unregister(kProviderId, |
155 GURL("http://foo.example.com/*"), | 138 GURL("http://foo.example.com/*"), |
156 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 139 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
157 Unregister(kProviderId, | 140 Unregister(kProviderId, |
158 GURL("http://www.example.com/*"), | 141 GURL("http://www.example.com/*"), |
159 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); | 142 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); |
160 } | 143 } |
161 | 144 |
162 // Disable this since now we cache command-line switch in | |
163 // ServiceWorkerUtils::IsFeatureEnabled() and this could be flaky depending | |
164 // on testing order. (crbug.com/352581) | |
165 // TODO(kinuko): Just remove DisabledCausesError test above and enable | |
166 // this test when we remove the --enable-service-worker flag. | |
167 TEST_F(ServiceWorkerDispatcherHostTest, DISABLED_Enabled) { | |
168 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | |
169 switches::kEnableServiceWorker)); | |
170 CommandLine::ForCurrentProcess()->AppendSwitch( | |
171 switches::kEnableServiceWorker); | |
172 | |
173 dispatcher_host_->OnMessageReceived( | |
174 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL())); | |
175 base::RunLoop().RunUntilIdle(); | |
176 | |
177 // TODO(alecflett): Pump the message loop when this becomes async. | |
178 ASSERT_EQ(2UL, dispatcher_host_->ipc_sink()->message_count()); | |
179 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | |
180 EmbeddedWorkerMsg_StartWorker::ID)); | |
181 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | |
182 ServiceWorkerMsg_ServiceWorkerRegistered::ID)); | |
183 } | |
184 | |
185 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { | 145 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { |
186 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | |
187 switches::kEnableServiceWorker)); | |
188 CommandLine::ForCurrentProcess()->AppendSwitch( | |
189 switches::kEnableServiceWorker); | |
190 | |
191 helper_->ShutdownContext(); | 146 helper_->ShutdownContext(); |
192 | 147 |
193 // Let the shutdown reach the simulated IO thread. | 148 // Let the shutdown reach the simulated IO thread. |
194 base::RunLoop().RunUntilIdle(); | 149 base::RunLoop().RunUntilIdle(); |
195 | 150 |
196 dispatcher_host_->OnMessageReceived( | 151 dispatcher_host_->OnMessageReceived( |
197 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL())); | 152 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL())); |
198 | 153 |
199 // TODO(alecflett): Pump the message loop when this becomes async. | 154 // TODO(alecflett): Pump the message loop when this becomes async. |
200 ASSERT_EQ(1UL, dispatcher_host_->ipc_sink()->message_count()); | 155 ASSERT_EQ(1UL, dispatcher_host_->ipc_sink()->message_count()); |
(...skipping 26 matching lines...) Expand all Loading... |
227 // process to get deleted as well. | 182 // process to get deleted as well. |
228 dispatcher_host_->OnMessageReceived( | 183 dispatcher_host_->OnMessageReceived( |
229 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); | 184 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); |
230 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 185 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
231 EXPECT_TRUE(dispatcher_host_->HasOneRef()); | 186 EXPECT_TRUE(dispatcher_host_->HasOneRef()); |
232 dispatcher_host_ = NULL; | 187 dispatcher_host_ = NULL; |
233 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 188 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
234 } | 189 } |
235 | 190 |
236 } // namespace content | 191 } // namespace content |
OLD | NEW |