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 pending_loaders_.erase(loader); |
112 DCHECK(iter != pending_loaders_.end()); | |
113 pending_loaders_.erase(iter); | |
114 } | 112 } |
115 | 113 |
116 WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( | 114 WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( |
117 WebURLLoader* default_loader) { | 115 WebURLLoader* default_loader) { |
118 DCHECK(default_loader); | 116 DCHECK(default_loader); |
119 return new WebURLLoaderMock(this, default_loader); | 117 return new WebURLLoaderMock(this, default_loader); |
120 } | 118 } |
121 | 119 |
122 void WebURLLoaderMockFactory::LoadSynchronously(const WebURLRequest& request, | 120 void WebURLLoaderMockFactory::LoadSynchronously(const WebURLRequest& request, |
123 WebURLResponse* response, | 121 WebURLResponse* response, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 } | 157 } |
160 | 158 |
161 bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { | 159 bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { |
162 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); | 160 LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); |
163 return iter != pending_loaders_.end(); | 161 return iter != pending_loaders_.end(); |
164 } | 162 } |
165 | 163 |
166 // static | 164 // static |
167 bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path, | 165 bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path, |
168 WebData* data) { | 166 WebData* data) { |
167 if (file_path.empty()) | |
sky
2015/08/26 17:52:39
This is subtle and worth a comment.
| |
168 return true; | |
169 | |
169 int64 file_size = 0; | 170 int64 file_size = 0; |
170 if (!base::GetFileSize(file_path, &file_size)) | 171 if (!base::GetFileSize(file_path, &file_size)) |
171 return false; | 172 return false; |
172 | 173 |
173 int size = static_cast<int>(file_size); | 174 int size = static_cast<int>(file_size); |
174 scoped_ptr<char[]> buffer(new char[size]); | 175 scoped_ptr<char[]> buffer(new char[size]); |
175 data->reset(); | 176 data->reset(); |
176 int read_count = base::ReadFile(file_path, buffer.get(), size); | 177 int read_count = base::ReadFile(file_path, buffer.get(), size); |
177 if (read_count == -1) | 178 if (read_count == -1) |
178 return false; | 179 return false; |
179 DCHECK(read_count == size); | 180 DCHECK(read_count == size); |
180 data->assign(buffer.get(), size); | 181 data->assign(buffer.get(), size); |
181 | 182 |
182 return true; | 183 return true; |
183 } | 184 } |
OLD | NEW |