OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net/url_request_mock_http_job.h" | 5 #include "content/test/net/url_request_mock_http_job.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // Private const version. | 137 // Private const version. |
138 void URLRequestMockHTTPJob::GetResponseInfoConst( | 138 void URLRequestMockHTTPJob::GetResponseInfoConst( |
139 net::HttpResponseInfo* info) const { | 139 net::HttpResponseInfo* info) const { |
140 // We have to load our headers from disk, but we only use this class | 140 // We have to load our headers from disk, but we only use this class |
141 // from tests, so allow these IO operations to happen on any thread. | 141 // from tests, so allow these IO operations to happen on any thread. |
142 base::ThreadRestrictions::ScopedAllowIO allow_io; | 142 base::ThreadRestrictions::ScopedAllowIO allow_io; |
143 | 143 |
144 base::FilePath header_file = | 144 base::FilePath header_file = |
145 base::FilePath(file_path_.value() + kMockHeaderFileSuffix); | 145 base::FilePath(file_path_.value() + kMockHeaderFileSuffix); |
146 std::string raw_headers; | 146 std::string raw_headers; |
147 if (!file_util::ReadFileToString(header_file, &raw_headers)) | 147 if (!base::ReadFileToString(header_file, &raw_headers)) |
148 return; | 148 return; |
149 | 149 |
150 // ParseRawHeaders expects \0 to end each header line. | 150 // ParseRawHeaders expects \0 to end each header line. |
151 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 151 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); |
152 info->headers = new net::HttpResponseHeaders(raw_headers); | 152 info->headers = new net::HttpResponseHeaders(raw_headers); |
153 } | 153 } |
154 | 154 |
155 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { | 155 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { |
156 net::HttpResponseInfo info; | 156 net::HttpResponseInfo info; |
157 GetResponseInfoConst(&info); | 157 GetResponseInfoConst(&info); |
158 return info.headers.get() && info.headers->GetMimeType(mime_type); | 158 return info.headers.get() && info.headers->GetMimeType(mime_type); |
159 } | 159 } |
160 | 160 |
161 int URLRequestMockHTTPJob::GetResponseCode() const { | 161 int URLRequestMockHTTPJob::GetResponseCode() const { |
162 net::HttpResponseInfo info; | 162 net::HttpResponseInfo info; |
163 GetResponseInfoConst(&info); | 163 GetResponseInfoConst(&info); |
164 // If we have headers, get the response code from them. | 164 // If we have headers, get the response code from them. |
165 if (info.headers.get()) | 165 if (info.headers.get()) |
166 return info.headers->response_code(); | 166 return info.headers->response_code(); |
167 return net::URLRequestJob::GetResponseCode(); | 167 return net::URLRequestJob::GetResponseCode(); |
168 } | 168 } |
169 | 169 |
170 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { | 170 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { |
171 net::HttpResponseInfo info; | 171 net::HttpResponseInfo info; |
172 GetResponseInfo(&info); | 172 GetResponseInfo(&info); |
173 return info.headers.get() && info.headers->GetCharset(charset); | 173 return info.headers.get() && info.headers->GetCharset(charset); |
174 } | 174 } |
175 | 175 |
176 } // namespace content | 176 } // namespace content |
OLD | NEW |