Chromium Code Reviews| 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/files/file_util.h" | 7 #include "base/files/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/weburl_loader_mock.h" | 10 #include "content/test/weburl_loader_mock.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 pending_loaders_.erase(loader); | 101 pending_loaders_.erase(loader); |
| 102 } | 102 } |
| 103 base::RunLoop().RunUntilIdle(); | 103 base::RunLoop().RunUntilIdle(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool WebURLLoaderMockFactory::IsMockedURL(const blink::WebURL& url) { | 106 bool WebURLLoaderMockFactory::IsMockedURL(const blink::WebURL& url) { |
| 107 return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); | 107 return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void WebURLLoaderMockFactory::CancelLoad(WebURLLoaderMock* loader) { | 110 void WebURLLoaderMockFactory::CancelLoad(WebURLLoaderMock* loader) { |
| 111 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); | 111 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); |
|
dcheng
2015/08/26 15:38:18
How about just replacing the entire body with pend
esprehn
2015/08/26 16:01:40
Done.
| |
| 112 DCHECK(iter != pending_loaders_.end()); | 112 if (iter == pending_loaders_.end()) |
| 113 return; | |
| 113 pending_loaders_.erase(iter); | 114 pending_loaders_.erase(iter); |
| 114 } | 115 } |
| 115 | 116 |
| 116 WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( | 117 WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( |
| 117 WebURLLoader* default_loader) { | 118 WebURLLoader* default_loader) { |
| 118 DCHECK(default_loader); | 119 DCHECK(default_loader); |
| 119 return new WebURLLoaderMock(this, default_loader); | 120 return new WebURLLoaderMock(this, default_loader); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void WebURLLoaderMockFactory::LoadSynchronously(const WebURLRequest& request, | 123 void WebURLLoaderMockFactory::LoadSynchronously(const WebURLRequest& request, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { | 162 bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { |
| 162 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); | 163 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); |
| 163 return iter != pending_loaders_.end(); | 164 return iter != pending_loaders_.end(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // static | 167 // static |
| 167 bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path, | 168 bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path, |
| 168 WebData* data) { | 169 WebData* data) { |
| 170 if (file_path.empty()) | |
| 171 return true; | |
| 172 | |
| 169 int64 file_size = 0; | 173 int64 file_size = 0; |
| 170 if (!base::GetFileSize(file_path, &file_size)) | 174 if (!base::GetFileSize(file_path, &file_size)) |
| 171 return false; | 175 return false; |
| 172 | 176 |
| 173 int size = static_cast<int>(file_size); | 177 int size = static_cast<int>(file_size); |
| 174 scoped_ptr<char[]> buffer(new char[size]); | 178 scoped_ptr<char[]> buffer(new char[size]); |
| 175 data->reset(); | 179 data->reset(); |
| 176 int read_count = base::ReadFile(file_path, buffer.get(), size); | 180 int read_count = base::ReadFile(file_path, buffer.get(), size); |
| 177 if (read_count == -1) | 181 if (read_count == -1) |
| 178 return false; | 182 return false; |
| 179 DCHECK(read_count == size); | 183 DCHECK(read_count == size); |
| 180 data->assign(buffer.get(), size); | 184 data->assign(buffer.get(), size); |
| 181 | 185 |
| 182 return true; | 186 return true; |
| 183 } | 187 } |
| OLD | NEW |