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

Side by Side Diff: Source/web/tests/AssociatedURLLoaderTest.cpp

Issue 689293003: Notify client when AssociatedURLLoader fail because of unallowed redirect. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 | « Source/web/AssociatedURLLoader.cpp ('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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 m_expectedLoader = createAssociatedURLLoader(); 471 m_expectedLoader = createAssociatedURLLoader();
472 EXPECT_TRUE(m_expectedLoader); 472 EXPECT_TRUE(m_expectedLoader);
473 m_expectedLoader->loadAsynchronously(request, this); 473 m_expectedLoader->loadAsynchronously(request, this);
474 serveRequests(); 474 serveRequests();
475 EXPECT_TRUE(m_willSendRequest); 475 EXPECT_TRUE(m_willSendRequest);
476 EXPECT_TRUE(m_didReceiveResponse); 476 EXPECT_TRUE(m_didReceiveResponse);
477 EXPECT_TRUE(m_didReceiveData); 477 EXPECT_TRUE(m_didReceiveData);
478 EXPECT_TRUE(m_didFinishLoading); 478 EXPECT_TRUE(m_didFinishLoading);
479 } 479 }
480 480
481 // Test a cross-origin URL redirect without Access Control set.
482 TEST_F(AssociatedURLLoaderTest, RedirectCrossOriginFailure)
483 {
484 KURL url = toKURL("http://www.test.com/RedirectCrossOriginFailure.html");
485 char redirect[] = "http://www.other.com/RedirectCrossOriginFailure.html"; / / Cross-origin
486 KURL redirectURL;
487
488 WebURLRequest request;
489 request.initialize();
490 request.setURL(url);
491
492 m_expectedRedirectResponse = WebURLResponse();
493 m_expectedRedirectResponse.initialize();
494 m_expectedRedirectResponse.setMIMEType("text/html");
495 m_expectedRedirectResponse.setHTTPStatusCode(301);
496 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect);
497 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRed irectResponse, m_frameFilePath);
498
499 m_expectedNewRequest = WebURLRequest();
500 m_expectedNewRequest.initialize();
501 m_expectedNewRequest.setURL(redirectURL);
502
503 m_expectedResponse = WebURLResponse();
504 m_expectedResponse.initialize();
505 m_expectedResponse.setMIMEType("text/html");
506 m_expectedResponse.setHTTPStatusCode(200);
507 Platform::current()->unitTestSupport()->registerMockedURL(redirectURL, m_exp ectedResponse, m_frameFilePath);
508
509 m_expectedLoader = createAssociatedURLLoader();
510 EXPECT_TRUE(m_expectedLoader);
511 m_expectedLoader->loadAsynchronously(request, this);
512
513 serveRequests();
514 EXPECT_FALSE(m_willSendRequest);
515 EXPECT_TRUE(m_didReceiveResponse);
516 EXPECT_TRUE(m_didReceiveData);
517 EXPECT_TRUE(m_didFinishLoading);
518 }
519
481 // Test that a cross origin redirect response without CORS headers fails. 520 // Test that a cross origin redirect response without CORS headers fails.
482 // Disabled, http://crbug.com/240912 . 521 TEST_F(AssociatedURLLoaderTest, RedirectCrossOriginWithAccessControlFailure)
483 TEST_F(AssociatedURLLoaderTest, DISABLED_RedirectCrossOriginWithAccessControlFai lure)
484 { 522 {
485 KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAccessControlF ailure.html"); 523 KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAccessControlF ailure.html");
486 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Failure.html"; // Cross-origin 524 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Failure.html"; // Cross-origin
487 KURL redirectURL = toKURL(redirect); 525 KURL redirectURL = toKURL(redirect);
488 526
489 WebURLRequest request; 527 WebURLRequest request;
490 request.initialize(); 528 request.initialize();
491 request.setURL(url); 529 request.setURL(url);
492 530
493 // Create a redirect response without CORS headers.
494 m_expectedRedirectResponse = WebURLResponse(); 531 m_expectedRedirectResponse = WebURLResponse();
495 m_expectedRedirectResponse.initialize(); 532 m_expectedRedirectResponse.initialize();
496 m_expectedRedirectResponse.setMIMEType("text/html"); 533 m_expectedRedirectResponse.setMIMEType("text/html");
497 m_expectedRedirectResponse.setHTTPStatusCode(301); 534 m_expectedRedirectResponse.setHTTPStatusCode(301);
498 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect); 535 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect);
499 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRed irectResponse, m_frameFilePath); 536 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRed irectResponse, m_frameFilePath);
500 537
538 m_expectedNewRequest = WebURLRequest();
539 m_expectedNewRequest.initialize();
540 m_expectedNewRequest.setURL(redirectURL);
541
542 m_expectedResponse = WebURLResponse();
543 m_expectedResponse.initialize();
544 m_expectedResponse.setMIMEType("text/html");
545 m_expectedResponse.setHTTPStatusCode(200);
546 Platform::current()->unitTestSupport()->registerMockedURL(redirectURL, m_exp ectedResponse, m_frameFilePath);
547
501 WebURLLoaderOptions options; 548 WebURLLoaderOptions options;
502 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl; 549 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl;
503 m_expectedLoader = createAssociatedURLLoader(options); 550 m_expectedLoader = createAssociatedURLLoader(options);
504 EXPECT_TRUE(m_expectedLoader); 551 EXPECT_TRUE(m_expectedLoader);
505 m_expectedLoader->loadAsynchronously(request, this); 552 m_expectedLoader->loadAsynchronously(request, this);
553
506 serveRequests(); 554 serveRequests();
507 // We should not receive a notification for the redirect or any response. 555 // We should get a notification about access control check failure.
508 EXPECT_FALSE(m_willSendRequest); 556 EXPECT_FALSE(m_willSendRequest);
509 EXPECT_FALSE(m_didReceiveResponse); 557 EXPECT_FALSE(m_didReceiveResponse);
510 EXPECT_FALSE(m_didReceiveData); 558 EXPECT_TRUE(m_didReceiveData);
511 EXPECT_FALSE(m_didFail); 559 EXPECT_TRUE(m_didFail);
512 } 560 }
513 561
514 // Test that a cross origin redirect response with CORS headers that allow the r equesting origin succeeds. 562 // Test that a cross origin redirect response with CORS headers that allow the r equesting origin succeeds.
515 TEST_F(AssociatedURLLoaderTest, RedirectCrossOriginWithAccessControlSuccess) 563 TEST_F(AssociatedURLLoaderTest, RedirectCrossOriginWithAccessControlSuccess)
516 { 564 {
517 KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAccessControlS uccess.html"); 565 KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAccessControlS uccess.html");
518 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Success.html"; // Cross-origin 566 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Success.html"; // Cross-origin
519 KURL redirectURL = toKURL(redirect); 567 KURL redirectURL = toKURL(redirect);
520 568
521 WebURLRequest request; 569 WebURLRequest request;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 m_expectedLoader->loadAsynchronously(request, this); 709 m_expectedLoader->loadAsynchronously(request, this);
662 serveRequests(); 710 serveRequests();
663 EXPECT_TRUE(m_didReceiveResponse); 711 EXPECT_TRUE(m_didReceiveResponse);
664 EXPECT_TRUE(m_didReceiveData); 712 EXPECT_TRUE(m_didReceiveData);
665 EXPECT_TRUE(m_didFinishLoading); 713 EXPECT_TRUE(m_didFinishLoading);
666 714
667 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); 715 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty());
668 } 716 }
669 717
670 } 718 }
OLDNEW
« no previous file with comments | « Source/web/AssociatedURLLoader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698