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

Side by Side Diff: chrome/browser/google_apis/gdata_wapi_requests_unittest.cc

Issue 16268017: GTTF: convert some tests in chrome to use EmbeddedTestServer patch nr 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // This is an initiating upload URL. 215 // This is an initiating upload URL.
216 scoped_ptr<net::test_server::BasicHttpResponse> http_response( 216 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
217 new net::test_server::BasicHttpResponse); 217 new net::test_server::BasicHttpResponse);
218 218
219 // Check an ETag. 219 // Check an ETag.
220 std::map<std::string, std::string>::const_iterator found = 220 std::map<std::string, std::string>::const_iterator found =
221 request.headers.find("If-Match"); 221 request.headers.find("If-Match");
222 if (found != request.headers.end() && 222 if (found != request.headers.end() &&
223 found->second != "*" && 223 found->second != "*" &&
224 found->second != kTestETag) { 224 found->second != kTestETag) {
225 http_response->set_code(net::test_server::PRECONDITION); 225 http_response->set_code(net::HTTP_PRECONDITION_FAILED);
226 return http_response.PassAs<net::test_server::HttpResponse>(); 226 return http_response.PassAs<net::test_server::HttpResponse>();
227 } 227 }
228 228
229 // Check if the X-Upload-Content-Length is present. If yes, store the 229 // Check if the X-Upload-Content-Length is present. If yes, store the
230 // length of the file. 230 // length of the file.
231 found = request.headers.find("X-Upload-Content-Length"); 231 found = request.headers.find("X-Upload-Content-Length");
232 if (found == request.headers.end() || 232 if (found == request.headers.end() ||
233 !base::StringToInt64(found->second, &content_length_)) { 233 !base::StringToInt64(found->second, &content_length_)) {
234 return scoped_ptr<net::test_server::HttpResponse>(); 234 return scoped_ptr<net::test_server::HttpResponse>();
235 } 235 }
236 received_bytes_ = 0; 236 received_bytes_ = 0;
237 237
238 http_response->set_code(net::test_server::SUCCESS); 238 http_response->set_code(net::HTTP_OK);
239 GURL upload_url; 239 GURL upload_url;
240 // POST is used for a new file, and PUT is used for an existing file. 240 // POST is used for a new file, and PUT is used for an existing file.
241 if (request.method == net::test_server::METHOD_POST) { 241 if (request.method == net::test_server::METHOD_POST) {
242 upload_url = test_server_.GetURL("/upload_new_file"); 242 upload_url = test_server_.GetURL("/upload_new_file");
243 } else if (request.method == net::test_server::METHOD_PUT) { 243 } else if (request.method == net::test_server::METHOD_PUT) {
244 upload_url = test_server_.GetURL("/upload_existing_file"); 244 upload_url = test_server_.GetURL("/upload_existing_file");
245 } else { 245 } else {
246 return scoped_ptr<net::test_server::HttpResponse>(); 246 return scoped_ptr<net::test_server::HttpResponse>();
247 } 247 }
248 http_response->AddCustomHeader("Location", upload_url.spec()); 248 http_response->AddCustomHeader("Location", upload_url.spec());
(...skipping 15 matching lines...) Expand all
264 } 264 }
265 265
266 // TODO(satorux): We should create a correct JSON data for the uploaded 266 // TODO(satorux): We should create a correct JSON data for the uploaded
267 // file, but for now, just return file_entry.json. 267 // file, but for now, just return file_entry.json.
268 scoped_ptr<net::test_server::BasicHttpResponse> response = 268 scoped_ptr<net::test_server::BasicHttpResponse> response =
269 test_util::CreateHttpResponseFromFile( 269 test_util::CreateHttpResponseFromFile(
270 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); 270 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"));
271 // response.code() is set to SUCCESS. Change it to CREATED if it's a new 271 // response.code() is set to SUCCESS. Change it to CREATED if it's a new
272 // file. 272 // file.
273 if (absolute_url.path() == "/upload_new_file") 273 if (absolute_url.path() == "/upload_new_file")
274 response->set_code(net::test_server::CREATED); 274 response->set_code(net::HTTP_CREATED);
275 275
276 // Check if the Content-Range header is present. This must be present if 276 // Check if the Content-Range header is present. This must be present if
277 // the request body is not empty. 277 // the request body is not empty.
278 if (!request.content.empty()) { 278 if (!request.content.empty()) {
279 std::map<std::string, std::string>::const_iterator iter = 279 std::map<std::string, std::string>::const_iterator iter =
280 request.headers.find("Content-Range"); 280 request.headers.find("Content-Range");
281 if (iter == request.headers.end()) 281 if (iter == request.headers.end())
282 return scoped_ptr<net::test_server::HttpResponse>(); 282 return scoped_ptr<net::test_server::HttpResponse>();
283 int64 length = 0; 283 int64 length = 0;
284 int64 start_position = 0; 284 int64 start_position = 0;
(...skipping 14 matching lines...) Expand all
299 // Content-Range header in the request. 299 // Content-Range header in the request.
300 // The header is annotated only when at least one byte is received. 300 // The header is annotated only when at least one byte is received.
301 if (received_bytes_ > 0) { 301 if (received_bytes_ > 0) {
302 response->AddCustomHeader( 302 response->AddCustomHeader(
303 "Range", 303 "Range",
304 "bytes=0-" + base::Int64ToString(received_bytes_ - 1)); 304 "bytes=0-" + base::Int64ToString(received_bytes_ - 1));
305 } 305 }
306 306
307 // Change the code to RESUME_INCOMPLETE if upload is not complete. 307 // Change the code to RESUME_INCOMPLETE if upload is not complete.
308 if (received_bytes_ < content_length_) 308 if (received_bytes_ < content_length_)
309 response->set_code(net::test_server::RESUME_INCOMPLETE); 309 response->set_code(static_cast<net::HttpStatusCode>(308));
310 310
311 return response.PassAs<net::test_server::HttpResponse>(); 311 return response.PassAs<net::test_server::HttpResponse>();
312 } 312 }
313 313
314 content::TestBrowserThreadBundle thread_bundle_; 314 content::TestBrowserThreadBundle thread_bundle_;
315 net::test_server::EmbeddedTestServer test_server_; 315 net::test_server::EmbeddedTestServer test_server_;
316 scoped_ptr<TestingProfile> profile_; 316 scoped_ptr<TestingProfile> profile_;
317 scoped_ptr<RequestSender> request_sender_; 317 scoped_ptr<RequestSender> request_sender_;
318 scoped_ptr<GDataWapiUrlGenerator> url_generator_; 318 scoped_ptr<GDataWapiUrlGenerator> url_generator_;
319 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; 319 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1566 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1567 http_request_.headers["X-Upload-Content-Length"]); 1567 http_request_.headers["X-Upload-Content-Length"]);
1568 // For updating an existing file, an empty body should be attached (PUT 1568 // For updating an existing file, an empty body should be attached (PUT
1569 // requires a body) 1569 // requires a body)
1570 EXPECT_TRUE(http_request_.has_content); 1570 EXPECT_TRUE(http_request_.has_content);
1571 EXPECT_EQ("", http_request_.content); 1571 EXPECT_EQ("", http_request_.content);
1572 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); 1572 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]);
1573 } 1573 }
1574 1574
1575 } // namespace google_apis 1575 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_requests_unittest.cc ('k') | chrome/browser/google_apis/test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698