| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/testing/weburl_loader_mock_factory_impl.h" | 5 #include "platform/testing/weburl_loader_mock_factory_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "platform/loader/fetch/MemoryCache.h" | 11 #include "platform/loader/fetch/MemoryCache.h" |
| 12 #include "platform/testing/TestingPlatformSupport.h" | 12 #include "platform/testing/TestingPlatformSupport.h" |
| 13 #include "platform/testing/UnitTestHelpers.h" | 13 #include "platform/testing/UnitTestHelpers.h" |
| 14 #include "platform/testing/weburl_loader_mock.h" | 14 #include "platform/testing/weburl_loader_mock.h" |
| 15 #include "public/platform/FilePathConversion.h" | 15 #include "public/platform/FilePathConversion.h" |
| 16 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
| 17 #include "public/platform/WebString.h" | 17 #include "public/platform/WebString.h" |
| 18 #include "public/platform/WebURLError.h" | 18 #include "public/platform/WebURLError.h" |
| 19 #include "public/platform/WebURLRequest.h" | 19 #include "public/platform/WebURLRequest.h" |
| 20 #include "public/platform/WebURLResponse.h" | 20 #include "public/platform/WebURLResponse.h" |
| 21 #include "wtf/PtrUtil.h" | 21 #include "wtf/PtrUtil.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 std::unique_ptr<WebURLLoaderMockFactory> WebURLLoaderMockFactory::create() | 25 std::unique_ptr<WebURLLoaderMockFactory> WebURLLoaderMockFactory::create() { |
| 26 { | |
| 27 return WTF::wrapUnique(new WebURLLoaderMockFactoryImpl(nullptr)); | 26 return WTF::wrapUnique(new WebURLLoaderMockFactoryImpl(nullptr)); |
| 28 } | 27 } |
| 29 | 28 |
| 30 WebURLLoaderMockFactoryImpl::WebURLLoaderMockFactoryImpl( | 29 WebURLLoaderMockFactoryImpl::WebURLLoaderMockFactoryImpl( |
| 31 TestingPlatformSupport* platform) | 30 TestingPlatformSupport* platform) |
| 32 : m_platform(platform) {} | 31 : m_platform(platform) {} |
| 33 | 32 |
| 34 WebURLLoaderMockFactoryImpl::~WebURLLoaderMockFactoryImpl() {} | 33 WebURLLoaderMockFactoryImpl::~WebURLLoaderMockFactoryImpl() {} |
| 35 | 34 |
| 36 WebURLLoader* WebURLLoaderMockFactoryImpl::createURLLoader( | 35 WebURLLoader* WebURLLoaderMockFactoryImpl::createURLLoader( |
| 37 WebURLLoader* default_loader) { | 36 WebURLLoader* default_loader) { |
| 38 return new WebURLLoaderMock(this, default_loader); | 37 return new WebURLLoaderMock(this, default_loader); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void WebURLLoaderMockFactoryImpl::registerURL(const WebURL& url, | 40 void WebURLLoaderMockFactoryImpl::registerURL(const WebURL& url, |
| 42 const WebURLResponse& response, | 41 const WebURLResponse& response, |
| 43 const WebString& file_path) { | 42 const WebString& file_path) { |
| 44 ResponseInfo response_info; | 43 ResponseInfo response_info; |
| 45 response_info.response = response; | 44 response_info.response = response; |
| 46 if (!file_path.isNull() && !file_path.isEmpty()) { | 45 if (!file_path.isNull() && !file_path.isEmpty()) { |
| 47 response_info.file_path = blink::WebStringToFilePath(file_path); | 46 response_info.file_path = blink::WebStringToFilePath(file_path); |
| 48 DCHECK(base::PathExists(response_info.file_path)) | 47 DCHECK(base::PathExists(response_info.file_path)) |
| 49 << response_info.file_path.MaybeAsASCII() << " does not exist."; | 48 << response_info.file_path.MaybeAsASCII() << " does not exist."; |
| 50 } | 49 } |
| 51 | 50 |
| 52 DCHECK(url_to_response_info_.find(url) == url_to_response_info_.end()); | 51 DCHECK(url_to_response_info_.find(url) == url_to_response_info_.end()); |
| 53 url_to_response_info_.set(url, response_info); | 52 url_to_response_info_.set(url, response_info); |
| 54 } | 53 } |
| 55 | 54 |
| 56 | |
| 57 void WebURLLoaderMockFactoryImpl::registerErrorURL( | 55 void WebURLLoaderMockFactoryImpl::registerErrorURL( |
| 58 const WebURL& url, | 56 const WebURL& url, |
| 59 const WebURLResponse& response, | 57 const WebURLResponse& response, |
| 60 const WebURLError& error) { | 58 const WebURLError& error) { |
| 61 DCHECK(url_to_response_info_.find(url) == url_to_response_info_.end()); | 59 DCHECK(url_to_response_info_.find(url) == url_to_response_info_.end()); |
| 62 registerURL(url, response, WebString()); | 60 registerURL(url, response, WebString()); |
| 63 url_to_error_info_.set(url, error); | 61 url_to_error_info_.set(url, error); |
| 64 } | 62 } |
| 65 | 63 |
| 66 void WebURLLoaderMockFactoryImpl::unregisterURL(const blink::WebURL& url) { | 64 void WebURLLoaderMockFactoryImpl::unregisterURL(const blink::WebURL& url) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return true; | 174 return true; |
| 177 | 175 |
| 178 std::string buffer; | 176 std::string buffer; |
| 179 if (!base::ReadFileToString(file_path, &buffer)) | 177 if (!base::ReadFileToString(file_path, &buffer)) |
| 180 return false; | 178 return false; |
| 181 | 179 |
| 182 data->assign(buffer.data(), buffer.size()); | 180 data->assign(buffer.data(), buffer.size()); |
| 183 return true; | 181 return true; |
| 184 } | 182 } |
| 185 | 183 |
| 186 } // namespace blink | 184 } // namespace blink |
| OLD | NEW |