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

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

Issue 16175003: google_apis: Rename OperationRunner to RequestSender (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) 2013 The Chromium Authors. All rights reserved. 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 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/google_apis/auth_service.h" 11 #include "chrome/browser/google_apis/auth_service.h"
12 #include "chrome/browser/google_apis/drive_api_operations.h" 12 #include "chrome/browser/google_apis/drive_api_operations.h"
13 #include "chrome/browser/google_apis/drive_api_parser.h" 13 #include "chrome/browser/google_apis/drive_api_parser.h"
14 #include "chrome/browser/google_apis/drive_api_url_generator.h" 14 #include "chrome/browser/google_apis/drive_api_url_generator.h"
15 #include "chrome/browser/google_apis/operation_runner.h" 15 #include "chrome/browser/google_apis/request_sender.h"
16 #include "chrome/browser/google_apis/task_util.h" 16 #include "chrome/browser/google_apis/task_util.h"
17 #include "chrome/browser/google_apis/test_util.h" 17 #include "chrome/browser/google_apis/test_util.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "net/test/embedded_test_server/http_request.h" 21 #include "net/test/embedded_test_server/http_request.h"
22 #include "net/test/embedded_test_server/http_response.h" 22 #include "net/test/embedded_test_server/http_response.h"
23 #include "net/url_request/url_request_test_util.h" 23 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
(...skipping 18 matching lines...) Expand all
44 44
45 } // namespace 45 } // namespace
46 46
47 class DriveApiOperationsTest : public testing::Test { 47 class DriveApiOperationsTest : public testing::Test {
48 public: 48 public:
49 DriveApiOperationsTest() 49 DriveApiOperationsTest()
50 : ui_thread_(content::BrowserThread::UI, &message_loop_), 50 : ui_thread_(content::BrowserThread::UI, &message_loop_),
51 file_thread_(content::BrowserThread::FILE), 51 file_thread_(content::BrowserThread::FILE),
52 io_thread_(content::BrowserThread::IO), 52 io_thread_(content::BrowserThread::IO),
53 test_server_(content::BrowserThread::GetMessageLoopProxyForThread( 53 test_server_(content::BrowserThread::GetMessageLoopProxyForThread(
54 content::BrowserThread::IO)) { 54 content::BrowserThread::IO)) {
55 } 55 }
56 56
57 virtual void SetUp() OVERRIDE { 57 virtual void SetUp() OVERRIDE {
58 file_thread_.Start(); 58 file_thread_.Start();
59 io_thread_.StartIOThread(); 59 io_thread_.StartIOThread();
60 profile_.reset(new TestingProfile); 60 profile_.reset(new TestingProfile);
61 61
62 request_context_getter_ = new net::TestURLRequestContextGetter( 62 request_context_getter_ = new net::TestURLRequestContextGetter(
63 content::BrowserThread::GetMessageLoopProxyForThread( 63 content::BrowserThread::GetMessageLoopProxyForThread(
64 content::BrowserThread::IO)); 64 content::BrowserThread::IO));
65 65
66 operation_runner_.reset(new OperationRunner(profile_.get(), 66 operation_runner_.reset(new RequestSender(profile_.get(),
67 request_context_getter_.get(), 67 request_context_getter_.get(),
68 std::vector<std::string>(), 68 std::vector<std::string>(),
69 kTestUserAgent)); 69 kTestUserAgent));
70 operation_runner_->auth_service()->set_access_token_for_testing( 70 operation_runner_->auth_service()->set_access_token_for_testing(
71 kTestDriveApiAuthToken); 71 kTestDriveApiAuthToken);
72 72
73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
74 74
75 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); 75 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
76 test_server_.RegisterRequestHandler( 76 test_server_.RegisterRequestHandler(
77 base::Bind(&DriveApiOperationsTest::HandleChildrenDeleteRequest, 77 base::Bind(&DriveApiOperationsTest::HandleChildrenDeleteRequest,
78 base::Unretained(this))); 78 base::Unretained(this)));
79 test_server_.RegisterRequestHandler( 79 test_server_.RegisterRequestHandler(
(...skipping 23 matching lines...) Expand all
103 request_context_getter_ = NULL; 103 request_context_getter_ = NULL;
104 ResetExpectedResponse(); 104 ResetExpectedResponse();
105 } 105 }
106 106
107 base::MessageLoopForUI message_loop_; 107 base::MessageLoopForUI message_loop_;
108 content::TestBrowserThread ui_thread_; 108 content::TestBrowserThread ui_thread_;
109 content::TestBrowserThread file_thread_; 109 content::TestBrowserThread file_thread_;
110 content::TestBrowserThread io_thread_; 110 content::TestBrowserThread io_thread_;
111 net::test_server::EmbeddedTestServer test_server_; 111 net::test_server::EmbeddedTestServer test_server_;
112 scoped_ptr<TestingProfile> profile_; 112 scoped_ptr<TestingProfile> profile_;
113 scoped_ptr<OperationRunner> operation_runner_; 113 scoped_ptr<RequestSender> operation_runner_;
114 scoped_ptr<DriveApiUrlGenerator> url_generator_; 114 scoped_ptr<DriveApiUrlGenerator> url_generator_;
115 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; 115 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
116 base::ScopedTempDir temp_dir_; 116 base::ScopedTempDir temp_dir_;
117 117
118 // This is a path to the file which contains expected response from 118 // This is a path to the file which contains expected response from
119 // the server. See also HandleDataFileRequest below. 119 // the server. See also HandleDataFileRequest below.
120 base::FilePath expected_data_file_path_; 120 base::FilePath expected_data_file_path_;
121 121
122 // This is a path string in the expected response header from the server 122 // This is a path string in the expected response header from the server
123 // for initiating file uploading. 123 // for initiating file uploading.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 GDataErrorCode error = GDATA_OTHER_ERROR; 324 GDataErrorCode error = GDATA_OTHER_ERROR;
325 scoped_ptr<AboutResource> about_resource; 325 scoped_ptr<AboutResource> about_resource;
326 326
327 GetAboutOperation* operation = new GetAboutOperation( 327 GetAboutOperation* operation = new GetAboutOperation(
328 operation_runner_.get(), 328 operation_runner_.get(),
329 request_context_getter_.get(), 329 request_context_getter_.get(),
330 *url_generator_, 330 *url_generator_,
331 CreateComposedCallback( 331 CreateComposedCallback(
332 base::Bind(&test_util::RunAndQuit), 332 base::Bind(&test_util::RunAndQuit),
333 test_util::CreateCopyResultCallback(&error, &about_resource))); 333 test_util::CreateCopyResultCallback(&error, &about_resource)));
334 operation_runner_->StartOperationWithRetry(operation); 334 operation_runner_->StartRequestWithRetry(operation);
335 base::MessageLoop::current()->Run(); 335 base::MessageLoop::current()->Run();
336 336
337 EXPECT_EQ(HTTP_SUCCESS, error); 337 EXPECT_EQ(HTTP_SUCCESS, error);
338 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 338 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
339 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 339 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
340 340
341 scoped_ptr<AboutResource> expected( 341 scoped_ptr<AboutResource> expected(
342 AboutResource::CreateFrom( 342 AboutResource::CreateFrom(
343 *test_util::LoadJSONFile("chromeos/drive/about.json"))); 343 *test_util::LoadJSONFile("chromeos/drive/about.json")));
344 ASSERT_TRUE(about_resource.get()); 344 ASSERT_TRUE(about_resource.get());
(...skipping 11 matching lines...) Expand all
356 GDataErrorCode error = GDATA_OTHER_ERROR; 356 GDataErrorCode error = GDATA_OTHER_ERROR;
357 scoped_ptr<AboutResource> about_resource; 357 scoped_ptr<AboutResource> about_resource;
358 358
359 GetAboutOperation* operation = new GetAboutOperation( 359 GetAboutOperation* operation = new GetAboutOperation(
360 operation_runner_.get(), 360 operation_runner_.get(),
361 request_context_getter_.get(), 361 request_context_getter_.get(),
362 *url_generator_, 362 *url_generator_,
363 CreateComposedCallback( 363 CreateComposedCallback(
364 base::Bind(&test_util::RunAndQuit), 364 base::Bind(&test_util::RunAndQuit),
365 test_util::CreateCopyResultCallback(&error, &about_resource))); 365 test_util::CreateCopyResultCallback(&error, &about_resource)));
366 operation_runner_->StartOperationWithRetry(operation); 366 operation_runner_->StartRequestWithRetry(operation);
367 base::MessageLoop::current()->Run(); 367 base::MessageLoop::current()->Run();
368 368
369 // "parse error" should be returned, and the about resource should be NULL. 369 // "parse error" should be returned, and the about resource should be NULL.
370 EXPECT_EQ(GDATA_PARSE_ERROR, error); 370 EXPECT_EQ(GDATA_PARSE_ERROR, error);
371 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 371 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
372 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 372 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
373 EXPECT_FALSE(about_resource.get()); 373 EXPECT_FALSE(about_resource.get());
374 } 374 }
375 375
376 TEST_F(DriveApiOperationsTest, GetApplistOperation) { 376 TEST_F(DriveApiOperationsTest, GetApplistOperation) {
377 // Set an expected data file containing valid result. 377 // Set an expected data file containing valid result.
378 expected_data_file_path_ = test_util::GetTestFilePath( 378 expected_data_file_path_ = test_util::GetTestFilePath(
379 "chromeos/drive/applist.json"); 379 "chromeos/drive/applist.json");
380 380
381 GDataErrorCode error = GDATA_OTHER_ERROR; 381 GDataErrorCode error = GDATA_OTHER_ERROR;
382 scoped_ptr<base::Value> result; 382 scoped_ptr<base::Value> result;
383 383
384 GetApplistOperation* operation = new GetApplistOperation( 384 GetApplistOperation* operation = new GetApplistOperation(
385 operation_runner_.get(), 385 operation_runner_.get(),
386 request_context_getter_.get(), 386 request_context_getter_.get(),
387 *url_generator_, 387 *url_generator_,
388 CreateComposedCallback( 388 CreateComposedCallback(
389 base::Bind(&test_util::RunAndQuit), 389 base::Bind(&test_util::RunAndQuit),
390 test_util::CreateCopyResultCallback(&error, &result))); 390 test_util::CreateCopyResultCallback(&error, &result)));
391 operation_runner_->StartOperationWithRetry(operation); 391 operation_runner_->StartRequestWithRetry(operation);
392 base::MessageLoop::current()->Run(); 392 base::MessageLoop::current()->Run();
393 393
394 EXPECT_EQ(HTTP_SUCCESS, error); 394 EXPECT_EQ(HTTP_SUCCESS, error);
395 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 395 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
396 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url); 396 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url);
397 EXPECT_TRUE(result); 397 EXPECT_TRUE(result);
398 } 398 }
399 399
400 TEST_F(DriveApiOperationsTest, GetChangelistOperation) { 400 TEST_F(DriveApiOperationsTest, GetChangelistOperation) {
401 // Set an expected data file containing valid result. 401 // Set an expected data file containing valid result.
402 expected_data_file_path_ = test_util::GetTestFilePath( 402 expected_data_file_path_ = test_util::GetTestFilePath(
403 "chromeos/drive/changelist.json"); 403 "chromeos/drive/changelist.json");
404 404
405 GDataErrorCode error = GDATA_OTHER_ERROR; 405 GDataErrorCode error = GDATA_OTHER_ERROR;
406 scoped_ptr<base::Value> result; 406 scoped_ptr<base::Value> result;
407 407
408 GetChangelistOperation* operation = new GetChangelistOperation( 408 GetChangelistOperation* operation = new GetChangelistOperation(
409 operation_runner_.get(), 409 operation_runner_.get(),
410 request_context_getter_.get(), 410 request_context_getter_.get(),
411 *url_generator_, 411 *url_generator_,
412 true, // include deleted 412 true, // include deleted
413 100, // start changestamp 413 100, // start changestamp
414 500, // max results 414 500, // max results
415 CreateComposedCallback( 415 CreateComposedCallback(
416 base::Bind(&test_util::RunAndQuit), 416 base::Bind(&test_util::RunAndQuit),
417 test_util::CreateCopyResultCallback(&error, &result))); 417 test_util::CreateCopyResultCallback(&error, &result)));
418 operation_runner_->StartOperationWithRetry(operation); 418 operation_runner_->StartRequestWithRetry(operation);
419 base::MessageLoop::current()->Run(); 419 base::MessageLoop::current()->Run();
420 420
421 EXPECT_EQ(HTTP_SUCCESS, error); 421 EXPECT_EQ(HTTP_SUCCESS, error);
422 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 422 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
423 EXPECT_EQ("/drive/v2/changes?startChangeId=100&maxResults=500", 423 EXPECT_EQ("/drive/v2/changes?startChangeId=100&maxResults=500",
424 http_request_.relative_url); 424 http_request_.relative_url);
425 EXPECT_TRUE(result); 425 EXPECT_TRUE(result);
426 } 426 }
427 427
428 TEST_F(DriveApiOperationsTest, GetFilelistOperation) { 428 TEST_F(DriveApiOperationsTest, GetFilelistOperation) {
429 // Set an expected data file containing valid result. 429 // Set an expected data file containing valid result.
430 expected_data_file_path_ = test_util::GetTestFilePath( 430 expected_data_file_path_ = test_util::GetTestFilePath(
431 "chromeos/drive/filelist.json"); 431 "chromeos/drive/filelist.json");
432 432
433 GDataErrorCode error = GDATA_OTHER_ERROR; 433 GDataErrorCode error = GDATA_OTHER_ERROR;
434 scoped_ptr<base::Value> result; 434 scoped_ptr<base::Value> result;
435 435
436 GetFilelistOperation* operation = new GetFilelistOperation( 436 GetFilelistOperation* operation = new GetFilelistOperation(
437 operation_runner_.get(), 437 operation_runner_.get(),
438 request_context_getter_.get(), 438 request_context_getter_.get(),
439 *url_generator_, 439 *url_generator_,
440 "\"abcde\" in parents", 440 "\"abcde\" in parents",
441 50, // max results 441 50, // max results
442 CreateComposedCallback( 442 CreateComposedCallback(
443 base::Bind(&test_util::RunAndQuit), 443 base::Bind(&test_util::RunAndQuit),
444 test_util::CreateCopyResultCallback(&error, &result))); 444 test_util::CreateCopyResultCallback(&error, &result)));
445 operation_runner_->StartOperationWithRetry(operation); 445 operation_runner_->StartRequestWithRetry(operation);
446 base::MessageLoop::current()->Run(); 446 base::MessageLoop::current()->Run();
447 447
448 EXPECT_EQ(HTTP_SUCCESS, error); 448 EXPECT_EQ(HTTP_SUCCESS, error);
449 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 449 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
450 EXPECT_EQ("/drive/v2/files?maxResults=50&q=%22abcde%22+in+parents", 450 EXPECT_EQ("/drive/v2/files?maxResults=50&q=%22abcde%22+in+parents",
451 http_request_.relative_url); 451 http_request_.relative_url);
452 EXPECT_TRUE(result); 452 EXPECT_TRUE(result);
453 } 453 }
454 454
455 TEST_F(DriveApiOperationsTest, ContinueGetFileListOperation) { 455 TEST_F(DriveApiOperationsTest, ContinueGetFileListOperation) {
456 // Set an expected data file containing valid result. 456 // Set an expected data file containing valid result.
457 expected_data_file_path_ = test_util::GetTestFilePath( 457 expected_data_file_path_ = test_util::GetTestFilePath(
458 "chromeos/drive/filelist.json"); 458 "chromeos/drive/filelist.json");
459 459
460 GDataErrorCode error = GDATA_OTHER_ERROR; 460 GDataErrorCode error = GDATA_OTHER_ERROR;
461 scoped_ptr<base::Value> result; 461 scoped_ptr<base::Value> result;
462 462
463 drive::ContinueGetFileListOperation* operation = 463 drive::ContinueGetFileListOperation* operation =
464 new drive::ContinueGetFileListOperation( 464 new drive::ContinueGetFileListOperation(
465 operation_runner_.get(), 465 operation_runner_.get(),
466 request_context_getter_.get(), 466 request_context_getter_.get(),
467 test_server_.GetURL("/continue/get/file/list"), 467 test_server_.GetURL("/continue/get/file/list"),
468 CreateComposedCallback( 468 CreateComposedCallback(
469 base::Bind(&test_util::RunAndQuit), 469 base::Bind(&test_util::RunAndQuit),
470 test_util::CreateCopyResultCallback(&error, &result))); 470 test_util::CreateCopyResultCallback(&error, &result)));
471 operation_runner_->StartOperationWithRetry(operation); 471 operation_runner_->StartRequestWithRetry(operation);
472 base::MessageLoop::current()->Run(); 472 base::MessageLoop::current()->Run();
473 473
474 EXPECT_EQ(HTTP_SUCCESS, error); 474 EXPECT_EQ(HTTP_SUCCESS, error);
475 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 475 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
476 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); 476 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url);
477 EXPECT_TRUE(result); 477 EXPECT_TRUE(result);
478 } 478 }
479 479
480 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) { 480 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) {
481 // Set an expected data file containing the directory's entry data. 481 // Set an expected data file containing the directory's entry data.
482 expected_data_file_path_ = 482 expected_data_file_path_ =
483 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); 483 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
484 484
485 GDataErrorCode error = GDATA_OTHER_ERROR; 485 GDataErrorCode error = GDATA_OTHER_ERROR;
486 scoped_ptr<FileResource> file_resource; 486 scoped_ptr<FileResource> file_resource;
487 487
488 // Create "new directory" in the root directory. 488 // Create "new directory" in the root directory.
489 drive::CreateDirectoryOperation* operation = 489 drive::CreateDirectoryOperation* operation =
490 new drive::CreateDirectoryOperation( 490 new drive::CreateDirectoryOperation(
491 operation_runner_.get(), 491 operation_runner_.get(),
492 request_context_getter_.get(), 492 request_context_getter_.get(),
493 *url_generator_, 493 *url_generator_,
494 "root", 494 "root",
495 "new directory", 495 "new directory",
496 CreateComposedCallback( 496 CreateComposedCallback(
497 base::Bind(&test_util::RunAndQuit), 497 base::Bind(&test_util::RunAndQuit),
498 test_util::CreateCopyResultCallback(&error, &file_resource))); 498 test_util::CreateCopyResultCallback(&error, &file_resource)));
499 operation_runner_->StartOperationWithRetry(operation); 499 operation_runner_->StartRequestWithRetry(operation);
500 base::MessageLoop::current()->Run(); 500 base::MessageLoop::current()->Run();
501 501
502 EXPECT_EQ(HTTP_SUCCESS, error); 502 EXPECT_EQ(HTTP_SUCCESS, error);
503 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 503 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
504 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); 504 EXPECT_EQ("/drive/v2/files", http_request_.relative_url);
505 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 505 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
506 506
507 EXPECT_TRUE(http_request_.has_content); 507 EXPECT_TRUE(http_request_.has_content);
508 508
509 scoped_ptr<FileResource> expected( 509 scoped_ptr<FileResource> expected(
(...skipping 21 matching lines...) Expand all
531 drive::RenameResourceOperation* operation = 531 drive::RenameResourceOperation* operation =
532 new drive::RenameResourceOperation( 532 new drive::RenameResourceOperation(
533 operation_runner_.get(), 533 operation_runner_.get(),
534 request_context_getter_.get(), 534 request_context_getter_.get(),
535 *url_generator_, 535 *url_generator_,
536 "resource_id", 536 "resource_id",
537 "new name", 537 "new name",
538 CreateComposedCallback( 538 CreateComposedCallback(
539 base::Bind(&test_util::RunAndQuit), 539 base::Bind(&test_util::RunAndQuit),
540 test_util::CreateCopyResultCallback(&error))); 540 test_util::CreateCopyResultCallback(&error)));
541 operation_runner_->StartOperationWithRetry(operation); 541 operation_runner_->StartRequestWithRetry(operation);
542 base::MessageLoop::current()->Run(); 542 base::MessageLoop::current()->Run();
543 543
544 EXPECT_EQ(HTTP_SUCCESS, error); 544 EXPECT_EQ(HTTP_SUCCESS, error);
545 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); 545 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method);
546 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); 546 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url);
547 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 547 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
548 548
549 EXPECT_TRUE(http_request_.has_content); 549 EXPECT_TRUE(http_request_.has_content);
550 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); 550 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content);
551 } 551 }
(...skipping 14 matching lines...) Expand all
566 drive::TouchResourceOperation* operation = new drive::TouchResourceOperation( 566 drive::TouchResourceOperation* operation = new drive::TouchResourceOperation(
567 operation_runner_.get(), 567 operation_runner_.get(),
568 request_context_getter_.get(), 568 request_context_getter_.get(),
569 *url_generator_, 569 *url_generator_,
570 "resource_id", 570 "resource_id",
571 base::Time::FromUTCExploded(kModifiedDate), 571 base::Time::FromUTCExploded(kModifiedDate),
572 base::Time::FromUTCExploded(kLastViewedByMeDate), 572 base::Time::FromUTCExploded(kLastViewedByMeDate),
573 CreateComposedCallback( 573 CreateComposedCallback(
574 base::Bind(&test_util::RunAndQuit), 574 base::Bind(&test_util::RunAndQuit),
575 test_util::CreateCopyResultCallback(&error, &file_resource))); 575 test_util::CreateCopyResultCallback(&error, &file_resource)));
576 operation_runner_->StartOperationWithRetry(operation); 576 operation_runner_->StartRequestWithRetry(operation);
577 base::MessageLoop::current()->Run(); 577 base::MessageLoop::current()->Run();
578 578
579 EXPECT_EQ(HTTP_SUCCESS, error); 579 EXPECT_EQ(HTTP_SUCCESS, error);
580 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); 580 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method);
581 EXPECT_EQ("/drive/v2/files/resource_id" 581 EXPECT_EQ("/drive/v2/files/resource_id"
582 "?setModifiedDate=true&updateViewedDate=false", 582 "?setModifiedDate=true&updateViewedDate=false",
583 http_request_.relative_url); 583 http_request_.relative_url);
584 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 584 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
585 585
586 EXPECT_TRUE(http_request_.has_content); 586 EXPECT_TRUE(http_request_.has_content);
(...skipping 16 matching lines...) Expand all
603 new drive::CopyResourceOperation( 603 new drive::CopyResourceOperation(
604 operation_runner_.get(), 604 operation_runner_.get(),
605 request_context_getter_.get(), 605 request_context_getter_.get(),
606 *url_generator_, 606 *url_generator_,
607 "resource_id", 607 "resource_id",
608 "parent_resource_id", 608 "parent_resource_id",
609 "new name", 609 "new name",
610 CreateComposedCallback( 610 CreateComposedCallback(
611 base::Bind(&test_util::RunAndQuit), 611 base::Bind(&test_util::RunAndQuit),
612 test_util::CreateCopyResultCallback(&error, &file_resource))); 612 test_util::CreateCopyResultCallback(&error, &file_resource)));
613 operation_runner_->StartOperationWithRetry(operation); 613 operation_runner_->StartRequestWithRetry(operation);
614 base::MessageLoop::current()->Run(); 614 base::MessageLoop::current()->Run();
615 615
616 EXPECT_EQ(HTTP_SUCCESS, error); 616 EXPECT_EQ(HTTP_SUCCESS, error);
617 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 617 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
618 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); 618 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url);
619 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 619 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
620 620
621 EXPECT_TRUE(http_request_.has_content); 621 EXPECT_TRUE(http_request_.has_content);
622 EXPECT_EQ( 622 EXPECT_EQ(
623 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new name\"}", 623 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new name\"}",
(...skipping 15 matching lines...) Expand all
639 new drive::CopyResourceOperation( 639 new drive::CopyResourceOperation(
640 operation_runner_.get(), 640 operation_runner_.get(),
641 request_context_getter_.get(), 641 request_context_getter_.get(),
642 *url_generator_, 642 *url_generator_,
643 "resource_id", 643 "resource_id",
644 std::string(), // parent resource id. 644 std::string(), // parent resource id.
645 "new name", 645 "new name",
646 CreateComposedCallback( 646 CreateComposedCallback(
647 base::Bind(&test_util::RunAndQuit), 647 base::Bind(&test_util::RunAndQuit),
648 test_util::CreateCopyResultCallback(&error, &file_resource))); 648 test_util::CreateCopyResultCallback(&error, &file_resource)));
649 operation_runner_->StartOperationWithRetry(operation); 649 operation_runner_->StartRequestWithRetry(operation);
650 base::MessageLoop::current()->Run(); 650 base::MessageLoop::current()->Run();
651 651
652 EXPECT_EQ(HTTP_SUCCESS, error); 652 EXPECT_EQ(HTTP_SUCCESS, error);
653 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 653 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
654 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); 654 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url);
655 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 655 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
656 656
657 EXPECT_TRUE(http_request_.has_content); 657 EXPECT_TRUE(http_request_.has_content);
658 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); 658 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content);
659 EXPECT_TRUE(file_resource); 659 EXPECT_TRUE(file_resource);
(...skipping 10 matching lines...) Expand all
670 // Trash a resource with the given resource id. 670 // Trash a resource with the given resource id.
671 drive::TrashResourceOperation* operation = 671 drive::TrashResourceOperation* operation =
672 new drive::TrashResourceOperation( 672 new drive::TrashResourceOperation(
673 operation_runner_.get(), 673 operation_runner_.get(),
674 request_context_getter_.get(), 674 request_context_getter_.get(),
675 *url_generator_, 675 *url_generator_,
676 "resource_id", 676 "resource_id",
677 CreateComposedCallback( 677 CreateComposedCallback(
678 base::Bind(&test_util::RunAndQuit), 678 base::Bind(&test_util::RunAndQuit),
679 test_util::CreateCopyResultCallback(&error))); 679 test_util::CreateCopyResultCallback(&error)));
680 operation_runner_->StartOperationWithRetry(operation); 680 operation_runner_->StartRequestWithRetry(operation);
681 base::MessageLoop::current()->Run(); 681 base::MessageLoop::current()->Run();
682 682
683 EXPECT_EQ(HTTP_SUCCESS, error); 683 EXPECT_EQ(HTTP_SUCCESS, error);
684 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 684 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
685 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url); 685 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url);
686 EXPECT_TRUE(http_request_.has_content); 686 EXPECT_TRUE(http_request_.has_content);
687 EXPECT_TRUE(http_request_.content.empty()); 687 EXPECT_TRUE(http_request_.content.empty());
688 } 688 }
689 689
690 TEST_F(DriveApiOperationsTest, InsertResourceOperation) { 690 TEST_F(DriveApiOperationsTest, InsertResourceOperation) {
691 // Set an expected data file containing the children entry. 691 // Set an expected data file containing the children entry.
692 expected_content_type_ = "application/json"; 692 expected_content_type_ = "application/json";
693 expected_content_ = kTestChildrenResponse; 693 expected_content_ = kTestChildrenResponse;
694 694
695 GDataErrorCode error = GDATA_OTHER_ERROR; 695 GDataErrorCode error = GDATA_OTHER_ERROR;
696 696
697 // Add a resource with "resource_id" to a directory with 697 // Add a resource with "resource_id" to a directory with
698 // "parent_resource_id". 698 // "parent_resource_id".
699 drive::InsertResourceOperation* operation = 699 drive::InsertResourceOperation* operation =
700 new drive::InsertResourceOperation( 700 new drive::InsertResourceOperation(
701 operation_runner_.get(), 701 operation_runner_.get(),
702 request_context_getter_.get(), 702 request_context_getter_.get(),
703 *url_generator_, 703 *url_generator_,
704 "parent_resource_id", 704 "parent_resource_id",
705 "resource_id", 705 "resource_id",
706 CreateComposedCallback( 706 CreateComposedCallback(
707 base::Bind(&test_util::RunAndQuit), 707 base::Bind(&test_util::RunAndQuit),
708 test_util::CreateCopyResultCallback(&error))); 708 test_util::CreateCopyResultCallback(&error)));
709 operation_runner_->StartOperationWithRetry(operation); 709 operation_runner_->StartRequestWithRetry(operation);
710 base::MessageLoop::current()->Run(); 710 base::MessageLoop::current()->Run();
711 711
712 EXPECT_EQ(HTTP_SUCCESS, error); 712 EXPECT_EQ(HTTP_SUCCESS, error);
713 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 713 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
714 EXPECT_EQ("/drive/v2/files/parent_resource_id/children", 714 EXPECT_EQ("/drive/v2/files/parent_resource_id/children",
715 http_request_.relative_url); 715 http_request_.relative_url);
716 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 716 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
717 717
718 EXPECT_TRUE(http_request_.has_content); 718 EXPECT_TRUE(http_request_.has_content);
719 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content); 719 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content);
720 } 720 }
721 721
722 TEST_F(DriveApiOperationsTest, DeleteResourceOperation) { 722 TEST_F(DriveApiOperationsTest, DeleteResourceOperation) {
723 GDataErrorCode error = GDATA_OTHER_ERROR; 723 GDataErrorCode error = GDATA_OTHER_ERROR;
724 724
725 // Remove a resource with "resource_id" from a directory with 725 // Remove a resource with "resource_id" from a directory with
726 // "parent_resource_id". 726 // "parent_resource_id".
727 drive::DeleteResourceOperation* operation = 727 drive::DeleteResourceOperation* operation =
728 new drive::DeleteResourceOperation( 728 new drive::DeleteResourceOperation(
729 operation_runner_.get(), 729 operation_runner_.get(),
730 request_context_getter_.get(), 730 request_context_getter_.get(),
731 *url_generator_, 731 *url_generator_,
732 "parent_resource_id", 732 "parent_resource_id",
733 "resource_id", 733 "resource_id",
734 CreateComposedCallback( 734 CreateComposedCallback(
735 base::Bind(&test_util::RunAndQuit), 735 base::Bind(&test_util::RunAndQuit),
736 test_util::CreateCopyResultCallback(&error))); 736 test_util::CreateCopyResultCallback(&error)));
737 operation_runner_->StartOperationWithRetry(operation); 737 operation_runner_->StartRequestWithRetry(operation);
738 base::MessageLoop::current()->Run(); 738 base::MessageLoop::current()->Run();
739 739
740 EXPECT_EQ(HTTP_NO_CONTENT, error); 740 EXPECT_EQ(HTTP_NO_CONTENT, error);
741 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); 741 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
742 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id", 742 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id",
743 http_request_.relative_url); 743 http_request_.relative_url);
744 EXPECT_FALSE(http_request_.has_content); 744 EXPECT_FALSE(http_request_.has_content);
745 } 745 }
746 746
747 TEST_F(DriveApiOperationsTest, UploadNewFileOperation) { 747 TEST_F(DriveApiOperationsTest, UploadNewFileOperation) {
(...skipping 17 matching lines...) Expand all
765 request_context_getter_.get(), 765 request_context_getter_.get(),
766 *url_generator_, 766 *url_generator_,
767 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 767 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
768 kTestContentType, 768 kTestContentType,
769 kTestContent.size(), 769 kTestContent.size(),
770 "parent_resource_id", // The resource id of the parent directory. 770 "parent_resource_id", // The resource id of the parent directory.
771 "new file title", // The title of the file being uploaded. 771 "new file title", // The title of the file being uploaded.
772 CreateComposedCallback( 772 CreateComposedCallback(
773 base::Bind(&test_util::RunAndQuit), 773 base::Bind(&test_util::RunAndQuit),
774 test_util::CreateCopyResultCallback(&error, &upload_url))); 774 test_util::CreateCopyResultCallback(&error, &upload_url)));
775 operation_runner_->StartOperationWithRetry(operation); 775 operation_runner_->StartRequestWithRetry(operation);
776 base::MessageLoop::current()->Run(); 776 base::MessageLoop::current()->Run();
777 777
778 EXPECT_EQ(HTTP_SUCCESS, error); 778 EXPECT_EQ(HTTP_SUCCESS, error);
779 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 779 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
780 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 780 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
781 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 781 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
782 http_request_.headers["X-Upload-Content-Length"]); 782 http_request_.headers["X-Upload-Content-Length"]);
783 783
784 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 784 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
785 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 785 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
786 http_request_.relative_url); 786 http_request_.relative_url);
787 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 787 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
788 EXPECT_TRUE(http_request_.has_content); 788 EXPECT_TRUE(http_request_.has_content);
789 EXPECT_EQ("{\"parents\":[{" 789 EXPECT_EQ("{\"parents\":[{"
790 "\"id\":\"parent_resource_id\"," 790 "\"id\":\"parent_resource_id\","
791 "\"kind\":\"drive#fileLink\"" 791 "\"kind\":\"drive#fileLink\""
792 "}]," 792 "}],"
793 "\"title\":\"new file title\"}", 793 "\"title\":\"new file title\"}",
794 http_request_.content); 794 http_request_.content);
795 795
796 // Upload the content to the upload URL. 796 // Upload the content to the upload URL.
797 UploadRangeResponse response; 797 UploadRangeResponse response;
798 scoped_ptr<FileResource> new_entry; 798 scoped_ptr<FileResource> new_entry;
799 799
800 drive::ResumeUploadOperation* resume_operation = 800 drive::ResumeUploadOperation* resume_operation =
801 new drive::ResumeUploadOperation( 801 new drive::ResumeUploadOperation(
802 operation_runner_.get(), 802 operation_runner_.get(),
803 request_context_getter_.get(), 803 request_context_getter_.get(),
804 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 804 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
805 upload_url, 805 upload_url,
806 0, // start_position 806 0, // start_position
807 kTestContent.size(), // end_position (exclusive) 807 kTestContent.size(), // end_position (exclusive)
808 kTestContent.size(), // content_length, 808 kTestContent.size(), // content_length,
809 kTestContentType, 809 kTestContentType,
810 kTestFilePath, 810 kTestFilePath,
811 CreateComposedCallback( 811 CreateComposedCallback(
812 base::Bind(&test_util::RunAndQuit), 812 base::Bind(&test_util::RunAndQuit),
813 test_util::CreateCopyResultCallback(&response, &new_entry)), 813 test_util::CreateCopyResultCallback(&response, &new_entry)),
814 ProgressCallback()); 814 ProgressCallback());
815 operation_runner_->StartOperationWithRetry(resume_operation); 815 operation_runner_->StartRequestWithRetry(resume_operation);
816 base::MessageLoop::current()->Run(); 816 base::MessageLoop::current()->Run();
817 817
818 // METHOD_PUT should be used to upload data. 818 // METHOD_PUT should be used to upload data.
819 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 819 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
820 // Request should go to the upload URL. 820 // Request should go to the upload URL.
821 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 821 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
822 // Content-Range header should be added. 822 // Content-Range header should be added.
823 EXPECT_EQ("bytes 0-" + 823 EXPECT_EQ("bytes 0-" +
824 base::Int64ToString(kTestContent.size() - 1) + "/" + 824 base::Int64ToString(kTestContent.size() - 1) + "/" +
825 base::Int64ToString(kTestContent.size()), 825 base::Int64ToString(kTestContent.size()),
(...skipping 29 matching lines...) Expand all
855 request_context_getter_.get(), 855 request_context_getter_.get(),
856 *url_generator_, 856 *url_generator_,
857 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 857 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
858 kTestContentType, 858 kTestContentType,
859 0, 859 0,
860 "parent_resource_id", // The resource id of the parent directory. 860 "parent_resource_id", // The resource id of the parent directory.
861 "new file title", // The title of the file being uploaded. 861 "new file title", // The title of the file being uploaded.
862 CreateComposedCallback( 862 CreateComposedCallback(
863 base::Bind(&test_util::RunAndQuit), 863 base::Bind(&test_util::RunAndQuit),
864 test_util::CreateCopyResultCallback(&error, &upload_url))); 864 test_util::CreateCopyResultCallback(&error, &upload_url)));
865 operation_runner_->StartOperationWithRetry(operation); 865 operation_runner_->StartRequestWithRetry(operation);
866 base::MessageLoop::current()->Run(); 866 base::MessageLoop::current()->Run();
867 867
868 EXPECT_EQ(HTTP_SUCCESS, error); 868 EXPECT_EQ(HTTP_SUCCESS, error);
869 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 869 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
870 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 870 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
871 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]); 871 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]);
872 872
873 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 873 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
874 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 874 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
875 http_request_.relative_url); 875 http_request_.relative_url);
876 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 876 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
877 EXPECT_TRUE(http_request_.has_content); 877 EXPECT_TRUE(http_request_.has_content);
878 EXPECT_EQ("{\"parents\":[{" 878 EXPECT_EQ("{\"parents\":[{"
879 "\"id\":\"parent_resource_id\"," 879 "\"id\":\"parent_resource_id\","
880 "\"kind\":\"drive#fileLink\"" 880 "\"kind\":\"drive#fileLink\""
881 "}]," 881 "}],"
882 "\"title\":\"new file title\"}", 882 "\"title\":\"new file title\"}",
883 http_request_.content); 883 http_request_.content);
884 884
885 // Upload the content to the upload URL. 885 // Upload the content to the upload URL.
886 UploadRangeResponse response; 886 UploadRangeResponse response;
887 scoped_ptr<FileResource> new_entry; 887 scoped_ptr<FileResource> new_entry;
888 888
889 drive::ResumeUploadOperation* resume_operation = 889 drive::ResumeUploadOperation* resume_operation =
890 new drive::ResumeUploadOperation( 890 new drive::ResumeUploadOperation(
891 operation_runner_.get(), 891 operation_runner_.get(),
892 request_context_getter_.get(), 892 request_context_getter_.get(),
893 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 893 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
894 upload_url, 894 upload_url,
895 0, // start_position 895 0, // start_position
896 0, // end_position (exclusive) 896 0, // end_position (exclusive)
897 0, // content_length, 897 0, // content_length,
898 kTestContentType, 898 kTestContentType,
899 kTestFilePath, 899 kTestFilePath,
900 CreateComposedCallback( 900 CreateComposedCallback(
901 base::Bind(&test_util::RunAndQuit), 901 base::Bind(&test_util::RunAndQuit),
902 test_util::CreateCopyResultCallback(&response, &new_entry)), 902 test_util::CreateCopyResultCallback(&response, &new_entry)),
903 ProgressCallback()); 903 ProgressCallback());
904 operation_runner_->StartOperationWithRetry(resume_operation); 904 operation_runner_->StartRequestWithRetry(resume_operation);
905 base::MessageLoop::current()->Run(); 905 base::MessageLoop::current()->Run();
906 906
907 // METHOD_PUT should be used to upload data. 907 // METHOD_PUT should be used to upload data.
908 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 908 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
909 // Request should go to the upload URL. 909 // Request should go to the upload URL.
910 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 910 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
911 // Content-Range header should NOT be added. 911 // Content-Range header should NOT be added.
912 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); 912 EXPECT_EQ(0U, http_request_.headers.count("Content-Range"));
913 // The upload content should be set in the HTTP request. 913 // The upload content should be set in the HTTP request.
914 EXPECT_TRUE(http_request_.has_content); 914 EXPECT_TRUE(http_request_.has_content);
(...skipping 30 matching lines...) Expand all
945 request_context_getter_.get(), 945 request_context_getter_.get(),
946 *url_generator_, 946 *url_generator_,
947 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 947 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
948 kTestContentType, 948 kTestContentType,
949 kTestContent.size(), 949 kTestContent.size(),
950 "parent_resource_id", // The resource id of the parent directory. 950 "parent_resource_id", // The resource id of the parent directory.
951 "new file title", // The title of the file being uploaded. 951 "new file title", // The title of the file being uploaded.
952 CreateComposedCallback( 952 CreateComposedCallback(
953 base::Bind(&test_util::RunAndQuit), 953 base::Bind(&test_util::RunAndQuit),
954 test_util::CreateCopyResultCallback(&error, &upload_url))); 954 test_util::CreateCopyResultCallback(&error, &upload_url)));
955 operation_runner_->StartOperationWithRetry(operation); 955 operation_runner_->StartRequestWithRetry(operation);
956 base::MessageLoop::current()->Run(); 956 base::MessageLoop::current()->Run();
957 957
958 EXPECT_EQ(HTTP_SUCCESS, error); 958 EXPECT_EQ(HTTP_SUCCESS, error);
959 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 959 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
960 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 960 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
961 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 961 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
962 http_request_.headers["X-Upload-Content-Length"]); 962 http_request_.headers["X-Upload-Content-Length"]);
963 963
964 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 964 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
965 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 965 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
966 http_request_.relative_url); 966 http_request_.relative_url);
967 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 967 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
968 EXPECT_TRUE(http_request_.has_content); 968 EXPECT_TRUE(http_request_.has_content);
969 EXPECT_EQ("{\"parents\":[{" 969 EXPECT_EQ("{\"parents\":[{"
970 "\"id\":\"parent_resource_id\"," 970 "\"id\":\"parent_resource_id\","
971 "\"kind\":\"drive#fileLink\"" 971 "\"kind\":\"drive#fileLink\""
972 "}]," 972 "}],"
973 "\"title\":\"new file title\"}", 973 "\"title\":\"new file title\"}",
974 http_request_.content); 974 http_request_.content);
975 975
976 #if !defined(NO_GET_UPLOAD_STATUS_TEST) 976 #if !defined(NO_GET_UPLOAD_STATUS_TEST)
977 // Before sending any data, check the current status. 977 // Before sending any data, check the current status.
978 // This is an edge case test for GetUploadStatusOperation. 978 // This is an edge case test for GetUploadStatusOperation.
979 { 979 {
980 UploadRangeResponse response; 980 UploadRangeResponse response;
981 scoped_ptr<FileResource> new_entry; 981 scoped_ptr<FileResource> new_entry;
982 982
983 // Check the response by GetUploadStatusOperation. 983 // Check the response by GetUploadStatusOperation.
984 drive::GetUploadStatusOperation* get_upload_status_operation = 984 drive::GetUploadStatusOperation* get_upload_status_operation =
985 new drive::GetUploadStatusOperation( 985 new drive::GetUploadStatusOperation(
986 operation_runner_.get(), 986 operation_runner_.get(),
987 request_context_getter_.get(), 987 request_context_getter_.get(),
988 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 988 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
989 upload_url, 989 upload_url,
990 kTestContent.size(), 990 kTestContent.size(),
991 CreateComposedCallback( 991 CreateComposedCallback(
992 base::Bind(&test_util::RunAndQuit), 992 base::Bind(&test_util::RunAndQuit),
993 test_util::CreateCopyResultCallback(&response, &new_entry))); 993 test_util::CreateCopyResultCallback(&response, &new_entry)));
994 operation_runner_->StartOperationWithRetry(get_upload_status_operation); 994 operation_runner_->StartRequestWithRetry(get_upload_status_operation);
995 base::MessageLoop::current()->Run(); 995 base::MessageLoop::current()->Run();
996 996
997 // METHOD_PUT should be used to upload data. 997 // METHOD_PUT should be used to upload data.
998 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 998 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
999 // Request should go to the upload URL. 999 // Request should go to the upload URL.
1000 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1000 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1001 // Content-Range header should be added. 1001 // Content-Range header should be added.
1002 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), 1002 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()),
1003 http_request_.headers["Content-Range"]); 1003 http_request_.headers["Content-Range"]);
1004 EXPECT_TRUE(http_request_.has_content); 1004 EXPECT_TRUE(http_request_.has_content);
(...skipping 25 matching lines...) Expand all
1030 upload_url, 1030 upload_url,
1031 start_position, 1031 start_position,
1032 end_position, 1032 end_position,
1033 kTestContent.size(), // content_length, 1033 kTestContent.size(), // content_length,
1034 kTestContentType, 1034 kTestContentType,
1035 kTestFilePath, 1035 kTestFilePath,
1036 CreateComposedCallback( 1036 CreateComposedCallback(
1037 base::Bind(&test_util::RunAndQuit), 1037 base::Bind(&test_util::RunAndQuit),
1038 test_util::CreateCopyResultCallback(&response, &new_entry)), 1038 test_util::CreateCopyResultCallback(&response, &new_entry)),
1039 ProgressCallback()); 1039 ProgressCallback());
1040 operation_runner_->StartOperationWithRetry(resume_operation); 1040 operation_runner_->StartRequestWithRetry(resume_operation);
1041 base::MessageLoop::current()->Run(); 1041 base::MessageLoop::current()->Run();
1042 1042
1043 // METHOD_PUT should be used to upload data. 1043 // METHOD_PUT should be used to upload data.
1044 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1044 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1045 // Request should go to the upload URL. 1045 // Request should go to the upload URL.
1046 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1046 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1047 // Content-Range header should be added. 1047 // Content-Range header should be added.
1048 EXPECT_EQ("bytes " + 1048 EXPECT_EQ("bytes " +
1049 base::Int64ToString(start_position) + "-" + 1049 base::Int64ToString(start_position) + "-" +
1050 base::Int64ToString(end_position - 1) + "/" + 1050 base::Int64ToString(end_position - 1) + "/" +
(...skipping 23 matching lines...) Expand all
1074 drive::GetUploadStatusOperation* get_upload_status_operation = 1074 drive::GetUploadStatusOperation* get_upload_status_operation =
1075 new drive::GetUploadStatusOperation( 1075 new drive::GetUploadStatusOperation(
1076 operation_runner_.get(), 1076 operation_runner_.get(),
1077 request_context_getter_.get(), 1077 request_context_getter_.get(),
1078 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 1078 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1079 upload_url, 1079 upload_url,
1080 kTestContent.size(), 1080 kTestContent.size(),
1081 CreateComposedCallback( 1081 CreateComposedCallback(
1082 base::Bind(&test_util::RunAndQuit), 1082 base::Bind(&test_util::RunAndQuit),
1083 test_util::CreateCopyResultCallback(&response, &new_entry))); 1083 test_util::CreateCopyResultCallback(&response, &new_entry)));
1084 operation_runner_->StartOperationWithRetry(get_upload_status_operation); 1084 operation_runner_->StartRequestWithRetry(get_upload_status_operation);
1085 base::MessageLoop::current()->Run(); 1085 base::MessageLoop::current()->Run();
1086 1086
1087 // METHOD_PUT should be used to upload data. 1087 // METHOD_PUT should be used to upload data.
1088 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1088 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1089 // Request should go to the upload URL. 1089 // Request should go to the upload URL.
1090 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1090 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1091 // Content-Range header should be added. 1091 // Content-Range header should be added.
1092 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), 1092 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()),
1093 http_request_.headers["Content-Range"]); 1093 http_request_.headers["Content-Range"]);
1094 EXPECT_TRUE(http_request_.has_content); 1094 EXPECT_TRUE(http_request_.has_content);
(...skipping 28 matching lines...) Expand all
1123 request_context_getter_.get(), 1123 request_context_getter_.get(),
1124 *url_generator_, 1124 *url_generator_,
1125 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 1125 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1126 kTestContentType, 1126 kTestContentType,
1127 kTestContent.size(), 1127 kTestContent.size(),
1128 "resource_id", // The resource id of the file to be overwritten. 1128 "resource_id", // The resource id of the file to be overwritten.
1129 std::string(), // No etag. 1129 std::string(), // No etag.
1130 CreateComposedCallback( 1130 CreateComposedCallback(
1131 base::Bind(&test_util::RunAndQuit), 1131 base::Bind(&test_util::RunAndQuit),
1132 test_util::CreateCopyResultCallback(&error, &upload_url))); 1132 test_util::CreateCopyResultCallback(&error, &upload_url)));
1133 operation_runner_->StartOperationWithRetry(operation); 1133 operation_runner_->StartRequestWithRetry(operation);
1134 base::MessageLoop::current()->Run(); 1134 base::MessageLoop::current()->Run();
1135 1135
1136 EXPECT_EQ(HTTP_SUCCESS, error); 1136 EXPECT_EQ(HTTP_SUCCESS, error);
1137 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); 1137 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
1138 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1138 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1139 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1139 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1140 http_request_.headers["X-Upload-Content-Length"]); 1140 http_request_.headers["X-Upload-Content-Length"]);
1141 EXPECT_EQ("*", http_request_.headers["If-Match"]); 1141 EXPECT_EQ("*", http_request_.headers["If-Match"]);
1142 1142
1143 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1143 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
(...skipping 14 matching lines...) Expand all
1158 upload_url, 1158 upload_url,
1159 0, // start_position 1159 0, // start_position
1160 kTestContent.size(), // end_position (exclusive) 1160 kTestContent.size(), // end_position (exclusive)
1161 kTestContent.size(), // content_length, 1161 kTestContent.size(), // content_length,
1162 kTestContentType, 1162 kTestContentType,
1163 kTestFilePath, 1163 kTestFilePath,
1164 CreateComposedCallback( 1164 CreateComposedCallback(
1165 base::Bind(&test_util::RunAndQuit), 1165 base::Bind(&test_util::RunAndQuit),
1166 test_util::CreateCopyResultCallback(&response, &new_entry)), 1166 test_util::CreateCopyResultCallback(&response, &new_entry)),
1167 ProgressCallback()); 1167 ProgressCallback());
1168 operation_runner_->StartOperationWithRetry(resume_operation); 1168 operation_runner_->StartRequestWithRetry(resume_operation);
1169 base::MessageLoop::current()->Run(); 1169 base::MessageLoop::current()->Run();
1170 1170
1171 // METHOD_PUT should be used to upload data. 1171 // METHOD_PUT should be used to upload data.
1172 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1172 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1173 // Request should go to the upload URL. 1173 // Request should go to the upload URL.
1174 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1174 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1175 // Content-Range header should be added. 1175 // Content-Range header should be added.
1176 EXPECT_EQ("bytes 0-" + 1176 EXPECT_EQ("bytes 0-" +
1177 base::Int64ToString(kTestContent.size() - 1) + "/" + 1177 base::Int64ToString(kTestContent.size() - 1) + "/" +
1178 base::Int64ToString(kTestContent.size()), 1178 base::Int64ToString(kTestContent.size()),
(...skipping 29 matching lines...) Expand all
1208 request_context_getter_.get(), 1208 request_context_getter_.get(),
1209 *url_generator_, 1209 *url_generator_,
1210 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 1210 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1211 kTestContentType, 1211 kTestContentType,
1212 kTestContent.size(), 1212 kTestContent.size(),
1213 "resource_id", // The resource id of the file to be overwritten. 1213 "resource_id", // The resource id of the file to be overwritten.
1214 kTestETag, 1214 kTestETag,
1215 CreateComposedCallback( 1215 CreateComposedCallback(
1216 base::Bind(&test_util::RunAndQuit), 1216 base::Bind(&test_util::RunAndQuit),
1217 test_util::CreateCopyResultCallback(&error, &upload_url))); 1217 test_util::CreateCopyResultCallback(&error, &upload_url)));
1218 operation_runner_->StartOperationWithRetry(operation); 1218 operation_runner_->StartRequestWithRetry(operation);
1219 base::MessageLoop::current()->Run(); 1219 base::MessageLoop::current()->Run();
1220 1220
1221 EXPECT_EQ(HTTP_SUCCESS, error); 1221 EXPECT_EQ(HTTP_SUCCESS, error);
1222 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); 1222 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
1223 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1223 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1224 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1224 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1225 http_request_.headers["X-Upload-Content-Length"]); 1225 http_request_.headers["X-Upload-Content-Length"]);
1226 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); 1226 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]);
1227 1227
1228 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1228 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
(...skipping 14 matching lines...) Expand all
1243 upload_url, 1243 upload_url,
1244 0, // start_position 1244 0, // start_position
1245 kTestContent.size(), // end_position (exclusive) 1245 kTestContent.size(), // end_position (exclusive)
1246 kTestContent.size(), // content_length, 1246 kTestContent.size(), // content_length,
1247 kTestContentType, 1247 kTestContentType,
1248 kTestFilePath, 1248 kTestFilePath,
1249 CreateComposedCallback( 1249 CreateComposedCallback(
1250 base::Bind(&test_util::RunAndQuit), 1250 base::Bind(&test_util::RunAndQuit),
1251 test_util::CreateCopyResultCallback(&response, &new_entry)), 1251 test_util::CreateCopyResultCallback(&response, &new_entry)),
1252 ProgressCallback()); 1252 ProgressCallback());
1253 operation_runner_->StartOperationWithRetry(resume_operation); 1253 operation_runner_->StartRequestWithRetry(resume_operation);
1254 base::MessageLoop::current()->Run(); 1254 base::MessageLoop::current()->Run();
1255 1255
1256 // METHOD_PUT should be used to upload data. 1256 // METHOD_PUT should be used to upload data.
1257 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1257 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1258 // Request should go to the upload URL. 1258 // Request should go to the upload URL.
1259 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1259 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1260 // Content-Range header should be added. 1260 // Content-Range header should be added.
1261 EXPECT_EQ("bytes 0-" + 1261 EXPECT_EQ("bytes 0-" +
1262 base::Int64ToString(kTestContent.size() - 1) + "/" + 1262 base::Int64ToString(kTestContent.size() - 1) + "/" +
1263 base::Int64ToString(kTestContent.size()), 1263 base::Int64ToString(kTestContent.size()),
(...skipping 26 matching lines...) Expand all
1290 request_context_getter_.get(), 1290 request_context_getter_.get(),
1291 *url_generator_, 1291 *url_generator_,
1292 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), 1292 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1293 kTestContentType, 1293 kTestContentType,
1294 kTestContent.size(), 1294 kTestContent.size(),
1295 "resource_id", // The resource id of the file to be overwritten. 1295 "resource_id", // The resource id of the file to be overwritten.
1296 "Conflicting-etag", 1296 "Conflicting-etag",
1297 CreateComposedCallback( 1297 CreateComposedCallback(
1298 base::Bind(&test_util::RunAndQuit), 1298 base::Bind(&test_util::RunAndQuit),
1299 test_util::CreateCopyResultCallback(&error, &upload_url))); 1299 test_util::CreateCopyResultCallback(&error, &upload_url)));
1300 operation_runner_->StartOperationWithRetry(operation); 1300 operation_runner_->StartRequestWithRetry(operation);
1301 base::MessageLoop::current()->Run(); 1301 base::MessageLoop::current()->Run();
1302 1302
1303 EXPECT_EQ(HTTP_PRECONDITION, error); 1303 EXPECT_EQ(HTTP_PRECONDITION, error);
1304 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1304 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1305 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1305 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1306 http_request_.headers["X-Upload-Content-Length"]); 1306 http_request_.headers["X-Upload-Content-Length"]);
1307 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); 1307 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]);
1308 1308
1309 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1309 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1310 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", 1310 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1311 http_request_.relative_url); 1311 http_request_.relative_url);
1312 EXPECT_TRUE(http_request_.has_content); 1312 EXPECT_TRUE(http_request_.has_content);
1313 EXPECT_TRUE(http_request_.content.empty()); 1313 EXPECT_TRUE(http_request_.content.empty());
1314 } 1314 }
1315 1315
1316 } // namespace google_apis 1316 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_operations.cc ('k') | chrome/browser/google_apis/drive_api_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698