summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 20:28:14 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 20:28:14 +0000
commit3db327abf6043d9a2a6a2f2213917bb4d33e212a (patch)
tree44263c4c93bf111424c5bc24020de099627d75de /chrome/browser/net
parent70b48bff644ad239eb636729104d53fd5dea6604 (diff)
downloadchromium_src-3db327abf6043d9a2a6a2f2213917bb4d33e212a.zip
chromium_src-3db327abf6043d9a2a6a2f2213917bb4d33e212a.tar.gz
chromium_src-3db327abf6043d9a2a6a2f2213917bb4d33e212a.tar.bz2
mock url tests: be more careful about string handling in URLs
BUG=69467 Review URL: http://codereview.chromium.org/6612018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76794 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r--chrome/browser/net/url_request_mock_http_job.cc17
-rw-r--r--chrome/browser/net/url_request_slow_http_job.cc4
2 files changed, 13 insertions, 8 deletions
diff --git a/chrome/browser/net/url_request_mock_http_job.cc b/chrome/browser/net/url_request_mock_http_job.cc
index 36113085..2b2ba96 100644
--- a/chrome/browser/net/url_request_mock_http_job.cc
+++ b/chrome/browser/net/url_request_mock_http_job.cc
@@ -42,7 +42,9 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const FilePath& path) {
std::string url = "http://";
url.append(kMockHostname);
url.append("/");
- url.append(WideToUTF8(path.ToWStringHack()));
+ std::string path_str = path.MaybeAsASCII();
+ DCHECK(!path_str.empty()); // We only expect ASCII paths in tests.
+ url.append(path_str);
return GURL(url);
}
@@ -58,13 +60,14 @@ GURL URLRequestMockHTTPJob::GetMockViewSourceUrl(const FilePath& path) {
FilePath URLRequestMockHTTPJob::GetOnDiskPath(const FilePath& base_path,
net::URLRequest* request,
const std::string& scheme) {
- std::string file_url("file:///");
- file_url += WideToUTF8(base_path.ToWStringHack());
- file_url += request->url().path();
-
- // Convert the file:/// URL to a path on disk.
+ // Conceptually we just want to "return base_path + request->url().path()".
+ // But path in the request URL is in URL space (i.e. %-encoded spaces).
+ // So first we convert base FilePath to a URL, then append the URL
+ // path to that, and convert the final URL back to a FilePath.
+ GURL file_url(net::FilePathToFileURL(base_path));
+ std::string url = file_url.spec() + request->url().path();
FilePath file_path;
- net::FileURLToFilePath(GURL(file_url), &file_path);
+ net::FileURLToFilePath(GURL(url), &file_path);
return file_path;
}
diff --git a/chrome/browser/net/url_request_slow_http_job.cc b/chrome/browser/net/url_request_slow_http_job.cc
index 04a24f9..f4c69cf 100644
--- a/chrome/browser/net/url_request_slow_http_job.cc
+++ b/chrome/browser/net/url_request_slow_http_job.cc
@@ -39,7 +39,9 @@ GURL URLRequestSlowHTTPJob::GetMockUrl(const FilePath& path) {
std::string url = "http://";
url.append(kMockHostname);
url.append("/");
- url.append(WideToUTF8(path.ToWStringHack()));
+ std::string path_str = path.MaybeAsASCII();
+ DCHECK(!path_str.empty()); // We only expect ASCII paths in tests.
+ url.append(path_str);
return GURL(url);
}