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

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

Issue 889323002: Allow SW registration only if it's secure AND it's HTTP or HTTPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove LOG(ERROR) Created 5 years, 10 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
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 228 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
229 } 229 }
230 230
231 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) { 231 TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) {
232 const int64 kProviderId = 99; // Dummy value 232 const int64 kProviderId = 99; // Dummy value
233 scoped_ptr<ServiceWorkerProviderHost> host( 233 scoped_ptr<ServiceWorkerProviderHost> host(
234 CreateServiceWorkerProviderHost(kProviderId)); 234 CreateServiceWorkerProviderHost(kProviderId));
235 host->SetDocumentUrl(GURL("http://www.example.com/foo")); 235 host->SetDocumentUrl(GURL("http://www.example.com/foo"));
236 context()->AddProviderHost(host.Pass()); 236 context()->AddProviderHost(host.Pass());
237 237
238 SendRegister(kProviderId, 238 Register(kProviderId,
239 GURL("http://www.example.com/"), 239 GURL("http://www.example.com/"),
240 GURL("http://www.example.com/bar")); 240 GURL("http://www.example.com/bar"),
241 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 241 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
242 } 242 }
243 243
244 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginShouldFail) { 244 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOriginShouldFail) {
245 const int64 kProviderId = 99; // Dummy value 245 const int64 kProviderId = 99; // Dummy value
246 scoped_ptr<ServiceWorkerProviderHost> host( 246 scoped_ptr<ServiceWorkerProviderHost> host(
247 CreateServiceWorkerProviderHost(kProviderId)); 247 CreateServiceWorkerProviderHost(kProviderId));
248 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 248 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
249 context()->AddProviderHost(host.Pass()); 249 context()->AddProviderHost(host.Pass());
250 250
251 // Script has a different host 251 // Script has a different host
252 SendRegister(kProviderId, 252 Register(kProviderId,
253 GURL("https://www.example.com/"), 253 GURL("https://www.example.com/"),
254 GURL("https://foo.example.com/bar")); 254 GURL("https://foo.example.com/bar"),
255 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 255 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
256 256
257 // Scope has a different host 257 // Scope has a different host
258 SendRegister(kProviderId, 258 Register(kProviderId,
259 GURL("https://foo.example.com/"), 259 GURL("https://foo.example.com/"),
260 GURL("https://www.example.com/bar")); 260 GURL("https://www.example.com/bar"),
261 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); 261 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
262 262
263 // Script has a different port 263 // Script has a different port
264 SendRegister(kProviderId, 264 Register(kProviderId,
265 GURL("https://www.example.com/"), 265 GURL("https://www.example.com/"),
266 GURL("https://www.example.com:8080/bar")); 266 GURL("https://www.example.com:8080/bar"),
267 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); 267 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
268 268
269 // Scope has a different transport 269 // Scope has a different transport
270 SendRegister(kProviderId, 270 Register(kProviderId,
271 GURL("wss://www.example.com/"), 271 GURL("wss://www.example.com/"),
272 GURL("https://www.example.com/bar")); 272 GURL("https://www.example.com/bar"),
273 EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_); 273 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
274 274
275 // Script and scope have a different host but match each other 275 // Script and scope have a different host but match each other
276 SendRegister(kProviderId, 276 Register(kProviderId,
277 GURL("https://foo.example.com/"), 277 GURL("https://foo.example.com/"),
278 GURL("https://foo.example.com/bar")); 278 GURL("https://foo.example.com/bar"),
279 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); 279 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
280 280
281 // Script and scope URLs are invalid 281 // Script and scope URLs are invalid
282 SendRegister(kProviderId, 282 SendRegister(kProviderId,
283 GURL(), 283 GURL(),
284 GURL("h@ttps://@")); 284 GURL("h@ttps://@"));
285 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); 285 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
286 }
287
288 TEST_F(ServiceWorkerDispatcherHostTest,
289 Register_FileSystemDocumentShouldFail) {
290 const int64 kProviderId = 99; // Dummy value
291 scoped_ptr<ServiceWorkerProviderHost> host(
292 CreateServiceWorkerProviderHost(kProviderId));
293 host->SetDocumentUrl(GURL("filesystem:https://www.example.com/temporary/a"));
294 context()->AddProviderHost(host.Pass());
295
296 Register(kProviderId,
297 GURL("filesystem:https://www.example.com/temporary/"),
298 GURL("https://www.example.com/temporary/bar"),
299 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
300
301 Register(kProviderId,
302 GURL("https://www.example.com/temporary/"),
303 GURL("filesystem:https://www.example.com/temporary/bar"),
304 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
305
306 Register(kProviderId,
307 GURL("filesystem:https://www.example.com/temporary/"),
308 GURL("filesystem:https://www.example.com/temporary/bar"),
309 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
310 }
311
312 TEST_F(ServiceWorkerDispatcherHostTest,
313 Register_FileSystemScriptOrScopeShouldFail) {
314 const int64 kProviderId = 99; // Dummy value
315 scoped_ptr<ServiceWorkerProviderHost> host(
316 CreateServiceWorkerProviderHost(kProviderId));
317 host->SetDocumentUrl(GURL("https://www.example.com/temporary/"));
318 context()->AddProviderHost(host.Pass());
319
320 Register(kProviderId,
321 GURL("filesystem:https://www.example.com/temporary/"),
322 GURL("https://www.example.com/temporary/bar"),
323 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
324
325 Register(kProviderId,
326 GURL("https://www.example.com/temporary/"),
327 GURL("filesystem:https://www.example.com/temporary/bar"),
328 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
329
330 Register(kProviderId,
331 GURL("filesystem:https://www.example.com/temporary/"),
332 GURL("filesystem:https://www.example.com/temporary/bar"),
333 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID);
286 } 334 }
287 335
288 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_HTTPS) { 336 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_HTTPS) {
289 const int64 kProviderId = 99; // Dummy value 337 const int64 kProviderId = 99; // Dummy value
290 scoped_ptr<ServiceWorkerProviderHost> host( 338 scoped_ptr<ServiceWorkerProviderHost> host(
291 CreateServiceWorkerProviderHost(kProviderId)); 339 CreateServiceWorkerProviderHost(kProviderId));
292 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 340 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
293 context()->AddProviderHost(host.Pass()); 341 context()->AddProviderHost(host.Pass());
294 342
295 Unregister(kProviderId, 343 Unregister(kProviderId,
(...skipping 14 matching lines...) Expand all
310 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); 358 ServiceWorkerMsg_ServiceWorkerUnregistered::ID);
311 } 359 }
312 360
313 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOriginShouldFail) { 361 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOriginShouldFail) {
314 const int64 kProviderId = 99; // Dummy value 362 const int64 kProviderId = 99; // Dummy value
315 scoped_ptr<ServiceWorkerProviderHost> host( 363 scoped_ptr<ServiceWorkerProviderHost> host(
316 CreateServiceWorkerProviderHost(kProviderId)); 364 CreateServiceWorkerProviderHost(kProviderId));
317 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 365 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
318 context()->AddProviderHost(host.Pass()); 366 context()->AddProviderHost(host.Pass());
319 367
320 SendUnregister(kProviderId, GURL("https://foo.example.com/")); 368 Unregister(kProviderId,
321 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 369 GURL("https://foo.example.com/"),
370 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID);
322 } 371 }
323 372
324 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_InvalidScopeShouldFail) { 373 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_InvalidScopeShouldFail) {
325 const int64 kProviderId = 99; // Dummy value 374 const int64 kProviderId = 99; // Dummy value
326 scoped_ptr<ServiceWorkerProviderHost> host( 375 scoped_ptr<ServiceWorkerProviderHost> host(
327 CreateServiceWorkerProviderHost(kProviderId)); 376 CreateServiceWorkerProviderHost(kProviderId));
328 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 377 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
329 context()->AddProviderHost(host.Pass()); 378 context()->AddProviderHost(host.Pass());
330 379
331 SendUnregister(kProviderId, GURL("")); 380 SendUnregister(kProviderId, GURL(""));
332 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 381 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
333 } 382 }
334 383
335 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) { 384 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) {
336 const int64 kProviderId = 99; // Dummy value 385 const int64 kProviderId = 99; // Dummy value
337 scoped_ptr<ServiceWorkerProviderHost> host( 386 scoped_ptr<ServiceWorkerProviderHost> host(
338 CreateServiceWorkerProviderHost(kProviderId)); 387 CreateServiceWorkerProviderHost(kProviderId));
339 host->SetDocumentUrl(GURL("http://www.example.com/foo")); 388 host->SetDocumentUrl(GURL("http://www.example.com/foo"));
340 context()->AddProviderHost(host.Pass()); 389 context()->AddProviderHost(host.Pass());
341 390
342 SendUnregister(kProviderId, GURL("http://www.example.com/")); 391 Unregister(kProviderId,
343 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 392 GURL("http://www.example.com/"),
393 ServiceWorkerMsg_ServiceWorkerUnregistrationError::ID);
344 } 394 }
345 395
346 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { 396 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) {
347 helper_->ShutdownContext(); 397 helper_->ShutdownContext();
348 398
349 // Let the shutdown reach the simulated IO thread. 399 // Let the shutdown reach the simulated IO thread.
350 base::RunLoop().RunUntilIdle(); 400 base::RunLoop().RunUntilIdle();
351 401
352 Register(-1, 402 Register(-1,
353 GURL(), 403 GURL(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 ServiceWorkerMsg_DidGetRegistration::ID); 448 ServiceWorkerMsg_DidGetRegistration::ID);
399 } 449 }
400 450
401 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) { 451 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) {
402 const int64 kProviderId = 99; // Dummy value 452 const int64 kProviderId = 99; // Dummy value
403 scoped_ptr<ServiceWorkerProviderHost> host( 453 scoped_ptr<ServiceWorkerProviderHost> host(
404 CreateServiceWorkerProviderHost(kProviderId)); 454 CreateServiceWorkerProviderHost(kProviderId));
405 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 455 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
406 context()->AddProviderHost(host.Pass()); 456 context()->AddProviderHost(host.Pass());
407 457
408 SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); 458 GetRegistration(kProviderId,
409 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 459 GURL("https://foo.example.com/"),
460 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID);
410 } 461 }
411 462
412 TEST_F(ServiceWorkerDispatcherHostTest, 463 TEST_F(ServiceWorkerDispatcherHostTest,
413 GetRegistration_InvalidScopeShouldFail) { 464 GetRegistration_InvalidScopeShouldFail) {
414 const int64 kProviderId = 99; // Dummy value 465 const int64 kProviderId = 99; // Dummy value
415 scoped_ptr<ServiceWorkerProviderHost> host( 466 scoped_ptr<ServiceWorkerProviderHost> host(
416 CreateServiceWorkerProviderHost(kProviderId)); 467 CreateServiceWorkerProviderHost(kProviderId));
417 host->SetDocumentUrl(GURL("https://www.example.com/foo")); 468 host->SetDocumentUrl(GURL("https://www.example.com/foo"));
418 context()->AddProviderHost(host.Pass()); 469 context()->AddProviderHost(host.Pass());
419 470
420 SendGetRegistration(kProviderId, GURL("")); 471 SendGetRegistration(kProviderId, GURL(""));
421 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 472 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
422 } 473 }
423 474
424 TEST_F(ServiceWorkerDispatcherHostTest, 475 TEST_F(ServiceWorkerDispatcherHostTest,
425 GetRegistration_NotSecureOriginShouldFail) { 476 GetRegistration_NotSecureOriginShouldFail) {
426 const int64 kProviderId = 99; // Dummy value 477 const int64 kProviderId = 99; // Dummy value
427 scoped_ptr<ServiceWorkerProviderHost> host( 478 scoped_ptr<ServiceWorkerProviderHost> host(
428 CreateServiceWorkerProviderHost(kProviderId)); 479 CreateServiceWorkerProviderHost(kProviderId));
429 host->SetDocumentUrl(GURL("http://www.example.com/foo")); 480 host->SetDocumentUrl(GURL("http://www.example.com/foo"));
430 context()->AddProviderHost(host.Pass()); 481 context()->AddProviderHost(host.Pass());
431 482
432 SendGetRegistration(kProviderId, GURL("http://www.example.com/")); 483 GetRegistration(kProviderId,
433 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); 484 GURL("http://www.example.com/"),
485 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID);
434 } 486 }
435 487
436 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { 488 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) {
437 helper_->ShutdownContext(); 489 helper_->ShutdownContext();
438 490
439 // Let the shutdown reach the simulated IO thread. 491 // Let the shutdown reach the simulated IO thread.
440 base::RunLoop().RunUntilIdle(); 492 base::RunLoop().RunUntilIdle();
441 493
442 GetRegistration(-1, 494 GetRegistration(-1,
443 GURL(), 495 GURL(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 544
493 // To show the new dispatcher can operate, simulate provider creation. Since 545 // To show the new dispatcher can operate, simulate provider creation. Since
494 // the old dispatcher cleaned up the old provider host, the new one won't 546 // the old dispatcher cleaned up the old provider host, the new one won't
495 // complain. 547 // complain.
496 new_dispatcher_host->OnMessageReceived( 548 new_dispatcher_host->OnMessageReceived(
497 ServiceWorkerHostMsg_ProviderCreated(kProviderId, MSG_ROUTING_NONE)); 549 ServiceWorkerHostMsg_ProviderCreated(kProviderId, MSG_ROUTING_NONE));
498 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_); 550 EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_);
499 } 551 }
500 552
501 } // namespace content 553 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698