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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "core/testing/URLTestHelpers.h" | 33 #include "core/testing/URLTestHelpers.h" |
| 34 #include "core/testing/UnitTestHelpers.h" |
34 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
35 #include "public/platform/WebString.h" | 36 #include "public/platform/WebString.h" |
36 #include "public/platform/WebThread.h" | 37 #include "public/platform/WebThread.h" |
37 #include "public/platform/WebURL.h" | 38 #include "public/platform/WebURL.h" |
38 #include "public/platform/WebURLLoader.h" | 39 #include "public/platform/WebURLLoader.h" |
39 #include "public/platform/WebURLLoaderClient.h" | 40 #include "public/platform/WebURLLoaderClient.h" |
40 #include "public/platform/WebURLRequest.h" | 41 #include "public/platform/WebURLRequest.h" |
41 #include "public/platform/WebURLResponse.h" | 42 #include "public/platform/WebURLResponse.h" |
42 #include "public/platform/WebUnitTestSupport.h" | 43 #include "public/platform/WebUnitTestSupport.h" |
43 #include "public/web/WebFrame.h" | 44 #include "public/web/WebFrame.h" |
44 #include "public/web/WebURLLoaderOptions.h" | 45 #include "public/web/WebURLLoaderOptions.h" |
45 #include "public/web/WebView.h" | 46 #include "public/web/WebView.h" |
46 #include "web/tests/FrameTestHelpers.h" | 47 #include "web/tests/FrameTestHelpers.h" |
47 #include "wtf/text/CString.h" | 48 #include "wtf/text/CString.h" |
48 #include "wtf/text/WTFString.h" | 49 #include "wtf/text/WTFString.h" |
49 | 50 |
50 #include <gtest/gtest.h> | 51 #include <gtest/gtest.h> |
51 | 52 |
52 using namespace blink; | 53 using namespace blink; |
53 using blink::URLTestHelpers::toKURL; | 54 using blink::URLTestHelpers::toKURL; |
| 55 using blink::testing::runPendingTasks; |
54 | 56 |
55 namespace { | 57 namespace { |
56 | 58 |
57 class AssociatedURLLoaderTest : public testing::Test, | 59 class AssociatedURLLoaderTest : public ::testing::Test, |
58 public WebURLLoaderClient { | 60 public WebURLLoaderClient { |
59 public: | 61 public: |
60 AssociatedURLLoaderTest() | 62 AssociatedURLLoaderTest() |
61 : m_willSendRequest(false) | 63 : m_willSendRequest(false) |
62 , m_didSendData(false) | 64 , m_didSendData(false) |
63 , m_didReceiveResponse(false) | 65 , m_didReceiveResponse(false) |
64 , m_didReceiveData(false) | 66 , m_didReceiveData(false) |
65 , m_didReceiveCachedMetadata(false) | 67 , m_didReceiveCachedMetadata(false) |
66 , m_didFinishLoading(false) | 68 , m_didFinishLoading(false) |
67 , m_didFail(false) | 69 , m_didFail(false) |
68 , m_runningMessageLoop(false) | |
69 { | 70 { |
70 // Reuse one of the test files from WebFrameTest. | 71 // Reuse one of the test files from WebFrameTest. |
71 m_baseFilePath = Platform::current()->unitTestSupport()->webKitRootDir()
; | 72 m_baseFilePath = Platform::current()->unitTestSupport()->webKitRootDir()
; |
72 m_baseFilePath.append("/Source/web/tests/data/"); | 73 m_baseFilePath.append("/Source/web/tests/data/"); |
73 m_frameFilePath = m_baseFilePath; | 74 m_frameFilePath = m_baseFilePath; |
74 m_frameFilePath.append("iframes_test.html"); | 75 m_frameFilePath.append("iframes_test.html"); |
75 } | 76 } |
76 | 77 |
77 KURL RegisterMockedUrl(const std::string& urlRoot, const WTF::String& filena
me) | 78 KURL RegisterMockedUrl(const std::string& urlRoot, const WTF::String& filena
me) |
78 { | 79 { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod
edDataLength) | 173 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod
edDataLength) |
173 { | 174 { |
174 m_didFinishLoading = true; | 175 m_didFinishLoading = true; |
175 EXPECT_EQ(m_expectedLoader, loader); | 176 EXPECT_EQ(m_expectedLoader, loader); |
176 } | 177 } |
177 | 178 |
178 void didFail(WebURLLoader* loader, const WebURLError& error) | 179 void didFail(WebURLLoader* loader, const WebURLError& error) |
179 { | 180 { |
180 m_didFail = true; | 181 m_didFail = true; |
181 EXPECT_EQ(m_expectedLoader, loader); | 182 EXPECT_EQ(m_expectedLoader, loader); |
182 if (m_runningMessageLoop) { | |
183 m_runningMessageLoop = false; | |
184 Platform::current()->currentThread()->exitRunLoop(); | |
185 } | |
186 } | 183 } |
187 | 184 |
188 void CheckMethodFails(const char* unsafeMethod) | 185 void CheckMethodFails(const char* unsafeMethod) |
189 { | 186 { |
190 WebURLRequest request; | 187 WebURLRequest request; |
191 request.initialize(); | 188 request.initialize(); |
192 request.setURL(toKURL("http://www.test.com/success.html")); | 189 request.setURL(toKURL("http://www.test.com/success.html")); |
193 request.setHTTPMethod(WebString::fromUTF8(unsafeMethod)); | 190 request.setHTTPMethod(WebString::fromUTF8(unsafeMethod)); |
194 WebURLLoaderOptions options; | 191 WebURLLoaderOptions options; |
195 options.untrustedHTTP = true; | 192 options.untrustedHTTP = true; |
(...skipping 21 matching lines...) Expand all Loading... |
217 | 214 |
218 void CheckFails(const WebURLRequest& request, WebURLLoaderOptions options =
WebURLLoaderOptions()) | 215 void CheckFails(const WebURLRequest& request, WebURLLoaderOptions options =
WebURLLoaderOptions()) |
219 { | 216 { |
220 m_expectedLoader = createAssociatedURLLoader(options); | 217 m_expectedLoader = createAssociatedURLLoader(options); |
221 EXPECT_TRUE(m_expectedLoader); | 218 EXPECT_TRUE(m_expectedLoader); |
222 m_didFail = false; | 219 m_didFail = false; |
223 m_expectedLoader->loadAsynchronously(request, this); | 220 m_expectedLoader->loadAsynchronously(request, this); |
224 // Failure should not be reported synchronously. | 221 // Failure should not be reported synchronously. |
225 EXPECT_FALSE(m_didFail); | 222 EXPECT_FALSE(m_didFail); |
226 // Allow the loader to return the error. | 223 // Allow the loader to return the error. |
227 m_runningMessageLoop = true; | 224 runPendingTasks(); |
228 Platform::current()->currentThread()->enterRunLoop(); | |
229 EXPECT_TRUE(m_didFail); | 225 EXPECT_TRUE(m_didFail); |
230 EXPECT_FALSE(m_didReceiveResponse); | 226 EXPECT_FALSE(m_didReceiveResponse); |
231 } | 227 } |
232 | 228 |
233 bool CheckAccessControlHeaders(const char* headerName, bool exposed) | 229 bool CheckAccessControlHeaders(const char* headerName, bool exposed) |
234 { | 230 { |
235 std::string id("http://www.other.com/CheckAccessControlExposeHeaders_"); | 231 std::string id("http://www.other.com/CheckAccessControlExposeHeaders_"); |
236 id.append(headerName); | 232 id.append(headerName); |
237 if (exposed) | 233 if (exposed) |
238 id.append("-Exposed"); | 234 id.append("-Exposed"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 WebURLRequest m_expectedNewRequest; | 276 WebURLRequest m_expectedNewRequest; |
281 WebURLResponse m_expectedRedirectResponse; | 277 WebURLResponse m_expectedRedirectResponse; |
282 bool m_willSendRequest; | 278 bool m_willSendRequest; |
283 bool m_didSendData; | 279 bool m_didSendData; |
284 bool m_didReceiveResponse; | 280 bool m_didReceiveResponse; |
285 bool m_didDownloadData; | 281 bool m_didDownloadData; |
286 bool m_didReceiveData; | 282 bool m_didReceiveData; |
287 bool m_didReceiveCachedMetadata; | 283 bool m_didReceiveCachedMetadata; |
288 bool m_didFinishLoading; | 284 bool m_didFinishLoading; |
289 bool m_didFail; | 285 bool m_didFail; |
290 bool m_runningMessageLoop; | |
291 }; | 286 }; |
292 | 287 |
293 // Test a successful same-origin URL load. | 288 // Test a successful same-origin URL load. |
294 TEST_F(AssociatedURLLoaderTest, SameOriginSuccess) | 289 TEST_F(AssociatedURLLoaderTest, SameOriginSuccess) |
295 { | 290 { |
296 KURL url = toKURL("http://www.test.com/SameOriginSuccess.html"); | 291 KURL url = toKURL("http://www.test.com/SameOriginSuccess.html"); |
297 WebURLRequest request; | 292 WebURLRequest request; |
298 request.initialize(); | 293 request.initialize(); |
299 request.setURL(url); | 294 request.setURL(url); |
300 | 295 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 m_expectedLoader->loadAsynchronously(request, this); | 704 m_expectedLoader->loadAsynchronously(request, this); |
710 serveRequests(); | 705 serveRequests(); |
711 EXPECT_TRUE(m_didReceiveResponse); | 706 EXPECT_TRUE(m_didReceiveResponse); |
712 EXPECT_TRUE(m_didReceiveData); | 707 EXPECT_TRUE(m_didReceiveData); |
713 EXPECT_TRUE(m_didFinishLoading); | 708 EXPECT_TRUE(m_didFinishLoading); |
714 | 709 |
715 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); | 710 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); |
716 } | 711 } |
717 | 712 |
718 } | 713 } |
OLD | NEW |