| OLD | NEW |
| 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/drive_api_operations.h" | 12 #include "chrome/browser/google_apis/drive_api_operations.h" |
| 12 #include "chrome/browser/google_apis/drive_api_parser.h" | 13 #include "chrome/browser/google_apis/drive_api_parser.h" |
| 13 #include "chrome/browser/google_apis/drive_api_url_generator.h" | 14 #include "chrome/browser/google_apis/drive_api_url_generator.h" |
| 14 #include "chrome/browser/google_apis/operation_registry.h" | 15 #include "chrome/browser/google_apis/operation_runner.h" |
| 15 #include "chrome/browser/google_apis/task_util.h" | 16 #include "chrome/browser/google_apis/task_util.h" |
| 16 #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" |
| 17 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 19 #include "net/test/embedded_test_server/http_request.h" | 21 #include "net/test/embedded_test_server/http_request.h" |
| 20 #include "net/test/embedded_test_server/http_response.h" | 22 #include "net/test/embedded_test_server/http_response.h" |
| 21 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 namespace google_apis { | 26 namespace google_apis { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 48 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 50 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 49 file_thread_(content::BrowserThread::FILE), | 51 file_thread_(content::BrowserThread::FILE), |
| 50 io_thread_(content::BrowserThread::IO), | 52 io_thread_(content::BrowserThread::IO), |
| 51 test_server_(content::BrowserThread::GetMessageLoopProxyForThread( | 53 test_server_(content::BrowserThread::GetMessageLoopProxyForThread( |
| 52 content::BrowserThread::IO)) { | 54 content::BrowserThread::IO)) { |
| 53 } | 55 } |
| 54 | 56 |
| 55 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
| 56 file_thread_.Start(); | 58 file_thread_.Start(); |
| 57 io_thread_.StartIOThread(); | 59 io_thread_.StartIOThread(); |
| 60 profile_.reset(new TestingProfile); |
| 58 | 61 |
| 59 request_context_getter_ = new net::TestURLRequestContextGetter( | 62 request_context_getter_ = new net::TestURLRequestContextGetter( |
| 60 content::BrowserThread::GetMessageLoopProxyForThread( | 63 content::BrowserThread::GetMessageLoopProxyForThread( |
| 61 content::BrowserThread::IO)); | 64 content::BrowserThread::IO)); |
| 62 | 65 |
| 66 operation_runner_.reset(new OperationRunner(profile_.get(), |
| 67 request_context_getter_, |
| 68 std::vector<std::string>(), |
| 69 kTestUserAgent)); |
| 70 operation_runner_->auth_service()->set_access_token_for_testing( |
| 71 kTestDriveApiAuthToken); |
| 72 |
| 63 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 64 | 74 |
| 65 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); | 75 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); |
| 66 test_server_.RegisterRequestHandler( | 76 test_server_.RegisterRequestHandler( |
| 67 base::Bind(&DriveApiOperationsTest::HandleChildrenDeleteRequest, | 77 base::Bind(&DriveApiOperationsTest::HandleChildrenDeleteRequest, |
| 68 base::Unretained(this))); | 78 base::Unretained(this))); |
| 69 test_server_.RegisterRequestHandler( | 79 test_server_.RegisterRequestHandler( |
| 70 base::Bind(&DriveApiOperationsTest::HandleDataFileRequest, | 80 base::Bind(&DriveApiOperationsTest::HandleDataFileRequest, |
| 71 base::Unretained(this))); | 81 base::Unretained(this))); |
| 72 test_server_.RegisterRequestHandler( | 82 test_server_.RegisterRequestHandler( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 92 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); | 102 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); |
| 93 request_context_getter_ = NULL; | 103 request_context_getter_ = NULL; |
| 94 ResetExpectedResponse(); | 104 ResetExpectedResponse(); |
| 95 } | 105 } |
| 96 | 106 |
| 97 MessageLoopForUI message_loop_; | 107 MessageLoopForUI message_loop_; |
| 98 content::TestBrowserThread ui_thread_; | 108 content::TestBrowserThread ui_thread_; |
| 99 content::TestBrowserThread file_thread_; | 109 content::TestBrowserThread file_thread_; |
| 100 content::TestBrowserThread io_thread_; | 110 content::TestBrowserThread io_thread_; |
| 101 net::test_server::EmbeddedTestServer test_server_; | 111 net::test_server::EmbeddedTestServer test_server_; |
| 102 OperationRegistry operation_registry_; | 112 scoped_ptr<TestingProfile> profile_; |
| 113 scoped_ptr<OperationRunner> operation_runner_; |
| 103 scoped_ptr<DriveApiUrlGenerator> url_generator_; | 114 scoped_ptr<DriveApiUrlGenerator> url_generator_; |
| 104 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 115 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 105 base::ScopedTempDir temp_dir_; | 116 base::ScopedTempDir temp_dir_; |
| 106 | 117 |
| 107 // 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 |
| 108 // the server. See also HandleDataFileRequest below. | 119 // the server. See also HandleDataFileRequest below. |
| 109 base::FilePath expected_data_file_path_; | 120 base::FilePath expected_data_file_path_; |
| 110 | 121 |
| 111 // 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 |
| 112 // for initiating file uploading. | 123 // for initiating file uploading. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 317 |
| 307 TEST_F(DriveApiOperationsTest, GetAboutOperation_ValidJson) { | 318 TEST_F(DriveApiOperationsTest, GetAboutOperation_ValidJson) { |
| 308 // Set an expected data file containing valid result. | 319 // Set an expected data file containing valid result. |
| 309 expected_data_file_path_ = test_util::GetTestFilePath( | 320 expected_data_file_path_ = test_util::GetTestFilePath( |
| 310 "chromeos/drive/about.json"); | 321 "chromeos/drive/about.json"); |
| 311 | 322 |
| 312 GDataErrorCode error = GDATA_OTHER_ERROR; | 323 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 313 scoped_ptr<AboutResource> about_resource; | 324 scoped_ptr<AboutResource> about_resource; |
| 314 | 325 |
| 315 GetAboutOperation* operation = new GetAboutOperation( | 326 GetAboutOperation* operation = new GetAboutOperation( |
| 316 &operation_registry_, | 327 operation_runner_.get(), |
| 317 request_context_getter_.get(), | 328 request_context_getter_.get(), |
| 318 *url_generator_, | 329 *url_generator_, |
| 319 CreateComposedCallback( | 330 CreateComposedCallback( |
| 320 base::Bind(&test_util::RunAndQuit), | 331 base::Bind(&test_util::RunAndQuit), |
| 321 test_util::CreateCopyResultCallback(&error, &about_resource))); | 332 test_util::CreateCopyResultCallback(&error, &about_resource))); |
| 322 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 333 operation_runner_->StartOperationWithRetry(operation); |
| 323 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 324 MessageLoop::current()->Run(); | 334 MessageLoop::current()->Run(); |
| 325 | 335 |
| 326 EXPECT_EQ(HTTP_SUCCESS, error); | 336 EXPECT_EQ(HTTP_SUCCESS, error); |
| 327 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 337 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 328 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); | 338 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); |
| 329 | 339 |
| 330 scoped_ptr<AboutResource> expected( | 340 scoped_ptr<AboutResource> expected( |
| 331 AboutResource::CreateFrom( | 341 AboutResource::CreateFrom( |
| 332 *test_util::LoadJSONFile("chromeos/drive/about.json"))); | 342 *test_util::LoadJSONFile("chromeos/drive/about.json"))); |
| 333 ASSERT_TRUE(about_resource.get()); | 343 ASSERT_TRUE(about_resource.get()); |
| 334 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id()); | 344 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id()); |
| 335 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total()); | 345 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total()); |
| 336 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used()); | 346 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used()); |
| 337 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id()); | 347 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id()); |
| 338 } | 348 } |
| 339 | 349 |
| 340 TEST_F(DriveApiOperationsTest, GetAboutOperation_InvalidJson) { | 350 TEST_F(DriveApiOperationsTest, GetAboutOperation_InvalidJson) { |
| 341 // Set an expected data file containing invalid result. | 351 // Set an expected data file containing invalid result. |
| 342 expected_data_file_path_ = test_util::GetTestFilePath( | 352 expected_data_file_path_ = test_util::GetTestFilePath( |
| 343 "chromeos/gdata/testfile.txt"); | 353 "chromeos/gdata/testfile.txt"); |
| 344 | 354 |
| 345 GDataErrorCode error = GDATA_OTHER_ERROR; | 355 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 346 scoped_ptr<AboutResource> about_resource; | 356 scoped_ptr<AboutResource> about_resource; |
| 347 | 357 |
| 348 GetAboutOperation* operation = new GetAboutOperation( | 358 GetAboutOperation* operation = new GetAboutOperation( |
| 349 &operation_registry_, | 359 operation_runner_.get(), |
| 350 request_context_getter_.get(), | 360 request_context_getter_.get(), |
| 351 *url_generator_, | 361 *url_generator_, |
| 352 CreateComposedCallback( | 362 CreateComposedCallback( |
| 353 base::Bind(&test_util::RunAndQuit), | 363 base::Bind(&test_util::RunAndQuit), |
| 354 test_util::CreateCopyResultCallback(&error, &about_resource))); | 364 test_util::CreateCopyResultCallback(&error, &about_resource))); |
| 355 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 365 operation_runner_->StartOperationWithRetry(operation); |
| 356 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 357 MessageLoop::current()->Run(); | 366 MessageLoop::current()->Run(); |
| 358 | 367 |
| 359 // "parse error" should be returned, and the about resource should be NULL. | 368 // "parse error" should be returned, and the about resource should be NULL. |
| 360 EXPECT_EQ(GDATA_PARSE_ERROR, error); | 369 EXPECT_EQ(GDATA_PARSE_ERROR, error); |
| 361 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 370 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 362 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); | 371 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); |
| 363 EXPECT_FALSE(about_resource.get()); | 372 EXPECT_FALSE(about_resource.get()); |
| 364 } | 373 } |
| 365 | 374 |
| 366 TEST_F(DriveApiOperationsTest, GetApplistOperation) { | 375 TEST_F(DriveApiOperationsTest, GetApplistOperation) { |
| 367 // Set an expected data file containing valid result. | 376 // Set an expected data file containing valid result. |
| 368 expected_data_file_path_ = test_util::GetTestFilePath( | 377 expected_data_file_path_ = test_util::GetTestFilePath( |
| 369 "chromeos/drive/applist.json"); | 378 "chromeos/drive/applist.json"); |
| 370 | 379 |
| 371 GDataErrorCode error = GDATA_OTHER_ERROR; | 380 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 372 scoped_ptr<base::Value> result; | 381 scoped_ptr<base::Value> result; |
| 373 | 382 |
| 374 GetApplistOperation* operation = new GetApplistOperation( | 383 GetApplistOperation* operation = new GetApplistOperation( |
| 375 &operation_registry_, | 384 operation_runner_.get(), |
| 376 request_context_getter_.get(), | 385 request_context_getter_.get(), |
| 377 *url_generator_, | 386 *url_generator_, |
| 378 CreateComposedCallback( | 387 CreateComposedCallback( |
| 379 base::Bind(&test_util::RunAndQuit), | 388 base::Bind(&test_util::RunAndQuit), |
| 380 test_util::CreateCopyResultCallback(&error, &result))); | 389 test_util::CreateCopyResultCallback(&error, &result))); |
| 381 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 390 operation_runner_->StartOperationWithRetry(operation); |
| 382 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 383 MessageLoop::current()->Run(); | 391 MessageLoop::current()->Run(); |
| 384 | 392 |
| 385 EXPECT_EQ(HTTP_SUCCESS, error); | 393 EXPECT_EQ(HTTP_SUCCESS, error); |
| 386 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 394 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 387 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url); | 395 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url); |
| 388 EXPECT_TRUE(result); | 396 EXPECT_TRUE(result); |
| 389 } | 397 } |
| 390 | 398 |
| 391 TEST_F(DriveApiOperationsTest, GetChangelistOperation) { | 399 TEST_F(DriveApiOperationsTest, GetChangelistOperation) { |
| 392 // Set an expected data file containing valid result. | 400 // Set an expected data file containing valid result. |
| 393 expected_data_file_path_ = test_util::GetTestFilePath( | 401 expected_data_file_path_ = test_util::GetTestFilePath( |
| 394 "chromeos/drive/changelist.json"); | 402 "chromeos/drive/changelist.json"); |
| 395 | 403 |
| 396 GDataErrorCode error = GDATA_OTHER_ERROR; | 404 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 397 scoped_ptr<base::Value> result; | 405 scoped_ptr<base::Value> result; |
| 398 | 406 |
| 399 GetChangelistOperation* operation = new GetChangelistOperation( | 407 GetChangelistOperation* operation = new GetChangelistOperation( |
| 400 &operation_registry_, | 408 operation_runner_.get(), |
| 401 request_context_getter_.get(), | 409 request_context_getter_.get(), |
| 402 *url_generator_, | 410 *url_generator_, |
| 403 true, // include deleted | 411 true, // include deleted |
| 404 100, // start changestamp | 412 100, // start changestamp |
| 405 500, // max results | 413 500, // max results |
| 406 CreateComposedCallback( | 414 CreateComposedCallback( |
| 407 base::Bind(&test_util::RunAndQuit), | 415 base::Bind(&test_util::RunAndQuit), |
| 408 test_util::CreateCopyResultCallback(&error, &result))); | 416 test_util::CreateCopyResultCallback(&error, &result))); |
| 409 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 417 operation_runner_->StartOperationWithRetry(operation); |
| 410 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 411 MessageLoop::current()->Run(); | 418 MessageLoop::current()->Run(); |
| 412 | 419 |
| 413 EXPECT_EQ(HTTP_SUCCESS, error); | 420 EXPECT_EQ(HTTP_SUCCESS, error); |
| 414 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 421 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 415 EXPECT_EQ("/drive/v2/changes?startChangeId=100&maxResults=500", | 422 EXPECT_EQ("/drive/v2/changes?startChangeId=100&maxResults=500", |
| 416 http_request_.relative_url); | 423 http_request_.relative_url); |
| 417 EXPECT_TRUE(result); | 424 EXPECT_TRUE(result); |
| 418 } | 425 } |
| 419 | 426 |
| 420 TEST_F(DriveApiOperationsTest, GetFilelistOperation) { | 427 TEST_F(DriveApiOperationsTest, GetFilelistOperation) { |
| 421 // Set an expected data file containing valid result. | 428 // Set an expected data file containing valid result. |
| 422 expected_data_file_path_ = test_util::GetTestFilePath( | 429 expected_data_file_path_ = test_util::GetTestFilePath( |
| 423 "chromeos/drive/filelist.json"); | 430 "chromeos/drive/filelist.json"); |
| 424 | 431 |
| 425 GDataErrorCode error = GDATA_OTHER_ERROR; | 432 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 426 scoped_ptr<base::Value> result; | 433 scoped_ptr<base::Value> result; |
| 427 | 434 |
| 428 GetFilelistOperation* operation = new GetFilelistOperation( | 435 GetFilelistOperation* operation = new GetFilelistOperation( |
| 429 &operation_registry_, | 436 operation_runner_.get(), |
| 430 request_context_getter_.get(), | 437 request_context_getter_.get(), |
| 431 *url_generator_, | 438 *url_generator_, |
| 432 "\"abcde\" in parents", | 439 "\"abcde\" in parents", |
| 433 50, // max results | 440 50, // max results |
| 434 CreateComposedCallback( | 441 CreateComposedCallback( |
| 435 base::Bind(&test_util::RunAndQuit), | 442 base::Bind(&test_util::RunAndQuit), |
| 436 test_util::CreateCopyResultCallback(&error, &result))); | 443 test_util::CreateCopyResultCallback(&error, &result))); |
| 437 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 444 operation_runner_->StartOperationWithRetry(operation); |
| 438 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 439 MessageLoop::current()->Run(); | 445 MessageLoop::current()->Run(); |
| 440 | 446 |
| 441 EXPECT_EQ(HTTP_SUCCESS, error); | 447 EXPECT_EQ(HTTP_SUCCESS, error); |
| 442 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 448 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 443 EXPECT_EQ("/drive/v2/files?maxResults=50&q=%22abcde%22+in+parents", | 449 EXPECT_EQ("/drive/v2/files?maxResults=50&q=%22abcde%22+in+parents", |
| 444 http_request_.relative_url); | 450 http_request_.relative_url); |
| 445 EXPECT_TRUE(result); | 451 EXPECT_TRUE(result); |
| 446 } | 452 } |
| 447 | 453 |
| 448 TEST_F(DriveApiOperationsTest, ContinueGetFileListOperation) { | 454 TEST_F(DriveApiOperationsTest, ContinueGetFileListOperation) { |
| 449 // Set an expected data file containing valid result. | 455 // Set an expected data file containing valid result. |
| 450 expected_data_file_path_ = test_util::GetTestFilePath( | 456 expected_data_file_path_ = test_util::GetTestFilePath( |
| 451 "chromeos/drive/filelist.json"); | 457 "chromeos/drive/filelist.json"); |
| 452 | 458 |
| 453 GDataErrorCode error = GDATA_OTHER_ERROR; | 459 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 454 scoped_ptr<base::Value> result; | 460 scoped_ptr<base::Value> result; |
| 455 | 461 |
| 456 drive::ContinueGetFileListOperation* operation = | 462 drive::ContinueGetFileListOperation* operation = |
| 457 new drive::ContinueGetFileListOperation( | 463 new drive::ContinueGetFileListOperation( |
| 458 &operation_registry_, | 464 operation_runner_.get(), |
| 459 request_context_getter_.get(), | 465 request_context_getter_.get(), |
| 460 test_server_.GetURL("/continue/get/file/list"), | 466 test_server_.GetURL("/continue/get/file/list"), |
| 461 CreateComposedCallback( | 467 CreateComposedCallback( |
| 462 base::Bind(&test_util::RunAndQuit), | 468 base::Bind(&test_util::RunAndQuit), |
| 463 test_util::CreateCopyResultCallback(&error, &result))); | 469 test_util::CreateCopyResultCallback(&error, &result))); |
| 464 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 470 operation_runner_->StartOperationWithRetry(operation); |
| 465 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 466 MessageLoop::current()->Run(); | 471 MessageLoop::current()->Run(); |
| 467 | 472 |
| 468 EXPECT_EQ(HTTP_SUCCESS, error); | 473 EXPECT_EQ(HTTP_SUCCESS, error); |
| 469 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 474 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 470 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); | 475 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); |
| 471 EXPECT_TRUE(result); | 476 EXPECT_TRUE(result); |
| 472 } | 477 } |
| 473 | 478 |
| 474 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) { | 479 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) { |
| 475 // Set an expected data file containing the directory's entry data. | 480 // Set an expected data file containing the directory's entry data. |
| 476 expected_data_file_path_ = | 481 expected_data_file_path_ = |
| 477 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); | 482 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); |
| 478 | 483 |
| 479 GDataErrorCode error = GDATA_OTHER_ERROR; | 484 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 480 scoped_ptr<FileResource> file_resource; | 485 scoped_ptr<FileResource> file_resource; |
| 481 | 486 |
| 482 // Create "new directory" in the root directory. | 487 // Create "new directory" in the root directory. |
| 483 drive::CreateDirectoryOperation* operation = | 488 drive::CreateDirectoryOperation* operation = |
| 484 new drive::CreateDirectoryOperation( | 489 new drive::CreateDirectoryOperation( |
| 485 &operation_registry_, | 490 operation_runner_.get(), |
| 486 request_context_getter_.get(), | 491 request_context_getter_.get(), |
| 487 *url_generator_, | 492 *url_generator_, |
| 488 "root", | 493 "root", |
| 489 "new directory", | 494 "new directory", |
| 490 CreateComposedCallback( | 495 CreateComposedCallback( |
| 491 base::Bind(&test_util::RunAndQuit), | 496 base::Bind(&test_util::RunAndQuit), |
| 492 test_util::CreateCopyResultCallback(&error, &file_resource))); | 497 test_util::CreateCopyResultCallback(&error, &file_resource))); |
| 493 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 498 operation_runner_->StartOperationWithRetry(operation); |
| 494 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 495 MessageLoop::current()->Run(); | 499 MessageLoop::current()->Run(); |
| 496 | 500 |
| 497 EXPECT_EQ(HTTP_SUCCESS, error); | 501 EXPECT_EQ(HTTP_SUCCESS, error); |
| 498 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 502 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 499 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); | 503 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); |
| 500 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 504 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 501 | 505 |
| 502 EXPECT_TRUE(http_request_.has_content); | 506 EXPECT_TRUE(http_request_.has_content); |
| 503 | 507 |
| 504 scoped_ptr<FileResource> expected( | 508 scoped_ptr<FileResource> expected( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 518 // Set an expected data file containing the directory's entry data. | 522 // Set an expected data file containing the directory's entry data. |
| 519 // It'd be returned if we rename a directory. | 523 // It'd be returned if we rename a directory. |
| 520 expected_data_file_path_ = | 524 expected_data_file_path_ = |
| 521 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); | 525 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); |
| 522 | 526 |
| 523 GDataErrorCode error = GDATA_OTHER_ERROR; | 527 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 524 | 528 |
| 525 // Create "new directory" in the root directory. | 529 // Create "new directory" in the root directory. |
| 526 drive::RenameResourceOperation* operation = | 530 drive::RenameResourceOperation* operation = |
| 527 new drive::RenameResourceOperation( | 531 new drive::RenameResourceOperation( |
| 528 &operation_registry_, | 532 operation_runner_.get(), |
| 529 request_context_getter_.get(), | 533 request_context_getter_.get(), |
| 530 *url_generator_, | 534 *url_generator_, |
| 531 "resource_id", | 535 "resource_id", |
| 532 "new name", | 536 "new name", |
| 533 CreateComposedCallback( | 537 CreateComposedCallback( |
| 534 base::Bind(&test_util::RunAndQuit), | 538 base::Bind(&test_util::RunAndQuit), |
| 535 test_util::CreateCopyResultCallback(&error))); | 539 test_util::CreateCopyResultCallback(&error))); |
| 536 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 540 operation_runner_->StartOperationWithRetry(operation); |
| 537 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 538 MessageLoop::current()->Run(); | 541 MessageLoop::current()->Run(); |
| 539 | 542 |
| 540 EXPECT_EQ(HTTP_SUCCESS, error); | 543 EXPECT_EQ(HTTP_SUCCESS, error); |
| 541 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); | 544 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); |
| 542 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); | 545 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); |
| 543 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 546 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 544 | 547 |
| 545 EXPECT_TRUE(http_request_.has_content); | 548 EXPECT_TRUE(http_request_.has_content); |
| 546 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); | 549 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); |
| 547 } | 550 } |
| 548 | 551 |
| 549 TEST_F(DriveApiOperationsTest, CopyResourceOperation) { | 552 TEST_F(DriveApiOperationsTest, CopyResourceOperation) { |
| 550 // Set an expected data file containing the dummy file entry data. | 553 // Set an expected data file containing the dummy file entry data. |
| 551 // It'd be returned if we copy a file. | 554 // It'd be returned if we copy a file. |
| 552 expected_data_file_path_ = | 555 expected_data_file_path_ = |
| 553 test_util::GetTestFilePath("chromeos/drive/file_entry.json"); | 556 test_util::GetTestFilePath("chromeos/drive/file_entry.json"); |
| 554 | 557 |
| 555 GDataErrorCode error = GDATA_OTHER_ERROR; | 558 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 556 scoped_ptr<FileResource> file_resource; | 559 scoped_ptr<FileResource> file_resource; |
| 557 | 560 |
| 558 // Copy the file to a new file named "new name". | 561 // Copy the file to a new file named "new name". |
| 559 drive::CopyResourceOperation* operation = | 562 drive::CopyResourceOperation* operation = |
| 560 new drive::CopyResourceOperation( | 563 new drive::CopyResourceOperation( |
| 561 &operation_registry_, | 564 operation_runner_.get(), |
| 562 request_context_getter_.get(), | 565 request_context_getter_.get(), |
| 563 *url_generator_, | 566 *url_generator_, |
| 564 "resource_id", | 567 "resource_id", |
| 565 "parent_resource_id", | 568 "parent_resource_id", |
| 566 "new name", | 569 "new name", |
| 567 CreateComposedCallback( | 570 CreateComposedCallback( |
| 568 base::Bind(&test_util::RunAndQuit), | 571 base::Bind(&test_util::RunAndQuit), |
| 569 test_util::CreateCopyResultCallback(&error, &file_resource))); | 572 test_util::CreateCopyResultCallback(&error, &file_resource))); |
| 570 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 573 operation_runner_->StartOperationWithRetry(operation); |
| 571 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 572 MessageLoop::current()->Run(); | 574 MessageLoop::current()->Run(); |
| 573 | 575 |
| 574 EXPECT_EQ(HTTP_SUCCESS, error); | 576 EXPECT_EQ(HTTP_SUCCESS, error); |
| 575 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 577 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 576 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); | 578 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); |
| 577 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 579 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 578 | 580 |
| 579 EXPECT_TRUE(http_request_.has_content); | 581 EXPECT_TRUE(http_request_.has_content); |
| 580 EXPECT_EQ( | 582 EXPECT_EQ( |
| 581 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new name\"}", | 583 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new name\"}", |
| 582 http_request_.content); | 584 http_request_.content); |
| 583 EXPECT_TRUE(file_resource); | 585 EXPECT_TRUE(file_resource); |
| 584 } | 586 } |
| 585 | 587 |
| 586 TEST_F(DriveApiOperationsTest, CopyResourceOperation_EmptyParentResourceId) { | 588 TEST_F(DriveApiOperationsTest, CopyResourceOperation_EmptyParentResourceId) { |
| 587 // Set an expected data file containing the dummy file entry data. | 589 // Set an expected data file containing the dummy file entry data. |
| 588 // It'd be returned if we copy a file. | 590 // It'd be returned if we copy a file. |
| 589 expected_data_file_path_ = | 591 expected_data_file_path_ = |
| 590 test_util::GetTestFilePath("chromeos/drive/file_entry.json"); | 592 test_util::GetTestFilePath("chromeos/drive/file_entry.json"); |
| 591 | 593 |
| 592 GDataErrorCode error = GDATA_OTHER_ERROR; | 594 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 593 scoped_ptr<FileResource> file_resource; | 595 scoped_ptr<FileResource> file_resource; |
| 594 | 596 |
| 595 // Copy the file to a new file named "new name". | 597 // Copy the file to a new file named "new name". |
| 596 drive::CopyResourceOperation* operation = | 598 drive::CopyResourceOperation* operation = |
| 597 new drive::CopyResourceOperation( | 599 new drive::CopyResourceOperation( |
| 598 &operation_registry_, | 600 operation_runner_.get(), |
| 599 request_context_getter_.get(), | 601 request_context_getter_.get(), |
| 600 *url_generator_, | 602 *url_generator_, |
| 601 "resource_id", | 603 "resource_id", |
| 602 std::string(), // parent resource id. | 604 std::string(), // parent resource id. |
| 603 "new name", | 605 "new name", |
| 604 CreateComposedCallback( | 606 CreateComposedCallback( |
| 605 base::Bind(&test_util::RunAndQuit), | 607 base::Bind(&test_util::RunAndQuit), |
| 606 test_util::CreateCopyResultCallback(&error, &file_resource))); | 608 test_util::CreateCopyResultCallback(&error, &file_resource))); |
| 607 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 609 operation_runner_->StartOperationWithRetry(operation); |
| 608 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 609 MessageLoop::current()->Run(); | 610 MessageLoop::current()->Run(); |
| 610 | 611 |
| 611 EXPECT_EQ(HTTP_SUCCESS, error); | 612 EXPECT_EQ(HTTP_SUCCESS, error); |
| 612 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 613 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 613 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); | 614 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); |
| 614 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 615 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 615 | 616 |
| 616 EXPECT_TRUE(http_request_.has_content); | 617 EXPECT_TRUE(http_request_.has_content); |
| 617 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); | 618 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); |
| 618 EXPECT_TRUE(file_resource); | 619 EXPECT_TRUE(file_resource); |
| 619 } | 620 } |
| 620 | 621 |
| 621 TEST_F(DriveApiOperationsTest, TrashResourceOperation) { | 622 TEST_F(DriveApiOperationsTest, TrashResourceOperation) { |
| 622 // Set data for the expected result. Directory entry should be returned | 623 // Set data for the expected result. Directory entry should be returned |
| 623 // if the trashing entry is a directory, so using it here should be fine. | 624 // if the trashing entry is a directory, so using it here should be fine. |
| 624 expected_data_file_path_ = | 625 expected_data_file_path_ = |
| 625 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); | 626 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); |
| 626 | 627 |
| 627 GDataErrorCode error = GDATA_OTHER_ERROR; | 628 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 628 | 629 |
| 629 // Trash a resource with the given resource id. | 630 // Trash a resource with the given resource id. |
| 630 drive::TrashResourceOperation* operation = | 631 drive::TrashResourceOperation* operation = |
| 631 new drive::TrashResourceOperation( | 632 new drive::TrashResourceOperation( |
| 632 &operation_registry_, | 633 operation_runner_.get(), |
| 633 request_context_getter_.get(), | 634 request_context_getter_.get(), |
| 634 *url_generator_, | 635 *url_generator_, |
| 635 "resource_id", | 636 "resource_id", |
| 636 CreateComposedCallback( | 637 CreateComposedCallback( |
| 637 base::Bind(&test_util::RunAndQuit), | 638 base::Bind(&test_util::RunAndQuit), |
| 638 test_util::CreateCopyResultCallback(&error))); | 639 test_util::CreateCopyResultCallback(&error))); |
| 639 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 640 operation_runner_->StartOperationWithRetry(operation); |
| 640 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 641 MessageLoop::current()->Run(); | 641 MessageLoop::current()->Run(); |
| 642 | 642 |
| 643 EXPECT_EQ(HTTP_SUCCESS, error); | 643 EXPECT_EQ(HTTP_SUCCESS, error); |
| 644 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 644 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 645 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url); | 645 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url); |
| 646 EXPECT_TRUE(http_request_.has_content); | 646 EXPECT_TRUE(http_request_.has_content); |
| 647 EXPECT_TRUE(http_request_.content.empty()); | 647 EXPECT_TRUE(http_request_.content.empty()); |
| 648 } | 648 } |
| 649 | 649 |
| 650 TEST_F(DriveApiOperationsTest, InsertResourceOperation) { | 650 TEST_F(DriveApiOperationsTest, InsertResourceOperation) { |
| 651 // Set an expected data file containing the children entry. | 651 // Set an expected data file containing the children entry. |
| 652 expected_content_type_ = "application/json"; | 652 expected_content_type_ = "application/json"; |
| 653 expected_content_ = kTestChildrenResponse; | 653 expected_content_ = kTestChildrenResponse; |
| 654 | 654 |
| 655 GDataErrorCode error = GDATA_OTHER_ERROR; | 655 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 656 | 656 |
| 657 // Add a resource with "resource_id" to a directory with | 657 // Add a resource with "resource_id" to a directory with |
| 658 // "parent_resource_id". | 658 // "parent_resource_id". |
| 659 drive::InsertResourceOperation* operation = | 659 drive::InsertResourceOperation* operation = |
| 660 new drive::InsertResourceOperation( | 660 new drive::InsertResourceOperation( |
| 661 &operation_registry_, | 661 operation_runner_.get(), |
| 662 request_context_getter_.get(), | 662 request_context_getter_.get(), |
| 663 *url_generator_, | 663 *url_generator_, |
| 664 "parent_resource_id", | 664 "parent_resource_id", |
| 665 "resource_id", | 665 "resource_id", |
| 666 CreateComposedCallback( | 666 CreateComposedCallback( |
| 667 base::Bind(&test_util::RunAndQuit), | 667 base::Bind(&test_util::RunAndQuit), |
| 668 test_util::CreateCopyResultCallback(&error))); | 668 test_util::CreateCopyResultCallback(&error))); |
| 669 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 669 operation_runner_->StartOperationWithRetry(operation); |
| 670 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 671 MessageLoop::current()->Run(); | 670 MessageLoop::current()->Run(); |
| 672 | 671 |
| 673 EXPECT_EQ(HTTP_SUCCESS, error); | 672 EXPECT_EQ(HTTP_SUCCESS, error); |
| 674 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 673 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 675 EXPECT_EQ("/drive/v2/files/parent_resource_id/children", | 674 EXPECT_EQ("/drive/v2/files/parent_resource_id/children", |
| 676 http_request_.relative_url); | 675 http_request_.relative_url); |
| 677 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 676 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 678 | 677 |
| 679 EXPECT_TRUE(http_request_.has_content); | 678 EXPECT_TRUE(http_request_.has_content); |
| 680 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content); | 679 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content); |
| 681 } | 680 } |
| 682 | 681 |
| 683 TEST_F(DriveApiOperationsTest, DeleteResourceOperation) { | 682 TEST_F(DriveApiOperationsTest, DeleteResourceOperation) { |
| 684 GDataErrorCode error = GDATA_OTHER_ERROR; | 683 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 685 | 684 |
| 686 // Remove a resource with "resource_id" from a directory with | 685 // Remove a resource with "resource_id" from a directory with |
| 687 // "parent_resource_id". | 686 // "parent_resource_id". |
| 688 drive::DeleteResourceOperation* operation = | 687 drive::DeleteResourceOperation* operation = |
| 689 new drive::DeleteResourceOperation( | 688 new drive::DeleteResourceOperation( |
| 690 &operation_registry_, | 689 operation_runner_.get(), |
| 691 request_context_getter_.get(), | 690 request_context_getter_.get(), |
| 692 *url_generator_, | 691 *url_generator_, |
| 693 "parent_resource_id", | 692 "parent_resource_id", |
| 694 "resource_id", | 693 "resource_id", |
| 695 CreateComposedCallback( | 694 CreateComposedCallback( |
| 696 base::Bind(&test_util::RunAndQuit), | 695 base::Bind(&test_util::RunAndQuit), |
| 697 test_util::CreateCopyResultCallback(&error))); | 696 test_util::CreateCopyResultCallback(&error))); |
| 698 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 697 operation_runner_->StartOperationWithRetry(operation); |
| 699 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 700 MessageLoop::current()->Run(); | 698 MessageLoop::current()->Run(); |
| 701 | 699 |
| 702 EXPECT_EQ(HTTP_NO_CONTENT, error); | 700 EXPECT_EQ(HTTP_NO_CONTENT, error); |
| 703 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); | 701 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); |
| 704 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id", | 702 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id", |
| 705 http_request_.relative_url); | 703 http_request_.relative_url); |
| 706 EXPECT_FALSE(http_request_.has_content); | 704 EXPECT_FALSE(http_request_.has_content); |
| 707 } | 705 } |
| 708 | 706 |
| 709 TEST_F(DriveApiOperationsTest, UploadNewFileOperation) { | 707 TEST_F(DriveApiOperationsTest, UploadNewFileOperation) { |
| 710 // Set an expected url for uploading. | 708 // Set an expected url for uploading. |
| 711 expected_upload_path_ = kTestUploadNewFilePath; | 709 expected_upload_path_ = kTestUploadNewFilePath; |
| 712 | 710 |
| 713 const char kTestContentType[] = "text/plain"; | 711 const char kTestContentType[] = "text/plain"; |
| 714 const std::string kTestContent(100, 'a'); | 712 const std::string kTestContent(100, 'a'); |
| 715 const base::FilePath kTestFilePath = | 713 const base::FilePath kTestFilePath = |
| 716 temp_dir_.path().AppendASCII("upload_file.txt"); | 714 temp_dir_.path().AppendASCII("upload_file.txt"); |
| 717 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 715 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 718 | 716 |
| 719 GDataErrorCode error = GDATA_OTHER_ERROR; | 717 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 720 GURL upload_url; | 718 GURL upload_url; |
| 721 | 719 |
| 722 // Initiate uploading a new file to the directory with | 720 // Initiate uploading a new file to the directory with |
| 723 // "parent_resource_id". | 721 // "parent_resource_id". |
| 724 drive::InitiateUploadNewFileOperation* operation = | 722 drive::InitiateUploadNewFileOperation* operation = |
| 725 new drive::InitiateUploadNewFileOperation( | 723 new drive::InitiateUploadNewFileOperation( |
| 726 &operation_registry_, | 724 operation_runner_.get(), |
| 727 request_context_getter_.get(), | 725 request_context_getter_.get(), |
| 728 *url_generator_, | 726 *url_generator_, |
| 729 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 727 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 730 kTestContentType, | 728 kTestContentType, |
| 731 kTestContent.size(), | 729 kTestContent.size(), |
| 732 "parent_resource_id", // The resource id of the parent directory. | 730 "parent_resource_id", // The resource id of the parent directory. |
| 733 "new file title", // The title of the file being uploaded. | 731 "new file title", // The title of the file being uploaded. |
| 734 CreateComposedCallback( | 732 CreateComposedCallback( |
| 735 base::Bind(&test_util::RunAndQuit), | 733 base::Bind(&test_util::RunAndQuit), |
| 736 test_util::CreateCopyResultCallback(&error, &upload_url))); | 734 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 737 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 735 operation_runner_->StartOperationWithRetry(operation); |
| 738 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 739 MessageLoop::current()->Run(); | 736 MessageLoop::current()->Run(); |
| 740 | 737 |
| 741 EXPECT_EQ(HTTP_SUCCESS, error); | 738 EXPECT_EQ(HTTP_SUCCESS, error); |
| 742 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); | 739 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); |
| 743 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 740 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 744 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 741 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 745 http_request_.headers["X-Upload-Content-Length"]); | 742 http_request_.headers["X-Upload-Content-Length"]); |
| 746 | 743 |
| 747 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 744 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 748 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", | 745 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", |
| 749 http_request_.relative_url); | 746 http_request_.relative_url); |
| 750 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 747 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 751 EXPECT_TRUE(http_request_.has_content); | 748 EXPECT_TRUE(http_request_.has_content); |
| 752 EXPECT_EQ("{\"parents\":[{" | 749 EXPECT_EQ("{\"parents\":[{" |
| 753 "\"id\":\"parent_resource_id\"," | 750 "\"id\":\"parent_resource_id\"," |
| 754 "\"kind\":\"drive#fileLink\"" | 751 "\"kind\":\"drive#fileLink\"" |
| 755 "}]," | 752 "}]," |
| 756 "\"title\":\"new file title\"}", | 753 "\"title\":\"new file title\"}", |
| 757 http_request_.content); | 754 http_request_.content); |
| 758 | 755 |
| 759 // Upload the content to the upload URL. | 756 // Upload the content to the upload URL. |
| 760 UploadRangeResponse response; | 757 UploadRangeResponse response; |
| 761 scoped_ptr<FileResource> new_entry; | 758 scoped_ptr<FileResource> new_entry; |
| 762 | 759 |
| 763 drive::ResumeUploadOperation* resume_operation = | 760 drive::ResumeUploadOperation* resume_operation = |
| 764 new drive::ResumeUploadOperation( | 761 new drive::ResumeUploadOperation( |
| 765 &operation_registry_, | 762 operation_runner_.get(), |
| 766 request_context_getter_.get(), | 763 request_context_getter_.get(), |
| 767 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 764 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 768 upload_url, | 765 upload_url, |
| 769 0, // start_position | 766 0, // start_position |
| 770 kTestContent.size(), // end_position (exclusive) | 767 kTestContent.size(), // end_position (exclusive) |
| 771 kTestContent.size(), // content_length, | 768 kTestContent.size(), // content_length, |
| 772 kTestContentType, | 769 kTestContentType, |
| 773 kTestFilePath, | 770 kTestFilePath, |
| 774 CreateComposedCallback( | 771 CreateComposedCallback( |
| 775 base::Bind(&test_util::RunAndQuit), | 772 base::Bind(&test_util::RunAndQuit), |
| 776 test_util::CreateCopyResultCallback(&response, &new_entry)), | 773 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 777 ProgressCallback()); | 774 ProgressCallback()); |
| 778 resume_operation->Start( | 775 operation_runner_->StartOperationWithRetry(resume_operation); |
| 779 kTestDriveApiAuthToken, kTestUserAgent, | |
| 780 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 781 MessageLoop::current()->Run(); | 776 MessageLoop::current()->Run(); |
| 782 | 777 |
| 783 // METHOD_PUT should be used to upload data. | 778 // METHOD_PUT should be used to upload data. |
| 784 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 779 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 785 // Request should go to the upload URL. | 780 // Request should go to the upload URL. |
| 786 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 781 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 787 // Content-Range header should be added. | 782 // Content-Range header should be added. |
| 788 EXPECT_EQ("bytes 0-" + | 783 EXPECT_EQ("bytes 0-" + |
| 789 base::Int64ToString(kTestContent.size() - 1) + "/" + | 784 base::Int64ToString(kTestContent.size() - 1) + "/" + |
| 790 base::Int64ToString(kTestContent.size()), | 785 base::Int64ToString(kTestContent.size()), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 809 const base::FilePath kTestFilePath = | 804 const base::FilePath kTestFilePath = |
| 810 temp_dir_.path().AppendASCII("empty_file.txt"); | 805 temp_dir_.path().AppendASCII("empty_file.txt"); |
| 811 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 806 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 812 | 807 |
| 813 GDataErrorCode error = GDATA_OTHER_ERROR; | 808 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 814 GURL upload_url; | 809 GURL upload_url; |
| 815 | 810 |
| 816 // Initiate uploading a new file to the directory with "parent_resource_id". | 811 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 817 drive::InitiateUploadNewFileOperation* operation = | 812 drive::InitiateUploadNewFileOperation* operation = |
| 818 new drive::InitiateUploadNewFileOperation( | 813 new drive::InitiateUploadNewFileOperation( |
| 819 &operation_registry_, | 814 operation_runner_.get(), |
| 820 request_context_getter_.get(), | 815 request_context_getter_.get(), |
| 821 *url_generator_, | 816 *url_generator_, |
| 822 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 817 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 823 kTestContentType, | 818 kTestContentType, |
| 824 0, | 819 0, |
| 825 "parent_resource_id", // The resource id of the parent directory. | 820 "parent_resource_id", // The resource id of the parent directory. |
| 826 "new file title", // The title of the file being uploaded. | 821 "new file title", // The title of the file being uploaded. |
| 827 CreateComposedCallback( | 822 CreateComposedCallback( |
| 828 base::Bind(&test_util::RunAndQuit), | 823 base::Bind(&test_util::RunAndQuit), |
| 829 test_util::CreateCopyResultCallback(&error, &upload_url))); | 824 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 830 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 825 operation_runner_->StartOperationWithRetry(operation); |
| 831 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 832 MessageLoop::current()->Run(); | 826 MessageLoop::current()->Run(); |
| 833 | 827 |
| 834 EXPECT_EQ(HTTP_SUCCESS, error); | 828 EXPECT_EQ(HTTP_SUCCESS, error); |
| 835 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); | 829 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); |
| 836 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 830 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 837 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]); | 831 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]); |
| 838 | 832 |
| 839 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 833 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 840 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", | 834 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", |
| 841 http_request_.relative_url); | 835 http_request_.relative_url); |
| 842 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 836 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 843 EXPECT_TRUE(http_request_.has_content); | 837 EXPECT_TRUE(http_request_.has_content); |
| 844 EXPECT_EQ("{\"parents\":[{" | 838 EXPECT_EQ("{\"parents\":[{" |
| 845 "\"id\":\"parent_resource_id\"," | 839 "\"id\":\"parent_resource_id\"," |
| 846 "\"kind\":\"drive#fileLink\"" | 840 "\"kind\":\"drive#fileLink\"" |
| 847 "}]," | 841 "}]," |
| 848 "\"title\":\"new file title\"}", | 842 "\"title\":\"new file title\"}", |
| 849 http_request_.content); | 843 http_request_.content); |
| 850 | 844 |
| 851 // Upload the content to the upload URL. | 845 // Upload the content to the upload URL. |
| 852 UploadRangeResponse response; | 846 UploadRangeResponse response; |
| 853 scoped_ptr<FileResource> new_entry; | 847 scoped_ptr<FileResource> new_entry; |
| 854 | 848 |
| 855 drive::ResumeUploadOperation* resume_operation = | 849 drive::ResumeUploadOperation* resume_operation = |
| 856 new drive::ResumeUploadOperation( | 850 new drive::ResumeUploadOperation( |
| 857 &operation_registry_, | 851 operation_runner_.get(), |
| 858 request_context_getter_.get(), | 852 request_context_getter_.get(), |
| 859 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 853 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 860 upload_url, | 854 upload_url, |
| 861 0, // start_position | 855 0, // start_position |
| 862 0, // end_position (exclusive) | 856 0, // end_position (exclusive) |
| 863 0, // content_length, | 857 0, // content_length, |
| 864 kTestContentType, | 858 kTestContentType, |
| 865 kTestFilePath, | 859 kTestFilePath, |
| 866 CreateComposedCallback( | 860 CreateComposedCallback( |
| 867 base::Bind(&test_util::RunAndQuit), | 861 base::Bind(&test_util::RunAndQuit), |
| 868 test_util::CreateCopyResultCallback(&response, &new_entry)), | 862 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 869 ProgressCallback()); | 863 ProgressCallback()); |
| 870 resume_operation->Start( | 864 operation_runner_->StartOperationWithRetry(resume_operation); |
| 871 kTestDriveApiAuthToken, kTestUserAgent, | |
| 872 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 873 MessageLoop::current()->Run(); | 865 MessageLoop::current()->Run(); |
| 874 | 866 |
| 875 // METHOD_PUT should be used to upload data. | 867 // METHOD_PUT should be used to upload data. |
| 876 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 868 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 877 // Request should go to the upload URL. | 869 // Request should go to the upload URL. |
| 878 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 870 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 879 // Content-Range header should NOT be added. | 871 // Content-Range header should NOT be added. |
| 880 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); | 872 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); |
| 881 // The upload content should be set in the HTTP request. | 873 // The upload content should be set in the HTTP request. |
| 882 EXPECT_TRUE(http_request_.has_content); | 874 EXPECT_TRUE(http_request_.has_content); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 902 const base::FilePath kTestFilePath = | 894 const base::FilePath kTestFilePath = |
| 903 temp_dir_.path().AppendASCII("upload_file.txt"); | 895 temp_dir_.path().AppendASCII("upload_file.txt"); |
| 904 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 896 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 905 | 897 |
| 906 GDataErrorCode error = GDATA_OTHER_ERROR; | 898 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 907 GURL upload_url; | 899 GURL upload_url; |
| 908 | 900 |
| 909 // Initiate uploading a new file to the directory with "parent_resource_id". | 901 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 910 drive::InitiateUploadNewFileOperation* operation = | 902 drive::InitiateUploadNewFileOperation* operation = |
| 911 new drive::InitiateUploadNewFileOperation( | 903 new drive::InitiateUploadNewFileOperation( |
| 912 &operation_registry_, | 904 operation_runner_.get(), |
| 913 request_context_getter_.get(), | 905 request_context_getter_.get(), |
| 914 *url_generator_, | 906 *url_generator_, |
| 915 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 907 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 916 kTestContentType, | 908 kTestContentType, |
| 917 kTestContent.size(), | 909 kTestContent.size(), |
| 918 "parent_resource_id", // The resource id of the parent directory. | 910 "parent_resource_id", // The resource id of the parent directory. |
| 919 "new file title", // The title of the file being uploaded. | 911 "new file title", // The title of the file being uploaded. |
| 920 CreateComposedCallback( | 912 CreateComposedCallback( |
| 921 base::Bind(&test_util::RunAndQuit), | 913 base::Bind(&test_util::RunAndQuit), |
| 922 test_util::CreateCopyResultCallback(&error, &upload_url))); | 914 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 923 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 915 operation_runner_->StartOperationWithRetry(operation); |
| 924 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 925 MessageLoop::current()->Run(); | 916 MessageLoop::current()->Run(); |
| 926 | 917 |
| 927 EXPECT_EQ(HTTP_SUCCESS, error); | 918 EXPECT_EQ(HTTP_SUCCESS, error); |
| 928 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); | 919 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); |
| 929 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 920 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 930 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 921 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 931 http_request_.headers["X-Upload-Content-Length"]); | 922 http_request_.headers["X-Upload-Content-Length"]); |
| 932 | 923 |
| 933 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 924 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 934 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", | 925 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 945 #if !defined(NO_GET_UPLOAD_STATUS_TEST) | 936 #if !defined(NO_GET_UPLOAD_STATUS_TEST) |
| 946 // Before sending any data, check the current status. | 937 // Before sending any data, check the current status. |
| 947 // This is an edge case test for GetUploadStatusOperation. | 938 // This is an edge case test for GetUploadStatusOperation. |
| 948 { | 939 { |
| 949 UploadRangeResponse response; | 940 UploadRangeResponse response; |
| 950 scoped_ptr<FileResource> new_entry; | 941 scoped_ptr<FileResource> new_entry; |
| 951 | 942 |
| 952 // Check the response by GetUploadStatusOperation. | 943 // Check the response by GetUploadStatusOperation. |
| 953 drive::GetUploadStatusOperation* get_upload_status_operation = | 944 drive::GetUploadStatusOperation* get_upload_status_operation = |
| 954 new drive::GetUploadStatusOperation( | 945 new drive::GetUploadStatusOperation( |
| 955 &operation_registry_, | 946 operation_runner_.get(), |
| 956 request_context_getter_.get(), | 947 request_context_getter_.get(), |
| 957 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 948 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 958 upload_url, | 949 upload_url, |
| 959 kTestContent.size(), | 950 kTestContent.size(), |
| 960 CreateComposedCallback( | 951 CreateComposedCallback( |
| 961 base::Bind(&test_util::RunAndQuit), | 952 base::Bind(&test_util::RunAndQuit), |
| 962 test_util::CreateCopyResultCallback(&response, &new_entry))); | 953 test_util::CreateCopyResultCallback(&response, &new_entry))); |
| 963 get_upload_status_operation->Start( | 954 operation_runner_->StartOperationWithRetry(get_upload_status_operation); |
| 964 kTestDriveApiAuthToken, kTestUserAgent, | |
| 965 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 966 MessageLoop::current()->Run(); | 955 MessageLoop::current()->Run(); |
| 967 | 956 |
| 968 // METHOD_PUT should be used to upload data. | 957 // METHOD_PUT should be used to upload data. |
| 969 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 958 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 970 // Request should go to the upload URL. | 959 // Request should go to the upload URL. |
| 971 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 960 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 972 // Content-Range header should be added. | 961 // Content-Range header should be added. |
| 973 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), | 962 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), |
| 974 http_request_.headers["Content-Range"]); | 963 http_request_.headers["Content-Range"]); |
| 975 EXPECT_TRUE(http_request_.has_content); | 964 EXPECT_TRUE(http_request_.has_content); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 988 const std::string payload = kTestContent.substr( | 977 const std::string payload = kTestContent.substr( |
| 989 start_position, | 978 start_position, |
| 990 std::min(kNumChunkBytes, kTestContent.size() - start_position)); | 979 std::min(kNumChunkBytes, kTestContent.size() - start_position)); |
| 991 const size_t end_position = start_position + payload.size(); | 980 const size_t end_position = start_position + payload.size(); |
| 992 | 981 |
| 993 UploadRangeResponse response; | 982 UploadRangeResponse response; |
| 994 scoped_ptr<FileResource> new_entry; | 983 scoped_ptr<FileResource> new_entry; |
| 995 | 984 |
| 996 drive::ResumeUploadOperation* resume_operation = | 985 drive::ResumeUploadOperation* resume_operation = |
| 997 new drive::ResumeUploadOperation( | 986 new drive::ResumeUploadOperation( |
| 998 &operation_registry_, | 987 operation_runner_.get(), |
| 999 request_context_getter_.get(), | 988 request_context_getter_.get(), |
| 1000 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 989 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1001 upload_url, | 990 upload_url, |
| 1002 start_position, | 991 start_position, |
| 1003 end_position, | 992 end_position, |
| 1004 kTestContent.size(), // content_length, | 993 kTestContent.size(), // content_length, |
| 1005 kTestContentType, | 994 kTestContentType, |
| 1006 kTestFilePath, | 995 kTestFilePath, |
| 1007 CreateComposedCallback( | 996 CreateComposedCallback( |
| 1008 base::Bind(&test_util::RunAndQuit), | 997 base::Bind(&test_util::RunAndQuit), |
| 1009 test_util::CreateCopyResultCallback(&response, &new_entry)), | 998 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1010 ProgressCallback()); | 999 ProgressCallback()); |
| 1011 resume_operation->Start( | 1000 operation_runner_->StartOperationWithRetry(resume_operation); |
| 1012 kTestDriveApiAuthToken, kTestUserAgent, | |
| 1013 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1014 MessageLoop::current()->Run(); | 1001 MessageLoop::current()->Run(); |
| 1015 | 1002 |
| 1016 // METHOD_PUT should be used to upload data. | 1003 // METHOD_PUT should be used to upload data. |
| 1017 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1004 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1018 // Request should go to the upload URL. | 1005 // Request should go to the upload URL. |
| 1019 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1006 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1020 // Content-Range header should be added. | 1007 // Content-Range header should be added. |
| 1021 EXPECT_EQ("bytes " + | 1008 EXPECT_EQ("bytes " + |
| 1022 base::Int64ToString(start_position) + "-" + | 1009 base::Int64ToString(start_position) + "-" + |
| 1023 base::Int64ToString(end_position - 1) + "/" + | 1010 base::Int64ToString(end_position - 1) + "/" + |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1039 | 1026 |
| 1040 // Check the response. | 1027 // Check the response. |
| 1041 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1028 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
| 1042 EXPECT_EQ(0, response.start_position_received); | 1029 EXPECT_EQ(0, response.start_position_received); |
| 1043 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received); | 1030 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received); |
| 1044 | 1031 |
| 1045 #if !defined(NO_GET_UPLOAD_STATUS_TEST) | 1032 #if !defined(NO_GET_UPLOAD_STATUS_TEST) |
| 1046 // Check the response by GetUploadStatusOperation. | 1033 // Check the response by GetUploadStatusOperation. |
| 1047 drive::GetUploadStatusOperation* get_upload_status_operation = | 1034 drive::GetUploadStatusOperation* get_upload_status_operation = |
| 1048 new drive::GetUploadStatusOperation( | 1035 new drive::GetUploadStatusOperation( |
| 1049 &operation_registry_, | 1036 operation_runner_.get(), |
| 1050 request_context_getter_.get(), | 1037 request_context_getter_.get(), |
| 1051 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 1038 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1052 upload_url, | 1039 upload_url, |
| 1053 kTestContent.size(), | 1040 kTestContent.size(), |
| 1054 CreateComposedCallback( | 1041 CreateComposedCallback( |
| 1055 base::Bind(&test_util::RunAndQuit), | 1042 base::Bind(&test_util::RunAndQuit), |
| 1056 test_util::CreateCopyResultCallback(&response, &new_entry))); | 1043 test_util::CreateCopyResultCallback(&response, &new_entry))); |
| 1057 get_upload_status_operation->Start( | 1044 operation_runner_->StartOperationWithRetry(get_upload_status_operation); |
| 1058 kTestDriveApiAuthToken, kTestUserAgent, | |
| 1059 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1060 MessageLoop::current()->Run(); | 1045 MessageLoop::current()->Run(); |
| 1061 | 1046 |
| 1062 // METHOD_PUT should be used to upload data. | 1047 // METHOD_PUT should be used to upload data. |
| 1063 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1048 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1064 // Request should go to the upload URL. | 1049 // Request should go to the upload URL. |
| 1065 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1050 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1066 // Content-Range header should be added. | 1051 // Content-Range header should be added. |
| 1067 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), | 1052 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), |
| 1068 http_request_.headers["Content-Range"]); | 1053 http_request_.headers["Content-Range"]); |
| 1069 EXPECT_TRUE(http_request_.has_content); | 1054 EXPECT_TRUE(http_request_.has_content); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1087 const base::FilePath kTestFilePath = | 1072 const base::FilePath kTestFilePath = |
| 1088 temp_dir_.path().AppendASCII("upload_file.txt"); | 1073 temp_dir_.path().AppendASCII("upload_file.txt"); |
| 1089 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1074 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1090 | 1075 |
| 1091 GDataErrorCode error = GDATA_OTHER_ERROR; | 1076 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1092 GURL upload_url; | 1077 GURL upload_url; |
| 1093 | 1078 |
| 1094 // Initiate uploading a new file to the directory with "parent_resource_id". | 1079 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1095 drive::InitiateUploadExistingFileOperation* operation = | 1080 drive::InitiateUploadExistingFileOperation* operation = |
| 1096 new drive::InitiateUploadExistingFileOperation( | 1081 new drive::InitiateUploadExistingFileOperation( |
| 1097 &operation_registry_, | 1082 operation_runner_.get(), |
| 1098 request_context_getter_.get(), | 1083 request_context_getter_.get(), |
| 1099 *url_generator_, | 1084 *url_generator_, |
| 1100 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 1085 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1101 kTestContentType, | 1086 kTestContentType, |
| 1102 kTestContent.size(), | 1087 kTestContent.size(), |
| 1103 "resource_id", // The resource id of the file to be overwritten. | 1088 "resource_id", // The resource id of the file to be overwritten. |
| 1104 std::string(), // No etag. | 1089 std::string(), // No etag. |
| 1105 CreateComposedCallback( | 1090 CreateComposedCallback( |
| 1106 base::Bind(&test_util::RunAndQuit), | 1091 base::Bind(&test_util::RunAndQuit), |
| 1107 test_util::CreateCopyResultCallback(&error, &upload_url))); | 1092 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 1108 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 1093 operation_runner_->StartOperationWithRetry(operation); |
| 1109 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1110 MessageLoop::current()->Run(); | 1094 MessageLoop::current()->Run(); |
| 1111 | 1095 |
| 1112 EXPECT_EQ(HTTP_SUCCESS, error); | 1096 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1113 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); | 1097 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); |
| 1114 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 1098 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 1115 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 1099 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 1116 http_request_.headers["X-Upload-Content-Length"]); | 1100 http_request_.headers["X-Upload-Content-Length"]); |
| 1117 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 1101 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
| 1118 | 1102 |
| 1119 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1103 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1120 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", | 1104 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", |
| 1121 http_request_.relative_url); | 1105 http_request_.relative_url); |
| 1122 EXPECT_TRUE(http_request_.has_content); | 1106 EXPECT_TRUE(http_request_.has_content); |
| 1123 EXPECT_TRUE(http_request_.content.empty()); | 1107 EXPECT_TRUE(http_request_.content.empty()); |
| 1124 | 1108 |
| 1125 // Upload the content to the upload URL. | 1109 // Upload the content to the upload URL. |
| 1126 UploadRangeResponse response; | 1110 UploadRangeResponse response; |
| 1127 scoped_ptr<FileResource> new_entry; | 1111 scoped_ptr<FileResource> new_entry; |
| 1128 | 1112 |
| 1129 drive::ResumeUploadOperation* resume_operation = | 1113 drive::ResumeUploadOperation* resume_operation = |
| 1130 new drive::ResumeUploadOperation( | 1114 new drive::ResumeUploadOperation( |
| 1131 &operation_registry_, | 1115 operation_runner_.get(), |
| 1132 request_context_getter_.get(), | 1116 request_context_getter_.get(), |
| 1133 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 1117 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1134 upload_url, | 1118 upload_url, |
| 1135 0, // start_position | 1119 0, // start_position |
| 1136 kTestContent.size(), // end_position (exclusive) | 1120 kTestContent.size(), // end_position (exclusive) |
| 1137 kTestContent.size(), // content_length, | 1121 kTestContent.size(), // content_length, |
| 1138 kTestContentType, | 1122 kTestContentType, |
| 1139 kTestFilePath, | 1123 kTestFilePath, |
| 1140 CreateComposedCallback( | 1124 CreateComposedCallback( |
| 1141 base::Bind(&test_util::RunAndQuit), | 1125 base::Bind(&test_util::RunAndQuit), |
| 1142 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1126 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1143 ProgressCallback()); | 1127 ProgressCallback()); |
| 1144 resume_operation->Start( | 1128 operation_runner_->StartOperationWithRetry(resume_operation); |
| 1145 kTestDriveApiAuthToken, kTestUserAgent, | |
| 1146 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1147 MessageLoop::current()->Run(); | 1129 MessageLoop::current()->Run(); |
| 1148 | 1130 |
| 1149 // METHOD_PUT should be used to upload data. | 1131 // METHOD_PUT should be used to upload data. |
| 1150 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1132 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1151 // Request should go to the upload URL. | 1133 // Request should go to the upload URL. |
| 1152 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1134 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1153 // Content-Range header should be added. | 1135 // Content-Range header should be added. |
| 1154 EXPECT_EQ("bytes 0-" + | 1136 EXPECT_EQ("bytes 0-" + |
| 1155 base::Int64ToString(kTestContent.size() - 1) + "/" + | 1137 base::Int64ToString(kTestContent.size() - 1) + "/" + |
| 1156 base::Int64ToString(kTestContent.size()), | 1138 base::Int64ToString(kTestContent.size()), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1175 const base::FilePath kTestFilePath = | 1157 const base::FilePath kTestFilePath = |
| 1176 temp_dir_.path().AppendASCII("upload_file.txt"); | 1158 temp_dir_.path().AppendASCII("upload_file.txt"); |
| 1177 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1159 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1178 | 1160 |
| 1179 GDataErrorCode error = GDATA_OTHER_ERROR; | 1161 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1180 GURL upload_url; | 1162 GURL upload_url; |
| 1181 | 1163 |
| 1182 // Initiate uploading a new file to the directory with "parent_resource_id". | 1164 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1183 drive::InitiateUploadExistingFileOperation* operation = | 1165 drive::InitiateUploadExistingFileOperation* operation = |
| 1184 new drive::InitiateUploadExistingFileOperation( | 1166 new drive::InitiateUploadExistingFileOperation( |
| 1185 &operation_registry_, | 1167 operation_runner_.get(), |
| 1186 request_context_getter_.get(), | 1168 request_context_getter_.get(), |
| 1187 *url_generator_, | 1169 *url_generator_, |
| 1188 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 1170 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1189 kTestContentType, | 1171 kTestContentType, |
| 1190 kTestContent.size(), | 1172 kTestContent.size(), |
| 1191 "resource_id", // The resource id of the file to be overwritten. | 1173 "resource_id", // The resource id of the file to be overwritten. |
| 1192 kTestETag, | 1174 kTestETag, |
| 1193 CreateComposedCallback( | 1175 CreateComposedCallback( |
| 1194 base::Bind(&test_util::RunAndQuit), | 1176 base::Bind(&test_util::RunAndQuit), |
| 1195 test_util::CreateCopyResultCallback(&error, &upload_url))); | 1177 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 1196 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 1178 operation_runner_->StartOperationWithRetry(operation); |
| 1197 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1198 MessageLoop::current()->Run(); | 1179 MessageLoop::current()->Run(); |
| 1199 | 1180 |
| 1200 EXPECT_EQ(HTTP_SUCCESS, error); | 1181 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1201 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); | 1182 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); |
| 1202 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 1183 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 1203 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 1184 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 1204 http_request_.headers["X-Upload-Content-Length"]); | 1185 http_request_.headers["X-Upload-Content-Length"]); |
| 1205 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); | 1186 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); |
| 1206 | 1187 |
| 1207 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1188 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1208 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", | 1189 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", |
| 1209 http_request_.relative_url); | 1190 http_request_.relative_url); |
| 1210 EXPECT_TRUE(http_request_.has_content); | 1191 EXPECT_TRUE(http_request_.has_content); |
| 1211 EXPECT_TRUE(http_request_.content.empty()); | 1192 EXPECT_TRUE(http_request_.content.empty()); |
| 1212 | 1193 |
| 1213 // Upload the content to the upload URL. | 1194 // Upload the content to the upload URL. |
| 1214 UploadRangeResponse response; | 1195 UploadRangeResponse response; |
| 1215 scoped_ptr<FileResource> new_entry; | 1196 scoped_ptr<FileResource> new_entry; |
| 1216 | 1197 |
| 1217 drive::ResumeUploadOperation* resume_operation = | 1198 drive::ResumeUploadOperation* resume_operation = |
| 1218 new drive::ResumeUploadOperation( | 1199 new drive::ResumeUploadOperation( |
| 1219 &operation_registry_, | 1200 operation_runner_.get(), |
| 1220 request_context_getter_.get(), | 1201 request_context_getter_.get(), |
| 1221 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 1202 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1222 upload_url, | 1203 upload_url, |
| 1223 0, // start_position | 1204 0, // start_position |
| 1224 kTestContent.size(), // end_position (exclusive) | 1205 kTestContent.size(), // end_position (exclusive) |
| 1225 kTestContent.size(), // content_length, | 1206 kTestContent.size(), // content_length, |
| 1226 kTestContentType, | 1207 kTestContentType, |
| 1227 kTestFilePath, | 1208 kTestFilePath, |
| 1228 CreateComposedCallback( | 1209 CreateComposedCallback( |
| 1229 base::Bind(&test_util::RunAndQuit), | 1210 base::Bind(&test_util::RunAndQuit), |
| 1230 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1211 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1231 ProgressCallback()); | 1212 ProgressCallback()); |
| 1232 resume_operation->Start( | 1213 operation_runner_->StartOperationWithRetry(resume_operation); |
| 1233 kTestDriveApiAuthToken, kTestUserAgent, | |
| 1234 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1235 MessageLoop::current()->Run(); | 1214 MessageLoop::current()->Run(); |
| 1236 | 1215 |
| 1237 // METHOD_PUT should be used to upload data. | 1216 // METHOD_PUT should be used to upload data. |
| 1238 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1217 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1239 // Request should go to the upload URL. | 1218 // Request should go to the upload URL. |
| 1240 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1219 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1241 // Content-Range header should be added. | 1220 // Content-Range header should be added. |
| 1242 EXPECT_EQ("bytes 0-" + | 1221 EXPECT_EQ("bytes 0-" + |
| 1243 base::Int64ToString(kTestContent.size() - 1) + "/" + | 1222 base::Int64ToString(kTestContent.size() - 1) + "/" + |
| 1244 base::Int64ToString(kTestContent.size()), | 1223 base::Int64ToString(kTestContent.size()), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1260 | 1239 |
| 1261 const char kTestContentType[] = "text/plain"; | 1240 const char kTestContentType[] = "text/plain"; |
| 1262 const std::string kTestContent(100, 'a'); | 1241 const std::string kTestContent(100, 'a'); |
| 1263 | 1242 |
| 1264 GDataErrorCode error = GDATA_OTHER_ERROR; | 1243 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1265 GURL upload_url; | 1244 GURL upload_url; |
| 1266 | 1245 |
| 1267 // Initiate uploading a new file to the directory with "parent_resource_id". | 1246 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1268 drive::InitiateUploadExistingFileOperation* operation = | 1247 drive::InitiateUploadExistingFileOperation* operation = |
| 1269 new drive::InitiateUploadExistingFileOperation( | 1248 new drive::InitiateUploadExistingFileOperation( |
| 1270 &operation_registry_, | 1249 operation_runner_.get(), |
| 1271 request_context_getter_.get(), | 1250 request_context_getter_.get(), |
| 1272 *url_generator_, | 1251 *url_generator_, |
| 1273 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), | 1252 base::FilePath(FILE_PATH_LITERAL("drive/file/path")), |
| 1274 kTestContentType, | 1253 kTestContentType, |
| 1275 kTestContent.size(), | 1254 kTestContent.size(), |
| 1276 "resource_id", // The resource id of the file to be overwritten. | 1255 "resource_id", // The resource id of the file to be overwritten. |
| 1277 "Conflicting-etag", | 1256 "Conflicting-etag", |
| 1278 CreateComposedCallback( | 1257 CreateComposedCallback( |
| 1279 base::Bind(&test_util::RunAndQuit), | 1258 base::Bind(&test_util::RunAndQuit), |
| 1280 test_util::CreateCopyResultCallback(&error, &upload_url))); | 1259 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 1281 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, | 1260 operation_runner_->StartOperationWithRetry(operation); |
| 1282 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
| 1283 MessageLoop::current()->Run(); | 1261 MessageLoop::current()->Run(); |
| 1284 | 1262 |
| 1285 EXPECT_EQ(HTTP_PRECONDITION, error); | 1263 EXPECT_EQ(HTTP_PRECONDITION, error); |
| 1286 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 1264 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 1287 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 1265 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 1288 http_request_.headers["X-Upload-Content-Length"]); | 1266 http_request_.headers["X-Upload-Content-Length"]); |
| 1289 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); | 1267 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); |
| 1290 | 1268 |
| 1291 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1269 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1292 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", | 1270 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", |
| 1293 http_request_.relative_url); | 1271 http_request_.relative_url); |
| 1294 EXPECT_TRUE(http_request_.has_content); | 1272 EXPECT_TRUE(http_request_.has_content); |
| 1295 EXPECT_TRUE(http_request_.content.empty()); | 1273 EXPECT_TRUE(http_request_.content.empty()); |
| 1296 } | 1274 } |
| 1297 | 1275 |
| 1298 } // namespace google_apis | 1276 } // namespace google_apis |
| OLD | NEW |