Chromium Code Reviews| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 179 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 180 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); | 180 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); |
| 181 context()->AddProviderHost(host.Pass()); | 181 context()->AddProviderHost(host.Pass()); |
| 182 | 182 |
| 183 Register(kProviderId, | 183 Register(kProviderId, |
| 184 GURL("http://127.0.0.3:81/bar"), | 184 GURL("http://127.0.0.3:81/bar"), |
| 185 GURL("http://127.0.0.3:81/baz"), | 185 GURL("http://127.0.0.3:81/baz"), |
| 186 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 186 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST_F(ServiceWorkerDispatcherHostTest, | |
| 190 Register_DifferentDirectoryThanScriptShouldFail) { | |
| 191 const int64 kProviderId = 99; // Dummy value | |
| 192 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | |
| 193 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | |
| 194 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | |
| 195 context()->AddProviderHost(host.Pass()); | |
| 196 | |
| 197 SendRegister(kProviderId, | |
| 198 GURL("https://www.example.com/hoge/piyo"), | |
| 199 GURL("https://www.example.com/bar/hoge.js")); | |
| 200 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | |
| 201 } | |
| 202 | |
| 203 TEST_F(ServiceWorkerDispatcherHostTest, | |
| 204 Register_SameDirectoryAsScriptButNoSlashShouldFail) { | |
| 205 const int64 kProviderId = 99; // Dummy value | |
| 206 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | |
| 207 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | |
| 208 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | |
| 209 context()->AddProviderHost(host.Pass()); | |
| 210 | |
| 211 SendRegister(kProviderId, | |
| 212 GURL("https://www.example.com/bar"), | |
| 213 GURL("https://www.example.com/bar/hoge.js")); | |
| 214 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | |
| 215 } | |
| 216 | |
|
falken
2014/10/27 03:54:17
Can you add checks for invalid GURLs too, like the
| |
| 189 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { | 217 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { |
| 190 const int64 kProviderId = 99; // Dummy value | 218 const int64 kProviderId = 99; // Dummy value |
| 191 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 219 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 192 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 220 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| 193 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 221 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 194 context()->AddProviderHost(host.Pass()); | 222 context()->AddProviderHost(host.Pass()); |
| 195 | 223 |
| 196 SendRegister(kProviderId, | 224 SendRegister(kProviderId, |
| 197 GURL("http://www.example.com/"), | 225 GURL("http://www.example.com/"), |
| 198 GURL("http://www.example.com/bar")); | 226 GURL("http://www.example.com/bar")); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 401 |
| 374 // Let the shutdown reach the simulated IO thread. | 402 // Let the shutdown reach the simulated IO thread. |
| 375 base::RunLoop().RunUntilIdle(); | 403 base::RunLoop().RunUntilIdle(); |
| 376 | 404 |
| 377 GetRegistration(-1, | 405 GetRegistration(-1, |
| 378 GURL(), | 406 GURL(), |
| 379 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 407 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 380 } | 408 } |
| 381 | 409 |
| 382 } // namespace content | 410 } // namespace content |
| OLD | NEW |