| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 #include "public/platform/WebURLLoaderClient.h" | 38 #include "public/platform/WebURLLoaderClient.h" |
| 39 #include "public/platform/WebURLLoaderMockFactory.h" | 39 #include "public/platform/WebURLLoaderMockFactory.h" |
| 40 #include "public/platform/WebURLRequest.h" | 40 #include "public/platform/WebURLRequest.h" |
| 41 #include "public/platform/WebURLResponse.h" | 41 #include "public/platform/WebURLResponse.h" |
| 42 #include "public/web/WebCache.h" | 42 #include "public/web/WebCache.h" |
| 43 #include "public/web/WebFrame.h" | 43 #include "public/web/WebFrame.h" |
| 44 #include "public/web/WebURLLoaderOptions.h" | 44 #include "public/web/WebURLLoaderOptions.h" |
| 45 #include "public/web/WebView.h" | 45 #include "public/web/WebView.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "web/tests/FrameTestHelpers.h" | 47 #include "web/tests/FrameTestHelpers.h" |
| 48 #include "wtf/PtrUtil.h" |
| 48 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| 49 #include "wtf/text/WTFString.h" | 50 #include "wtf/text/WTFString.h" |
| 51 #include <memory> |
| 50 | 52 |
| 51 using blink::URLTestHelpers::toKURL; | 53 using blink::URLTestHelpers::toKURL; |
| 52 using blink::testing::runPendingTasks; | 54 using blink::testing::runPendingTasks; |
| 53 | 55 |
| 54 namespace blink { | 56 namespace blink { |
| 55 | 57 |
| 56 class AssociatedURLLoaderTest : public ::testing::Test, | 58 class AssociatedURLLoaderTest : public ::testing::Test, |
| 57 public WebURLLoaderClient { | 59 public WebURLLoaderClient { |
| 58 public: | 60 public: |
| 59 AssociatedURLLoaderTest() | 61 AssociatedURLLoaderTest() |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 { | 110 { |
| 109 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 111 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
| 110 WebCache::clear(); | 112 WebCache::clear(); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void serveRequests() | 115 void serveRequests() |
| 114 { | 116 { |
| 115 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); | 117 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest
s(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 PassOwnPtr<WebURLLoader> createAssociatedURLLoader(const WebURLLoaderOptions
options = WebURLLoaderOptions()) | 120 std::unique_ptr<WebURLLoader> createAssociatedURLLoader(const WebURLLoaderOp
tions options = WebURLLoaderOptions()) |
| 119 { | 121 { |
| 120 return adoptPtr(mainFrame()->createAssociatedURLLoader(options)); | 122 return wrapUnique(mainFrame()->createAssociatedURLLoader(options)); |
| 121 } | 123 } |
| 122 | 124 |
| 123 // WebURLLoaderClient implementation. | 125 // WebURLLoaderClient implementation. |
| 124 void willFollowRedirect(WebURLLoader* loader, WebURLRequest& newRequest, con
st WebURLResponse& redirectResponse) override | 126 void willFollowRedirect(WebURLLoader* loader, WebURLRequest& newRequest, con
st WebURLResponse& redirectResponse) override |
| 125 { | 127 { |
| 126 m_willFollowRedirect = true; | 128 m_willFollowRedirect = true; |
| 127 EXPECT_EQ(m_expectedLoader, loader); | 129 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 128 EXPECT_EQ(m_expectedNewRequest.url(), newRequest.url()); | 130 EXPECT_EQ(m_expectedNewRequest.url(), newRequest.url()); |
| 129 // Check that CORS simple headers are transferred to the new request. | 131 // Check that CORS simple headers are transferred to the new request. |
| 130 EXPECT_EQ(m_expectedNewRequest.httpHeaderField("accept"), newRequest.htt
pHeaderField("accept")); | 132 EXPECT_EQ(m_expectedNewRequest.httpHeaderField("accept"), newRequest.htt
pHeaderField("accept")); |
| 131 EXPECT_EQ(m_expectedRedirectResponse.url(), redirectResponse.url()); | 133 EXPECT_EQ(m_expectedRedirectResponse.url(), redirectResponse.url()); |
| 132 EXPECT_EQ(m_expectedRedirectResponse.httpStatusCode(), redirectResponse.
httpStatusCode()); | 134 EXPECT_EQ(m_expectedRedirectResponse.httpStatusCode(), redirectResponse.
httpStatusCode()); |
| 133 EXPECT_EQ(m_expectedRedirectResponse.mimeType(), redirectResponse.mimeTy
pe()); | 135 EXPECT_EQ(m_expectedRedirectResponse.mimeType(), redirectResponse.mimeTy
pe()); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void didSendData(WebURLLoader* loader, unsigned long long bytesSent, unsigne
d long long totalBytesToBeSent) override | 138 void didSendData(WebURLLoader* loader, unsigned long long bytesSent, unsigne
d long long totalBytesToBeSent) override |
| 137 { | 139 { |
| 138 m_didSendData = true; | 140 m_didSendData = true; |
| 139 EXPECT_EQ(m_expectedLoader, loader); | 141 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void didReceiveResponse(WebURLLoader* loader, const WebURLResponse& response
) override | 144 void didReceiveResponse(WebURLLoader* loader, const WebURLResponse& response
) override |
| 143 { | 145 { |
| 144 m_didReceiveResponse = true; | 146 m_didReceiveResponse = true; |
| 145 m_actualResponse = WebURLResponse(response); | 147 m_actualResponse = WebURLResponse(response); |
| 146 EXPECT_EQ(m_expectedLoader, loader); | 148 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 147 EXPECT_EQ(m_expectedResponse.url(), response.url()); | 149 EXPECT_EQ(m_expectedResponse.url(), response.url()); |
| 148 EXPECT_EQ(m_expectedResponse.httpStatusCode(), response.httpStatusCode()
); | 150 EXPECT_EQ(m_expectedResponse.httpStatusCode(), response.httpStatusCode()
); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void didDownloadData(WebURLLoader* loader, int dataLength, int encodedDataLe
ngth) override | 153 void didDownloadData(WebURLLoader* loader, int dataLength, int encodedDataLe
ngth) override |
| 152 { | 154 { |
| 153 m_didDownloadData = true; | 155 m_didDownloadData = true; |
| 154 EXPECT_EQ(m_expectedLoader, loader); | 156 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 155 } | 157 } |
| 156 | 158 |
| 157 void didReceiveData(WebURLLoader* loader, const char* data, int dataLength,
int encodedDataLength) override | 159 void didReceiveData(WebURLLoader* loader, const char* data, int dataLength,
int encodedDataLength) override |
| 158 { | 160 { |
| 159 m_didReceiveData = true; | 161 m_didReceiveData = true; |
| 160 EXPECT_EQ(m_expectedLoader, loader); | 162 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 161 EXPECT_TRUE(data); | 163 EXPECT_TRUE(data); |
| 162 EXPECT_GT(dataLength, 0); | 164 EXPECT_GT(dataLength, 0); |
| 163 } | 165 } |
| 164 | 166 |
| 165 void didReceiveCachedMetadata(WebURLLoader* loader, const char* data, int da
taLength) override | 167 void didReceiveCachedMetadata(WebURLLoader* loader, const char* data, int da
taLength) override |
| 166 { | 168 { |
| 167 m_didReceiveCachedMetadata = true; | 169 m_didReceiveCachedMetadata = true; |
| 168 EXPECT_EQ(m_expectedLoader, loader); | 170 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 169 } | 171 } |
| 170 | 172 |
| 171 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod
edDataLength) override | 173 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod
edDataLength) override |
| 172 { | 174 { |
| 173 m_didFinishLoading = true; | 175 m_didFinishLoading = true; |
| 174 EXPECT_EQ(m_expectedLoader, loader); | 176 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 175 } | 177 } |
| 176 | 178 |
| 177 void didFail(WebURLLoader* loader, const WebURLError& error) override | 179 void didFail(WebURLLoader* loader, const WebURLError& error) override |
| 178 { | 180 { |
| 179 m_didFail = true; | 181 m_didFail = true; |
| 180 EXPECT_EQ(m_expectedLoader, loader); | 182 EXPECT_EQ(m_expectedLoader.get(), loader); |
| 181 } | 183 } |
| 182 | 184 |
| 183 void CheckMethodFails(const char* unsafeMethod) | 185 void CheckMethodFails(const char* unsafeMethod) |
| 184 { | 186 { |
| 185 WebURLRequest request; | 187 WebURLRequest request; |
| 186 request.initialize(); | 188 request.initialize(); |
| 187 request.setURL(toKURL("http://www.test.com/success.html")); | 189 request.setURL(toKURL("http://www.test.com/success.html")); |
| 188 request.setHTTPMethod(WebString::fromUTF8(unsafeMethod)); | 190 request.setHTTPMethod(WebString::fromUTF8(unsafeMethod)); |
| 189 WebURLLoaderOptions options; | 191 WebURLLoaderOptions options; |
| 190 options.untrustedHTTP = true; | 192 options.untrustedHTTP = true; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 return !m_actualResponse.httpHeaderField(headerNameString).isEmpty(); | 263 return !m_actualResponse.httpHeaderField(headerNameString).isEmpty(); |
| 262 } | 264 } |
| 263 | 265 |
| 264 WebFrame* mainFrame() const { return m_helper.webView()->mainFrame(); } | 266 WebFrame* mainFrame() const { return m_helper.webView()->mainFrame(); } |
| 265 | 267 |
| 266 protected: | 268 protected: |
| 267 String m_baseFilePath; | 269 String m_baseFilePath; |
| 268 String m_frameFilePath; | 270 String m_frameFilePath; |
| 269 FrameTestHelpers::WebViewHelper m_helper; | 271 FrameTestHelpers::WebViewHelper m_helper; |
| 270 | 272 |
| 271 OwnPtr<WebURLLoader> m_expectedLoader; | 273 std::unique_ptr<WebURLLoader> m_expectedLoader; |
| 272 WebURLResponse m_actualResponse; | 274 WebURLResponse m_actualResponse; |
| 273 WebURLResponse m_expectedResponse; | 275 WebURLResponse m_expectedResponse; |
| 274 WebURLRequest m_expectedNewRequest; | 276 WebURLRequest m_expectedNewRequest; |
| 275 WebURLResponse m_expectedRedirectResponse; | 277 WebURLResponse m_expectedRedirectResponse; |
| 276 bool m_willFollowRedirect; | 278 bool m_willFollowRedirect; |
| 277 bool m_didSendData; | 279 bool m_didSendData; |
| 278 bool m_didReceiveResponse; | 280 bool m_didReceiveResponse; |
| 279 bool m_didDownloadData; | 281 bool m_didDownloadData; |
| 280 bool m_didReceiveData; | 282 bool m_didReceiveData; |
| 281 bool m_didReceiveCachedMetadata; | 283 bool m_didReceiveCachedMetadata; |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 m_expectedLoader->loadAsynchronously(request, this); | 714 m_expectedLoader->loadAsynchronously(request, this); |
| 713 serveRequests(); | 715 serveRequests(); |
| 714 EXPECT_TRUE(m_didReceiveResponse); | 716 EXPECT_TRUE(m_didReceiveResponse); |
| 715 EXPECT_TRUE(m_didReceiveData); | 717 EXPECT_TRUE(m_didReceiveData); |
| 716 EXPECT_TRUE(m_didFinishLoading); | 718 EXPECT_TRUE(m_didFinishLoading); |
| 717 | 719 |
| 718 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); | 720 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); |
| 719 } | 721 } |
| 720 | 722 |
| 721 } // namespace blink | 723 } // namespace blink |
| OLD | NEW |