Modified: trunk/Source/WebKit/chromium/tests/AssociatedURLLoaderTest.cpp (103611 => 103612)
--- trunk/Source/WebKit/chromium/tests/AssociatedURLLoaderTest.cpp 2011-12-23 09:12:28 UTC (rev 103611)
+++ trunk/Source/WebKit/chromium/tests/AssociatedURLLoaderTest.cpp 2011-12-23 09:52:23 UTC (rev 103612)
@@ -72,6 +72,7 @@
, m_didReceiveCachedMetadata(false)
, m_didFinishLoading(false)
, m_didFail(false)
+ , m_runningMessageLoop(false)
{
// Reuse one of the test files from WebFrameTest.
std::string filePath = webkit_support::GetWebKitRootDir().utf8();
@@ -123,8 +124,8 @@
EXPECT_EQ(m_expectedLoader, loader);
EXPECT_EQ(m_expectedNewRequest.url(), newRequest.url());
EXPECT_EQ(m_expectedRedirectResponse.url(), redirectResponse.url());
+ EXPECT_EQ(m_expectedRedirectResponse.httpStatusCode(), redirectResponse.httpStatusCode());
EXPECT_EQ(m_expectedRedirectResponse.mimeType(), redirectResponse.mimeType());
- EXPECT_EQ(m_expectedRedirectResponse.httpStatusCode(), redirectResponse.httpStatusCode());
}
void didSendData(WebURLLoader* loader, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
@@ -171,7 +172,10 @@
{
m_didFail = true;
EXPECT_EQ(m_expectedLoader, loader);
- webkit_support::QuitMessageLoop();
+ if (m_runningMessageLoop) {
+ m_runningMessageLoop = false;
+ webkit_support::QuitMessageLoop();
+ }
}
void CheckMethodFails(const char* unsafeMethod)
@@ -210,8 +214,10 @@
// Failure should not be reported synchronously.
EXPECT_FALSE(m_didFail);
// Allow the loader to return the error.
+ m_runningMessageLoop = true;
webkit_support::RunMessageLoop();
EXPECT_TRUE(m_didFail);
+ EXPECT_FALSE(m_didReceiveResponse);
}
protected:
@@ -231,12 +237,13 @@
bool m_didReceiveCachedMetadata;
bool m_didFinishLoading;
bool m_didFail;
+ bool m_runningMessageLoop;
};
-// Test a successful URL load.
-TEST_F(AssociatedURLLoaderTest, Success)
+// Test a successful same-origin URL load.
+TEST_F(AssociatedURLLoaderTest, SameOriginSuccess)
{
- GURL url = ""
+ GURL url = ""
WebURLRequest request;
request.initialize();
request.setURL(url);
@@ -259,7 +266,7 @@
TEST_F(AssociatedURLLoaderTest, SameOriginRestriction)
{
// This is cross-origin since the frame was loaded from www.test.com.
- GURL url = ""
+ GURL url = ""
WebURLRequest request;
request.initialize();
request.setURL(url);
@@ -270,7 +277,7 @@
TEST_F(AssociatedURLLoaderTest, CrossOriginSuccess)
{
// This is cross-origin since the frame was loaded from www.test.com.
- GURL url = ""
+ GURL url = ""
WebURLRequest request;
request.initialize();
request.setURL(url);
@@ -291,6 +298,142 @@
EXPECT_TRUE(m_didFinishLoading);
}
+// Test a successful cross-origin load using CORS.
+TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlSuccess)
+{
+ // This is cross-origin since the frame was loaded from www.test.com.
+ GURL url = ""
+ WebURLRequest request;
+ request.initialize();
+ request.setURL(url);
+
+ m_expectedResponse = WebURLResponse();
+ m_expectedResponse.initialize();
+ m_expectedResponse.setMIMEType("text/html");
+ m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*");
+ webkit_support::RegisterMockedURL(url, m_expectedResponse, m_frameFilePath);
+
+ WebURLLoaderOptions options;
+ options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
+ m_expectedLoader = createAssociatedURLLoader(options);
+ EXPECT_TRUE(m_expectedLoader);
+ m_expectedLoader->loadAsynchronously(request, this);
+ serveRequests();
+ EXPECT_TRUE(m_didReceiveResponse);
+ EXPECT_TRUE(m_didReceiveData);
+ EXPECT_TRUE(m_didFinishLoading);
+}
+
+// Test an unsuccessful cross-origin load using CORS.
+TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlFailure)
+{
+ // This is cross-origin since the frame was loaded from www.test.com.
+ GURL url = ""
+ WebURLRequest request;
+ request.initialize();
+ request.setURL(url);
+
+ m_expectedResponse = WebURLResponse();
+ m_expectedResponse.initialize();
+ m_expectedResponse.setMIMEType("text/html");
+ m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*");
+ webkit_support::RegisterMockedURL(url, m_expectedResponse, m_frameFilePath);
+
+ WebURLLoaderOptions options;
+ // Send credentials. This will cause the CORS checks to fail, because credentials can't be
+ // sent to a server which returns the header "access-control-allow-origin" with "*" as its value.
+ options.allowCredentials = true;
+ options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
+ m_expectedLoader = createAssociatedURLLoader(options);
+ EXPECT_TRUE(m_expectedLoader);
+ m_expectedLoader->loadAsynchronously(request, this);
+
+ // Failure should not be reported synchronously.
+ EXPECT_FALSE(m_didFail);
+ // The loader needs to receive the response, before doing the CORS check.
+ serveRequests();
+ EXPECT_TRUE(m_didFail);
+ EXPECT_FALSE(m_didReceiveResponse);
+}
+
+// Test a same-origin URL redirect and load.
+TEST_F(AssociatedURLLoaderTest, RedirectSuccess)
+{
+ GURL url = ""
+ char redirect[] = "http://www.test.com/RedirectSuccess2.html"; // Same-origin
+ GURL redirectURL = GURL(redirect);
+
+ WebURLRequest request;
+ request.initialize();
+ request.setURL(url);
+
+ m_expectedRedirectResponse = WebURLResponse();
+ m_expectedRedirectResponse.initialize();
+ m_expectedRedirectResponse.setMIMEType("text/html");
+ m_expectedRedirectResponse.setHTTPStatusCode(301);
+ m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect);
+ webkit_support::RegisterMockedURL(url, m_expectedRedirectResponse, m_frameFilePath);
+
+ m_expectedNewRequest = WebURLRequest();
+ m_expectedNewRequest.initialize();
+ m_expectedNewRequest.setURL(redirectURL);
+
+ m_expectedResponse = WebURLResponse();
+ m_expectedResponse.initialize();
+ m_expectedResponse.setMIMEType("text/html");
+ webkit_support::RegisterMockedURL(redirectURL, m_expectedResponse, m_frameFilePath);
+
+ m_expectedLoader = createAssociatedURLLoader();
+ EXPECT_TRUE(m_expectedLoader);
+ m_expectedLoader->loadAsynchronously(request, this);
+ serveRequests();
+ EXPECT_TRUE(m_willSendRequest);
+ EXPECT_TRUE(m_didReceiveResponse);
+ EXPECT_TRUE(m_didReceiveData);
+ EXPECT_TRUE(m_didFinishLoading);
+}
+
+// Test a successful redirect and cross-origin load using CORS.
+// FIXME: Enable this when DocumentThreadableLoader supports cross-origin redirects.
+TEST_F(AssociatedURLLoaderTest, DISABLED_RedirectCrossOriginWithAccessControlSuccess)
+{
+ GURL url = ""
+ char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControlSuccess.html"; // Cross-origin
+ GURL redirectURL = GURL(redirect);
+
+ WebURLRequest request;
+ request.initialize();
+ request.setURL(url);
+
+ m_expectedRedirectResponse = WebURLResponse();
+ m_expectedRedirectResponse.initialize();
+ m_expectedRedirectResponse.setMIMEType("text/html");
+ m_expectedRedirectResponse.setHTTPStatusCode(301);
+ m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect);
+ webkit_support::RegisterMockedURL(url, m_expectedRedirectResponse, m_frameFilePath);
+
+ m_expectedNewRequest = WebURLRequest();
+ m_expectedNewRequest.initialize();
+ m_expectedNewRequest.setURL(redirectURL);
+
+ m_expectedResponse = WebURLResponse();
+ m_expectedResponse.initialize();
+ m_expectedResponse.setMIMEType("text/html");
+ m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*");
+ webkit_support::RegisterMockedURL(redirectURL, m_expectedResponse, m_frameFilePath);
+
+ WebURLLoaderOptions options;
+ options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
+ m_expectedLoader = createAssociatedURLLoader(options);
+ EXPECT_TRUE(m_expectedLoader);
+ m_expectedLoader->loadAsynchronously(request, this);
+ serveRequests();
+ EXPECT_TRUE(m_willSendRequest);
+ EXPECT_TRUE(m_didReceiveResponse);
+ EXPECT_TRUE(m_didReceiveData);
+ EXPECT_TRUE(m_didFinishLoading);
+}
+
// Test that untrusted loads can't use a forbidden method.
TEST_F(AssociatedURLLoaderTest, UntrustedCheckMethods)
{