| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 GURL("https://foo.example.com/bar")); | 303 GURL("https://foo.example.com/bar")); |
| 304 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); | 304 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); |
| 305 | 305 |
| 306 // Script and scope URLs are invalid | 306 // Script and scope URLs are invalid |
| 307 SendRegister(kProviderId, | 307 SendRegister(kProviderId, |
| 308 GURL(), | 308 GURL(), |
| 309 GURL("h@ttps://@")); | 309 GURL("h@ttps://@")); |
| 310 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); | 310 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
| 311 } | 311 } |
| 312 | 312 |
| 313 TEST_F(ServiceWorkerDispatcherHostTest, Register_BadCharactersShouldFail) { |
| 314 const int64 kProviderId = 99; // Dummy value |
| 315 scoped_ptr<ServiceWorkerProviderHost> host( |
| 316 CreateServiceWorkerProviderHost(kProviderId)); |
| 317 host->SetDocumentUrl(GURL("https://www.example.com/")); |
| 318 context()->AddProviderHost(host.Pass()); |
| 319 |
| 320 SendRegister(kProviderId, GURL("https://www.example.com/%2f"), |
| 321 GURL("https://www.example.com/")); |
| 322 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 323 |
| 324 SendRegister(kProviderId, GURL("https://www.example.com/%2F"), |
| 325 GURL("https://www.example.com/")); |
| 326 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| 327 |
| 328 SendRegister(kProviderId, GURL("https://www.example.com/"), |
| 329 GURL("https://www.example.com/%2f")); |
| 330 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
| 331 |
| 332 SendRegister(kProviderId, GURL("https://www.example.com/%5c"), |
| 333 GURL("https://www.example.com/")); |
| 334 EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_); |
| 335 |
| 336 SendRegister(kProviderId, GURL("https://www.example.com/"), |
| 337 GURL("https://www.example.com/%5c")); |
| 338 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); |
| 339 |
| 340 SendRegister(kProviderId, GURL("https://www.example.com/"), |
| 341 GURL("https://www.example.com/%5C")); |
| 342 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
| 343 } |
| 344 |
| 313 TEST_F(ServiceWorkerDispatcherHostTest, | 345 TEST_F(ServiceWorkerDispatcherHostTest, |
| 314 Register_FileSystemDocumentShouldFail) { | 346 Register_FileSystemDocumentShouldFail) { |
| 315 const int64 kProviderId = 99; // Dummy value | 347 const int64 kProviderId = 99; // Dummy value |
| 316 scoped_ptr<ServiceWorkerProviderHost> host( | 348 scoped_ptr<ServiceWorkerProviderHost> host( |
| 317 CreateServiceWorkerProviderHost(kProviderId)); | 349 CreateServiceWorkerProviderHost(kProviderId)); |
| 318 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a")); | 350 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a")); |
| 319 context()->AddProviderHost(host.Pass()); | 351 context()->AddProviderHost(host.Pass()); |
| 320 | 352 |
| 321 SendRegister(kProviderId, | 353 SendRegister(kProviderId, |
| 322 GURL("filesystem:https://www.example.com/temporary/"), | 354 GURL("filesystem:https://www.example.com/temporary/"), |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 587 |
| 556 // To show the new dispatcher can operate, simulate provider creation. Since | 588 // To show the new dispatcher can operate, simulate provider creation. Since |
| 557 // the old dispatcher cleaned up the old provider host, the new one won't | 589 // the old dispatcher cleaned up the old provider host, the new one won't |
| 558 // complain. | 590 // complain. |
| 559 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 591 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 560 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 592 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
| 561 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 593 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
| 562 } | 594 } |
| 563 | 595 |
| 564 } // namespace content | 596 } // namespace content |
| OLD | NEW |