Fix build break
[chromium-blink-merge.git] / chrome / browser / google_apis / drive_api_operations_unittest.cc
blob834f487d1c3e3b1463c1679d2e85589b97da3b94
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/files/file_path.h"
7 #include "base/message_loop_proxy.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/google_apis/drive_api_operations.h"
11 #include "chrome/browser/google_apis/drive_api_parser.h"
12 #include "chrome/browser/google_apis/drive_api_url_generator.h"
13 #include "chrome/browser/google_apis/operation_registry.h"
14 #include "chrome/browser/google_apis/task_util.h"
15 #include "chrome/browser/google_apis/test_server/http_request.h"
16 #include "chrome/browser/google_apis/test_server/http_response.h"
17 #include "chrome/browser/google_apis/test_server/http_server.h"
18 #include "chrome/browser/google_apis/test_util.h"
19 #include "content/public/test/test_browser_thread.h"
20 #include "net/url_request/url_request_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h"
23 namespace google_apis {
25 namespace {
27 const char kTestDriveApiAuthToken[] = "testtoken";
28 const char kTestETag[] = "test_etag";
29 const char kTestUserAgent[] = "test-user-agent";
31 const char kTestChildrenResponse[] =
32 "{\n"
33 "\"kind\": \"drive#childReference\",\n"
34 "\"id\": \"resource_id\",\n"
35 "\"selfLink\": \"self_link\",\n"
36 "\"childLink\": \"child_link\",\n"
37 "}\n";
39 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path";
40 const char kTestUploadNewFilePath[] = "/upload/newfile/path";
42 } // namespace
44 class DriveApiOperationsTest : public testing::Test {
45 public:
46 DriveApiOperationsTest()
47 : ui_thread_(content::BrowserThread::UI, &message_loop_),
48 file_thread_(content::BrowserThread::FILE),
49 io_thread_(content::BrowserThread::IO) {
52 virtual void SetUp() OVERRIDE {
53 file_thread_.Start();
54 io_thread_.StartIOThread();
56 request_context_getter_ = new net::TestURLRequestContextGetter(
57 content::BrowserThread::GetMessageLoopProxyForThread(
58 content::BrowserThread::IO));
60 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
61 test_server_.RegisterRequestHandler(
62 base::Bind(&DriveApiOperationsTest::HandleChildrenDeleteRequest,
63 base::Unretained(this)));
64 test_server_.RegisterRequestHandler(
65 base::Bind(&DriveApiOperationsTest::HandleDataFileRequest,
66 base::Unretained(this)));
67 test_server_.RegisterRequestHandler(
68 base::Bind(&DriveApiOperationsTest::HandleResumeUploadRequest,
69 base::Unretained(this)));
70 test_server_.RegisterRequestHandler(
71 base::Bind(&DriveApiOperationsTest::HandleInitiateUploadRequest,
72 base::Unretained(this)));
73 test_server_.RegisterRequestHandler(
74 base::Bind(&DriveApiOperationsTest::HandleContentResponse,
75 base::Unretained(this)));
77 url_generator_.reset(new DriveApiUrlGenerator(
78 test_util::GetBaseUrlForTesting(test_server_.port())));
80 // Reset the server's expected behavior just in case.
81 ResetExpectedResponse();
82 received_bytes_ = 0;
83 content_length_ = 0;
86 virtual void TearDown() OVERRIDE {
87 test_server_.ShutdownAndWaitUntilComplete();
88 request_context_getter_ = NULL;
89 ResetExpectedResponse();
92 MessageLoopForUI message_loop_;
93 content::TestBrowserThread ui_thread_;
94 content::TestBrowserThread file_thread_;
95 content::TestBrowserThread io_thread_;
96 test_server::HttpServer test_server_;
97 OperationRegistry operation_registry_;
98 scoped_ptr<DriveApiUrlGenerator> url_generator_;
99 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
101 // This is a path to the file which contains expected response from
102 // the server. See also HandleDataFileRequest below.
103 base::FilePath expected_data_file_path_;
105 // This is a path string in the expected response header from the server
106 // for initiating file uploading.
107 std::string expected_upload_path_;
109 // These are content and its type in the expected response from the server.
110 // See also HandleContentResponse below.
111 std::string expected_content_type_;
112 std::string expected_content_;
114 // The incoming HTTP request is saved so tests can verify the request
115 // parameters like HTTP method (ex. some operations should use DELETE
116 // instead of GET).
117 test_server::HttpRequest http_request_;
119 private:
120 void ResetExpectedResponse() {
121 expected_data_file_path_.clear();
122 expected_upload_path_.clear();
123 expected_content_type_.clear();
124 expected_content_.clear();
127 // For "Children: delete" request, the server will return "204 No Content"
128 // response meaning "success".
129 scoped_ptr<test_server::HttpResponse> HandleChildrenDeleteRequest(
130 const test_server::HttpRequest& request) {
131 if (request.method != test_server::METHOD_DELETE ||
132 request.relative_url.find("/children/") == string::npos) {
133 // The request is not the "Children: delete" operation. Delegate the
134 // processing to the next handler.
135 return scoped_ptr<test_server::HttpResponse>();
138 http_request_ = request;
140 // Return the response with just "204 No Content" status code.
141 scoped_ptr<test_server::HttpResponse> http_response(
142 new test_server::HttpResponse);
143 http_response->set_code(test_server::NO_CONTENT);
144 return http_response.Pass();
147 // Reads the data file of |expected_data_file_path_| and returns its content
148 // for the request.
149 // To use this method, it is necessary to set |expected_data_file_path_|
150 // to the appropriate file path before sending the request to the server.
151 scoped_ptr<test_server::HttpResponse> HandleDataFileRequest(
152 const test_server::HttpRequest& request) {
153 if (expected_data_file_path_.empty()) {
154 // The file is not specified. Delegate the processing to the next
155 // handler.
156 return scoped_ptr<test_server::HttpResponse>();
159 http_request_ = request;
161 // Return the response from the data file.
162 return test_util::CreateHttpResponseFromFile(expected_data_file_path_);
165 // Returns the response based on set expected upload url.
166 // The response contains the url in its "Location: " header. Also, it doesn't
167 // have any content.
168 // To use this method, it is necessary to set |expected_upload_path_|
169 // to the string representation of the url to be returned.
170 scoped_ptr<test_server::HttpResponse> HandleInitiateUploadRequest(
171 const test_server::HttpRequest& request) {
172 if (request.relative_url == expected_upload_path_ ||
173 expected_upload_path_.empty()) {
174 // The request is for resume uploading or the expected upload url is not
175 // set. Delegate the processing to the next handler.
176 return scoped_ptr<test_server::HttpResponse>();
179 http_request_ = request;
181 scoped_ptr<test_server::HttpResponse> response(
182 new test_server::HttpResponse);
184 // Check an ETag.
185 std::map<std::string, std::string>::const_iterator found =
186 request.headers.find("If-Match");
187 if (found != request.headers.end() &&
188 found->second != "*" &&
189 found->second != kTestETag) {
190 response->set_code(test_server::PRECONDITION);
191 return response.Pass();
194 // Check if the X-Upload-Content-Length is present. If yes, store the
195 // length of the file.
196 found = request.headers.find("X-Upload-Content-Length");
197 if (found == request.headers.end() ||
198 !base::StringToInt64(found->second, &content_length_)) {
199 return scoped_ptr<test_server::HttpResponse>();
201 received_bytes_ = 0;
203 response->set_code(test_server::SUCCESS);
204 response->AddCustomHeader(
205 "Location",
206 test_server_.base_url().Resolve(expected_upload_path_).spec());
207 return response.Pass();
210 scoped_ptr<test_server::HttpResponse> HandleResumeUploadRequest(
211 const test_server::HttpRequest& request) {
212 if (request.relative_url != expected_upload_path_) {
213 // The request path is different from the expected path for uploading.
214 // Delegate the processing to the next handler.
215 return scoped_ptr<test_server::HttpResponse>();
218 http_request_ = request;
220 if (!request.content.empty()) {
221 std::map<std::string, std::string>::const_iterator iter =
222 request.headers.find("Content-Range");
223 if (iter == request.headers.end()) {
224 // The range must be set.
225 return scoped_ptr<test_server::HttpResponse>();
228 int64 length = 0;
229 int64 start_position = 0;
230 int64 end_position = 0;
231 if (!test_util::ParseContentRangeHeader(
232 iter->second, &start_position, &end_position, &length)) {
233 // Invalid "Content-Range" value.
234 return scoped_ptr<test_server::HttpResponse>();
237 EXPECT_EQ(start_position, received_bytes_);
238 EXPECT_EQ(length, content_length_);
240 // end_position is inclusive, but so +1 to change the range to byte size.
241 received_bytes_ = end_position + 1;
244 if (received_bytes_ < content_length_) {
245 scoped_ptr<test_server::HttpResponse> response(
246 new test_server::HttpResponse);
247 // Set RESUME INCOMPLETE (308) status code.
248 response->set_code(test_server::RESUME_INCOMPLETE);
250 // Add Range header to the response, based on the values of
251 // Content-Range header in the request.
252 // The header is annotated only when at least one byte is received.
253 if (received_bytes_ > 0) {
254 response->AddCustomHeader(
255 "Range", "bytes=0-" + base::Int64ToString(received_bytes_ - 1));
258 return response.Pass();
261 // All bytes are received. Return the "success" response with the file's
262 // (dummy) metadata.
263 scoped_ptr<test_server::HttpResponse> response =
264 test_util::CreateHttpResponseFromFile(
265 test_util::GetTestFilePath("chromeos/drive/file_entry.json"));
267 // The response code is CREATED if it is new file uploading.
268 if (http_request_.relative_url == kTestUploadNewFilePath) {
269 response->set_code(test_server::CREATED);
272 return response.Pass();
275 // Returns the response based on set expected content and its type.
276 // To use this method, both |expected_content_type_| and |expected_content_|
277 // must be set in advance.
278 scoped_ptr<test_server::HttpResponse> HandleContentResponse(
279 const test_server::HttpRequest& request) {
280 if (expected_content_type_.empty() || expected_content_.empty()) {
281 // Expected content is not set. Delegate the processing to the next
282 // handler.
283 return scoped_ptr<test_server::HttpResponse>();
286 http_request_ = request;
288 scoped_ptr<test_server::HttpResponse> response(
289 new test_server::HttpResponse);
290 response->set_code(test_server::SUCCESS);
291 response->set_content_type(expected_content_type_);
292 response->set_content(expected_content_);
293 return response.Pass();
296 // These are for the current upload file status.
297 int64 received_bytes_;
298 int64 content_length_;
301 TEST_F(DriveApiOperationsTest, GetAboutOperation_ValidJson) {
302 // Set an expected data file containing valid result.
303 expected_data_file_path_ = test_util::GetTestFilePath(
304 "chromeos/drive/about.json");
306 GDataErrorCode error = GDATA_OTHER_ERROR;
307 scoped_ptr<AboutResource> about_resource;
309 GetAboutOperation* operation = new GetAboutOperation(
310 &operation_registry_,
311 request_context_getter_.get(),
312 *url_generator_,
313 CreateComposedCallback(
314 base::Bind(&test_util::RunAndQuit),
315 test_util::CreateCopyResultCallback(&error, &about_resource)));
316 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
317 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
318 MessageLoop::current()->Run();
320 EXPECT_EQ(HTTP_SUCCESS, error);
321 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
322 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
324 scoped_ptr<AboutResource> expected(
325 AboutResource::CreateFrom(
326 *test_util::LoadJSONFile("chromeos/drive/about.json")));
327 ASSERT_TRUE(about_resource.get());
328 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id());
329 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total());
330 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used());
331 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id());
334 TEST_F(DriveApiOperationsTest, GetAboutOperation_InvalidJson) {
335 // Set an expected data file containing invalid result.
336 expected_data_file_path_ = test_util::GetTestFilePath(
337 "chromeos/gdata/testfile.txt");
339 GDataErrorCode error = GDATA_OTHER_ERROR;
340 scoped_ptr<AboutResource> about_resource;
342 GetAboutOperation* operation = new GetAboutOperation(
343 &operation_registry_,
344 request_context_getter_.get(),
345 *url_generator_,
346 CreateComposedCallback(
347 base::Bind(&test_util::RunAndQuit),
348 test_util::CreateCopyResultCallback(&error, &about_resource)));
349 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
350 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
351 MessageLoop::current()->Run();
353 // "parse error" should be returned, and the about resource should be NULL.
354 EXPECT_EQ(GDATA_PARSE_ERROR, error);
355 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
356 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
357 EXPECT_FALSE(about_resource.get());
360 TEST_F(DriveApiOperationsTest, GetApplistOperation) {
361 // Set an expected data file containing valid result.
362 expected_data_file_path_ = test_util::GetTestFilePath(
363 "chromeos/drive/applist.json");
365 GDataErrorCode error = GDATA_OTHER_ERROR;
366 scoped_ptr<base::Value> result;
368 GetApplistOperation* operation = new GetApplistOperation(
369 &operation_registry_,
370 request_context_getter_.get(),
371 *url_generator_,
372 CreateComposedCallback(
373 base::Bind(&test_util::RunAndQuit),
374 test_util::CreateCopyResultCallback(&error, &result)));
375 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
376 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
377 MessageLoop::current()->Run();
379 EXPECT_EQ(HTTP_SUCCESS, error);
380 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
381 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url);
382 EXPECT_TRUE(result);
385 TEST_F(DriveApiOperationsTest, GetChangelistOperation) {
386 // Set an expected data file containing valid result.
387 expected_data_file_path_ = test_util::GetTestFilePath(
388 "chromeos/drive/changelist.json");
390 GDataErrorCode error = GDATA_OTHER_ERROR;
391 scoped_ptr<base::Value> result;
393 GetChangelistOperation* operation = new GetChangelistOperation(
394 &operation_registry_,
395 request_context_getter_.get(),
396 *url_generator_,
397 true, // include deleted
398 100, // start changestamp
399 CreateComposedCallback(
400 base::Bind(&test_util::RunAndQuit),
401 test_util::CreateCopyResultCallback(&error, &result)));
402 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
403 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
404 MessageLoop::current()->Run();
406 EXPECT_EQ(HTTP_SUCCESS, error);
407 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
408 EXPECT_EQ("/drive/v2/changes?startChangeId=100", http_request_.relative_url);
409 EXPECT_TRUE(result);
412 TEST_F(DriveApiOperationsTest, GetFilelistOperation) {
413 // Set an expected data file containing valid result.
414 expected_data_file_path_ = test_util::GetTestFilePath(
415 "chromeos/drive/filelist.json");
417 GDataErrorCode error = GDATA_OTHER_ERROR;
418 scoped_ptr<base::Value> result;
420 GetFilelistOperation* operation = new GetFilelistOperation(
421 &operation_registry_,
422 request_context_getter_.get(),
423 *url_generator_,
424 "\"abcde\" in parents",
425 CreateComposedCallback(
426 base::Bind(&test_util::RunAndQuit),
427 test_util::CreateCopyResultCallback(&error, &result)));
428 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
429 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
430 MessageLoop::current()->Run();
432 EXPECT_EQ(HTTP_SUCCESS, error);
433 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
434 EXPECT_EQ("/drive/v2/files?q=%22abcde%22+in+parents",
435 http_request_.relative_url);
436 EXPECT_TRUE(result);
439 TEST_F(DriveApiOperationsTest, ContinueGetFileListOperation) {
440 // Set an expected data file containing valid result.
441 expected_data_file_path_ = test_util::GetTestFilePath(
442 "chromeos/drive/filelist.json");
444 GDataErrorCode error = GDATA_OTHER_ERROR;
445 scoped_ptr<base::Value> result;
447 drive::ContinueGetFileListOperation* operation =
448 new drive::ContinueGetFileListOperation(
449 &operation_registry_,
450 request_context_getter_.get(),
451 test_server_.GetURL("/continue/get/file/list"),
452 CreateComposedCallback(
453 base::Bind(&test_util::RunAndQuit),
454 test_util::CreateCopyResultCallback(&error, &result)));
455 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
456 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
457 MessageLoop::current()->Run();
459 EXPECT_EQ(HTTP_SUCCESS, error);
460 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
461 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url);
462 EXPECT_TRUE(result);
465 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) {
466 // Set an expected data file containing the directory's entry data.
467 expected_data_file_path_ =
468 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
470 GDataErrorCode error = GDATA_OTHER_ERROR;
471 scoped_ptr<FileResource> file_resource;
473 // Create "new directory" in the root directory.
474 drive::CreateDirectoryOperation* operation =
475 new drive::CreateDirectoryOperation(
476 &operation_registry_,
477 request_context_getter_.get(),
478 *url_generator_,
479 "root",
480 "new directory",
481 CreateComposedCallback(
482 base::Bind(&test_util::RunAndQuit),
483 test_util::CreateCopyResultCallback(&error, &file_resource)));
484 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
485 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
486 MessageLoop::current()->Run();
488 EXPECT_EQ(HTTP_SUCCESS, error);
489 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
490 EXPECT_EQ("/drive/v2/files", http_request_.relative_url);
491 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
493 EXPECT_TRUE(http_request_.has_content);
495 scoped_ptr<FileResource> expected(
496 FileResource::CreateFrom(
497 *test_util::LoadJSONFile("chromeos/drive/directory_entry.json")));
499 // Sanity check.
500 ASSERT_TRUE(file_resource.get());
502 EXPECT_EQ(expected->file_id(), file_resource->file_id());
503 EXPECT_EQ(expected->title(), file_resource->title());
504 EXPECT_EQ(expected->mime_type(), file_resource->mime_type());
505 EXPECT_EQ(expected->parents().size(), file_resource->parents().size());
508 TEST_F(DriveApiOperationsTest, RenameResourceOperation) {
509 // Set an expected data file containing the directory's entry data.
510 // It'd be returned if we rename a directory.
511 expected_data_file_path_ =
512 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
514 GDataErrorCode error = GDATA_OTHER_ERROR;
516 // Create "new directory" in the root directory.
517 drive::RenameResourceOperation* operation =
518 new drive::RenameResourceOperation(
519 &operation_registry_,
520 request_context_getter_.get(),
521 *url_generator_,
522 "resource_id",
523 "new name",
524 CreateComposedCallback(
525 base::Bind(&test_util::RunAndQuit),
526 test_util::CreateCopyResultCallback(&error)));
527 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
528 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
529 MessageLoop::current()->Run();
531 EXPECT_EQ(HTTP_SUCCESS, error);
532 EXPECT_EQ(test_server::METHOD_PATCH, http_request_.method);
533 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url);
534 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
536 EXPECT_TRUE(http_request_.has_content);
537 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content);
540 TEST_F(DriveApiOperationsTest, CopyResourceOperation) {
541 // Set an expected data file containing the dummy file entry data.
542 // It'd be returned if we copy a file.
543 expected_data_file_path_ =
544 test_util::GetTestFilePath("chromeos/drive/file_entry.json");
546 GDataErrorCode error = GDATA_OTHER_ERROR;
547 scoped_ptr<FileResource> file_resource;
549 // Copy the file to a new file named "new name".
550 drive::CopyResourceOperation* operation =
551 new drive::CopyResourceOperation(
552 &operation_registry_,
553 request_context_getter_.get(),
554 *url_generator_,
555 "resource_id",
556 "new name",
557 CreateComposedCallback(
558 base::Bind(&test_util::RunAndQuit),
559 test_util::CreateCopyResultCallback(&error, &file_resource)));
560 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
561 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
562 MessageLoop::current()->Run();
564 EXPECT_EQ(HTTP_SUCCESS, error);
565 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
566 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url);
567 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
569 EXPECT_TRUE(http_request_.has_content);
570 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content);
571 EXPECT_TRUE(file_resource);
574 TEST_F(DriveApiOperationsTest, TrashResourceOperation) {
575 // Set data for the expected result. Directory entry should be returned
576 // if the trashing entry is a directory, so using it here should be fine.
577 expected_data_file_path_ =
578 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
580 GDataErrorCode error = GDATA_OTHER_ERROR;
582 // Trash a resource with the given resource id.
583 drive::TrashResourceOperation* operation =
584 new drive::TrashResourceOperation(
585 &operation_registry_,
586 request_context_getter_.get(),
587 *url_generator_,
588 "resource_id",
589 CreateComposedCallback(
590 base::Bind(&test_util::RunAndQuit),
591 test_util::CreateCopyResultCallback(&error)));
592 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
593 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
594 MessageLoop::current()->Run();
596 EXPECT_EQ(HTTP_SUCCESS, error);
597 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
598 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url);
599 EXPECT_TRUE(http_request_.has_content);
600 EXPECT_TRUE(http_request_.content.empty());
603 TEST_F(DriveApiOperationsTest, InsertResourceOperation) {
604 // Set an expected data file containing the children entry.
605 expected_content_type_ = "application/json";
606 expected_content_ = kTestChildrenResponse;
608 GDataErrorCode error = GDATA_OTHER_ERROR;
610 // Add a resource with "resource_id" to a directory with
611 // "parent_resource_id".
612 drive::InsertResourceOperation* operation =
613 new drive::InsertResourceOperation(
614 &operation_registry_,
615 request_context_getter_.get(),
616 *url_generator_,
617 "parent_resource_id",
618 "resource_id",
619 CreateComposedCallback(
620 base::Bind(&test_util::RunAndQuit),
621 test_util::CreateCopyResultCallback(&error)));
622 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
623 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
624 MessageLoop::current()->Run();
626 EXPECT_EQ(HTTP_SUCCESS, error);
627 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
628 EXPECT_EQ("/drive/v2/files/parent_resource_id/children",
629 http_request_.relative_url);
630 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
632 EXPECT_TRUE(http_request_.has_content);
633 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content);
636 TEST_F(DriveApiOperationsTest, DeleteResourceOperation) {
637 GDataErrorCode error = GDATA_OTHER_ERROR;
639 // Remove a resource with "resource_id" from a directory with
640 // "parent_resource_id".
641 drive::DeleteResourceOperation* operation =
642 new drive::DeleteResourceOperation(
643 &operation_registry_,
644 request_context_getter_.get(),
645 *url_generator_,
646 "parent_resource_id",
647 "resource_id",
648 CreateComposedCallback(
649 base::Bind(&test_util::RunAndQuit),
650 test_util::CreateCopyResultCallback(&error)));
651 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
652 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
653 MessageLoop::current()->Run();
655 EXPECT_EQ(HTTP_NO_CONTENT, error);
656 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method);
657 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id",
658 http_request_.relative_url);
659 EXPECT_FALSE(http_request_.has_content);
662 TEST_F(DriveApiOperationsTest, UploadNewFileOperation) {
663 // Set an expected url for uploading.
664 expected_upload_path_ = kTestUploadNewFilePath;
666 const char kTestContentType[] = "text/plain";
667 const std::string kTestContent(100, 'a');
669 GDataErrorCode error = GDATA_OTHER_ERROR;
670 GURL upload_url;
672 // 1) Initiate uploading a new file to the directory with
673 // "parent_resource_id".
674 drive::InitiateUploadNewFileOperation* operation =
675 new drive::InitiateUploadNewFileOperation(
676 &operation_registry_,
677 request_context_getter_.get(),
678 *url_generator_,
679 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
680 kTestContentType,
681 kTestContent.size(),
682 "parent_resource_id", // The resource id of the parent directory.
683 "new file title", // The title of the file being uploaded.
684 CreateComposedCallback(
685 base::Bind(&test_util::RunAndQuit),
686 test_util::CreateCopyResultCallback(&error, &upload_url)));
687 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
688 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
689 MessageLoop::current()->Run();
691 EXPECT_EQ(HTTP_SUCCESS, error);
692 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
693 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
694 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
695 http_request_.headers["X-Upload-Content-Length"]);
697 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
698 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
699 http_request_.relative_url);
700 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
701 EXPECT_TRUE(http_request_.has_content);
702 EXPECT_EQ("{\"parents\":[{"
703 "\"id\":\"parent_resource_id\","
704 "\"kind\":\"drive#fileLink\""
705 "}],"
706 "\"title\":\"new file title\"}",
707 http_request_.content);
709 // 2) Upload the content to the upload URL.
710 scoped_refptr<net::IOBuffer> buffer = new net::StringIOBuffer(kTestContent);
712 UploadRangeResponse response;
713 scoped_ptr<FileResource> new_entry;
715 drive::ResumeUploadOperation* resume_operation =
716 new drive::ResumeUploadOperation(
717 &operation_registry_,
718 request_context_getter_.get(),
719 UPLOAD_NEW_FILE,
720 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
721 upload_url,
722 0, // start_position
723 kTestContent.size(), // end_position (exclusive)
724 kTestContent.size(), // content_length,
725 kTestContentType,
726 buffer,
727 CreateComposedCallback(
728 base::Bind(&test_util::RunAndQuit),
729 test_util::CreateCopyResultCallback(&response, &new_entry)),
730 ProgressCallback());
731 resume_operation->Start(
732 kTestDriveApiAuthToken, kTestUserAgent,
733 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
734 MessageLoop::current()->Run();
736 // METHOD_PUT should be used to upload data.
737 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
738 // Request should go to the upload URL.
739 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
740 // Content-Range header should be added.
741 EXPECT_EQ("bytes 0-" +
742 base::Int64ToString(kTestContent.size() - 1) + "/" +
743 base::Int64ToString(kTestContent.size()),
744 http_request_.headers["Content-Range"]);
745 // The upload content should be set in the HTTP request.
746 EXPECT_TRUE(http_request_.has_content);
747 EXPECT_EQ(kTestContent, http_request_.content);
749 // Check the response.
750 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file
751 // The start and end positions should be set to -1, if an upload is complete.
752 EXPECT_EQ(-1, response.start_position_received);
753 EXPECT_EQ(-1, response.end_position_received);
756 TEST_F(DriveApiOperationsTest, UploadNewEmptyFileOperation) {
757 // Set an expected url for uploading.
758 expected_upload_path_ = kTestUploadNewFilePath;
760 const char kTestContentType[] = "text/plain";
761 const char kTestContent[] = "";
763 GDataErrorCode error = GDATA_OTHER_ERROR;
764 GURL upload_url;
766 // 1) Initiate uploading a new file to the directory with
767 // "parent_resource_id".
768 drive::InitiateUploadNewFileOperation* operation =
769 new drive::InitiateUploadNewFileOperation(
770 &operation_registry_,
771 request_context_getter_.get(),
772 *url_generator_,
773 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
774 kTestContentType,
776 "parent_resource_id", // The resource id of the parent directory.
777 "new file title", // The title of the file being uploaded.
778 CreateComposedCallback(
779 base::Bind(&test_util::RunAndQuit),
780 test_util::CreateCopyResultCallback(&error, &upload_url)));
781 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
782 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
783 MessageLoop::current()->Run();
785 EXPECT_EQ(HTTP_SUCCESS, error);
786 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
787 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
788 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]);
790 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
791 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
792 http_request_.relative_url);
793 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
794 EXPECT_TRUE(http_request_.has_content);
795 EXPECT_EQ("{\"parents\":[{"
796 "\"id\":\"parent_resource_id\","
797 "\"kind\":\"drive#fileLink\""
798 "}],"
799 "\"title\":\"new file title\"}",
800 http_request_.content);
802 // 2) Upload the content to the upload URL.
803 scoped_refptr<net::IOBuffer> buffer = new net::StringIOBuffer(kTestContent);
805 UploadRangeResponse response;
806 scoped_ptr<FileResource> new_entry;
808 drive::ResumeUploadOperation* resume_operation =
809 new drive::ResumeUploadOperation(
810 &operation_registry_,
811 request_context_getter_.get(),
812 UPLOAD_NEW_FILE,
813 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
814 upload_url,
815 0, // start_position
816 0, // end_position (exclusive)
817 0, // content_length,
818 kTestContentType,
819 buffer,
820 CreateComposedCallback(
821 base::Bind(&test_util::RunAndQuit),
822 test_util::CreateCopyResultCallback(&response, &new_entry)),
823 ProgressCallback());
824 resume_operation->Start(
825 kTestDriveApiAuthToken, kTestUserAgent,
826 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
827 MessageLoop::current()->Run();
829 // METHOD_PUT should be used to upload data.
830 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
831 // Request should go to the upload URL.
832 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
833 // Content-Range header should NOT be added.
834 EXPECT_EQ(0U, http_request_.headers.count("Content-Range"));
835 // The upload content should be set in the HTTP request.
836 EXPECT_TRUE(http_request_.has_content);
837 EXPECT_EQ(kTestContent, http_request_.content);
839 // Check the response.
840 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file
841 // The start and end positions should be set to -1, if an upload is complete.
842 EXPECT_EQ(-1, response.start_position_received);
843 EXPECT_EQ(-1, response.end_position_received);
846 TEST_F(DriveApiOperationsTest, UploadNewLargeFileOperation) {
847 // Set an expected url for uploading.
848 expected_upload_path_ = kTestUploadNewFilePath;
850 const char kTestContentType[] = "text/plain";
851 const size_t kNumChunkBytes = 10; // Num bytes in a chunk.
852 const std::string kTestContent(100, 'a');
854 GDataErrorCode error = GDATA_OTHER_ERROR;
855 GURL upload_url;
857 // 1) Initiate uploading a new file to the directory with
858 // "parent_resource_id".
859 drive::InitiateUploadNewFileOperation* operation =
860 new drive::InitiateUploadNewFileOperation(
861 &operation_registry_,
862 request_context_getter_.get(),
863 *url_generator_,
864 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
865 kTestContentType,
866 kTestContent.size(),
867 "parent_resource_id", // The resource id of the parent directory.
868 "new file title", // The title of the file being uploaded.
869 CreateComposedCallback(
870 base::Bind(&test_util::RunAndQuit),
871 test_util::CreateCopyResultCallback(&error, &upload_url)));
872 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
873 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
874 MessageLoop::current()->Run();
876 EXPECT_EQ(HTTP_SUCCESS, error);
877 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
878 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
879 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
880 http_request_.headers["X-Upload-Content-Length"]);
882 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
883 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
884 http_request_.relative_url);
885 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
886 EXPECT_TRUE(http_request_.has_content);
887 EXPECT_EQ("{\"parents\":[{"
888 "\"id\":\"parent_resource_id\","
889 "\"kind\":\"drive#fileLink\""
890 "}],"
891 "\"title\":\"new file title\"}",
892 http_request_.content);
894 // 2) Upload the content to the upload URL.
895 for (size_t start_position = 0; start_position < kTestContent.size();
896 start_position += kNumChunkBytes) {
897 const std::string payload = kTestContent.substr(
898 start_position,
899 std::min(kNumChunkBytes, kTestContent.size() - start_position));
900 const size_t end_position = start_position + payload.size();
901 scoped_refptr<net::IOBuffer> buffer = new net::StringIOBuffer(payload);
903 UploadRangeResponse response;
904 scoped_ptr<FileResource> new_entry;
906 drive::ResumeUploadOperation* resume_operation =
907 new drive::ResumeUploadOperation(
908 &operation_registry_,
909 request_context_getter_.get(),
910 UPLOAD_NEW_FILE,
911 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
912 upload_url,
913 start_position,
914 end_position,
915 kTestContent.size(), // content_length,
916 kTestContentType,
917 buffer,
918 CreateComposedCallback(
919 base::Bind(&test_util::RunAndQuit),
920 test_util::CreateCopyResultCallback(&response, &new_entry)),
921 ProgressCallback());
922 resume_operation->Start(
923 kTestDriveApiAuthToken, kTestUserAgent,
924 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
925 MessageLoop::current()->Run();
927 // METHOD_PUT should be used to upload data.
928 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
929 // Request should go to the upload URL.
930 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
931 // Content-Range header should be added.
932 EXPECT_EQ("bytes " +
933 base::Int64ToString(start_position) + "-" +
934 base::Int64ToString(end_position - 1) + "/" +
935 base::Int64ToString(kTestContent.size()),
936 http_request_.headers["Content-Range"]);
937 // The upload content should be set in the HTTP request.
938 EXPECT_TRUE(http_request_.has_content);
939 EXPECT_EQ(payload, http_request_.content);
941 if (end_position == kTestContent.size()) {
942 // Check the response.
943 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file
944 // The start and end positions should be set to -1, if an upload is
945 // complete.
946 EXPECT_EQ(-1, response.start_position_received);
947 EXPECT_EQ(-1, response.end_position_received);
948 } else {
949 // Check the response.
950 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
951 EXPECT_EQ(0, response.start_position_received);
952 EXPECT_EQ(static_cast<int64>(end_position),
953 response.end_position_received);
958 TEST_F(DriveApiOperationsTest, UploadExistingFileOperation) {
959 // Set an expected url for uploading.
960 expected_upload_path_ = kTestUploadExistingFilePath;
962 const char kTestContentType[] = "text/plain";
963 const std::string kTestContent(100, 'a');
965 GDataErrorCode error = GDATA_OTHER_ERROR;
966 GURL upload_url;
968 // Initiate uploading a new file to the directory with "parent_resource_id".
969 drive::InitiateUploadExistingFileOperation* operation =
970 new drive::InitiateUploadExistingFileOperation(
971 &operation_registry_,
972 request_context_getter_.get(),
973 *url_generator_,
974 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
975 kTestContentType,
976 kTestContent.size(),
977 "resource_id", // The resource id of the file to be overwritten.
978 std::string(), // No etag.
979 CreateComposedCallback(
980 base::Bind(&test_util::RunAndQuit),
981 test_util::CreateCopyResultCallback(&error, &upload_url)));
982 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
983 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
984 MessageLoop::current()->Run();
986 EXPECT_EQ(HTTP_SUCCESS, error);
987 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
988 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
989 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
990 http_request_.headers["X-Upload-Content-Length"]);
991 EXPECT_EQ("*", http_request_.headers["If-Match"]);
993 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
994 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
995 http_request_.relative_url);
996 EXPECT_TRUE(http_request_.has_content);
997 EXPECT_TRUE(http_request_.content.empty());
999 // 2) Upload the content to the upload URL.
1000 scoped_refptr<net::IOBuffer> buffer = new net::StringIOBuffer(kTestContent);
1002 UploadRangeResponse response;
1003 scoped_ptr<FileResource> new_entry;
1005 drive::ResumeUploadOperation* resume_operation =
1006 new drive::ResumeUploadOperation(
1007 &operation_registry_,
1008 request_context_getter_.get(),
1009 UPLOAD_EXISTING_FILE,
1010 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1011 upload_url,
1012 0, // start_position
1013 kTestContent.size(), // end_position (exclusive)
1014 kTestContent.size(), // content_length,
1015 kTestContentType,
1016 buffer,
1017 CreateComposedCallback(
1018 base::Bind(&test_util::RunAndQuit),
1019 test_util::CreateCopyResultCallback(&response, &new_entry)),
1020 ProgressCallback());
1021 resume_operation->Start(
1022 kTestDriveApiAuthToken, kTestUserAgent,
1023 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1024 MessageLoop::current()->Run();
1026 // METHOD_PUT should be used to upload data.
1027 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
1028 // Request should go to the upload URL.
1029 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1030 // Content-Range header should be added.
1031 EXPECT_EQ("bytes 0-" +
1032 base::Int64ToString(kTestContent.size() - 1) + "/" +
1033 base::Int64ToString(kTestContent.size()),
1034 http_request_.headers["Content-Range"]);
1035 // The upload content should be set in the HTTP request.
1036 EXPECT_TRUE(http_request_.has_content);
1037 EXPECT_EQ(kTestContent, http_request_.content);
1039 // Check the response.
1040 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file
1041 // The start and end positions should be set to -1, if an upload is complete.
1042 EXPECT_EQ(-1, response.start_position_received);
1043 EXPECT_EQ(-1, response.end_position_received);
1046 TEST_F(DriveApiOperationsTest, UploadExistingFileOperationWithETag) {
1047 // Set an expected url for uploading.
1048 expected_upload_path_ = kTestUploadExistingFilePath;
1050 const char kTestContentType[] = "text/plain";
1051 const std::string kTestContent(100, 'a');
1053 GDataErrorCode error = GDATA_OTHER_ERROR;
1054 GURL upload_url;
1056 // Initiate uploading a new file to the directory with "parent_resource_id".
1057 drive::InitiateUploadExistingFileOperation* operation =
1058 new drive::InitiateUploadExistingFileOperation(
1059 &operation_registry_,
1060 request_context_getter_.get(),
1061 *url_generator_,
1062 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1063 kTestContentType,
1064 kTestContent.size(),
1065 "resource_id", // The resource id of the file to be overwritten.
1066 kTestETag,
1067 CreateComposedCallback(
1068 base::Bind(&test_util::RunAndQuit),
1069 test_util::CreateCopyResultCallback(&error, &upload_url)));
1070 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
1071 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1072 MessageLoop::current()->Run();
1074 EXPECT_EQ(HTTP_SUCCESS, error);
1075 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
1076 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1077 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1078 http_request_.headers["X-Upload-Content-Length"]);
1079 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]);
1081 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
1082 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1083 http_request_.relative_url);
1084 EXPECT_TRUE(http_request_.has_content);
1085 EXPECT_TRUE(http_request_.content.empty());
1087 // 2) Upload the content to the upload URL.
1088 scoped_refptr<net::IOBuffer> buffer = new net::StringIOBuffer(kTestContent);
1090 UploadRangeResponse response;
1091 scoped_ptr<FileResource> new_entry;
1093 drive::ResumeUploadOperation* resume_operation =
1094 new drive::ResumeUploadOperation(
1095 &operation_registry_,
1096 request_context_getter_.get(),
1097 UPLOAD_EXISTING_FILE,
1098 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1099 upload_url,
1100 0, // start_position
1101 kTestContent.size(), // end_position (exclusive)
1102 kTestContent.size(), // content_length,
1103 kTestContentType,
1104 buffer,
1105 CreateComposedCallback(
1106 base::Bind(&test_util::RunAndQuit),
1107 test_util::CreateCopyResultCallback(&response, &new_entry)),
1108 ProgressCallback());
1109 resume_operation->Start(
1110 kTestDriveApiAuthToken, kTestUserAgent,
1111 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1112 MessageLoop::current()->Run();
1114 // METHOD_PUT should be used to upload data.
1115 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
1116 // Request should go to the upload URL.
1117 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1118 // Content-Range header should be added.
1119 EXPECT_EQ("bytes 0-" +
1120 base::Int64ToString(kTestContent.size() - 1) + "/" +
1121 base::Int64ToString(kTestContent.size()),
1122 http_request_.headers["Content-Range"]);
1123 // The upload content should be set in the HTTP request.
1124 EXPECT_TRUE(http_request_.has_content);
1125 EXPECT_EQ(kTestContent, http_request_.content);
1127 // Check the response.
1128 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file
1129 // The start and end positions should be set to -1, if an upload is complete.
1130 EXPECT_EQ(-1, response.start_position_received);
1131 EXPECT_EQ(-1, response.end_position_received);
1134 TEST_F(DriveApiOperationsTest, UploadExistingFileOperationWithETagConflicting) {
1135 // Set an expected url for uploading.
1136 expected_upload_path_ = kTestUploadExistingFilePath;
1138 const char kTestContentType[] = "text/plain";
1139 const std::string kTestContent(100, 'a');
1141 GDataErrorCode error = GDATA_OTHER_ERROR;
1142 GURL upload_url;
1144 // Initiate uploading a new file to the directory with "parent_resource_id".
1145 drive::InitiateUploadExistingFileOperation* operation =
1146 new drive::InitiateUploadExistingFileOperation(
1147 &operation_registry_,
1148 request_context_getter_.get(),
1149 *url_generator_,
1150 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1151 kTestContentType,
1152 kTestContent.size(),
1153 "resource_id", // The resource id of the file to be overwritten.
1154 "Conflicting-etag",
1155 CreateComposedCallback(
1156 base::Bind(&test_util::RunAndQuit),
1157 test_util::CreateCopyResultCallback(&error, &upload_url)));
1158 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
1159 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1160 MessageLoop::current()->Run();
1162 EXPECT_EQ(HTTP_PRECONDITION, error);
1163 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1164 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1165 http_request_.headers["X-Upload-Content-Length"]);
1166 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]);
1168 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
1169 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1170 http_request_.relative_url);
1171 EXPECT_TRUE(http_request_.has_content);
1172 EXPECT_TRUE(http_request_.content.empty());
1175 } // namespace google_apis