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

Side by Side Diff: third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp

Issue 2654933003: platform/testing/{URL|Unit}TestHelpers improvements (Closed)
Patch Set: header changes Created 3 years, 10 months 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
OLDNEW
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
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 <string>
34 #include "base/files/file_path.h"
35 #include "base/files/file_util.h"
33 #include "platform/testing/UnitTestHelpers.h" 36 #include "platform/testing/UnitTestHelpers.h"
37 #include "public/platform/FilePathConversion.h"
34 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
35 #include "public/platform/WebURL.h" 39 #include "public/platform/WebURL.h"
36 #include "public/platform/WebURLError.h" 40 #include "public/platform/WebURLError.h"
37 #include "public/platform/WebURLLoadTiming.h" 41 #include "public/platform/WebURLLoadTiming.h"
38 #include "public/platform/WebURLLoaderMockFactory.h" 42 #include "public/platform/WebURLLoaderMockFactory.h"
39 #include "public/platform/WebURLResponse.h" 43 #include "public/platform/WebURLResponse.h"
40 44
41 namespace blink { 45 namespace blink {
42 namespace URLTestHelpers { 46 namespace URLTestHelpers {
43 47
44 void registerMockedURLFromBaseURL(const WebString& baseURL, 48 WebURL registerMockedURLLoadFromBase(const WebString& baseURL,
45 const WebString& fileName, 49 const WebString& basePath,
46 const WebString& mimeType) { 50 const WebString& fileName,
51 const WebString& mimeType) {
47 // fullURL = baseURL + fileName. 52 // fullURL = baseURL + fileName.
48 std::string fullString = 53 std::string fullURL =
49 std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data()); 54 std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data());
50 registerMockedURLLoad(toKURL(fullString.c_str()), fileName, 55
51 WebString::fromUTF8(""), mimeType); 56 // filePath = basePath + ("/" +) fileName.
57 base::FilePath filePath =
58 WebStringToFilePath(basePath).Append(WebStringToFilePath(fileName));
59
60 KURL url = toKURL(fullURL);
61 registerMockedURLLoad(url, FilePathToWebString(filePath), mimeType);
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698