| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 13 #include "content/browser/service_worker/embedded_worker_instance.h" | 14 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 14 #include "content/browser/service_worker/embedded_worker_registry.h" | 15 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 15 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 16 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 16 #include "content/browser/service_worker/service_worker_context_core.h" | 17 #include "content/browser/service_worker/service_worker_context_core.h" |
| 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 TEST_F(ServiceWorkerDispatcherHostTest, | 175 TEST_F(ServiceWorkerDispatcherHostTest, |
| 175 Register_ContentSettingsDisallowsServiceWorker) { | 176 Register_ContentSettingsDisallowsServiceWorker) { |
| 176 ServiceWorkerTestContentBrowserClient test_browser_client; | 177 ServiceWorkerTestContentBrowserClient test_browser_client; |
| 177 ContentBrowserClient* old_browser_client = | 178 ContentBrowserClient* old_browser_client = |
| 178 SetBrowserClientForTesting(&test_browser_client); | 179 SetBrowserClientForTesting(&test_browser_client); |
| 179 | 180 |
| 180 const int64_t kProviderId = 99; // Dummy value | 181 const int64_t kProviderId = 99; // Dummy value |
| 181 scoped_ptr<ServiceWorkerProviderHost> host( | 182 scoped_ptr<ServiceWorkerProviderHost> host( |
| 182 CreateServiceWorkerProviderHost(kProviderId)); | 183 CreateServiceWorkerProviderHost(kProviderId)); |
| 183 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 184 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 184 context()->AddProviderHost(host.Pass()); | 185 context()->AddProviderHost(std::move(host)); |
| 185 | 186 |
| 186 Register(kProviderId, | 187 Register(kProviderId, |
| 187 GURL("https://www.example.com/"), | 188 GURL("https://www.example.com/"), |
| 188 GURL("https://www.example.com/bar"), | 189 GURL("https://www.example.com/bar"), |
| 189 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); | 190 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID); |
| 190 GetRegistration(kProviderId, | 191 GetRegistration(kProviderId, |
| 191 GURL("https://www.example.com/"), | 192 GURL("https://www.example.com/"), |
| 192 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 193 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 193 GetRegistrations(kProviderId, | 194 GetRegistrations(kProviderId, |
| 194 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); | 195 ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID); |
| 195 | 196 |
| 196 // Add a registration into a live registration map so that Unregister() can | 197 // Add a registration into a live registration map so that Unregister() can |
| 197 // find it. | 198 // find it. |
| 198 const int64_t kRegistrationId = 999; // Dummy value | 199 const int64_t kRegistrationId = 999; // Dummy value |
| 199 scoped_refptr<ServiceWorkerRegistration> registration( | 200 scoped_refptr<ServiceWorkerRegistration> registration( |
| 200 new ServiceWorkerRegistration(GURL("https://www.example.com/"), | 201 new ServiceWorkerRegistration(GURL("https://www.example.com/"), |
| 201 kRegistrationId, context()->AsWeakPtr())); | 202 kRegistrationId, context()->AsWeakPtr())); |
| 202 Unregister(kProviderId, kRegistrationId, | 203 Unregister(kProviderId, kRegistrationId, |
| 203 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); | 204 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID); |
| 204 | 205 |
| 205 SetBrowserClientForTesting(old_browser_client); | 206 SetBrowserClientForTesting(old_browser_client); |
| 206 } | 207 } |
| 207 | 208 |
| 208 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { | 209 TEST_F(ServiceWorkerDispatcherHostTest, Register_HTTPS) { |
| 209 const int64_t kProviderId = 99; // Dummy value | 210 const int64_t kProviderId = 99; // Dummy value |
| 210 scoped_ptr<ServiceWorkerProviderHost> host( | 211 scoped_ptr<ServiceWorkerProviderHost> host( |
| 211 CreateServiceWorkerProviderHost(kProviderId)); | 212 CreateServiceWorkerProviderHost(kProviderId)); |
| 212 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 213 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 213 context()->AddProviderHost(host.Pass()); | 214 context()->AddProviderHost(std::move(host)); |
| 214 | 215 |
| 215 Register(kProviderId, | 216 Register(kProviderId, |
| 216 GURL("https://www.example.com/"), | 217 GURL("https://www.example.com/"), |
| 217 GURL("https://www.example.com/bar"), | 218 GURL("https://www.example.com/bar"), |
| 218 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 219 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
| 219 } | 220 } |
| 220 | 221 |
| 221 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureTransportLocalhost) { | 222 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureTransportLocalhost) { |
| 222 const int64_t kProviderId = 99; // Dummy value | 223 const int64_t kProviderId = 99; // Dummy value |
| 223 scoped_ptr<ServiceWorkerProviderHost> host( | 224 scoped_ptr<ServiceWorkerProviderHost> host( |
| 224 CreateServiceWorkerProviderHost(kProviderId)); | 225 CreateServiceWorkerProviderHost(kProviderId)); |
| 225 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); | 226 host->SetDocumentUrl(GURL("http://127.0.0.3:81/foo")); |
| 226 context()->AddProviderHost(host.Pass()); | 227 context()->AddProviderHost(std::move(host)); |
| 227 | 228 |
| 228 Register(kProviderId, | 229 Register(kProviderId, |
| 229 GURL("http://127.0.0.3:81/bar"), | 230 GURL("http://127.0.0.3:81/bar"), |
| 230 GURL("http://127.0.0.3:81/baz"), | 231 GURL("http://127.0.0.3:81/baz"), |
| 231 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 232 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
| 232 } | 233 } |
| 233 | 234 |
| 234 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScopeShouldFail) { | 235 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScopeShouldFail) { |
| 235 const int64_t kProviderId = 99; // Dummy value | 236 const int64_t kProviderId = 99; // Dummy value |
| 236 scoped_ptr<ServiceWorkerProviderHost> host( | 237 scoped_ptr<ServiceWorkerProviderHost> host( |
| 237 CreateServiceWorkerProviderHost(kProviderId)); | 238 CreateServiceWorkerProviderHost(kProviderId)); |
| 238 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 239 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 239 context()->AddProviderHost(host.Pass()); | 240 context()->AddProviderHost(std::move(host)); |
| 240 | 241 |
| 241 SendRegister(kProviderId, GURL(""), | 242 SendRegister(kProviderId, GURL(""), |
| 242 GURL("https://www.example.com/bar/hoge.js")); | 243 GURL("https://www.example.com/bar/hoge.js")); |
| 243 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 244 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 244 } | 245 } |
| 245 | 246 |
| 246 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScriptShouldFail) { | 247 TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScriptShouldFail) { |
| 247 const int64_t kProviderId = 99; // Dummy value | 248 const int64_t kProviderId = 99; // Dummy value |
| 248 scoped_ptr<ServiceWorkerProviderHost> host( | 249 scoped_ptr<ServiceWorkerProviderHost> host( |
| 249 CreateServiceWorkerProviderHost(kProviderId)); | 250 CreateServiceWorkerProviderHost(kProviderId)); |
| 250 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 251 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 251 context()->AddProviderHost(host.Pass()); | 252 context()->AddProviderHost(std::move(host)); |
| 252 | 253 |
| 253 SendRegister(kProviderId, GURL("https://www.example.com/bar/"), GURL("")); | 254 SendRegister(kProviderId, GURL("https://www.example.com/bar/"), GURL("")); |
| 254 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 255 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 255 } | 256 } |
| 256 | 257 |
| 257 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { | 258 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { |
| 258 const int64_t kProviderId = 99; // Dummy value | 259 const int64_t kProviderId = 99; // Dummy value |
| 259 scoped_ptr<ServiceWorkerProviderHost> host( | 260 scoped_ptr<ServiceWorkerProviderHost> host( |
| 260 CreateServiceWorkerProviderHost(kProviderId)); | 261 CreateServiceWorkerProviderHost(kProviderId)); |
| 261 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 262 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 262 context()->AddProviderHost(host.Pass()); | 263 context()->AddProviderHost(std::move(host)); |
| 263 | 264 |
| 264 SendRegister(kProviderId, | 265 SendRegister(kProviderId, |
| 265 GURL("http://www.example.com/"), | 266 GURL("http://www.example.com/"), |
| 266 GURL("http://www.example.com/bar")); | 267 GURL("http://www.example.com/bar")); |
| 267 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 268 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 268 } | 269 } |
| 269 | 270 |
| 270 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginShouldFail) { | 271 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginShouldFail) { |
| 271 const int64_t kProviderId = 99; // Dummy value | 272 const int64_t kProviderId = 99; // Dummy value |
| 272 scoped_ptr<ServiceWorkerProviderHost> host( | 273 scoped_ptr<ServiceWorkerProviderHost> host( |
| 273 CreateServiceWorkerProviderHost(kProviderId)); | 274 CreateServiceWorkerProviderHost(kProviderId)); |
| 274 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 275 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 275 context()->AddProviderHost(host.Pass()); | 276 context()->AddProviderHost(std::move(host)); |
| 276 | 277 |
| 277 // Script has a different host | 278 // Script has a different host |
| 278 SendRegister(kProviderId, | 279 SendRegister(kProviderId, |
| 279 GURL("https://www.example.com/"), | 280 GURL("https://www.example.com/"), |
| 280 GURL("https://foo.example.com/bar")); | 281 GURL("https://foo.example.com/bar")); |
| 281 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 282 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 282 | 283 |
| 283 // Scope has a different host | 284 // Scope has a different host |
| 284 SendRegister(kProviderId, | 285 SendRegister(kProviderId, |
| 285 GURL("https://foo.example.com/"), | 286 GURL("https://foo.example.com/"), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 309 GURL(), | 310 GURL(), |
| 310 GURL("h@ttps://@")); | 311 GURL("h@ttps://@")); |
| 311 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); | 312 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
| 312 } | 313 } |
| 313 | 314 |
| 314 TEST_F(ServiceWorkerDispatcherHostTest, Register_BadCharactersShouldFail) { | 315 TEST_F(ServiceWorkerDispatcherHostTest, Register_BadCharactersShouldFail) { |
| 315 const int64_t kProviderId = 99; // Dummy value | 316 const int64_t kProviderId = 99; // Dummy value |
| 316 scoped_ptr<ServiceWorkerProviderHost> host( | 317 scoped_ptr<ServiceWorkerProviderHost> host( |
| 317 CreateServiceWorkerProviderHost(kProviderId)); | 318 CreateServiceWorkerProviderHost(kProviderId)); |
| 318 host->SetDocumentUrl(GURL("https://www.example.com/")); | 319 host->SetDocumentUrl(GURL("https://www.example.com/")); |
| 319 context()->AddProviderHost(host.Pass()); | 320 context()->AddProviderHost(std::move(host)); |
| 320 | 321 |
| 321 SendRegister(kProviderId, GURL("https://www.example.com/%2f"), | 322 SendRegister(kProviderId, GURL("https://www.example.com/%2f"), |
| 322 GURL("https://www.example.com/")); | 323 GURL("https://www.example.com/")); |
| 323 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 324 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 324 | 325 |
| 325 SendRegister(kProviderId, GURL("https://www.example.com/%2F"), | 326 SendRegister(kProviderId, GURL("https://www.example.com/%2F"), |
| 326 GURL("https://www.example.com/")); | 327 GURL("https://www.example.com/")); |
| 327 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 328 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| 328 | 329 |
| 329 SendRegister(kProviderId, GURL("https://www.example.com/"), | 330 SendRegister(kProviderId, GURL("https://www.example.com/"), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 342 GURL("https://www.example.com/%5C")); | 343 GURL("https://www.example.com/%5C")); |
| 343 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); | 344 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
| 344 } | 345 } |
| 345 | 346 |
| 346 TEST_F(ServiceWorkerDispatcherHostTest, | 347 TEST_F(ServiceWorkerDispatcherHostTest, |
| 347 Register_FileSystemDocumentShouldFail) { | 348 Register_FileSystemDocumentShouldFail) { |
| 348 const int64_t kProviderId = 99; // Dummy value | 349 const int64_t kProviderId = 99; // Dummy value |
| 349 scoped_ptr<ServiceWorkerProviderHost> host( | 350 scoped_ptr<ServiceWorkerProviderHost> host( |
| 350 CreateServiceWorkerProviderHost(kProviderId)); | 351 CreateServiceWorkerProviderHost(kProviderId)); |
| 351 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a")); | 352 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a")); |
| 352 context()->AddProviderHost(host.Pass()); | 353 context()->AddProviderHost(std::move(host)); |
| 353 | 354 |
| 354 SendRegister(kProviderId, | 355 SendRegister(kProviderId, |
| 355 GURL("filesystem:https://www.example.com/temporary/"), | 356 GURL("filesystem:https://www.example.com/temporary/"), |
| 356 GURL("https://www.example.com/temporary/bar")); | 357 GURL("https://www.example.com/temporary/bar")); |
| 357 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 358 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 358 | 359 |
| 359 SendRegister(kProviderId, | 360 SendRegister(kProviderId, |
| 360 GURL("https://www.example.com/temporary/"), | 361 GURL("https://www.example.com/temporary/"), |
| 361 GURL("filesystem:https://www.example.com/temporary/bar")); | 362 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 362 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 363 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| 363 | 364 |
| 364 SendRegister(kProviderId, | 365 SendRegister(kProviderId, |
| 365 GURL("filesystem:https://www.example.com/temporary/"), | 366 GURL("filesystem:https://www.example.com/temporary/"), |
| 366 GURL("filesystem:https://www.example.com/temporary/bar")); | 367 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 367 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); | 368 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
| 368 } | 369 } |
| 369 | 370 |
| 370 TEST_F(ServiceWorkerDispatcherHostTest, | 371 TEST_F(ServiceWorkerDispatcherHostTest, |
| 371 Register_FileSystemScriptOrScopeShouldFail) { | 372 Register_FileSystemScriptOrScopeShouldFail) { |
| 372 const int64_t kProviderId = 99; // Dummy value | 373 const int64_t kProviderId = 99; // Dummy value |
| 373 scoped_ptr<ServiceWorkerProviderHost> host( | 374 scoped_ptr<ServiceWorkerProviderHost> host( |
| 374 CreateServiceWorkerProviderHost(kProviderId)); | 375 CreateServiceWorkerProviderHost(kProviderId)); |
| 375 host->SetDocumentUrl(GURL("https://www.example.com/temporary/")); | 376 host->SetDocumentUrl(GURL("https://www.example.com/temporary/")); |
| 376 context()->AddProviderHost(host.Pass()); | 377 context()->AddProviderHost(std::move(host)); |
| 377 | 378 |
| 378 SendRegister(kProviderId, | 379 SendRegister(kProviderId, |
| 379 GURL("filesystem:https://www.example.com/temporary/"), | 380 GURL("filesystem:https://www.example.com/temporary/"), |
| 380 GURL("https://www.example.com/temporary/bar")); | 381 GURL("https://www.example.com/temporary/bar")); |
| 381 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 382 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 382 | 383 |
| 383 SendRegister(kProviderId, | 384 SendRegister(kProviderId, |
| 384 GURL("https://www.example.com/temporary/"), | 385 GURL("https://www.example.com/temporary/"), |
| 385 GURL("filesystem:https://www.example.com/temporary/bar")); | 386 GURL("filesystem:https://www.example.com/temporary/bar")); |
| 386 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 387 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 EXPECT_TRUE(dispatcher_host_->HasOneRef()); | 434 EXPECT_TRUE(dispatcher_host_->HasOneRef()); |
| 434 dispatcher_host_ = NULL; | 435 dispatcher_host_ = NULL; |
| 435 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); | 436 EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId)); |
| 436 } | 437 } |
| 437 | 438 |
| 438 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { | 439 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { |
| 439 const int64_t kProviderId = 99; // Dummy value | 440 const int64_t kProviderId = 99; // Dummy value |
| 440 scoped_ptr<ServiceWorkerProviderHost> host( | 441 scoped_ptr<ServiceWorkerProviderHost> host( |
| 441 CreateServiceWorkerProviderHost(kProviderId)); | 442 CreateServiceWorkerProviderHost(kProviderId)); |
| 442 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 443 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 443 context()->AddProviderHost(host.Pass()); | 444 context()->AddProviderHost(std::move(host)); |
| 444 | 445 |
| 445 GetRegistration(kProviderId, | 446 GetRegistration(kProviderId, |
| 446 GURL("https://www.example.com/"), | 447 GURL("https://www.example.com/"), |
| 447 ServiceWorkerMsg_DidGetRegistration::ID); | 448 ServiceWorkerMsg_DidGetRegistration::ID); |
| 448 } | 449 } |
| 449 | 450 |
| 450 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) { | 451 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) { |
| 451 const int64_t kProviderId = 99; // Dummy value | 452 const int64_t kProviderId = 99; // Dummy value |
| 452 scoped_ptr<ServiceWorkerProviderHost> host( | 453 scoped_ptr<ServiceWorkerProviderHost> host( |
| 453 CreateServiceWorkerProviderHost(kProviderId)); | 454 CreateServiceWorkerProviderHost(kProviderId)); |
| 454 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 455 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 455 context()->AddProviderHost(host.Pass()); | 456 context()->AddProviderHost(std::move(host)); |
| 456 | 457 |
| 457 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); | 458 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); |
| 458 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 459 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 459 } | 460 } |
| 460 | 461 |
| 461 TEST_F(ServiceWorkerDispatcherHostTest, | 462 TEST_F(ServiceWorkerDispatcherHostTest, |
| 462 GetRegistration_InvalidScopeShouldFail) { | 463 GetRegistration_InvalidScopeShouldFail) { |
| 463 const int64_t kProviderId = 99; // Dummy value | 464 const int64_t kProviderId = 99; // Dummy value |
| 464 scoped_ptr<ServiceWorkerProviderHost> host( | 465 scoped_ptr<ServiceWorkerProviderHost> host( |
| 465 CreateServiceWorkerProviderHost(kProviderId)); | 466 CreateServiceWorkerProviderHost(kProviderId)); |
| 466 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 467 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 467 context()->AddProviderHost(host.Pass()); | 468 context()->AddProviderHost(std::move(host)); |
| 468 | 469 |
| 469 SendGetRegistration(kProviderId, GURL("")); | 470 SendGetRegistration(kProviderId, GURL("")); |
| 470 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 471 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 471 } | 472 } |
| 472 | 473 |
| 473 TEST_F(ServiceWorkerDispatcherHostTest, | 474 TEST_F(ServiceWorkerDispatcherHostTest, |
| 474 GetRegistration_NonSecureOriginShouldFail) { | 475 GetRegistration_NonSecureOriginShouldFail) { |
| 475 const int64_t kProviderId = 99; // Dummy value | 476 const int64_t kProviderId = 99; // Dummy value |
| 476 scoped_ptr<ServiceWorkerProviderHost> host( | 477 scoped_ptr<ServiceWorkerProviderHost> host( |
| 477 CreateServiceWorkerProviderHost(kProviderId)); | 478 CreateServiceWorkerProviderHost(kProviderId)); |
| 478 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 479 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 479 context()->AddProviderHost(host.Pass()); | 480 context()->AddProviderHost(std::move(host)); |
| 480 | 481 |
| 481 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); | 482 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); |
| 482 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 483 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 483 } | 484 } |
| 484 | 485 |
| 485 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { | 486 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { |
| 486 helper_->ShutdownContext(); | 487 helper_->ShutdownContext(); |
| 487 | 488 |
| 488 // Let the shutdown reach the simulated IO thread. | 489 // Let the shutdown reach the simulated IO thread. |
| 489 base::RunLoop().RunUntilIdle(); | 490 base::RunLoop().RunUntilIdle(); |
| 490 | 491 |
| 491 GetRegistration(-1, | 492 GetRegistration(-1, |
| 492 GURL(), | 493 GURL(), |
| 493 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | 494 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| 494 } | 495 } |
| 495 | 496 |
| 496 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_SecureOrigin) { | 497 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_SecureOrigin) { |
| 497 const int64_t kProviderId = 99; // Dummy value | 498 const int64_t kProviderId = 99; // Dummy value |
| 498 scoped_ptr<ServiceWorkerProviderHost> host( | 499 scoped_ptr<ServiceWorkerProviderHost> host( |
| 499 CreateServiceWorkerProviderHost(kProviderId)); | 500 CreateServiceWorkerProviderHost(kProviderId)); |
| 500 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 501 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| 501 context()->AddProviderHost(host.Pass()); | 502 context()->AddProviderHost(std::move(host)); |
| 502 | 503 |
| 503 GetRegistrations(kProviderId, ServiceWorkerMsg_DidGetRegistrations::ID); | 504 GetRegistrations(kProviderId, ServiceWorkerMsg_DidGetRegistrations::ID); |
| 504 } | 505 } |
| 505 | 506 |
| 506 TEST_F(ServiceWorkerDispatcherHostTest, | 507 TEST_F(ServiceWorkerDispatcherHostTest, |
| 507 GetRegistrations_NonSecureOriginShouldFail) { | 508 GetRegistrations_NonSecureOriginShouldFail) { |
| 508 const int64_t kProviderId = 99; // Dummy value | 509 const int64_t kProviderId = 99; // Dummy value |
| 509 scoped_ptr<ServiceWorkerProviderHost> host( | 510 scoped_ptr<ServiceWorkerProviderHost> host( |
| 510 CreateServiceWorkerProviderHost(kProviderId)); | 511 CreateServiceWorkerProviderHost(kProviderId)); |
| 511 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 512 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
| 512 context()->AddProviderHost(host.Pass()); | 513 context()->AddProviderHost(std::move(host)); |
| 513 | 514 |
| 514 SendGetRegistrations(kProviderId); | 515 SendGetRegistrations(kProviderId); |
| 515 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 516 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
| 516 } | 517 } |
| 517 | 518 |
| 518 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_EarlyContextDeletion) { | 519 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_EarlyContextDeletion) { |
| 519 helper_->ShutdownContext(); | 520 helper_->ShutdownContext(); |
| 520 | 521 |
| 521 // Let the shutdown reach the simulated IO thread. | 522 // Let the shutdown reach the simulated IO thread. |
| 522 base::RunLoop().RunUntilIdle(); | 523 base::RunLoop().RunUntilIdle(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 590 |
| 590 // To show the new dispatcher can operate, simulate provider creation. Since | 591 // To show the new dispatcher can operate, simulate provider creation. Since |
| 591 // the old dispatcher cleaned up the old provider host, the new one won't | 592 // the old dispatcher cleaned up the old provider host, the new one won't |
| 592 // complain. | 593 // complain. |
| 593 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( | 594 new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated( |
| 594 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); | 595 kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW)); |
| 595 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); | 596 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); |
| 596 } | 597 } |
| 597 | 598 |
| 598 } // namespace content | 599 } // namespace content |
| OLD | NEW |