OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 12 matching lines...) Expand all Loading... | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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 "platform/testing/URLTestHelpers.h" | 31 #include "platform/testing/URLTestHelpers.h" |
32 | 32 |
33 #include "base/files/file_path.h" | |
34 #include "base/files/file_util.h" | |
33 #include "platform/testing/UnitTestHelpers.h" | 35 #include "platform/testing/UnitTestHelpers.h" |
34 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
35 #include "public/platform/WebURL.h" | 37 #include "public/platform/WebURL.h" |
36 #include "public/platform/WebURLError.h" | 38 #include "public/platform/WebURLError.h" |
37 #include "public/platform/WebURLLoadTiming.h" | 39 #include "public/platform/WebURLLoadTiming.h" |
38 #include "public/platform/WebURLLoaderMockFactory.h" | 40 #include "public/platform/WebURLLoaderMockFactory.h" |
39 #include "public/platform/WebURLResponse.h" | 41 #include "public/platform/WebURLResponse.h" |
42 #include <string> | |
40 | 43 |
41 namespace blink { | 44 namespace blink { |
42 namespace URLTestHelpers { | 45 namespace URLTestHelpers { |
43 | 46 |
44 void registerMockedURLFromBaseURL(const WebString& baseURL, | 47 WebURL registerMockedURLLoadFromBase(const WebString& baseURL, |
45 const WebString& fileName, | 48 const WebString& basePath, |
46 const WebString& mimeType) { | 49 const WebString& fileName, |
50 const WebString& mimeType) { | |
47 // fullURL = baseURL + fileName. | 51 // fullURL = baseURL + fileName. |
48 std::string fullString = | 52 std::string fullURL = |
49 std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data()); | 53 std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data()); |
50 registerMockedURLLoad(toKURL(fullString.c_str()), fileName, | 54 |
51 WebString::fromUTF8(""), mimeType); | 55 // filePath = basePath + ("/" +) fileName. |
56 base::FilePath filePath = | |
57 base::FilePath(basePath.utf8().data()) | |
kinuko
2017/01/26 09:32:41
Let's use WebStringToFilePath()
Takashi Toyoshima
2017/01/26 10:57:57
Thanks, correct conversion looks more complicated
| |
58 .Append(FILE_PATH_LITERAL(fileName.utf8().data())); | |
kinuko
2017/01/26 09:32:40
Ditto
Takashi Toyoshima
2017/01/26 10:57:57
Done.
| |
59 | |
60 KURL url = toKURL(fullURL); | |
61 registerMockedURLLoad(url, String(filePath.AsUTF8Unsafe().c_str()), mimeType); | |
kinuko
2017/01/26 09:32:41
FilePathToWebString
Takashi Toyoshima
2017/01/26 10:57:57
Done.
| |
62 return WebURL(url); | |
52 } | 63 } |
53 | 64 |
54 void registerMockedURLLoad(const WebURL& fullURL, | 65 void registerMockedURLLoad(const WebURL& fullURL, |
55 const WebString& fileName, | 66 const WebString& filePath, |
56 const WebString& mimeType) { | |
57 registerMockedURLLoad(fullURL, fileName, WebString::fromUTF8(""), mimeType); | |
58 } | |
59 | |
60 void registerMockedURLLoad(const WebURL& fullURL, | |
61 const WebString& fileName, | |
62 const WebString& relativeBaseDirectory, | |
63 const WebString& mimeType) { | 67 const WebString& mimeType) { |
64 WebURLLoadTiming timing; | 68 WebURLLoadTiming timing; |
65 timing.initialize(); | 69 timing.initialize(); |
66 | 70 |
67 WebURLResponse response(fullURL); | 71 WebURLResponse response(fullURL); |
68 response.setMIMEType(mimeType); | 72 response.setMIMEType(mimeType); |
69 response.setHTTPStatusCode(200); | 73 response.setHTTPStatusCode(200); |
70 response.setLoadTiming(timing); | 74 response.setLoadTiming(timing); |
71 | 75 |
72 registerMockedURLLoadWithCustomResponse(fullURL, fileName, | 76 registerMockedURLLoadWithCustomResponse(fullURL, filePath, response); |
73 relativeBaseDirectory, response); | |
74 } | 77 } |
75 | 78 |
76 void registerMockedErrorURLLoad(const WebURL& fullURL) { | 79 void registerMockedErrorURLLoad(const WebURL& fullURL) { |
77 WebURLLoadTiming timing; | 80 WebURLLoadTiming timing; |
78 timing.initialize(); | 81 timing.initialize(); |
79 | 82 |
80 WebURLResponse response; | 83 WebURLResponse response; |
81 response.setMIMEType("image/png"); | 84 response.setMIMEType("image/png"); |
82 response.setHTTPStatusCode(404); | 85 response.setHTTPStatusCode(404); |
83 response.setLoadTiming(timing); | 86 response.setLoadTiming(timing); |
84 | 87 |
85 WebURLError error; | 88 WebURLError error; |
86 error.reason = 404; | 89 error.reason = 404; |
87 Platform::current()->getURLLoaderMockFactory()->registerErrorURL( | 90 Platform::current()->getURLLoaderMockFactory()->registerErrorURL( |
88 fullURL, response, error); | 91 fullURL, response, error); |
89 } | 92 } |
90 | 93 |
91 void registerMockedURLLoadWithCustomResponse( | 94 void registerMockedURLLoadWithCustomResponse(const WebURL& fullURL, |
92 const WebURL& fullURL, | 95 const WebString& filePath, |
93 const WebString& fileName, | 96 WebURLResponse response) { |
94 const WebString& relativeBaseDirectory, | |
95 WebURLResponse response) { | |
96 // Physical file path for the mock = | |
97 // <webkitRootDir> + relativeBaseDirectory + fileName. | |
98 String filePath = testing::blinkRootDir(); | |
99 filePath.append("/Source/web/tests/data/"); | |
100 filePath.append(relativeBaseDirectory); | |
101 filePath.append(fileName); | |
102 | |
103 Platform::current()->getURLLoaderMockFactory()->registerURL(fullURL, response, | 97 Platform::current()->getURLLoaderMockFactory()->registerURL(fullURL, response, |
104 filePath); | 98 filePath); |
105 } | 99 } |
106 | 100 |
107 } // namespace URLTestHelpers | 101 } // namespace URLTestHelpers |
108 } // namespace blink | 102 } // namespace blink |
OLD | NEW |