Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: content/test/weburl_loader_mock_factory.cc

Issue 1310153003: Change WebURLLoaderMockFactory for future FOUC tests in blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments + default Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/weburl_loader_mock_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 the path is empty then we return an empty file so tests can simulate
168 // requests without needing to actually load files.
169 if (file_path.empty())
170 return true;
171
169 int64 file_size = 0; 172 int64 file_size = 0;
170 if (!base::GetFileSize(file_path, &file_size)) 173 if (!base::GetFileSize(file_path, &file_size))
171 return false; 174 return false;
172 175
173 int size = static_cast<int>(file_size); 176 int size = static_cast<int>(file_size);
174 scoped_ptr<char[]> buffer(new char[size]); 177 scoped_ptr<char[]> buffer(new char[size]);
175 data->reset(); 178 data->reset();
176 int read_count = base::ReadFile(file_path, buffer.get(), size); 179 int read_count = base::ReadFile(file_path, buffer.get(), size);
177 if (read_count == -1) 180 if (read_count == -1)
178 return false; 181 return false;
179 DCHECK(read_count == size); 182 DCHECK(read_count == size);
180 data->assign(buffer.get(), size); 183 data->assign(buffer.get(), size);
181 184
182 return true; 185 return true;
183 } 186 }
OLDNEW
« no previous file with comments | « content/test/weburl_loader_mock_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698