OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/support/weburl_loader_mock_factory.h" | 5 #include "webkit/support/weburl_loader_mock_factory.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
13 #include "webkit/support/weburl_loader_mock.h" | 13 #include "webkit/support/weburl_loader_mock.h" |
14 | 14 |
15 using WebKit::WebData; | 15 using WebKit::WebData; |
16 using WebKit::WebString; | 16 using WebKit::WebString; |
17 using WebKit::WebURL; | 17 using WebKit::WebURL; |
18 using WebKit::WebURLError; | 18 using WebKit::WebURLError; |
19 using WebKit::WebURLLoader; | 19 using WebKit::WebURLLoader; |
20 using WebKit::WebURLRequest; | 20 using WebKit::WebURLRequest; |
21 using WebKit::WebURLResponse; | 21 using WebKit::WebURLResponse; |
22 | 22 |
| 23 struct WebURLLoaderMockFactory::ResponseInfo { |
| 24 WebKit::WebURLResponse response; |
| 25 FilePath file_path; |
| 26 }; |
| 27 |
| 28 WebURLLoaderMockFactory::WebURLLoaderMockFactory() {} |
| 29 |
| 30 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} |
| 31 |
23 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, | 32 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, |
24 const WebURLResponse& response, | 33 const WebURLResponse& response, |
25 const WebString& file_path) { | 34 const WebString& file_path) { |
26 ResponseInfo response_info; | 35 ResponseInfo response_info; |
27 response_info.response = response; | 36 response_info.response = response; |
28 if (!file_path.isNull() && !file_path.isEmpty()) { | 37 if (!file_path.isNull() && !file_path.isEmpty()) { |
29 #if defined(OS_POSIX) | 38 #if defined(OS_POSIX) |
30 // TODO(jcivelli): On Linux, UTF8 might not be correct. | 39 // TODO(jcivelli): On Linux, UTF8 might not be correct. |
31 response_info.file_path = | 40 response_info.file_path = |
32 FilePath(static_cast<std::string>(file_path.utf8())); | 41 FilePath(static_cast<std::string>(file_path.utf8())); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 scoped_array<char> buffer(new char[size]); | 137 scoped_array<char> buffer(new char[size]); |
129 data->reset(); | 138 data->reset(); |
130 int read_count = file_util::ReadFile(file_path, buffer.get(), size); | 139 int read_count = file_util::ReadFile(file_path, buffer.get(), size); |
131 if (read_count == -1) | 140 if (read_count == -1) |
132 return false; | 141 return false; |
133 DCHECK(read_count == size); | 142 DCHECK(read_count == size); |
134 data->assign(buffer.get(), size); | 143 data->assign(buffer.get(), size); |
135 | 144 |
136 return true; | 145 return true; |
137 } | 146 } |
OLD | NEW |