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

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

Issue 1686263008: Add utility method for WebString to base::FilePath conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase! Created 4 years, 10 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "content/test/weburl_loader_mock.h" 13 #include "content/test/weburl_loader_mock.h"
14 #include "third_party/WebKit/public/platform/FilePathConversion.h"
14 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebURLError.h" 16 #include "third_party/WebKit/public/platform/WebURLError.h"
16 #include "third_party/WebKit/public/platform/WebURLRequest.h" 17 #include "third_party/WebKit/public/platform/WebURLRequest.h"
17 #include "third_party/WebKit/public/platform/WebURLResponse.h" 18 #include "third_party/WebKit/public/platform/WebURLResponse.h"
18 #include "third_party/WebKit/public/web/WebCache.h" 19 #include "third_party/WebKit/public/web/WebCache.h"
19 20
20 using blink::WebCache; 21 using blink::WebCache;
21 using blink::WebData; 22 using blink::WebData;
22 using blink::WebString; 23 using blink::WebString;
23 using blink::WebURL; 24 using blink::WebURL;
24 using blink::WebURLError; 25 using blink::WebURLError;
25 using blink::WebURLLoader; 26 using blink::WebURLLoader;
26 using blink::WebURLRequest; 27 using blink::WebURLRequest;
27 using blink::WebURLResponse; 28 using blink::WebURLResponse;
28 29
29 WebURLLoaderMockFactory::WebURLLoaderMockFactory() : delegate_(nullptr) {} 30 WebURLLoaderMockFactory::WebURLLoaderMockFactory() : delegate_(nullptr) {}
30 31
31 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} 32 WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {}
32 33
33 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, 34 void WebURLLoaderMockFactory::RegisterURL(const WebURL& url,
34 const WebURLResponse& response, 35 const WebURLResponse& response,
35 const WebString& file_path) { 36 const WebString& file_path) {
36 ResponseInfo response_info; 37 ResponseInfo response_info;
37 response_info.response = response; 38 response_info.response = response;
38 if (!file_path.isNull() && !file_path.isEmpty()) { 39 if (!file_path.isNull() && !file_path.isEmpty()) {
39 #if defined(OS_POSIX) 40 response_info.file_path = blink::WebStringToFilePath(file_path);
40 // TODO(jcivelli): On Linux, UTF8 might not be correct.
41 response_info.file_path =
42 base::FilePath(static_cast<std::string>(file_path.utf8()));
43 #elif defined(OS_WIN)
44 base::string16 file_path_16 = file_path;
45 response_info.file_path = base::FilePath(std::wstring(
46 file_path_16.data(), file_path_16.length()));
47 #endif
48 DCHECK(base::PathExists(response_info.file_path)) 41 DCHECK(base::PathExists(response_info.file_path))
49 << response_info.file_path.MaybeAsASCII() << " does not exist."; 42 << response_info.file_path.MaybeAsASCII() << " does not exist.";
50 } 43 }
51 44
52 DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); 45 DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end());
53 url_to_reponse_info_[url] = response_info; 46 url_to_reponse_info_[url] = response_info;
54 } 47 }
55 48
56 49
57 void WebURLLoaderMockFactory::RegisterErrorURL(const WebURL& url, 50 void WebURLLoaderMockFactory::RegisterErrorURL(const WebURL& url,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 scoped_ptr<char[]> buffer(new char[size]); 173 scoped_ptr<char[]> buffer(new char[size]);
181 data->reset(); 174 data->reset();
182 int read_count = base::ReadFile(file_path, buffer.get(), size); 175 int read_count = base::ReadFile(file_path, buffer.get(), size);
183 if (read_count == -1) 176 if (read_count == -1)
184 return false; 177 return false;
185 DCHECK(read_count == size); 178 DCHECK(read_count == size);
186 data->assign(buffer.get(), size); 179 data->assign(buffer.get(), size);
187 180
188 return true; 181 return true;
189 } 182 }
OLDNEW
« no previous file with comments | « content/shell/renderer/layout_test/blink_test_runner.cc ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698