| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/json/json_reader.h" | |
| 12 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 13 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 14 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 15 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 16 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 15 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
| 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 18 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 17 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
| 19 #include "chrome/browser/google_apis/operation_registry.h" | 18 #include "chrome/browser/google_apis/operation_registry.h" |
| 20 #include "chrome/browser/google_apis/test_server/http_server.h" | 19 #include "chrome/browser/google_apis/test_server/http_server.h" |
| 21 #include "chrome/browser/google_apis/test_util.h" | 20 #include "chrome/browser/google_apis/test_util.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 24 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 25 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
| 26 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 27 |
| 29 namespace google_apis { | 28 namespace google_apis { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 const char kTestGDataAuthToken[] = "testtoken"; | 32 const char kTestGDataAuthToken[] = "testtoken"; |
| 34 const char kTestUserAgent[] = "test-user-agent"; | 33 const char kTestUserAgent[] = "test-user-agent"; |
| 35 const char kTestETag[] = "test_etag"; | 34 const char kTestETag[] = "test_etag"; |
| 36 | 35 |
| 37 // Copies the results from GetDataCallback and quit the message loop. | |
| 38 void CopyResultsFromGetDataCallbackAndQuit( | |
| 39 GDataErrorCode* out_result_code, | |
| 40 scoped_ptr<base::Value>* out_result_data, | |
| 41 GDataErrorCode result_code, | |
| 42 scoped_ptr<base::Value> result_data) { | |
| 43 *out_result_code = result_code; | |
| 44 *out_result_data = result_data.Pass(); | |
| 45 MessageLoop::current()->Quit(); | |
| 46 } | |
| 47 | |
| 48 // Copies the results from DownloadActionCallback and quit the message loop. | 36 // Copies the results from DownloadActionCallback and quit the message loop. |
| 49 // The contents of the download cache file are copied to a string, and the | 37 // The contents of the download cache file are copied to a string, and the |
| 50 // file is removed. | 38 // file is removed. |
| 51 void CopyResultsFromDownloadActionCallbackAndQuit( | 39 void CopyResultsFromDownloadActionCallbackAndQuit( |
| 52 GDataErrorCode* out_result_code, | 40 GDataErrorCode* out_result_code, |
| 53 std::string* contents, | 41 std::string* contents, |
| 54 GDataErrorCode result_code, | 42 GDataErrorCode result_code, |
| 55 const FilePath& cache_file_path) { | 43 const FilePath& cache_file_path) { |
| 56 *out_result_code = result_code; | 44 *out_result_code = result_code; |
| 57 file_util::ReadFileToString(cache_file_path, contents); | 45 file_util::ReadFileToString(cache_file_path, contents); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 82 void CopyResultFromResumeUploadCallbackAndQuit( | 70 void CopyResultFromResumeUploadCallbackAndQuit( |
| 83 ResumeUploadResponse* out_response, | 71 ResumeUploadResponse* out_response, |
| 84 scoped_ptr<ResourceEntry>* out_new_entry, | 72 scoped_ptr<ResourceEntry>* out_new_entry, |
| 85 const ResumeUploadResponse& response, | 73 const ResumeUploadResponse& response, |
| 86 scoped_ptr<ResourceEntry> new_entry) { | 74 scoped_ptr<ResourceEntry> new_entry) { |
| 87 *out_response = response; | 75 *out_response = response; |
| 88 *out_new_entry = new_entry.Pass(); | 76 *out_new_entry = new_entry.Pass(); |
| 89 MessageLoop::current()->Quit(); | 77 MessageLoop::current()->Quit(); |
| 90 } | 78 } |
| 91 | 79 |
| 92 // Returns true if |json_data| equals to JSON data in |expected_json_file_path|. | |
| 93 bool VerifyJsonData(const FilePath& expected_json_file_path, | |
| 94 const base::Value* json_data) { | |
| 95 std::string expected_contents; | |
| 96 if (!file_util::ReadFileToString(expected_json_file_path, &expected_contents)) | |
| 97 return false; | |
| 98 | |
| 99 scoped_ptr<base::Value> expected_data( | |
| 100 base::JSONReader::Read(expected_contents)); | |
| 101 return base::Value::Equals(expected_data.get(), json_data); | |
| 102 } | |
| 103 | |
| 104 // Removes |prefix| from |input| and stores the result in |output|. Returns | 80 // Removes |prefix| from |input| and stores the result in |output|. Returns |
| 105 // true if the prefix is removed. | 81 // true if the prefix is removed. |
| 106 bool RemovePrefix(const std::string& input, | 82 bool RemovePrefix(const std::string& input, |
| 107 const std::string& prefix, | 83 const std::string& prefix, |
| 108 std::string* output) { | 84 std::string* output) { |
| 109 if (!StartsWithASCII(input, prefix, true /* case sensitive */)) | 85 if (!StartsWithASCII(input, prefix, true /* case sensitive */)) |
| 110 return false; | 86 return false; |
| 111 | 87 |
| 112 *output = input.substr(prefix.size()); | 88 *output = input.substr(prefix.size()); |
| 113 return true; | 89 return true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 139 | 115 |
| 140 parts.clear(); | 116 parts.clear(); |
| 141 base::SplitString(range, '-', &parts); | 117 base::SplitString(range, '-', &parts); |
| 142 if (parts.size() != 2U) | 118 if (parts.size() != 2U) |
| 143 return false; | 119 return false; |
| 144 | 120 |
| 145 return (base::StringToInt64(parts[0], start_position) && | 121 return (base::StringToInt64(parts[0], start_position) && |
| 146 base::StringToInt64(parts[1], end_position)); | 122 base::StringToInt64(parts[1], end_position)); |
| 147 } | 123 } |
| 148 | 124 |
| 149 // Does nothing for ReAuthenticateCallback(). This function should not be | |
| 150 // reached as there won't be any authentication failures in the test. | |
| 151 void DoNothingForReAuthenticateCallback( | |
| 152 AuthenticatedOperationInterface* /* operation */) { | |
| 153 NOTREACHED(); | |
| 154 } | |
| 155 | |
| 156 class GDataWapiOperationsTest : public testing::Test { | 125 class GDataWapiOperationsTest : public testing::Test { |
| 157 public: | 126 public: |
| 158 GDataWapiOperationsTest() | 127 GDataWapiOperationsTest() |
| 159 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 128 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 160 file_thread_(content::BrowserThread::FILE), | 129 file_thread_(content::BrowserThread::FILE), |
| 161 io_thread_(content::BrowserThread::IO) { | 130 io_thread_(content::BrowserThread::IO) { |
| 162 } | 131 } |
| 163 | 132 |
| 164 virtual void SetUp() OVERRIDE { | 133 virtual void SetUp() OVERRIDE { |
| 165 file_thread_.Start(); | 134 file_thread_.Start(); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 379 |
| 411 GetResourceListOperation* operation = new GetResourceListOperation( | 380 GetResourceListOperation* operation = new GetResourceListOperation( |
| 412 &operation_registry_, | 381 &operation_registry_, |
| 413 request_context_getter_.get(), | 382 request_context_getter_.get(), |
| 414 *url_generator_, | 383 *url_generator_, |
| 415 GURL(), // Pass an empty URL to use the default feed | 384 GURL(), // Pass an empty URL to use the default feed |
| 416 0, // start changestamp | 385 0, // start changestamp |
| 417 "", // search string | 386 "", // search string |
| 418 false, // shared with me | 387 false, // shared with me |
| 419 "", // directory resource ID | 388 "", // directory resource ID |
| 420 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 389 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 421 &result_code, | 390 &result_code, |
| 422 &result_data)); | 391 &result_data)); |
| 423 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 392 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 424 base::Bind(&DoNothingForReAuthenticateCallback)); | 393 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 425 MessageLoop::current()->Run(); | 394 MessageLoop::current()->Run(); |
| 426 | 395 |
| 427 EXPECT_EQ(HTTP_SUCCESS, result_code); | 396 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 428 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 397 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 429 EXPECT_EQ("/feeds/default/private/full/-/mine?v=3&alt=json&showfolders=true" | 398 EXPECT_EQ("/feeds/default/private/full/-/mine?v=3&alt=json&showfolders=true" |
| 430 "&max-results=500&include-installed-apps=true", | 399 "&max-results=500&include-installed-apps=true", |
| 431 http_request_.relative_url); | 400 http_request_.relative_url); |
| 432 ASSERT_TRUE(result_data); | 401 EXPECT_TRUE(test_util::VerifyJsonData( |
| 433 EXPECT_TRUE(VerifyJsonData( | |
| 434 test_util::GetTestFilePath("gdata/root_feed.json"), | 402 test_util::GetTestFilePath("gdata/root_feed.json"), |
| 435 result_data.get())); | 403 result_data.get())); |
| 436 } | 404 } |
| 437 | 405 |
| 438 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_ValidFeed) { | 406 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_ValidFeed) { |
| 439 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 407 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 440 scoped_ptr<base::Value> result_data; | 408 scoped_ptr<base::Value> result_data; |
| 441 | 409 |
| 442 GetResourceListOperation* operation = new GetResourceListOperation( | 410 GetResourceListOperation* operation = new GetResourceListOperation( |
| 443 &operation_registry_, | 411 &operation_registry_, |
| 444 request_context_getter_.get(), | 412 request_context_getter_.get(), |
| 445 *url_generator_, | 413 *url_generator_, |
| 446 test_server_.GetURL("/files/gdata/root_feed.json"), | 414 test_server_.GetURL("/files/gdata/root_feed.json"), |
| 447 0, // start changestamp | 415 0, // start changestamp |
| 448 "", // search string | 416 "", // search string |
| 449 false, // shared with me | 417 false, // shared with me |
| 450 "", // directory resource ID | 418 "", // directory resource ID |
| 451 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 419 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 452 &result_code, | 420 &result_code, |
| 453 &result_data)); | 421 &result_data)); |
| 454 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 422 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 455 base::Bind(&DoNothingForReAuthenticateCallback)); | 423 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 456 MessageLoop::current()->Run(); | 424 MessageLoop::current()->Run(); |
| 457 | 425 |
| 458 EXPECT_EQ(HTTP_SUCCESS, result_code); | 426 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 459 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 427 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 460 EXPECT_EQ("/files/gdata/root_feed.json?v=3&alt=json&showfolders=true" | 428 EXPECT_EQ("/files/gdata/root_feed.json?v=3&alt=json&showfolders=true" |
| 461 "&max-results=500&include-installed-apps=true", | 429 "&max-results=500&include-installed-apps=true", |
| 462 http_request_.relative_url); | 430 http_request_.relative_url); |
| 463 ASSERT_TRUE(result_data); | 431 EXPECT_TRUE(test_util::VerifyJsonData( |
| 464 EXPECT_TRUE(VerifyJsonData( | |
| 465 test_util::GetTestFilePath("gdata/root_feed.json"), | 432 test_util::GetTestFilePath("gdata/root_feed.json"), |
| 466 result_data.get())); | 433 result_data.get())); |
| 467 } | 434 } |
| 468 | 435 |
| 469 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_InvalidFeed) { | 436 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_InvalidFeed) { |
| 470 // testfile.txt exists but the response is not JSON, so it should | 437 // testfile.txt exists but the response is not JSON, so it should |
| 471 // emit a parse error instead. | 438 // emit a parse error instead. |
| 472 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 439 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 473 scoped_ptr<base::Value> result_data; | 440 scoped_ptr<base::Value> result_data; |
| 474 | 441 |
| 475 GetResourceListOperation* operation = new GetResourceListOperation( | 442 GetResourceListOperation* operation = new GetResourceListOperation( |
| 476 &operation_registry_, | 443 &operation_registry_, |
| 477 request_context_getter_.get(), | 444 request_context_getter_.get(), |
| 478 *url_generator_, | 445 *url_generator_, |
| 479 test_server_.GetURL("/files/gdata/testfile.txt"), | 446 test_server_.GetURL("/files/gdata/testfile.txt"), |
| 480 0, // start changestamp | 447 0, // start changestamp |
| 481 "", // search string | 448 "", // search string |
| 482 false, // shared with me | 449 false, // shared with me |
| 483 "", // directory resource ID | 450 "", // directory resource ID |
| 484 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 451 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 485 &result_code, | 452 &result_code, |
| 486 &result_data)); | 453 &result_data)); |
| 487 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 454 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 488 base::Bind(&DoNothingForReAuthenticateCallback)); | 455 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 489 MessageLoop::current()->Run(); | 456 MessageLoop::current()->Run(); |
| 490 | 457 |
| 491 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); | 458 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); |
| 492 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 459 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 493 EXPECT_EQ("/files/gdata/testfile.txt?v=3&alt=json&showfolders=true" | 460 EXPECT_EQ("/files/gdata/testfile.txt?v=3&alt=json&showfolders=true" |
| 494 "&max-results=500&include-installed-apps=true", | 461 "&max-results=500&include-installed-apps=true", |
| 495 http_request_.relative_url); | 462 http_request_.relative_url); |
| 496 EXPECT_FALSE(result_data); | 463 EXPECT_FALSE(result_data); |
| 497 } | 464 } |
| 498 | 465 |
| 499 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_ValidResourceId) { | 466 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_ValidResourceId) { |
| 500 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 467 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 501 scoped_ptr<base::Value> result_data; | 468 scoped_ptr<base::Value> result_data; |
| 502 | 469 |
| 503 GetResourceEntryOperation* operation = new GetResourceEntryOperation( | 470 GetResourceEntryOperation* operation = new GetResourceEntryOperation( |
| 504 &operation_registry_, | 471 &operation_registry_, |
| 505 request_context_getter_.get(), | 472 request_context_getter_.get(), |
| 506 *url_generator_, | 473 *url_generator_, |
| 507 "file:2_file_resource_id", // resource ID | 474 "file:2_file_resource_id", // resource ID |
| 508 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 475 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 509 &result_code, | 476 &result_code, |
| 510 &result_data)); | 477 &result_data)); |
| 511 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 478 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 512 base::Bind(&DoNothingForReAuthenticateCallback)); | 479 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 513 MessageLoop::current()->Run(); | 480 MessageLoop::current()->Run(); |
| 514 | 481 |
| 515 EXPECT_EQ(HTTP_SUCCESS, result_code); | 482 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 516 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 483 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 517 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" | 484 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" |
| 518 "?v=3&alt=json", | 485 "?v=3&alt=json", |
| 519 http_request_.relative_url); | 486 http_request_.relative_url); |
| 520 ASSERT_TRUE(result_data); | 487 EXPECT_TRUE(test_util::VerifyJsonData( |
| 521 EXPECT_TRUE(VerifyJsonData( | |
| 522 test_util::GetTestFilePath("gdata/file_entry.json"), | 488 test_util::GetTestFilePath("gdata/file_entry.json"), |
| 523 result_data.get())); | 489 result_data.get())); |
| 524 } | 490 } |
| 525 | 491 |
| 526 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_InvalidResourceId) { | 492 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_InvalidResourceId) { |
| 527 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 493 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 528 scoped_ptr<base::Value> result_data; | 494 scoped_ptr<base::Value> result_data; |
| 529 | 495 |
| 530 GetResourceEntryOperation* operation = new GetResourceEntryOperation( | 496 GetResourceEntryOperation* operation = new GetResourceEntryOperation( |
| 531 &operation_registry_, | 497 &operation_registry_, |
| 532 request_context_getter_.get(), | 498 request_context_getter_.get(), |
| 533 *url_generator_, | 499 *url_generator_, |
| 534 "<invalid>", // resource ID | 500 "<invalid>", // resource ID |
| 535 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 501 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 536 &result_code, | 502 &result_code, |
| 537 &result_data)); | 503 &result_data)); |
| 538 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 504 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 539 base::Bind(&DoNothingForReAuthenticateCallback)); | 505 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 540 MessageLoop::current()->Run(); | 506 MessageLoop::current()->Run(); |
| 541 | 507 |
| 542 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 508 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
| 543 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 509 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 544 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json", | 510 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json", |
| 545 http_request_.relative_url); | 511 http_request_.relative_url); |
| 546 ASSERT_FALSE(result_data); | 512 ASSERT_FALSE(result_data); |
| 547 } | 513 } |
| 548 | 514 |
| 549 TEST_F(GDataWapiOperationsTest, GetAccountMetadataOperation) { | 515 TEST_F(GDataWapiOperationsTest, GetAccountMetadataOperation) { |
| 550 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 516 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 551 scoped_ptr<base::Value> result_data; | 517 scoped_ptr<base::Value> result_data; |
| 552 | 518 |
| 553 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( | 519 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( |
| 554 &operation_registry_, | 520 &operation_registry_, |
| 555 request_context_getter_.get(), | 521 request_context_getter_.get(), |
| 556 *url_generator_, | 522 *url_generator_, |
| 557 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 523 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 558 &result_code, | 524 &result_code, |
| 559 &result_data)); | 525 &result_data)); |
| 560 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 526 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 561 base::Bind(&DoNothingForReAuthenticateCallback)); | 527 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 562 MessageLoop::current()->Run(); | 528 MessageLoop::current()->Run(); |
| 563 | 529 |
| 564 EXPECT_EQ(HTTP_SUCCESS, result_code); | 530 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 565 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 531 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 566 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&include-installed-apps=true", | 532 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&include-installed-apps=true", |
| 567 http_request_.relative_url); | 533 http_request_.relative_url); |
| 568 EXPECT_TRUE(VerifyJsonData( | 534 EXPECT_TRUE(test_util::VerifyJsonData( |
| 569 test_util::GetTestFilePath("gdata/account_metadata.json"), | 535 test_util::GetTestFilePath("gdata/account_metadata.json"), |
| 570 result_data.get())); | 536 result_data.get())); |
| 571 } | 537 } |
| 572 | 538 |
| 573 TEST_F(GDataWapiOperationsTest, DownloadFileOperation_ValidFile) { | 539 TEST_F(GDataWapiOperationsTest, DownloadFileOperation_ValidFile) { |
| 574 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 540 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 575 std::string contents; | 541 std::string contents; |
| 576 DownloadFileOperation* operation = new DownloadFileOperation( | 542 DownloadFileOperation* operation = new DownloadFileOperation( |
| 577 &operation_registry_, | 543 &operation_registry_, |
| 578 request_context_getter_.get(), | 544 request_context_getter_.get(), |
| 579 base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit, | 545 base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit, |
| 580 &result_code, | 546 &result_code, |
| 581 &contents), | 547 &contents), |
| 582 GetContentCallback(), | 548 GetContentCallback(), |
| 583 test_server_.GetURL("/files/gdata/testfile.txt"), | 549 test_server_.GetURL("/files/gdata/testfile.txt"), |
| 584 FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), | 550 FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), |
| 585 GetTestCachedFilePath(FilePath::FromUTF8Unsafe("cached_testfile.txt"))); | 551 GetTestCachedFilePath(FilePath::FromUTF8Unsafe("cached_testfile.txt"))); |
| 586 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 552 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 587 base::Bind(&DoNothingForReAuthenticateCallback)); | 553 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 588 MessageLoop::current()->Run(); | 554 MessageLoop::current()->Run(); |
| 589 | 555 |
| 590 EXPECT_EQ(HTTP_SUCCESS, result_code); | 556 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 591 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 557 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 592 EXPECT_EQ("/files/gdata/testfile.txt", http_request_.relative_url); | 558 EXPECT_EQ("/files/gdata/testfile.txt", http_request_.relative_url); |
| 593 | 559 |
| 594 const FilePath expected_path = | 560 const FilePath expected_path = |
| 595 test_util::GetTestFilePath("gdata/testfile.txt"); | 561 test_util::GetTestFilePath("gdata/testfile.txt"); |
| 596 std::string expected_contents; | 562 std::string expected_contents; |
| 597 file_util::ReadFileToString(expected_path, &expected_contents); | 563 file_util::ReadFileToString(expected_path, &expected_contents); |
| 598 EXPECT_EQ(expected_contents, contents); | 564 EXPECT_EQ(expected_contents, contents); |
| 599 } | 565 } |
| 600 | 566 |
| 601 TEST_F(GDataWapiOperationsTest, DownloadFileOperation_NonExistentFile) { | 567 TEST_F(GDataWapiOperationsTest, DownloadFileOperation_NonExistentFile) { |
| 602 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 568 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 603 std::string contents; | 569 std::string contents; |
| 604 DownloadFileOperation* operation = new DownloadFileOperation( | 570 DownloadFileOperation* operation = new DownloadFileOperation( |
| 605 &operation_registry_, | 571 &operation_registry_, |
| 606 request_context_getter_.get(), | 572 request_context_getter_.get(), |
| 607 base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit, | 573 base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit, |
| 608 &result_code, | 574 &result_code, |
| 609 &contents), | 575 &contents), |
| 610 GetContentCallback(), | 576 GetContentCallback(), |
| 611 test_server_.GetURL("/files/gdata/no-such-file.txt"), | 577 test_server_.GetURL("/files/gdata/no-such-file.txt"), |
| 612 FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"), | 578 FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"), |
| 613 GetTestCachedFilePath( | 579 GetTestCachedFilePath( |
| 614 FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); | 580 FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); |
| 615 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 581 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 616 base::Bind(&DoNothingForReAuthenticateCallback)); | 582 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 617 MessageLoop::current()->Run(); | 583 MessageLoop::current()->Run(); |
| 618 | 584 |
| 619 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 585 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
| 620 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 586 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); |
| 621 EXPECT_EQ("/files/gdata/no-such-file.txt", http_request_.relative_url); | 587 EXPECT_EQ("/files/gdata/no-such-file.txt", http_request_.relative_url); |
| 622 // Do not verify the not found message. | 588 // Do not verify the not found message. |
| 623 } | 589 } |
| 624 | 590 |
| 625 TEST_F(GDataWapiOperationsTest, DeleteResourceOperation) { | 591 TEST_F(GDataWapiOperationsTest, DeleteResourceOperation) { |
| 626 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 592 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 627 | 593 |
| 628 DeleteResourceOperation* operation = new DeleteResourceOperation( | 594 DeleteResourceOperation* operation = new DeleteResourceOperation( |
| 629 &operation_registry_, | 595 &operation_registry_, |
| 630 request_context_getter_.get(), | 596 request_context_getter_.get(), |
| 631 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, | 597 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, |
| 632 &result_code), | 598 &result_code), |
| 633 test_server_.GetURL( | 599 test_server_.GetURL( |
| 634 "/feeds/default/private/full/file:2_file_resource_id")); | 600 "/feeds/default/private/full/file:2_file_resource_id")); |
| 635 | 601 |
| 636 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 602 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 637 base::Bind(&DoNothingForReAuthenticateCallback)); | 603 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 638 MessageLoop::current()->Run(); | 604 MessageLoop::current()->Run(); |
| 639 | 605 |
| 640 EXPECT_EQ(HTTP_SUCCESS, result_code); | 606 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 641 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); | 607 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); |
| 642 EXPECT_EQ("/feeds/default/private/full/file:2_file_resource_id?v=3&alt=json", | 608 EXPECT_EQ("/feeds/default/private/full/file:2_file_resource_id?v=3&alt=json", |
| 643 http_request_.relative_url); | 609 http_request_.relative_url); |
| 644 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 610 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
| 645 } | 611 } |
| 646 | 612 |
| 647 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { | 613 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { |
| 648 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 614 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 649 scoped_ptr<base::Value> result_data; | 615 scoped_ptr<base::Value> result_data; |
| 650 | 616 |
| 651 // Create "new directory" in the root directory. | 617 // Create "new directory" in the root directory. |
| 652 CreateDirectoryOperation* operation = new CreateDirectoryOperation( | 618 CreateDirectoryOperation* operation = new CreateDirectoryOperation( |
| 653 &operation_registry_, | 619 &operation_registry_, |
| 654 request_context_getter_.get(), | 620 request_context_getter_.get(), |
| 655 *url_generator_, | 621 *url_generator_, |
| 656 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 622 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 657 &result_code, | 623 &result_code, |
| 658 &result_data), | 624 &result_data), |
| 659 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), | 625 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), |
| 660 FILE_PATH_LITERAL("new directory")); | 626 FILE_PATH_LITERAL("new directory")); |
| 661 | 627 |
| 662 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 628 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 663 base::Bind(&DoNothingForReAuthenticateCallback)); | 629 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 664 MessageLoop::current()->Run(); | 630 MessageLoop::current()->Run(); |
| 665 | 631 |
| 666 EXPECT_EQ(HTTP_SUCCESS, result_code); | 632 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 667 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 633 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 668 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot?v=3&alt=json", | 634 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot?v=3&alt=json", |
| 669 http_request_.relative_url); | 635 http_request_.relative_url); |
| 670 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 636 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 671 | 637 |
| 672 EXPECT_TRUE(http_request_.has_content); | 638 EXPECT_TRUE(http_request_.has_content); |
| 673 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 639 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 674 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 640 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
| 675 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " | 641 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " |
| 676 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" | 642 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" |
| 677 " <title>new directory</title>\n" | 643 " <title>new directory</title>\n" |
| 678 "</entry>\n", | 644 "</entry>\n", |
| 679 http_request_.content); | 645 http_request_.content); |
| 680 } | 646 } |
| 681 | 647 |
| 682 TEST_F(GDataWapiOperationsTest, CopyHostedDocumentOperation) { | 648 TEST_F(GDataWapiOperationsTest, CopyHostedDocumentOperation) { |
| 683 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 649 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 684 scoped_ptr<base::Value> result_data; | 650 scoped_ptr<base::Value> result_data; |
| 685 | 651 |
| 686 // Copy a document with a new name "New Document". | 652 // Copy a document with a new name "New Document". |
| 687 CopyHostedDocumentOperation* operation = new CopyHostedDocumentOperation( | 653 CopyHostedDocumentOperation* operation = new CopyHostedDocumentOperation( |
| 688 &operation_registry_, | 654 &operation_registry_, |
| 689 request_context_getter_.get(), | 655 request_context_getter_.get(), |
| 690 *url_generator_, | 656 *url_generator_, |
| 691 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 657 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 692 &result_code, | 658 &result_code, |
| 693 &result_data), | 659 &result_data), |
| 694 "document:5_document_resource_id", // source resource ID | 660 "document:5_document_resource_id", // source resource ID |
| 695 FILE_PATH_LITERAL("New Document")); | 661 FILE_PATH_LITERAL("New Document")); |
| 696 | 662 |
| 697 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 663 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 698 base::Bind(&DoNothingForReAuthenticateCallback)); | 664 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 699 MessageLoop::current()->Run(); | 665 MessageLoop::current()->Run(); |
| 700 | 666 |
| 701 EXPECT_EQ(HTTP_SUCCESS, result_code); | 667 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 702 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 668 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 703 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json", | 669 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json", |
| 704 http_request_.relative_url); | 670 http_request_.relative_url); |
| 705 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 671 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 706 | 672 |
| 707 EXPECT_TRUE(http_request_.has_content); | 673 EXPECT_TRUE(http_request_.has_content); |
| 708 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 674 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 720 RenameResourceOperation* operation = new RenameResourceOperation( | 686 RenameResourceOperation* operation = new RenameResourceOperation( |
| 721 &operation_registry_, | 687 &operation_registry_, |
| 722 request_context_getter_.get(), | 688 request_context_getter_.get(), |
| 723 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, | 689 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, |
| 724 &result_code), | 690 &result_code), |
| 725 test_server_.GetURL( | 691 test_server_.GetURL( |
| 726 "/feeds/default/private/full/file:2_file_resource_id"), | 692 "/feeds/default/private/full/file:2_file_resource_id"), |
| 727 FILE_PATH_LITERAL("New File")); | 693 FILE_PATH_LITERAL("New File")); |
| 728 | 694 |
| 729 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 695 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 730 base::Bind(&DoNothingForReAuthenticateCallback)); | 696 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 731 MessageLoop::current()->Run(); | 697 MessageLoop::current()->Run(); |
| 732 | 698 |
| 733 EXPECT_EQ(HTTP_SUCCESS, result_code); | 699 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 734 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 700 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 735 EXPECT_EQ("/feeds/default/private/full/file:2_file_resource_id?v=3&alt=json", | 701 EXPECT_EQ("/feeds/default/private/full/file:2_file_resource_id?v=3&alt=json", |
| 736 http_request_.relative_url); | 702 http_request_.relative_url); |
| 737 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 703 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 738 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 704 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
| 739 | 705 |
| 740 EXPECT_TRUE(http_request_.has_content); | 706 EXPECT_TRUE(http_request_.has_content); |
| 741 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 707 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 742 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 708 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
| 743 " <title>New File</title>\n" | 709 " <title>New File</title>\n" |
| 744 "</entry>\n", | 710 "</entry>\n", |
| 745 http_request_.content); | 711 http_request_.content); |
| 746 } | 712 } |
| 747 | 713 |
| 748 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { | 714 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { |
| 749 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 715 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 750 scoped_ptr<base::Value> result_data; | 716 scoped_ptr<base::Value> result_data; |
| 751 | 717 |
| 752 // Authorize an app with APP_ID to access to a document. | 718 // Authorize an app with APP_ID to access to a document. |
| 753 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 719 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
| 754 &operation_registry_, | 720 &operation_registry_, |
| 755 request_context_getter_.get(), | 721 request_context_getter_.get(), |
| 756 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 722 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 757 &result_code, | 723 &result_code, |
| 758 &result_data), | 724 &result_data), |
| 759 test_server_.GetURL( | 725 test_server_.GetURL( |
| 760 "/feeds/default/private/full/file:2_file_resource_id"), | 726 "/feeds/default/private/full/file:2_file_resource_id"), |
| 761 "APP_ID"); | 727 "APP_ID"); |
| 762 | 728 |
| 763 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 729 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 764 base::Bind(&DoNothingForReAuthenticateCallback)); | 730 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 765 MessageLoop::current()->Run(); | 731 MessageLoop::current()->Run(); |
| 766 | 732 |
| 767 EXPECT_EQ(HTTP_SUCCESS, result_code); | 733 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 768 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 734 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 769 EXPECT_EQ("/feeds/default/private/full/file:2_file_resource_id?v=3&alt=json", | 735 EXPECT_EQ("/feeds/default/private/full/file:2_file_resource_id?v=3&alt=json", |
| 770 http_request_.relative_url); | 736 http_request_.relative_url); |
| 771 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 737 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 772 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 738 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
| 773 | 739 |
| 774 EXPECT_TRUE(http_request_.has_content); | 740 EXPECT_TRUE(http_request_.has_content); |
| 775 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 741 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 776 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 742 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
| 777 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 743 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
| 778 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" | 744 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" |
| 779 "</entry>\n", | 745 "</entry>\n", |
| 780 http_request_.content); | 746 http_request_.content); |
| 781 } | 747 } |
| 782 | 748 |
| 783 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { | 749 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { |
| 784 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 750 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 785 scoped_ptr<base::Value> result_data; | 751 scoped_ptr<base::Value> result_data; |
| 786 | 752 |
| 787 // Authorize an app with APP_ID to access to a document but an invalid feed. | 753 // Authorize an app with APP_ID to access to a document but an invalid feed. |
| 788 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 754 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
| 789 &operation_registry_, | 755 &operation_registry_, |
| 790 request_context_getter_.get(), | 756 request_context_getter_.get(), |
| 791 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, | 757 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, |
| 792 &result_code, | 758 &result_code, |
| 793 &result_data), | 759 &result_data), |
| 794 test_server_.GetURL("/files/gdata/testfile.txt"), | 760 test_server_.GetURL("/files/gdata/testfile.txt"), |
| 795 "APP_ID"); | 761 "APP_ID"); |
| 796 | 762 |
| 797 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 763 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 798 base::Bind(&DoNothingForReAuthenticateCallback)); | 764 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 799 MessageLoop::current()->Run(); | 765 MessageLoop::current()->Run(); |
| 800 | 766 |
| 801 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); | 767 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); |
| 802 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 768 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 803 EXPECT_EQ("/files/gdata/testfile.txt?v=3&alt=json", | 769 EXPECT_EQ("/files/gdata/testfile.txt?v=3&alt=json", |
| 804 http_request_.relative_url); | 770 http_request_.relative_url); |
| 805 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 771 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 806 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 772 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
| 807 | 773 |
| 808 EXPECT_TRUE(http_request_.has_content); | 774 EXPECT_TRUE(http_request_.has_content); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 823 &operation_registry_, | 789 &operation_registry_, |
| 824 request_context_getter_.get(), | 790 request_context_getter_.get(), |
| 825 *url_generator_, | 791 *url_generator_, |
| 826 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, | 792 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, |
| 827 &result_code), | 793 &result_code), |
| 828 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), | 794 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), |
| 829 test_server_.GetURL( | 795 test_server_.GetURL( |
| 830 "/feeds/default/private/full/file:2_file_resource_id")); | 796 "/feeds/default/private/full/file:2_file_resource_id")); |
| 831 | 797 |
| 832 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 798 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 833 base::Bind(&DoNothingForReAuthenticateCallback)); | 799 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 834 MessageLoop::current()->Run(); | 800 MessageLoop::current()->Run(); |
| 835 | 801 |
| 836 EXPECT_EQ(HTTP_SUCCESS, result_code); | 802 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 837 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 803 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 838 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot?v=3&alt=json", | 804 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot?v=3&alt=json", |
| 839 http_request_.relative_url); | 805 http_request_.relative_url); |
| 840 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 806 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 841 | 807 |
| 842 EXPECT_TRUE(http_request_.has_content); | 808 EXPECT_TRUE(http_request_.has_content); |
| 843 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 809 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 855 RemoveResourceFromDirectoryOperation* operation = | 821 RemoveResourceFromDirectoryOperation* operation = |
| 856 new RemoveResourceFromDirectoryOperation( | 822 new RemoveResourceFromDirectoryOperation( |
| 857 &operation_registry_, | 823 &operation_registry_, |
| 858 request_context_getter_.get(), | 824 request_context_getter_.get(), |
| 859 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, | 825 base::Bind(&CopyResultFromEntryActionCallbackAndQuit, |
| 860 &result_code), | 826 &result_code), |
| 861 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), | 827 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), |
| 862 "file:2_file_resource_id"); | 828 "file:2_file_resource_id"); |
| 863 | 829 |
| 864 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 830 operation->Start(kTestGDataAuthToken, kTestUserAgent, |
| 865 base::Bind(&DoNothingForReAuthenticateCallback)); | 831 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 866 MessageLoop::current()->Run(); | 832 MessageLoop::current()->Run(); |
| 867 | 833 |
| 868 EXPECT_EQ(HTTP_SUCCESS, result_code); | 834 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 869 // DELETE method should be used, without the body content. | 835 // DELETE method should be used, without the body content. |
| 870 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); | 836 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); |
| 871 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/" | 837 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/" |
| 872 "file%3A2_file_resource_id?v=3&alt=json", | 838 "file%3A2_file_resource_id?v=3&alt=json", |
| 873 http_request_.relative_url); | 839 http_request_.relative_url); |
| 874 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 840 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
| 875 EXPECT_FALSE(http_request_.has_content); | 841 EXPECT_FALSE(http_request_.has_content); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 893 "" /* etag */); | 859 "" /* etag */); |
| 894 | 860 |
| 895 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( | 861 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( |
| 896 &operation_registry_, | 862 &operation_registry_, |
| 897 request_context_getter_.get(), | 863 request_context_getter_.get(), |
| 898 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, | 864 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, |
| 899 &result_code, | 865 &result_code, |
| 900 &upload_url), | 866 &upload_url), |
| 901 initiate_params); | 867 initiate_params); |
| 902 | 868 |
| 903 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 869 initiate_operation->Start( |
| 904 base::Bind(&DoNothingForReAuthenticateCallback)); | 870 kTestGDataAuthToken, kTestUserAgent, |
| 871 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 905 MessageLoop::current()->Run(); | 872 MessageLoop::current()->Run(); |
| 906 | 873 |
| 907 EXPECT_EQ(HTTP_SUCCESS, result_code); | 874 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 908 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 875 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
| 909 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 876 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 910 // convert=false should be passed as files should be uploaded as-is. | 877 // convert=false should be passed as files should be uploaded as-is. |
| 911 EXPECT_EQ("/feeds/upload/create-session/default/private/full" | 878 EXPECT_EQ("/feeds/upload/create-session/default/private/full" |
| 912 "?convert=false&v=3&alt=json", | 879 "?convert=false&v=3&alt=json", |
| 913 http_request_.relative_url); | 880 http_request_.relative_url); |
| 914 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 881 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 940 scoped_ptr<ResourceEntry> new_entry; | 907 scoped_ptr<ResourceEntry> new_entry; |
| 941 | 908 |
| 942 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 909 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
| 943 &operation_registry_, | 910 &operation_registry_, |
| 944 request_context_getter_.get(), | 911 request_context_getter_.get(), |
| 945 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, | 912 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, |
| 946 &response, | 913 &response, |
| 947 &new_entry), | 914 &new_entry), |
| 948 resume_params); | 915 resume_params); |
| 949 | 916 |
| 950 resume_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 917 resume_operation->Start( |
| 951 base::Bind(&DoNothingForReAuthenticateCallback)); | 918 kTestGDataAuthToken, kTestUserAgent, |
| 919 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 952 MessageLoop::current()->Run(); | 920 MessageLoop::current()->Run(); |
| 953 | 921 |
| 954 // METHOD_PUT should be used to upload data. | 922 // METHOD_PUT should be used to upload data. |
| 955 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 923 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 956 // Request should go to the upload URL. | 924 // Request should go to the upload URL. |
| 957 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 925 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 958 // Content-Range header should be added. | 926 // Content-Range header should be added. |
| 959 EXPECT_EQ("bytes 0-" + | 927 EXPECT_EQ("bytes 0-" + |
| 960 base::Int64ToString(kUploadContent.size() -1) + "/" + | 928 base::Int64ToString(kUploadContent.size() -1) + "/" + |
| 961 base::Int64ToString(kUploadContent.size()), | 929 base::Int64ToString(kUploadContent.size()), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 "" /* etag */); | 961 "" /* etag */); |
| 994 | 962 |
| 995 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( | 963 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( |
| 996 &operation_registry_, | 964 &operation_registry_, |
| 997 request_context_getter_.get(), | 965 request_context_getter_.get(), |
| 998 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, | 966 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, |
| 999 &result_code, | 967 &result_code, |
| 1000 &upload_url), | 968 &upload_url), |
| 1001 initiate_params); | 969 initiate_params); |
| 1002 | 970 |
| 1003 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 971 initiate_operation->Start( |
| 1004 base::Bind(&DoNothingForReAuthenticateCallback)); | 972 kTestGDataAuthToken, kTestUserAgent, |
| 973 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1005 MessageLoop::current()->Run(); | 974 MessageLoop::current()->Run(); |
| 1006 | 975 |
| 1007 EXPECT_EQ(HTTP_SUCCESS, result_code); | 976 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1008 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 977 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
| 1009 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 978 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 1010 // convert=false should be passed as files should be uploaded as-is. | 979 // convert=false should be passed as files should be uploaded as-is. |
| 1011 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" | 980 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" |
| 1012 "&v=3&alt=json", | 981 "&v=3&alt=json", |
| 1013 http_request_.relative_url); | 982 http_request_.relative_url); |
| 1014 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 983 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 scoped_ptr<ResourceEntry> new_entry; | 1022 scoped_ptr<ResourceEntry> new_entry; |
| 1054 | 1023 |
| 1055 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1024 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
| 1056 &operation_registry_, | 1025 &operation_registry_, |
| 1057 request_context_getter_.get(), | 1026 request_context_getter_.get(), |
| 1058 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, | 1027 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, |
| 1059 &response, | 1028 &response, |
| 1060 &new_entry), | 1029 &new_entry), |
| 1061 resume_params); | 1030 resume_params); |
| 1062 | 1031 |
| 1063 resume_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1032 resume_operation->Start( |
| 1064 base::Bind(&DoNothingForReAuthenticateCallback)); | 1033 kTestGDataAuthToken, kTestUserAgent, |
| 1034 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1065 MessageLoop::current()->Run(); | 1035 MessageLoop::current()->Run(); |
| 1066 | 1036 |
| 1067 // METHOD_PUT should be used to upload data. | 1037 // METHOD_PUT should be used to upload data. |
| 1068 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1038 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1069 // Request should go to the upload URL. | 1039 // Request should go to the upload URL. |
| 1070 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1040 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1071 // Content-Range header should be added. | 1041 // Content-Range header should be added. |
| 1072 EXPECT_EQ("bytes " + | 1042 EXPECT_EQ("bytes " + |
| 1073 base::Int64ToString(start_position) + "-" + | 1043 base::Int64ToString(start_position) + "-" + |
| 1074 base::Int64ToString(end_position - 1) + "/" + | 1044 base::Int64ToString(end_position - 1) + "/" + |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 "" /* etag */); | 1088 "" /* etag */); |
| 1119 | 1089 |
| 1120 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( | 1090 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( |
| 1121 &operation_registry_, | 1091 &operation_registry_, |
| 1122 request_context_getter_.get(), | 1092 request_context_getter_.get(), |
| 1123 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, | 1093 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, |
| 1124 &result_code, | 1094 &result_code, |
| 1125 &upload_url), | 1095 &upload_url), |
| 1126 initiate_params); | 1096 initiate_params); |
| 1127 | 1097 |
| 1128 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1098 initiate_operation->Start( |
| 1129 base::Bind(&DoNothingForReAuthenticateCallback)); | 1099 kTestGDataAuthToken, kTestUserAgent, |
| 1100 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1130 MessageLoop::current()->Run(); | 1101 MessageLoop::current()->Run(); |
| 1131 | 1102 |
| 1132 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1103 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1133 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1104 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
| 1134 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 1105 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 1135 // convert=false should be passed as files should be uploaded as-is. | 1106 // convert=false should be passed as files should be uploaded as-is. |
| 1136 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" | 1107 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" |
| 1137 "&v=3&alt=json", | 1108 "&v=3&alt=json", |
| 1138 http_request_.relative_url); | 1109 http_request_.relative_url); |
| 1139 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1110 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1165 scoped_ptr<ResourceEntry> new_entry; | 1136 scoped_ptr<ResourceEntry> new_entry; |
| 1166 | 1137 |
| 1167 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1138 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
| 1168 &operation_registry_, | 1139 &operation_registry_, |
| 1169 request_context_getter_.get(), | 1140 request_context_getter_.get(), |
| 1170 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, | 1141 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, |
| 1171 &response, | 1142 &response, |
| 1172 &new_entry), | 1143 &new_entry), |
| 1173 resume_params); | 1144 resume_params); |
| 1174 | 1145 |
| 1175 resume_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1146 resume_operation->Start( |
| 1176 base::Bind(&DoNothingForReAuthenticateCallback)); | 1147 kTestGDataAuthToken, kTestUserAgent, |
| 1148 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1177 MessageLoop::current()->Run(); | 1149 MessageLoop::current()->Run(); |
| 1178 | 1150 |
| 1179 // METHOD_PUT should be used to upload data. | 1151 // METHOD_PUT should be used to upload data. |
| 1180 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1152 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1181 // Request should go to the upload URL. | 1153 // Request should go to the upload URL. |
| 1182 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1154 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1183 // Content-Range header should not exit if the content is empty. | 1155 // Content-Range header should not exit if the content is empty. |
| 1184 // We should not generate the header with an invalid value "bytes 0--1/0". | 1156 // We should not generate the header with an invalid value "bytes 0--1/0". |
| 1185 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); | 1157 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); |
| 1186 // The upload content should be set in the HTTP request. | 1158 // The upload content should be set in the HTTP request. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1213 "" /* etag */); | 1185 "" /* etag */); |
| 1214 | 1186 |
| 1215 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( | 1187 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( |
| 1216 &operation_registry_, | 1188 &operation_registry_, |
| 1217 request_context_getter_.get(), | 1189 request_context_getter_.get(), |
| 1218 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, | 1190 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, |
| 1219 &result_code, | 1191 &result_code, |
| 1220 &upload_url), | 1192 &upload_url), |
| 1221 initiate_params); | 1193 initiate_params); |
| 1222 | 1194 |
| 1223 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1195 initiate_operation->Start( |
| 1224 base::Bind(&DoNothingForReAuthenticateCallback)); | 1196 kTestGDataAuthToken, kTestUserAgent, |
| 1197 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1225 MessageLoop::current()->Run(); | 1198 MessageLoop::current()->Run(); |
| 1226 | 1199 |
| 1227 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1200 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1228 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1201 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
| 1229 // For updating an existing file, METHOD_PUT should be used. | 1202 // For updating an existing file, METHOD_PUT should be used. |
| 1230 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1203 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1231 // convert=false should be passed as files should be uploaded as-is. | 1204 // convert=false should be passed as files should be uploaded as-is. |
| 1232 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" | 1205 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" |
| 1233 "?convert=false&v=3&alt=json", | 1206 "?convert=false&v=3&alt=json", |
| 1234 http_request_.relative_url); | 1207 http_request_.relative_url); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1260 scoped_ptr<ResourceEntry> new_entry; | 1233 scoped_ptr<ResourceEntry> new_entry; |
| 1261 | 1234 |
| 1262 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1235 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
| 1263 &operation_registry_, | 1236 &operation_registry_, |
| 1264 request_context_getter_.get(), | 1237 request_context_getter_.get(), |
| 1265 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, | 1238 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, |
| 1266 &response, | 1239 &response, |
| 1267 &new_entry), | 1240 &new_entry), |
| 1268 resume_params); | 1241 resume_params); |
| 1269 | 1242 |
| 1270 resume_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1243 resume_operation->Start( |
| 1271 base::Bind(&DoNothingForReAuthenticateCallback)); | 1244 kTestGDataAuthToken, kTestUserAgent, |
| 1245 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1272 MessageLoop::current()->Run(); | 1246 MessageLoop::current()->Run(); |
| 1273 | 1247 |
| 1274 // METHOD_PUT should be used to upload data. | 1248 // METHOD_PUT should be used to upload data. |
| 1275 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1249 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1276 // Request should go to the upload URL. | 1250 // Request should go to the upload URL. |
| 1277 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1251 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1278 // Content-Range header should be added. | 1252 // Content-Range header should be added. |
| 1279 EXPECT_EQ("bytes 0-" + | 1253 EXPECT_EQ("bytes 0-" + |
| 1280 base::Int64ToString(kUploadContent.size() -1) + "/" + | 1254 base::Int64ToString(kUploadContent.size() -1) + "/" + |
| 1281 base::Int64ToString(kUploadContent.size()), | 1255 base::Int64ToString(kUploadContent.size()), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1310 kTestETag); | 1284 kTestETag); |
| 1311 | 1285 |
| 1312 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( | 1286 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( |
| 1313 &operation_registry_, | 1287 &operation_registry_, |
| 1314 request_context_getter_.get(), | 1288 request_context_getter_.get(), |
| 1315 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, | 1289 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, |
| 1316 &result_code, | 1290 &result_code, |
| 1317 &upload_url), | 1291 &upload_url), |
| 1318 initiate_params); | 1292 initiate_params); |
| 1319 | 1293 |
| 1320 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1294 initiate_operation->Start( |
| 1321 base::Bind(&DoNothingForReAuthenticateCallback)); | 1295 kTestGDataAuthToken, kTestUserAgent, |
| 1296 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1322 MessageLoop::current()->Run(); | 1297 MessageLoop::current()->Run(); |
| 1323 | 1298 |
| 1324 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1299 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1325 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1300 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
| 1326 // For updating an existing file, METHOD_PUT should be used. | 1301 // For updating an existing file, METHOD_PUT should be used. |
| 1327 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1302 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1328 // convert=false should be passed as files should be uploaded as-is. | 1303 // convert=false should be passed as files should be uploaded as-is. |
| 1329 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" | 1304 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" |
| 1330 "?convert=false&v=3&alt=json", | 1305 "?convert=false&v=3&alt=json", |
| 1331 http_request_.relative_url); | 1306 http_request_.relative_url); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1357 scoped_ptr<ResourceEntry> new_entry; | 1332 scoped_ptr<ResourceEntry> new_entry; |
| 1358 | 1333 |
| 1359 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1334 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
| 1360 &operation_registry_, | 1335 &operation_registry_, |
| 1361 request_context_getter_.get(), | 1336 request_context_getter_.get(), |
| 1362 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, | 1337 base::Bind(&CopyResultFromResumeUploadCallbackAndQuit, |
| 1363 &response, | 1338 &response, |
| 1364 &new_entry), | 1339 &new_entry), |
| 1365 resume_params); | 1340 resume_params); |
| 1366 | 1341 |
| 1367 resume_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1342 resume_operation->Start( |
| 1368 base::Bind(&DoNothingForReAuthenticateCallback)); | 1343 kTestGDataAuthToken, kTestUserAgent, |
| 1344 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1369 MessageLoop::current()->Run(); | 1345 MessageLoop::current()->Run(); |
| 1370 | 1346 |
| 1371 // METHOD_PUT should be used to upload data. | 1347 // METHOD_PUT should be used to upload data. |
| 1372 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1348 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1373 // Request should go to the upload URL. | 1349 // Request should go to the upload URL. |
| 1374 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1350 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1375 // Content-Range header should be added. | 1351 // Content-Range header should be added. |
| 1376 EXPECT_EQ("bytes 0-" + | 1352 EXPECT_EQ("bytes 0-" + |
| 1377 base::Int64ToString(kUploadContent.size() -1) + "/" + | 1353 base::Int64ToString(kUploadContent.size() -1) + "/" + |
| 1378 base::Int64ToString(kUploadContent.size()), | 1354 base::Int64ToString(kUploadContent.size()), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1407 kWrongETag); | 1383 kWrongETag); |
| 1408 | 1384 |
| 1409 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( | 1385 InitiateUploadOperation* initiate_operation = new InitiateUploadOperation( |
| 1410 &operation_registry_, | 1386 &operation_registry_, |
| 1411 request_context_getter_.get(), | 1387 request_context_getter_.get(), |
| 1412 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, | 1388 base::Bind(&CopyResultFromInitiateUploadCallbackAndQuit, |
| 1413 &result_code, | 1389 &result_code, |
| 1414 &upload_url), | 1390 &upload_url), |
| 1415 initiate_params); | 1391 initiate_params); |
| 1416 | 1392 |
| 1417 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1393 initiate_operation->Start( |
| 1418 base::Bind(&DoNothingForReAuthenticateCallback)); | 1394 kTestGDataAuthToken, kTestUserAgent, |
| 1395 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 1419 MessageLoop::current()->Run(); | 1396 MessageLoop::current()->Run(); |
| 1420 | 1397 |
| 1421 EXPECT_EQ(HTTP_PRECONDITION, result_code); | 1398 EXPECT_EQ(HTTP_PRECONDITION, result_code); |
| 1422 // For updating an existing file, METHOD_PUT should be used. | 1399 // For updating an existing file, METHOD_PUT should be used. |
| 1423 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1400 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
| 1424 // convert=false should be passed as files should be uploaded as-is. | 1401 // convert=false should be passed as files should be uploaded as-is. |
| 1425 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" | 1402 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" |
| 1426 "?convert=false&v=3&alt=json", | 1403 "?convert=false&v=3&alt=json", |
| 1427 http_request_.relative_url); | 1404 http_request_.relative_url); |
| 1428 // Even though the body is empty, the content type should be set to | 1405 // Even though the body is empty, the content type should be set to |
| 1429 // "text/plain". | 1406 // "text/plain". |
| 1430 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1407 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
| 1431 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1408 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
| 1432 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1409 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
| 1433 http_request_.headers["X-Upload-Content-Length"]); | 1410 http_request_.headers["X-Upload-Content-Length"]); |
| 1434 // For updating an existing file, an empty body should be attached (PUT | 1411 // For updating an existing file, an empty body should be attached (PUT |
| 1435 // requires a body) | 1412 // requires a body) |
| 1436 EXPECT_TRUE(http_request_.has_content); | 1413 EXPECT_TRUE(http_request_.has_content); |
| 1437 EXPECT_EQ("", http_request_.content); | 1414 EXPECT_EQ("", http_request_.content); |
| 1438 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); | 1415 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); |
| 1439 } | 1416 } |
| 1440 | 1417 |
| 1441 } // namespace google_apis | 1418 } // namespace google_apis |
| OLD | NEW |