| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/Platform/chromium/public/WebString.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" |
| 14 #include "webkit/support/webkit_support.h" | 14 #include "webkit/support/webkit_support.h" |
| 15 #include "webkit/support/weburl_loader_mock.h" | 15 #include "webkit/support/weburl_loader_mock.h" |
| 16 | 16 |
| 17 using WebKit::WebCache; | 17 using WebKit::WebCache; |
| 18 using WebKit::WebData; | 18 using WebKit::WebData; |
| 19 using WebKit::WebString; | 19 using WebKit::WebString; |
| 20 using WebKit::WebURL; | 20 using WebKit::WebURL; |
| 21 using WebKit::WebURLError; | 21 using WebKit::WebURLError; |
| 22 using WebKit::WebURLLoader; | 22 using WebKit::WebURLLoader; |
| 23 using WebKit::WebURLRequest; | 23 using WebKit::WebURLRequest; |
| 24 using WebKit::WebURLResponse; | 24 using WebKit::WebURLResponse; |
| 25 | 25 |
| 26 struct WebURLLoaderMockFactory::ResponseInfo { | 26 struct WebURLLoaderMockFactory::ResponseInfo { |
| 27 WebKit::WebURLResponse response; | 27 WebKit::WebURLResponse response; |
| 28 FilePath file_path; | 28 base::FilePath file_path; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 WebURLLoaderMockFactory::WebURLLoaderMockFactory() {} | 31 WebURLLoaderMockFactory::WebURLLoaderMockFactory() {} |
| 32 | 32 |
| 33 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} | 33 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} |
| 34 | 34 |
| 35 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, | 35 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, |
| 36 const WebURLResponse& response, | 36 const WebURLResponse& response, |
| 37 const WebString& file_path) { | 37 const WebString& file_path) { |
| 38 ResponseInfo response_info; | 38 ResponseInfo response_info; |
| 39 response_info.response = response; | 39 response_info.response = response; |
| 40 if (!file_path.isNull() && !file_path.isEmpty()) { | 40 if (!file_path.isNull() && !file_path.isEmpty()) { |
| 41 #if defined(OS_POSIX) | 41 #if defined(OS_POSIX) |
| 42 // TODO(jcivelli): On Linux, UTF8 might not be correct. | 42 // TODO(jcivelli): On Linux, UTF8 might not be correct. |
| 43 response_info.file_path = | 43 response_info.file_path = |
| 44 FilePath(static_cast<std::string>(file_path.utf8())); | 44 base::FilePath(static_cast<std::string>(file_path.utf8())); |
| 45 #elif defined(OS_WIN) | 45 #elif defined(OS_WIN) |
| 46 response_info.file_path = | 46 response_info.file_path = |
| 47 FilePath(std::wstring(file_path.data(), file_path.length())); | 47 base::FilePath(std::wstring(file_path.data(), file_path.length())); |
| 48 #endif | 48 #endif |
| 49 DCHECK(file_util::PathExists(response_info.file_path)) | 49 DCHECK(file_util::PathExists(response_info.file_path)) |
| 50 << response_info.file_path.MaybeAsASCII() << " does not exist."; | 50 << response_info.file_path.MaybeAsASCII() << " does not exist."; |
| 51 } | 51 } |
| 52 | 52 |
| 53 DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); | 53 DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); |
| 54 url_to_reponse_info_[url] = response_info; | 54 url_to_reponse_info_[url] = response_info; |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 *response = iter->second.response; | 170 *response = iter->second.response; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { | 173 bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { |
| 174 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); | 174 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); |
| 175 return iter != pending_loaders_.end(); | 175 return iter != pending_loaders_.end(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // static | 178 // static |
| 179 bool WebURLLoaderMockFactory::ReadFile(const FilePath& file_path, | 179 bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path, |
| 180 WebData* data) { | 180 WebData* data) { |
| 181 int64 file_size = 0; | 181 int64 file_size = 0; |
| 182 if (!file_util::GetFileSize(file_path, &file_size)) | 182 if (!file_util::GetFileSize(file_path, &file_size)) |
| 183 return false; | 183 return false; |
| 184 | 184 |
| 185 int size = static_cast<int>(file_size); | 185 int size = static_cast<int>(file_size); |
| 186 scoped_array<char> buffer(new char[size]); | 186 scoped_array<char> buffer(new char[size]); |
| 187 data->reset(); | 187 data->reset(); |
| 188 int read_count = file_util::ReadFile(file_path, buffer.get(), size); | 188 int read_count = file_util::ReadFile(file_path, buffer.get(), size); |
| 189 if (read_count == -1) | 189 if (read_count == -1) |
| 190 return false; | 190 return false; |
| 191 DCHECK(read_count == size); | 191 DCHECK(read_count == size); |
| 192 data->assign(buffer.get(), size); | 192 data->assign(buffer.get(), size); |
| 193 | 193 |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| OLD | NEW |