| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/test/weburl_loader_mock_factory.h" | 5 #include "content/test/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 "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/test/webkit_support.h" | 10 #include "content/test/webkit_support.h" |
| 11 #include "content/test/weburl_loader_mock.h" | 11 #include "content/test/weburl_loader_mock.h" |
| 12 #include "third_party/WebKit/public/platform/WebString.h" | 12 #include "third_party/WebKit/public/platform/WebString.h" |
| 13 #include "third_party/WebKit/public/platform/WebURLError.h" | 13 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 14 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 15 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 16 #include "third_party/WebKit/public/web/WebCache.h" | 16 #include "third_party/WebKit/public/web/WebCache.h" |
| 17 | 17 |
| 18 using WebKit::WebCache; | 18 using blink::WebCache; |
| 19 using WebKit::WebData; | 19 using blink::WebData; |
| 20 using WebKit::WebString; | 20 using blink::WebString; |
| 21 using WebKit::WebURL; | 21 using blink::WebURL; |
| 22 using WebKit::WebURLError; | 22 using blink::WebURLError; |
| 23 using WebKit::WebURLLoader; | 23 using blink::WebURLLoader; |
| 24 using WebKit::WebURLRequest; | 24 using blink::WebURLRequest; |
| 25 using WebKit::WebURLResponse; | 25 using blink::WebURLResponse; |
| 26 | 26 |
| 27 WebURLLoaderMockFactory::WebURLLoaderMockFactory() {} | 27 WebURLLoaderMockFactory::WebURLLoaderMockFactory() {} |
| 28 | 28 |
| 29 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} | 29 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} |
| 30 | 30 |
| 31 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, | 31 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, |
| 32 const WebURLResponse& response, | 32 const WebURLResponse& response, |
| 33 const WebString& file_path) { | 33 const WebString& file_path) { |
| 34 ResponseInfo response_info; | 34 ResponseInfo response_info; |
| 35 response_info.response = response; | 35 response_info.response = response; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 | 54 |
| 55 void WebURLLoaderMockFactory::RegisterErrorURL(const WebURL& url, | 55 void WebURLLoaderMockFactory::RegisterErrorURL(const WebURL& url, |
| 56 const WebURLResponse& response, | 56 const WebURLResponse& response, |
| 57 const WebURLError& error) { | 57 const WebURLError& error) { |
| 58 DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); | 58 DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); |
| 59 RegisterURL(url, response, WebString()); | 59 RegisterURL(url, response, WebString()); |
| 60 url_to_error_info_[url] = error; | 60 url_to_error_info_[url] = error; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void WebURLLoaderMockFactory::UnregisterURL(const WebKit::WebURL& url) { | 63 void WebURLLoaderMockFactory::UnregisterURL(const blink::WebURL& url) { |
| 64 URLToResponseMap::iterator iter = url_to_reponse_info_.find(url); | 64 URLToResponseMap::iterator iter = url_to_reponse_info_.find(url); |
| 65 DCHECK(iter != url_to_reponse_info_.end()); | 65 DCHECK(iter != url_to_reponse_info_.end()); |
| 66 url_to_reponse_info_.erase(iter); | 66 url_to_reponse_info_.erase(iter); |
| 67 | 67 |
| 68 URLToErrorMap::iterator error_iter = url_to_error_info_.find(url); | 68 URLToErrorMap::iterator error_iter = url_to_error_info_.find(url); |
| 69 if (error_iter != url_to_error_info_.end()) | 69 if (error_iter != url_to_error_info_.end()) |
| 70 url_to_error_info_.erase(error_iter); | 70 url_to_error_info_.erase(error_iter); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void WebURLLoaderMockFactory::UnregisterAllURLs() { | 73 void WebURLLoaderMockFactory::UnregisterAllURLs() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 100 } | 100 } |
| 101 // Serve the request if the loader is still active. | 101 // Serve the request if the loader is still active. |
| 102 if (IsPending(loader) && !loader->isDeferred()) | 102 if (IsPending(loader) && !loader->isDeferred()) |
| 103 loader->ServeAsynchronousRequest(response, data, error); | 103 loader->ServeAsynchronousRequest(response, data, error); |
| 104 // The loader might have already been removed. | 104 // The loader might have already been removed. |
| 105 pending_loaders_.erase(loader); | 105 pending_loaders_.erase(loader); |
| 106 } | 106 } |
| 107 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 WebKit::WebURLRequest | 110 blink::WebURLRequest |
| 111 WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest() { | 111 WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest() { |
| 112 return last_handled_asynchronous_request_; | 112 return last_handled_asynchronous_request_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool WebURLLoaderMockFactory::IsMockedURL(const WebKit::WebURL& url) { | 115 bool WebURLLoaderMockFactory::IsMockedURL(const blink::WebURL& url) { |
| 116 return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); | 116 return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void WebURLLoaderMockFactory::CancelLoad(WebURLLoaderMock* loader) { | 119 void WebURLLoaderMockFactory::CancelLoad(WebURLLoaderMock* loader) { |
| 120 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); | 120 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); |
| 121 DCHECK(iter != pending_loaders_.end()); | 121 DCHECK(iter != pending_loaders_.end()); |
| 122 pending_loaders_.erase(iter); | 122 pending_loaders_.erase(iter); |
| 123 } | 123 } |
| 124 | 124 |
| 125 WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( | 125 WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 scoped_ptr<char[]> buffer(new char[size]); | 183 scoped_ptr<char[]> buffer(new char[size]); |
| 184 data->reset(); | 184 data->reset(); |
| 185 int read_count = file_util::ReadFile(file_path, buffer.get(), size); | 185 int read_count = file_util::ReadFile(file_path, buffer.get(), size); |
| 186 if (read_count == -1) | 186 if (read_count == -1) |
| 187 return false; | 187 return false; |
| 188 DCHECK(read_count == size); | 188 DCHECK(read_count == size); |
| 189 data->assign(buffer.get(), size); | 189 data->assign(buffer.get(), size); |
| 190 | 190 |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| OLD | NEW |