Chromium Code Reviews| Index: third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp |
| diff --git a/third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp b/third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp |
| index 6022f38426655a628e263e8c09fefb2dbfa230b7..e6057f9f1c27bd1b08ba65123f138c8386f57727 100644 |
| --- a/third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp |
| +++ b/third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp |
| @@ -30,6 +30,8 @@ |
| #include "platform/testing/URLTestHelpers.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| #include "platform/testing/UnitTestHelpers.h" |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebURL.h" |
| @@ -37,29 +39,31 @@ |
| #include "public/platform/WebURLLoadTiming.h" |
| #include "public/platform/WebURLLoaderMockFactory.h" |
| #include "public/platform/WebURLResponse.h" |
| +#include <string> |
| namespace blink { |
| namespace URLTestHelpers { |
| -void registerMockedURLFromBaseURL(const WebString& baseURL, |
| - const WebString& fileName, |
| - const WebString& mimeType) { |
| +WebURL registerMockedURLLoadFromBase(const WebString& baseURL, |
| + const WebString& basePath, |
| + const WebString& fileName, |
| + const WebString& mimeType) { |
| // fullURL = baseURL + fileName. |
| - std::string fullString = |
| + std::string fullURL = |
| std::string(baseURL.utf8().data()) + std::string(fileName.utf8().data()); |
| - registerMockedURLLoad(toKURL(fullString.c_str()), fileName, |
| - WebString::fromUTF8(""), mimeType); |
| -} |
| -void registerMockedURLLoad(const WebURL& fullURL, |
| - const WebString& fileName, |
| - const WebString& mimeType) { |
| - registerMockedURLLoad(fullURL, fileName, WebString::fromUTF8(""), mimeType); |
| + // filePath = basePath + ("/" +) fileName. |
| + base::FilePath filePath = |
| + 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
|
| + .Append(FILE_PATH_LITERAL(fileName.utf8().data())); |
|
kinuko
2017/01/26 09:32:40
Ditto
Takashi Toyoshima
2017/01/26 10:57:57
Done.
|
| + |
| + KURL url = toKURL(fullURL); |
| + 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.
|
| + return WebURL(url); |
| } |
| void registerMockedURLLoad(const WebURL& fullURL, |
| - const WebString& fileName, |
| - const WebString& relativeBaseDirectory, |
| + const WebString& filePath, |
| const WebString& mimeType) { |
| WebURLLoadTiming timing; |
| timing.initialize(); |
| @@ -69,8 +73,7 @@ void registerMockedURLLoad(const WebURL& fullURL, |
| response.setHTTPStatusCode(200); |
| response.setLoadTiming(timing); |
| - registerMockedURLLoadWithCustomResponse(fullURL, fileName, |
| - relativeBaseDirectory, response); |
| + registerMockedURLLoadWithCustomResponse(fullURL, filePath, response); |
| } |
| void registerMockedErrorURLLoad(const WebURL& fullURL) { |
| @@ -88,18 +91,9 @@ void registerMockedErrorURLLoad(const WebURL& fullURL) { |
| fullURL, response, error); |
| } |
| -void registerMockedURLLoadWithCustomResponse( |
| - const WebURL& fullURL, |
| - const WebString& fileName, |
| - const WebString& relativeBaseDirectory, |
| - WebURLResponse response) { |
| - // Physical file path for the mock = |
| - // <webkitRootDir> + relativeBaseDirectory + fileName. |
| - String filePath = testing::blinkRootDir(); |
| - filePath.append("/Source/web/tests/data/"); |
| - filePath.append(relativeBaseDirectory); |
| - filePath.append(fileName); |
| - |
| +void registerMockedURLLoadWithCustomResponse(const WebURL& fullURL, |
| + const WebString& filePath, |
| + WebURLResponse response) { |
| Platform::current()->getURLLoaderMockFactory()->registerURL(fullURL, response, |
| filePath); |
| } |