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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/google_apis/auth_service.h" |
17 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 18 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 19 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
19 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 20 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
20 #include "chrome/browser/google_apis/operation_registry.h" | 21 #include "chrome/browser/google_apis/operation_runner.h" |
21 #include "chrome/browser/google_apis/task_util.h" | 22 #include "chrome/browser/google_apis/task_util.h" |
22 #include "chrome/browser/google_apis/test_util.h" | 23 #include "chrome/browser/google_apis/test_util.h" |
23 #include "chrome/browser/profiles/profile.h" | |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
26 #include "net/base/escape.h" | 26 #include "net/base/escape.h" |
27 #include "net/test/embedded_test_server/embedded_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
28 #include "net/test/embedded_test_server/http_request.h" | 28 #include "net/test/embedded_test_server/http_request.h" |
29 #include "net/test/embedded_test_server/http_response.h" | 29 #include "net/test/embedded_test_server/http_response.h" |
30 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 namespace google_apis { | 33 namespace google_apis { |
(...skipping 16 matching lines...) Expand all Loading... |
50 | 50 |
51 virtual void SetUp() OVERRIDE { | 51 virtual void SetUp() OVERRIDE { |
52 file_thread_.Start(); | 52 file_thread_.Start(); |
53 io_thread_.StartIOThread(); | 53 io_thread_.StartIOThread(); |
54 profile_.reset(new TestingProfile); | 54 profile_.reset(new TestingProfile); |
55 | 55 |
56 request_context_getter_ = new net::TestURLRequestContextGetter( | 56 request_context_getter_ = new net::TestURLRequestContextGetter( |
57 content::BrowserThread::GetMessageLoopProxyForThread( | 57 content::BrowserThread::GetMessageLoopProxyForThread( |
58 content::BrowserThread::IO)); | 58 content::BrowserThread::IO)); |
59 | 59 |
| 60 operation_runner_.reset(new OperationRunner(profile_.get(), |
| 61 request_context_getter_, |
| 62 std::vector<std::string>(), |
| 63 kTestUserAgent)); |
| 64 operation_runner_->auth_service()->set_access_token_for_testing( |
| 65 kTestGDataAuthToken); |
| 66 |
60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
61 | 68 |
62 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); | 69 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); |
63 test_server_.RegisterRequestHandler( | 70 test_server_.RegisterRequestHandler( |
64 base::Bind(&test_util::HandleDownloadRequest, | 71 base::Bind(&test_util::HandleDownloadRequest, |
65 test_server_.base_url(), | 72 test_server_.base_url(), |
66 base::Unretained(&http_request_))); | 73 base::Unretained(&http_request_))); |
67 test_server_.RegisterRequestHandler( | 74 test_server_.RegisterRequestHandler( |
68 base::Bind(&GDataWapiOperationsTest::HandleResourceFeedRequest, | 75 base::Bind(&GDataWapiOperationsTest::HandleResourceFeedRequest, |
69 base::Unretained(this))); | 76 base::Unretained(this))); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 301 |
295 return response.Pass(); | 302 return response.Pass(); |
296 } | 303 } |
297 | 304 |
298 MessageLoopForUI message_loop_; | 305 MessageLoopForUI message_loop_; |
299 content::TestBrowserThread ui_thread_; | 306 content::TestBrowserThread ui_thread_; |
300 content::TestBrowserThread file_thread_; | 307 content::TestBrowserThread file_thread_; |
301 content::TestBrowserThread io_thread_; | 308 content::TestBrowserThread io_thread_; |
302 net::test_server::EmbeddedTestServer test_server_; | 309 net::test_server::EmbeddedTestServer test_server_; |
303 scoped_ptr<TestingProfile> profile_; | 310 scoped_ptr<TestingProfile> profile_; |
304 OperationRegistry operation_registry_; | 311 scoped_ptr<OperationRunner> operation_runner_; |
305 scoped_ptr<GDataWapiUrlGenerator> url_generator_; | 312 scoped_ptr<GDataWapiUrlGenerator> url_generator_; |
306 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 313 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
307 base::ScopedTempDir temp_dir_; | 314 base::ScopedTempDir temp_dir_; |
308 | 315 |
309 // These fields are used to keep the current upload state during a | 316 // These fields are used to keep the current upload state during a |
310 // test case. These values are updated by the request from | 317 // test case. These values are updated by the request from |
311 // ResumeUploadOperation, and used to construct the response for | 318 // ResumeUploadOperation, and used to construct the response for |
312 // both ResumeUploadOperation and GetUploadStatusOperation, to emulate | 319 // both ResumeUploadOperation and GetUploadStatusOperation, to emulate |
313 // the WAPI server. | 320 // the WAPI server. |
314 int64 received_bytes_; | 321 int64 received_bytes_; |
315 int64 content_length_; | 322 int64 content_length_; |
316 | 323 |
317 // The incoming HTTP request is saved so tests can verify the request | 324 // The incoming HTTP request is saved so tests can verify the request |
318 // parameters like HTTP method (ex. some operations should use DELETE | 325 // parameters like HTTP method (ex. some operations should use DELETE |
319 // instead of GET). | 326 // instead of GET). |
320 net::test_server::HttpRequest http_request_; | 327 net::test_server::HttpRequest http_request_; |
321 }; | 328 }; |
322 | 329 |
323 } // namespace | 330 } // namespace |
324 | 331 |
325 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_DefaultFeed) { | 332 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_DefaultFeed) { |
326 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 333 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
327 scoped_ptr<ResourceList> result_data; | 334 scoped_ptr<ResourceList> result_data; |
328 | 335 |
329 GetResourceListOperation* operation = new GetResourceListOperation( | 336 GetResourceListOperation* operation = new GetResourceListOperation( |
330 &operation_registry_, | 337 operation_runner_.get(), |
331 request_context_getter_.get(), | 338 request_context_getter_.get(), |
332 *url_generator_, | 339 *url_generator_, |
333 GURL(), // Pass an empty URL to use the default feed | 340 GURL(), // Pass an empty URL to use the default feed |
334 0, // start changestamp | 341 0, // start changestamp |
335 std::string(), // search string | 342 std::string(), // search string |
336 std::string(), // directory resource ID | 343 std::string(), // directory resource ID |
337 CreateComposedCallback( | 344 CreateComposedCallback( |
338 base::Bind(&test_util::RunAndQuit), | 345 base::Bind(&test_util::RunAndQuit), |
339 test_util::CreateCopyResultCallback(&result_code, &result_data))); | 346 test_util::CreateCopyResultCallback(&result_code, &result_data))); |
340 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 347 operation_runner_->StartOperationWithRetry(operation); |
341 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
342 MessageLoop::current()->Run(); | 348 MessageLoop::current()->Run(); |
343 | 349 |
344 EXPECT_EQ(HTTP_SUCCESS, result_code); | 350 EXPECT_EQ(HTTP_SUCCESS, result_code); |
345 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 351 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
346 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" | 352 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" |
347 "showfolders=true&include-shared=true&max-results=500", | 353 "showfolders=true&include-shared=true&max-results=500", |
348 http_request_.relative_url); | 354 http_request_.relative_url); |
349 | 355 |
350 // Sanity check of the result. | 356 // Sanity check of the result. |
351 scoped_ptr<ResourceList> expected( | 357 scoped_ptr<ResourceList> expected( |
352 ResourceList::ExtractAndParse( | 358 ResourceList::ExtractAndParse( |
353 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); | 359 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); |
354 ASSERT_TRUE(result_data); | 360 ASSERT_TRUE(result_data); |
355 EXPECT_EQ(expected->title(), result_data->title()); | 361 EXPECT_EQ(expected->title(), result_data->title()); |
356 } | 362 } |
357 | 363 |
358 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_ValidFeed) { | 364 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_ValidFeed) { |
359 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 365 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
360 scoped_ptr<ResourceList> result_data; | 366 scoped_ptr<ResourceList> result_data; |
361 | 367 |
362 GetResourceListOperation* operation = new GetResourceListOperation( | 368 GetResourceListOperation* operation = new GetResourceListOperation( |
363 &operation_registry_, | 369 operation_runner_.get(), |
364 request_context_getter_.get(), | 370 request_context_getter_.get(), |
365 *url_generator_, | 371 *url_generator_, |
366 test_server_.GetURL("/files/chromeos/gdata/root_feed.json"), | 372 test_server_.GetURL("/files/chromeos/gdata/root_feed.json"), |
367 0, // start changestamp | 373 0, // start changestamp |
368 std::string(), // search string | 374 std::string(), // search string |
369 std::string(), // directory resource ID | 375 std::string(), // directory resource ID |
370 CreateComposedCallback( | 376 CreateComposedCallback( |
371 base::Bind(&test_util::RunAndQuit), | 377 base::Bind(&test_util::RunAndQuit), |
372 test_util::CreateCopyResultCallback(&result_code, &result_data))); | 378 test_util::CreateCopyResultCallback(&result_code, &result_data))); |
373 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 379 operation_runner_->StartOperationWithRetry(operation); |
374 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
375 MessageLoop::current()->Run(); | 380 MessageLoop::current()->Run(); |
376 | 381 |
377 EXPECT_EQ(HTTP_SUCCESS, result_code); | 382 EXPECT_EQ(HTTP_SUCCESS, result_code); |
378 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 383 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
379 EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&" | 384 EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&" |
380 "showfolders=true&include-shared=true&max-results=500", | 385 "showfolders=true&include-shared=true&max-results=500", |
381 http_request_.relative_url); | 386 http_request_.relative_url); |
382 | 387 |
383 scoped_ptr<ResourceList> expected( | 388 scoped_ptr<ResourceList> expected( |
384 ResourceList::ExtractAndParse( | 389 ResourceList::ExtractAndParse( |
385 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); | 390 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); |
386 ASSERT_TRUE(result_data); | 391 ASSERT_TRUE(result_data); |
387 EXPECT_EQ(expected->title(), result_data->title()); | 392 EXPECT_EQ(expected->title(), result_data->title()); |
388 } | 393 } |
389 | 394 |
390 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_InvalidFeed) { | 395 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_InvalidFeed) { |
391 // testfile.txt exists but the response is not JSON, so it should | 396 // testfile.txt exists but the response is not JSON, so it should |
392 // emit a parse error instead. | 397 // emit a parse error instead. |
393 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 398 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
394 scoped_ptr<ResourceList> result_data; | 399 scoped_ptr<ResourceList> result_data; |
395 | 400 |
396 GetResourceListOperation* operation = new GetResourceListOperation( | 401 GetResourceListOperation* operation = new GetResourceListOperation( |
397 &operation_registry_, | 402 operation_runner_.get(), |
398 request_context_getter_.get(), | 403 request_context_getter_.get(), |
399 *url_generator_, | 404 *url_generator_, |
400 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), | 405 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), |
401 0, // start changestamp | 406 0, // start changestamp |
402 std::string(), // search string | 407 std::string(), // search string |
403 std::string(), // directory resource ID | 408 std::string(), // directory resource ID |
404 CreateComposedCallback( | 409 CreateComposedCallback( |
405 base::Bind(&test_util::RunAndQuit), | 410 base::Bind(&test_util::RunAndQuit), |
406 test_util::CreateCopyResultCallback(&result_code, &result_data))); | 411 test_util::CreateCopyResultCallback(&result_code, &result_data))); |
407 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 412 operation_runner_->StartOperationWithRetry(operation); |
408 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
409 MessageLoop::current()->Run(); | 413 MessageLoop::current()->Run(); |
410 | 414 |
411 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); | 415 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); |
412 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 416 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
413 EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&" | 417 EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&" |
414 "showfolders=true&include-shared=true&max-results=500", | 418 "showfolders=true&include-shared=true&max-results=500", |
415 http_request_.relative_url); | 419 http_request_.relative_url); |
416 EXPECT_FALSE(result_data); | 420 EXPECT_FALSE(result_data); |
417 } | 421 } |
418 | 422 |
419 TEST_F(GDataWapiOperationsTest, SearchByTitleOperation) { | 423 TEST_F(GDataWapiOperationsTest, SearchByTitleOperation) { |
420 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 424 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
421 scoped_ptr<ResourceList> result_data; | 425 scoped_ptr<ResourceList> result_data; |
422 | 426 |
423 SearchByTitleOperation* operation = new SearchByTitleOperation( | 427 SearchByTitleOperation* operation = new SearchByTitleOperation( |
424 &operation_registry_, | 428 operation_runner_.get(), |
425 request_context_getter_.get(), | 429 request_context_getter_.get(), |
426 *url_generator_, | 430 *url_generator_, |
427 "search-title", | 431 "search-title", |
428 std::string(), // directory resource id | 432 std::string(), // directory resource id |
429 CreateComposedCallback( | 433 CreateComposedCallback( |
430 base::Bind(&test_util::RunAndQuit), | 434 base::Bind(&test_util::RunAndQuit), |
431 test_util::CreateCopyResultCallback(&result_code, &result_data))); | 435 test_util::CreateCopyResultCallback(&result_code, &result_data))); |
432 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 436 operation_runner_->StartOperationWithRetry(operation); |
433 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
434 MessageLoop::current()->Run(); | 437 MessageLoop::current()->Run(); |
435 | 438 |
436 EXPECT_EQ(HTTP_SUCCESS, result_code); | 439 EXPECT_EQ(HTTP_SUCCESS, result_code); |
437 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 440 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
438 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" | 441 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" |
439 "showfolders=true&include-shared=true&max-results=500" | 442 "showfolders=true&include-shared=true&max-results=500" |
440 "&title=search-title&title-exact=true", | 443 "&title=search-title&title-exact=true", |
441 http_request_.relative_url); | 444 http_request_.relative_url); |
442 EXPECT_TRUE(result_data); | 445 EXPECT_TRUE(result_data); |
443 } | 446 } |
444 | 447 |
445 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_ValidResourceId) { | 448 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_ValidResourceId) { |
446 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 449 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
447 scoped_ptr<base::Value> result_data; | 450 scoped_ptr<base::Value> result_data; |
448 | 451 |
449 GetResourceEntryOperation* operation = new GetResourceEntryOperation( | 452 GetResourceEntryOperation* operation = new GetResourceEntryOperation( |
450 &operation_registry_, | 453 operation_runner_.get(), |
451 request_context_getter_.get(), | 454 request_context_getter_.get(), |
452 *url_generator_, | 455 *url_generator_, |
453 "file:2_file_resource_id", // resource ID | 456 "file:2_file_resource_id", // resource ID |
454 CreateComposedCallback( | 457 CreateComposedCallback( |
455 base::Bind(&test_util::RunAndQuit), | 458 base::Bind(&test_util::RunAndQuit), |
456 test_util::CreateCopyResultCallback(&result_code, &result_data))); | 459 test_util::CreateCopyResultCallback(&result_code, &result_data))); |
457 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 460 operation_runner_->StartOperationWithRetry(operation); |
458 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
459 MessageLoop::current()->Run(); | 461 MessageLoop::current()->Run(); |
460 | 462 |
461 EXPECT_EQ(HTTP_SUCCESS, result_code); | 463 EXPECT_EQ(HTTP_SUCCESS, result_code); |
462 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 464 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
463 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" | 465 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" |
464 "?v=3&alt=json&showroot=true", | 466 "?v=3&alt=json&showroot=true", |
465 http_request_.relative_url); | 467 http_request_.relative_url); |
466 EXPECT_TRUE(test_util::VerifyJsonData( | 468 EXPECT_TRUE(test_util::VerifyJsonData( |
467 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"), | 469 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"), |
468 result_data.get())); | 470 result_data.get())); |
469 } | 471 } |
470 | 472 |
471 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_InvalidResourceId) { | 473 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_InvalidResourceId) { |
472 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 474 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
473 scoped_ptr<base::Value> result_data; | 475 scoped_ptr<base::Value> result_data; |
474 | 476 |
475 GetResourceEntryOperation* operation = new GetResourceEntryOperation( | 477 GetResourceEntryOperation* operation = new GetResourceEntryOperation( |
476 &operation_registry_, | 478 operation_runner_.get(), |
477 request_context_getter_.get(), | 479 request_context_getter_.get(), |
478 *url_generator_, | 480 *url_generator_, |
479 "<invalid>", // resource ID | 481 "<invalid>", // resource ID |
480 CreateComposedCallback( | 482 CreateComposedCallback( |
481 base::Bind(&test_util::RunAndQuit), | 483 base::Bind(&test_util::RunAndQuit), |
482 test_util::CreateCopyResultCallback(&result_code, &result_data))); | 484 test_util::CreateCopyResultCallback(&result_code, &result_data))); |
483 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 485 operation_runner_->StartOperationWithRetry(operation); |
484 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
485 MessageLoop::current()->Run(); | 486 MessageLoop::current()->Run(); |
486 | 487 |
487 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 488 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
488 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 489 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
489 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json" | 490 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json" |
490 "&showroot=true", | 491 "&showroot=true", |
491 http_request_.relative_url); | 492 http_request_.relative_url); |
492 ASSERT_FALSE(result_data); | 493 ASSERT_FALSE(result_data); |
493 } | 494 } |
494 | 495 |
495 TEST_F(GDataWapiOperationsTest, GetAccountMetadataOperation) { | 496 TEST_F(GDataWapiOperationsTest, GetAccountMetadataOperation) { |
496 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 497 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
497 scoped_ptr<AccountMetadata> result_data; | 498 scoped_ptr<AccountMetadata> result_data; |
498 | 499 |
499 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( | 500 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( |
500 &operation_registry_, | 501 operation_runner_.get(), |
501 request_context_getter_.get(), | 502 request_context_getter_.get(), |
502 *url_generator_, | 503 *url_generator_, |
503 CreateComposedCallback( | 504 CreateComposedCallback( |
504 base::Bind(&test_util::RunAndQuit), | 505 base::Bind(&test_util::RunAndQuit), |
505 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 506 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
506 true); // Include installed apps. | 507 true); // Include installed apps. |
507 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 508 operation_runner_->StartOperationWithRetry(operation); |
508 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
509 MessageLoop::current()->Run(); | 509 MessageLoop::current()->Run(); |
510 | 510 |
511 EXPECT_EQ(HTTP_SUCCESS, result_code); | 511 EXPECT_EQ(HTTP_SUCCESS, result_code); |
512 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 512 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
513 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true" | 513 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true" |
514 "&include-installed-apps=true", | 514 "&include-installed-apps=true", |
515 http_request_.relative_url); | 515 http_request_.relative_url); |
516 | 516 |
517 scoped_ptr<AccountMetadata> expected( | 517 scoped_ptr<AccountMetadata> expected( |
518 AccountMetadata::CreateFrom( | 518 AccountMetadata::CreateFrom( |
(...skipping 11 matching lines...) Expand all Loading... |
530 EXPECT_EQ(expected->installed_apps().size(), | 530 EXPECT_EQ(expected->installed_apps().size(), |
531 result_data->installed_apps().size()); | 531 result_data->installed_apps().size()); |
532 } | 532 } |
533 | 533 |
534 TEST_F(GDataWapiOperationsTest, | 534 TEST_F(GDataWapiOperationsTest, |
535 GetAccountMetadataOperationWithoutInstalledApps) { | 535 GetAccountMetadataOperationWithoutInstalledApps) { |
536 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 536 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
537 scoped_ptr<AccountMetadata> result_data; | 537 scoped_ptr<AccountMetadata> result_data; |
538 | 538 |
539 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( | 539 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( |
540 &operation_registry_, | 540 operation_runner_.get(), |
541 request_context_getter_.get(), | 541 request_context_getter_.get(), |
542 *url_generator_, | 542 *url_generator_, |
543 CreateComposedCallback( | 543 CreateComposedCallback( |
544 base::Bind(&test_util::RunAndQuit), | 544 base::Bind(&test_util::RunAndQuit), |
545 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 545 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
546 false); // Exclude installed apps. | 546 false); // Exclude installed apps. |
547 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 547 operation_runner_->StartOperationWithRetry(operation); |
548 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
549 MessageLoop::current()->Run(); | 548 MessageLoop::current()->Run(); |
550 | 549 |
551 EXPECT_EQ(HTTP_SUCCESS, result_code); | 550 EXPECT_EQ(HTTP_SUCCESS, result_code); |
552 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 551 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
553 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true", | 552 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true", |
554 http_request_.relative_url); | 553 http_request_.relative_url); |
555 | 554 |
556 scoped_ptr<AccountMetadata> expected( | 555 scoped_ptr<AccountMetadata> expected( |
557 AccountMetadata::CreateFrom( | 556 AccountMetadata::CreateFrom( |
558 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"))); | 557 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"))); |
559 | 558 |
560 ASSERT_TRUE(result_data.get()); | 559 ASSERT_TRUE(result_data.get()); |
561 EXPECT_EQ(expected->largest_changestamp(), | 560 EXPECT_EQ(expected->largest_changestamp(), |
562 result_data->largest_changestamp()); | 561 result_data->largest_changestamp()); |
563 EXPECT_EQ(expected->quota_bytes_total(), | 562 EXPECT_EQ(expected->quota_bytes_total(), |
564 result_data->quota_bytes_total()); | 563 result_data->quota_bytes_total()); |
565 EXPECT_EQ(expected->quota_bytes_used(), | 564 EXPECT_EQ(expected->quota_bytes_used(), |
566 result_data->quota_bytes_used()); | 565 result_data->quota_bytes_used()); |
567 | 566 |
568 // Installed apps shouldn't be included. | 567 // Installed apps shouldn't be included. |
569 EXPECT_EQ(0U, result_data->installed_apps().size()); | 568 EXPECT_EQ(0U, result_data->installed_apps().size()); |
570 } | 569 } |
571 | 570 |
572 TEST_F(GDataWapiOperationsTest, DeleteResourceOperation) { | 571 TEST_F(GDataWapiOperationsTest, DeleteResourceOperation) { |
573 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 572 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
574 | 573 |
575 DeleteResourceOperation* operation = new DeleteResourceOperation( | 574 DeleteResourceOperation* operation = new DeleteResourceOperation( |
576 &operation_registry_, | 575 operation_runner_.get(), |
577 request_context_getter_.get(), | 576 request_context_getter_.get(), |
578 *url_generator_, | 577 *url_generator_, |
579 CreateComposedCallback(base::Bind(&test_util::RunAndQuit), | 578 CreateComposedCallback(base::Bind(&test_util::RunAndQuit), |
580 test_util::CreateCopyResultCallback(&result_code)), | 579 test_util::CreateCopyResultCallback(&result_code)), |
581 "file:2_file_resource_id", | 580 "file:2_file_resource_id", |
582 std::string()); | 581 std::string()); |
583 | 582 |
584 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 583 operation_runner_->StartOperationWithRetry(operation); |
585 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
586 MessageLoop::current()->Run(); | 584 MessageLoop::current()->Run(); |
587 | 585 |
588 EXPECT_EQ(HTTP_SUCCESS, result_code); | 586 EXPECT_EQ(HTTP_SUCCESS, result_code); |
589 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); | 587 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); |
590 EXPECT_EQ( | 588 EXPECT_EQ( |
591 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" | 589 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" |
592 "&showroot=true", | 590 "&showroot=true", |
593 http_request_.relative_url); | 591 http_request_.relative_url); |
594 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 592 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
595 } | 593 } |
596 | 594 |
597 TEST_F(GDataWapiOperationsTest, DeleteResourceOperationWithETag) { | 595 TEST_F(GDataWapiOperationsTest, DeleteResourceOperationWithETag) { |
598 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 596 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
599 | 597 |
600 DeleteResourceOperation* operation = new DeleteResourceOperation( | 598 DeleteResourceOperation* operation = new DeleteResourceOperation( |
601 &operation_registry_, | 599 operation_runner_.get(), |
602 request_context_getter_.get(), | 600 request_context_getter_.get(), |
603 *url_generator_, | 601 *url_generator_, |
604 CreateComposedCallback( | 602 CreateComposedCallback( |
605 base::Bind(&test_util::RunAndQuit), | 603 base::Bind(&test_util::RunAndQuit), |
606 test_util::CreateCopyResultCallback(&result_code)), | 604 test_util::CreateCopyResultCallback(&result_code)), |
607 "file:2_file_resource_id", | 605 "file:2_file_resource_id", |
608 "etag"); | 606 "etag"); |
609 | 607 |
610 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 608 operation_runner_->StartOperationWithRetry(operation); |
611 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
612 MessageLoop::current()->Run(); | 609 MessageLoop::current()->Run(); |
613 | 610 |
614 EXPECT_EQ(HTTP_SUCCESS, result_code); | 611 EXPECT_EQ(HTTP_SUCCESS, result_code); |
615 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); | 612 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); |
616 EXPECT_EQ( | 613 EXPECT_EQ( |
617 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" | 614 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" |
618 "&showroot=true", | 615 "&showroot=true", |
619 http_request_.relative_url); | 616 http_request_.relative_url); |
620 EXPECT_EQ("etag", http_request_.headers["If-Match"]); | 617 EXPECT_EQ("etag", http_request_.headers["If-Match"]); |
621 } | 618 } |
622 | 619 |
623 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { | 620 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { |
624 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 621 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
625 scoped_ptr<base::Value> result_data; | 622 scoped_ptr<base::Value> result_data; |
626 | 623 |
627 // Create "new directory" in the root directory. | 624 // Create "new directory" in the root directory. |
628 CreateDirectoryOperation* operation = new CreateDirectoryOperation( | 625 CreateDirectoryOperation* operation = new CreateDirectoryOperation( |
629 &operation_registry_, | 626 operation_runner_.get(), |
630 request_context_getter_.get(), | 627 request_context_getter_.get(), |
631 *url_generator_, | 628 *url_generator_, |
632 CreateComposedCallback( | 629 CreateComposedCallback( |
633 base::Bind(&test_util::RunAndQuit), | 630 base::Bind(&test_util::RunAndQuit), |
634 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 631 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
635 "folder:root", | 632 "folder:root", |
636 "new directory"); | 633 "new directory"); |
637 | 634 |
638 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 635 operation_runner_->StartOperationWithRetry(operation); |
639 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
640 MessageLoop::current()->Run(); | 636 MessageLoop::current()->Run(); |
641 | 637 |
642 EXPECT_EQ(HTTP_SUCCESS, result_code); | 638 EXPECT_EQ(HTTP_SUCCESS, result_code); |
643 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 639 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
644 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" | 640 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" |
645 "&showroot=true", | 641 "&showroot=true", |
646 http_request_.relative_url); | 642 http_request_.relative_url); |
647 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 643 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
648 | 644 |
649 EXPECT_TRUE(http_request_.has_content); | 645 EXPECT_TRUE(http_request_.has_content); |
650 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 646 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
651 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 647 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
652 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " | 648 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " |
653 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" | 649 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" |
654 " <title>new directory</title>\n" | 650 " <title>new directory</title>\n" |
655 "</entry>\n", | 651 "</entry>\n", |
656 http_request_.content); | 652 http_request_.content); |
657 } | 653 } |
658 | 654 |
659 TEST_F(GDataWapiOperationsTest, CopyHostedDocumentOperation) { | 655 TEST_F(GDataWapiOperationsTest, CopyHostedDocumentOperation) { |
660 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 656 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
661 scoped_ptr<base::Value> result_data; | 657 scoped_ptr<base::Value> result_data; |
662 | 658 |
663 // Copy a document with a new name "New Document". | 659 // Copy a document with a new name "New Document". |
664 CopyHostedDocumentOperation* operation = new CopyHostedDocumentOperation( | 660 CopyHostedDocumentOperation* operation = new CopyHostedDocumentOperation( |
665 &operation_registry_, | 661 operation_runner_.get(), |
666 request_context_getter_.get(), | 662 request_context_getter_.get(), |
667 *url_generator_, | 663 *url_generator_, |
668 CreateComposedCallback( | 664 CreateComposedCallback( |
669 base::Bind(&test_util::RunAndQuit), | 665 base::Bind(&test_util::RunAndQuit), |
670 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 666 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
671 "document:5_document_resource_id", // source resource ID | 667 "document:5_document_resource_id", // source resource ID |
672 "New Document"); | 668 "New Document"); |
673 | 669 |
674 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 670 operation_runner_->StartOperationWithRetry(operation); |
675 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
676 MessageLoop::current()->Run(); | 671 MessageLoop::current()->Run(); |
677 | 672 |
678 EXPECT_EQ(HTTP_SUCCESS, result_code); | 673 EXPECT_EQ(HTTP_SUCCESS, result_code); |
679 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 674 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
680 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true", | 675 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true", |
681 http_request_.relative_url); | 676 http_request_.relative_url); |
682 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 677 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
683 | 678 |
684 EXPECT_TRUE(http_request_.has_content); | 679 EXPECT_TRUE(http_request_.has_content); |
685 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 680 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
686 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 681 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
687 " <id>document:5_document_resource_id</id>\n" | 682 " <id>document:5_document_resource_id</id>\n" |
688 " <title>New Document</title>\n" | 683 " <title>New Document</title>\n" |
689 "</entry>\n", | 684 "</entry>\n", |
690 http_request_.content); | 685 http_request_.content); |
691 } | 686 } |
692 | 687 |
693 TEST_F(GDataWapiOperationsTest, RenameResourceOperation) { | 688 TEST_F(GDataWapiOperationsTest, RenameResourceOperation) { |
694 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 689 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
695 | 690 |
696 // Rename a file with a new name "New File". | 691 // Rename a file with a new name "New File". |
697 RenameResourceOperation* operation = new RenameResourceOperation( | 692 RenameResourceOperation* operation = new RenameResourceOperation( |
698 &operation_registry_, | 693 operation_runner_.get(), |
699 request_context_getter_.get(), | 694 request_context_getter_.get(), |
700 *url_generator_, | 695 *url_generator_, |
701 CreateComposedCallback( | 696 CreateComposedCallback( |
702 base::Bind(&test_util::RunAndQuit), | 697 base::Bind(&test_util::RunAndQuit), |
703 test_util::CreateCopyResultCallback(&result_code)), | 698 test_util::CreateCopyResultCallback(&result_code)), |
704 "file:2_file_resource_id", | 699 "file:2_file_resource_id", |
705 "New File"); | 700 "New File"); |
706 | 701 |
707 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 702 operation_runner_->StartOperationWithRetry(operation); |
708 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
709 MessageLoop::current()->Run(); | 703 MessageLoop::current()->Run(); |
710 | 704 |
711 EXPECT_EQ(HTTP_SUCCESS, result_code); | 705 EXPECT_EQ(HTTP_SUCCESS, result_code); |
712 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 706 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
713 EXPECT_EQ( | 707 EXPECT_EQ( |
714 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" | 708 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" |
715 "&showroot=true", | 709 "&showroot=true", |
716 http_request_.relative_url); | 710 http_request_.relative_url); |
717 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 711 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
718 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 712 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
719 | 713 |
720 EXPECT_TRUE(http_request_.has_content); | 714 EXPECT_TRUE(http_request_.has_content); |
721 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 715 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
722 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 716 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
723 " <title>New File</title>\n" | 717 " <title>New File</title>\n" |
724 "</entry>\n", | 718 "</entry>\n", |
725 http_request_.content); | 719 http_request_.content); |
726 } | 720 } |
727 | 721 |
728 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { | 722 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { |
729 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 723 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
730 GURL result_data; | 724 GURL result_data; |
731 | 725 |
732 // Authorize an app with APP_ID to access to a document. | 726 // Authorize an app with APP_ID to access to a document. |
733 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 727 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
734 &operation_registry_, | 728 operation_runner_.get(), |
735 request_context_getter_.get(), | 729 request_context_getter_.get(), |
736 *url_generator_, | 730 *url_generator_, |
737 CreateComposedCallback( | 731 CreateComposedCallback( |
738 base::Bind(&test_util::RunAndQuit), | 732 base::Bind(&test_util::RunAndQuit), |
739 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 733 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
740 "file:2_file_resource_id", | 734 "file:2_file_resource_id", |
741 "the_app_id"); | 735 "the_app_id"); |
742 | 736 |
743 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 737 operation_runner_->StartOperationWithRetry(operation); |
744 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
745 MessageLoop::current()->Run(); | 738 MessageLoop::current()->Run(); |
746 | 739 |
747 EXPECT_EQ(HTTP_SUCCESS, result_code); | 740 EXPECT_EQ(HTTP_SUCCESS, result_code); |
748 EXPECT_EQ(GURL("https://entry1_open_with_link/"), result_data); | 741 EXPECT_EQ(GURL("https://entry1_open_with_link/"), result_data); |
749 | 742 |
750 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 743 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
751 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" | 744 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" |
752 "?v=3&alt=json&showroot=true", | 745 "?v=3&alt=json&showroot=true", |
753 http_request_.relative_url); | 746 http_request_.relative_url); |
754 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 747 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
755 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 748 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
756 | 749 |
757 EXPECT_TRUE(http_request_.has_content); | 750 EXPECT_TRUE(http_request_.has_content); |
758 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 751 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
759 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 752 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
760 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 753 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
761 " <docs:authorizedApp>the_app_id</docs:authorizedApp>\n" | 754 " <docs:authorizedApp>the_app_id</docs:authorizedApp>\n" |
762 "</entry>\n", | 755 "</entry>\n", |
763 http_request_.content); | 756 http_request_.content); |
764 } | 757 } |
765 | 758 |
766 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_NotFound) { | 759 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_NotFound) { |
767 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 760 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
768 GURL result_data; | 761 GURL result_data; |
769 | 762 |
770 // Authorize an app with APP_ID to access to a document. | 763 // Authorize an app with APP_ID to access to a document. |
771 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 764 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
772 &operation_registry_, | 765 operation_runner_.get(), |
773 request_context_getter_.get(), | 766 request_context_getter_.get(), |
774 *url_generator_, | 767 *url_generator_, |
775 CreateComposedCallback( | 768 CreateComposedCallback( |
776 base::Bind(&test_util::RunAndQuit), | 769 base::Bind(&test_util::RunAndQuit), |
777 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 770 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
778 "file:2_file_resource_id", | 771 "file:2_file_resource_id", |
779 "unauthorized_app_id"); | 772 "unauthorized_app_id"); |
780 | 773 |
781 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 774 operation_runner_->StartOperationWithRetry(operation); |
782 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
783 MessageLoop::current()->Run(); | 775 MessageLoop::current()->Run(); |
784 | 776 |
785 EXPECT_EQ(GDATA_OTHER_ERROR, result_code); | 777 EXPECT_EQ(GDATA_OTHER_ERROR, result_code); |
786 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 778 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
787 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" | 779 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" |
788 "?v=3&alt=json&showroot=true", | 780 "?v=3&alt=json&showroot=true", |
789 http_request_.relative_url); | 781 http_request_.relative_url); |
790 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 782 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
791 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 783 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
792 | 784 |
793 EXPECT_TRUE(http_request_.has_content); | 785 EXPECT_TRUE(http_request_.has_content); |
794 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 786 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
795 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 787 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
796 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 788 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
797 " <docs:authorizedApp>unauthorized_app_id</docs:authorizedApp>\n" | 789 " <docs:authorizedApp>unauthorized_app_id</docs:authorizedApp>\n" |
798 "</entry>\n", | 790 "</entry>\n", |
799 http_request_.content); | 791 http_request_.content); |
800 } | 792 } |
801 | 793 |
802 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { | 794 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { |
803 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 795 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
804 GURL result_data; | 796 GURL result_data; |
805 | 797 |
806 // Authorize an app with APP_ID to access to a document but an invalid feed. | 798 // Authorize an app with APP_ID to access to a document but an invalid feed. |
807 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 799 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
808 &operation_registry_, | 800 operation_runner_.get(), |
809 request_context_getter_.get(), | 801 request_context_getter_.get(), |
810 *url_generator_, | 802 *url_generator_, |
811 CreateComposedCallback( | 803 CreateComposedCallback( |
812 base::Bind(&test_util::RunAndQuit), | 804 base::Bind(&test_util::RunAndQuit), |
813 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 805 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
814 "invalid_resource_id", | 806 "invalid_resource_id", |
815 "APP_ID"); | 807 "APP_ID"); |
816 | 808 |
817 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 809 operation_runner_->StartOperationWithRetry(operation); |
818 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
819 MessageLoop::current()->Run(); | 810 MessageLoop::current()->Run(); |
820 | 811 |
821 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); | 812 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); |
822 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 813 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
823 EXPECT_EQ("/feeds/default/private/full/invalid_resource_id" | 814 EXPECT_EQ("/feeds/default/private/full/invalid_resource_id" |
824 "?v=3&alt=json&showroot=true", | 815 "?v=3&alt=json&showroot=true", |
825 http_request_.relative_url); | 816 http_request_.relative_url); |
826 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 817 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
827 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 818 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
828 | 819 |
829 EXPECT_TRUE(http_request_.has_content); | 820 EXPECT_TRUE(http_request_.has_content); |
830 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 821 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
831 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 822 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
832 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 823 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
833 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" | 824 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" |
834 "</entry>\n", | 825 "</entry>\n", |
835 http_request_.content); | 826 http_request_.content); |
836 } | 827 } |
837 | 828 |
838 TEST_F(GDataWapiOperationsTest, AddResourceToDirectoryOperation) { | 829 TEST_F(GDataWapiOperationsTest, AddResourceToDirectoryOperation) { |
839 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 830 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
840 | 831 |
841 // Add a file to the root directory. | 832 // Add a file to the root directory. |
842 AddResourceToDirectoryOperation* operation = | 833 AddResourceToDirectoryOperation* operation = |
843 new AddResourceToDirectoryOperation( | 834 new AddResourceToDirectoryOperation( |
844 &operation_registry_, | 835 operation_runner_.get(), |
845 request_context_getter_.get(), | 836 request_context_getter_.get(), |
846 *url_generator_, | 837 *url_generator_, |
847 CreateComposedCallback( | 838 CreateComposedCallback( |
848 base::Bind(&test_util::RunAndQuit), | 839 base::Bind(&test_util::RunAndQuit), |
849 test_util::CreateCopyResultCallback(&result_code)), | 840 test_util::CreateCopyResultCallback(&result_code)), |
850 "folder:root", | 841 "folder:root", |
851 "file:2_file_resource_id"); | 842 "file:2_file_resource_id"); |
852 | 843 |
853 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 844 operation_runner_->StartOperationWithRetry(operation); |
854 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
855 MessageLoop::current()->Run(); | 845 MessageLoop::current()->Run(); |
856 | 846 |
857 EXPECT_EQ(HTTP_SUCCESS, result_code); | 847 EXPECT_EQ(HTTP_SUCCESS, result_code); |
858 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 848 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
859 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" | 849 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" |
860 "&showroot=true", | 850 "&showroot=true", |
861 http_request_.relative_url); | 851 http_request_.relative_url); |
862 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 852 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
863 | 853 |
864 EXPECT_TRUE(http_request_.has_content); | 854 EXPECT_TRUE(http_request_.has_content); |
865 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 855 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
866 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 856 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
867 " <id>http://127.0.0.1:8040/feeds/default/private/full/" | 857 " <id>http://127.0.0.1:8040/feeds/default/private/full/" |
868 "file%3A2_file_resource_id</id>\n" | 858 "file%3A2_file_resource_id</id>\n" |
869 "</entry>\n", | 859 "</entry>\n", |
870 http_request_.content); | 860 http_request_.content); |
871 } | 861 } |
872 | 862 |
873 TEST_F(GDataWapiOperationsTest, RemoveResourceFromDirectoryOperation) { | 863 TEST_F(GDataWapiOperationsTest, RemoveResourceFromDirectoryOperation) { |
874 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 864 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
875 | 865 |
876 // Remove a file from the root directory. | 866 // Remove a file from the root directory. |
877 RemoveResourceFromDirectoryOperation* operation = | 867 RemoveResourceFromDirectoryOperation* operation = |
878 new RemoveResourceFromDirectoryOperation( | 868 new RemoveResourceFromDirectoryOperation( |
879 &operation_registry_, | 869 operation_runner_.get(), |
880 request_context_getter_.get(), | 870 request_context_getter_.get(), |
881 *url_generator_, | 871 *url_generator_, |
882 CreateComposedCallback( | 872 CreateComposedCallback( |
883 base::Bind(&test_util::RunAndQuit), | 873 base::Bind(&test_util::RunAndQuit), |
884 test_util::CreateCopyResultCallback(&result_code)), | 874 test_util::CreateCopyResultCallback(&result_code)), |
885 "folder:root", | 875 "folder:root", |
886 "file:2_file_resource_id"); | 876 "file:2_file_resource_id"); |
887 | 877 |
888 operation->Start(kTestGDataAuthToken, kTestUserAgent, | 878 operation_runner_->StartOperationWithRetry(operation); |
889 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
890 MessageLoop::current()->Run(); | 879 MessageLoop::current()->Run(); |
891 | 880 |
892 EXPECT_EQ(HTTP_SUCCESS, result_code); | 881 EXPECT_EQ(HTTP_SUCCESS, result_code); |
893 // DELETE method should be used, without the body content. | 882 // DELETE method should be used, without the body content. |
894 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); | 883 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); |
895 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/" | 884 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/" |
896 "file%3A2_file_resource_id?v=3&alt=json&showroot=true", | 885 "file%3A2_file_resource_id?v=3&alt=json&showroot=true", |
897 http_request_.relative_url); | 886 http_request_.relative_url); |
898 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 887 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
899 EXPECT_FALSE(http_request_.has_content); | 888 EXPECT_FALSE(http_request_.has_content); |
900 } | 889 } |
901 | 890 |
902 // This test exercises InitiateUploadNewFileOperation and | 891 // This test exercises InitiateUploadNewFileOperation and |
903 // ResumeUploadOperation for a scenario of uploading a new file. | 892 // ResumeUploadOperation for a scenario of uploading a new file. |
904 TEST_F(GDataWapiOperationsTest, UploadNewFile) { | 893 TEST_F(GDataWapiOperationsTest, UploadNewFile) { |
905 const std::string kUploadContent = "hello"; | 894 const std::string kUploadContent = "hello"; |
906 const base::FilePath kTestFilePath = | 895 const base::FilePath kTestFilePath = |
907 temp_dir_.path().AppendASCII("upload_file.txt"); | 896 temp_dir_.path().AppendASCII("upload_file.txt"); |
908 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 897 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
909 | 898 |
910 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 899 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
911 GURL upload_url; | 900 GURL upload_url; |
912 | 901 |
913 // 1) Get the upload URL for uploading a new file. | 902 // 1) Get the upload URL for uploading a new file. |
914 InitiateUploadNewFileOperation* initiate_operation = | 903 InitiateUploadNewFileOperation* initiate_operation = |
915 new InitiateUploadNewFileOperation( | 904 new InitiateUploadNewFileOperation( |
916 &operation_registry_, | 905 operation_runner_.get(), |
917 request_context_getter_.get(), | 906 request_context_getter_.get(), |
918 *url_generator_, | 907 *url_generator_, |
919 CreateComposedCallback( | 908 CreateComposedCallback( |
920 base::Bind(&test_util::RunAndQuit), | 909 base::Bind(&test_util::RunAndQuit), |
921 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 910 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
922 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 911 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
923 "text/plain", | 912 "text/plain", |
924 kUploadContent.size(), | 913 kUploadContent.size(), |
925 "folder:id", | 914 "folder:id", |
926 "New file"); | 915 "New file"); |
927 | 916 |
928 initiate_operation->Start( | 917 operation_runner_->StartOperationWithRetry(initiate_operation); |
929 kTestGDataAuthToken, kTestUserAgent, | |
930 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
931 MessageLoop::current()->Run(); | 918 MessageLoop::current()->Run(); |
932 | 919 |
933 EXPECT_EQ(HTTP_SUCCESS, result_code); | 920 EXPECT_EQ(HTTP_SUCCESS, result_code); |
934 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 921 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
935 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 922 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
936 // convert=false should be passed as files should be uploaded as-is. | 923 // convert=false should be passed as files should be uploaded as-is. |
937 EXPECT_EQ( | 924 EXPECT_EQ( |
938 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" | 925 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" |
939 "?convert=false&v=3&alt=json&showroot=true", | 926 "?convert=false&v=3&alt=json&showroot=true", |
940 http_request_.relative_url); | 927 http_request_.relative_url); |
941 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 928 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
942 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 929 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
943 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 930 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
944 http_request_.headers["X-Upload-Content-Length"]); | 931 http_request_.headers["X-Upload-Content-Length"]); |
945 | 932 |
946 EXPECT_TRUE(http_request_.has_content); | 933 EXPECT_TRUE(http_request_.has_content); |
947 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 934 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
948 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 935 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
949 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 936 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
950 " <title>New file</title>\n" | 937 " <title>New file</title>\n" |
951 "</entry>\n", | 938 "</entry>\n", |
952 http_request_.content); | 939 http_request_.content); |
953 | 940 |
954 // 2) Upload the content to the upload URL. | 941 // 2) Upload the content to the upload URL. |
955 UploadRangeResponse response; | 942 UploadRangeResponse response; |
956 scoped_ptr<ResourceEntry> new_entry; | 943 scoped_ptr<ResourceEntry> new_entry; |
957 | 944 |
958 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 945 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
959 &operation_registry_, | 946 operation_runner_.get(), |
960 request_context_getter_.get(), | 947 request_context_getter_.get(), |
961 CreateComposedCallback( | 948 CreateComposedCallback( |
962 base::Bind(&test_util::RunAndQuit), | 949 base::Bind(&test_util::RunAndQuit), |
963 test_util::CreateCopyResultCallback(&response, &new_entry)), | 950 test_util::CreateCopyResultCallback(&response, &new_entry)), |
964 ProgressCallback(), | 951 ProgressCallback(), |
965 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 952 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
966 upload_url, | 953 upload_url, |
967 0, // start_position | 954 0, // start_position |
968 kUploadContent.size(), // end_position (exclusive) | 955 kUploadContent.size(), // end_position (exclusive) |
969 kUploadContent.size(), // content_length, | 956 kUploadContent.size(), // content_length, |
970 "text/plain", // content_type | 957 "text/plain", // content_type |
971 kTestFilePath); | 958 kTestFilePath); |
972 | 959 |
973 resume_operation->Start( | 960 operation_runner_->StartOperationWithRetry(resume_operation); |
974 kTestGDataAuthToken, kTestUserAgent, | |
975 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
976 MessageLoop::current()->Run(); | 961 MessageLoop::current()->Run(); |
977 | 962 |
978 // METHOD_PUT should be used to upload data. | 963 // METHOD_PUT should be used to upload data. |
979 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 964 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
980 // Request should go to the upload URL. | 965 // Request should go to the upload URL. |
981 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 966 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
982 // Content-Range header should be added. | 967 // Content-Range header should be added. |
983 EXPECT_EQ("bytes 0-" + | 968 EXPECT_EQ("bytes 0-" + |
984 base::Int64ToString(kUploadContent.size() -1) + "/" + | 969 base::Int64ToString(kUploadContent.size() -1) + "/" + |
985 base::Int64ToString(kUploadContent.size()), | 970 base::Int64ToString(kUploadContent.size()), |
(...skipping 26 matching lines...) Expand all Loading... |
1012 const base::FilePath kTestFilePath = | 997 const base::FilePath kTestFilePath = |
1013 temp_dir_.path().AppendASCII("upload_file.txt"); | 998 temp_dir_.path().AppendASCII("upload_file.txt"); |
1014 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 999 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
1015 | 1000 |
1016 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1001 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
1017 GURL upload_url; | 1002 GURL upload_url; |
1018 | 1003 |
1019 // 1) Get the upload URL for uploading a new file. | 1004 // 1) Get the upload URL for uploading a new file. |
1020 InitiateUploadNewFileOperation* initiate_operation = | 1005 InitiateUploadNewFileOperation* initiate_operation = |
1021 new InitiateUploadNewFileOperation( | 1006 new InitiateUploadNewFileOperation( |
1022 &operation_registry_, | 1007 operation_runner_.get(), |
1023 request_context_getter_.get(), | 1008 request_context_getter_.get(), |
1024 *url_generator_, | 1009 *url_generator_, |
1025 CreateComposedCallback( | 1010 CreateComposedCallback( |
1026 base::Bind(&test_util::RunAndQuit), | 1011 base::Bind(&test_util::RunAndQuit), |
1027 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1012 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
1028 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 1013 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
1029 "text/plain", | 1014 "text/plain", |
1030 kUploadContent.size(), | 1015 kUploadContent.size(), |
1031 "folder:id", | 1016 "folder:id", |
1032 "New file"); | 1017 "New file"); |
1033 | 1018 |
1034 initiate_operation->Start( | 1019 operation_runner_->StartOperationWithRetry(initiate_operation); |
1035 kTestGDataAuthToken, kTestUserAgent, | |
1036 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1037 MessageLoop::current()->Run(); | 1020 MessageLoop::current()->Run(); |
1038 | 1021 |
1039 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1022 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1040 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1023 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
1041 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 1024 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
1042 // convert=false should be passed as files should be uploaded as-is. | 1025 // convert=false should be passed as files should be uploaded as-is. |
1043 EXPECT_EQ( | 1026 EXPECT_EQ( |
1044 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" | 1027 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" |
1045 "?convert=false&v=3&alt=json&showroot=true", | 1028 "?convert=false&v=3&alt=json&showroot=true", |
1046 http_request_.relative_url); | 1029 http_request_.relative_url); |
(...skipping 14 matching lines...) Expand all Loading... |
1061 // 2) Before sending any data, check the current status. | 1044 // 2) Before sending any data, check the current status. |
1062 // This is an edge case test for GetUploadStatusOperation | 1045 // This is an edge case test for GetUploadStatusOperation |
1063 // (UploadRangeOperationBase). | 1046 // (UploadRangeOperationBase). |
1064 { | 1047 { |
1065 UploadRangeResponse response; | 1048 UploadRangeResponse response; |
1066 scoped_ptr<ResourceEntry> new_entry; | 1049 scoped_ptr<ResourceEntry> new_entry; |
1067 | 1050 |
1068 // Check the response by GetUploadStatusOperation. | 1051 // Check the response by GetUploadStatusOperation. |
1069 GetUploadStatusOperation* get_upload_status_operation = | 1052 GetUploadStatusOperation* get_upload_status_operation = |
1070 new GetUploadStatusOperation( | 1053 new GetUploadStatusOperation( |
1071 &operation_registry_, | 1054 operation_runner_.get(), |
1072 request_context_getter_.get(), | 1055 request_context_getter_.get(), |
1073 CreateComposedCallback( | 1056 CreateComposedCallback( |
1074 base::Bind(&test_util::RunAndQuit), | 1057 base::Bind(&test_util::RunAndQuit), |
1075 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1058 test_util::CreateCopyResultCallback(&response, &new_entry)), |
1076 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 1059 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
1077 upload_url, | 1060 upload_url, |
1078 kUploadContent.size()); | 1061 kUploadContent.size()); |
1079 get_upload_status_operation->Start( | 1062 operation_runner_->StartOperationWithRetry(get_upload_status_operation); |
1080 kTestGDataAuthToken, kTestUserAgent, | |
1081 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1082 MessageLoop::current()->Run(); | 1063 MessageLoop::current()->Run(); |
1083 | 1064 |
1084 // METHOD_PUT should be used to upload data. | 1065 // METHOD_PUT should be used to upload data. |
1085 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1066 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1086 // Request should go to the upload URL. | 1067 // Request should go to the upload URL. |
1087 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1068 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
1088 // Content-Range header should be added. | 1069 // Content-Range header should be added. |
1089 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), | 1070 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), |
1090 http_request_.headers["Content-Range"]); | 1071 http_request_.headers["Content-Range"]); |
1091 EXPECT_TRUE(http_request_.has_content); | 1072 EXPECT_TRUE(http_request_.has_content); |
(...skipping 17 matching lines...) Expand all Loading... |
1109 const std::string payload = kUploadContent.substr( | 1090 const std::string payload = kUploadContent.substr( |
1110 start_position, std::min(kMaxNumBytes, remaining_size)); | 1091 start_position, std::min(kMaxNumBytes, remaining_size)); |
1111 num_bytes_consumed += payload.size(); | 1092 num_bytes_consumed += payload.size(); |
1112 // The end position is exclusive. | 1093 // The end position is exclusive. |
1113 const size_t end_position = start_position + payload.size(); | 1094 const size_t end_position = start_position + payload.size(); |
1114 | 1095 |
1115 UploadRangeResponse response; | 1096 UploadRangeResponse response; |
1116 scoped_ptr<ResourceEntry> new_entry; | 1097 scoped_ptr<ResourceEntry> new_entry; |
1117 | 1098 |
1118 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1099 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
1119 &operation_registry_, | 1100 operation_runner_.get(), |
1120 request_context_getter_.get(), | 1101 request_context_getter_.get(), |
1121 CreateComposedCallback( | 1102 CreateComposedCallback( |
1122 base::Bind(&test_util::RunAndQuit), | 1103 base::Bind(&test_util::RunAndQuit), |
1123 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1104 test_util::CreateCopyResultCallback(&response, &new_entry)), |
1124 ProgressCallback(), | 1105 ProgressCallback(), |
1125 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 1106 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
1126 upload_url, | 1107 upload_url, |
1127 start_position, | 1108 start_position, |
1128 end_position, | 1109 end_position, |
1129 kUploadContent.size(), // content_length, | 1110 kUploadContent.size(), // content_length, |
1130 "text/plain", // content_type | 1111 "text/plain", // content_type |
1131 kTestFilePath); | 1112 kTestFilePath); |
1132 | 1113 |
1133 resume_operation->Start( | 1114 operation_runner_->StartOperationWithRetry(resume_operation); |
1134 kTestGDataAuthToken, kTestUserAgent, | |
1135 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1136 MessageLoop::current()->Run(); | 1115 MessageLoop::current()->Run(); |
1137 | 1116 |
1138 // METHOD_PUT should be used to upload data. | 1117 // METHOD_PUT should be used to upload data. |
1139 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1118 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1140 // Request should go to the upload URL. | 1119 // Request should go to the upload URL. |
1141 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1120 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
1142 // Content-Range header should be added. | 1121 // Content-Range header should be added. |
1143 EXPECT_EQ("bytes " + | 1122 EXPECT_EQ("bytes " + |
1144 base::Int64ToString(start_position) + "-" + | 1123 base::Int64ToString(start_position) + "-" + |
1145 base::Int64ToString(end_position - 1) + "/" + | 1124 base::Int64ToString(end_position - 1) + "/" + |
(...skipping 16 matching lines...) Expand all Loading... |
1162 | 1141 |
1163 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1142 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
1164 EXPECT_EQ(0, response.start_position_received); | 1143 EXPECT_EQ(0, response.start_position_received); |
1165 EXPECT_EQ(static_cast<int64>(end_position), | 1144 EXPECT_EQ(static_cast<int64>(end_position), |
1166 response.end_position_received); | 1145 response.end_position_received); |
1167 | 1146 |
1168 #if !defined(NO_GET_UPLOAD_STATUS_TEST) | 1147 #if !defined(NO_GET_UPLOAD_STATUS_TEST) |
1169 // Check the response by GetUploadStatusOperation. | 1148 // Check the response by GetUploadStatusOperation. |
1170 GetUploadStatusOperation* get_upload_status_operation = | 1149 GetUploadStatusOperation* get_upload_status_operation = |
1171 new GetUploadStatusOperation( | 1150 new GetUploadStatusOperation( |
1172 &operation_registry_, | 1151 operation_runner_.get(), |
1173 request_context_getter_.get(), | 1152 request_context_getter_.get(), |
1174 CreateComposedCallback( | 1153 CreateComposedCallback( |
1175 base::Bind(&test_util::RunAndQuit), | 1154 base::Bind(&test_util::RunAndQuit), |
1176 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1155 test_util::CreateCopyResultCallback(&response, &new_entry)), |
1177 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 1156 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
1178 upload_url, | 1157 upload_url, |
1179 kUploadContent.size()); | 1158 kUploadContent.size()); |
1180 get_upload_status_operation->Start( | 1159 operation_runner_->StartOperationWithRetry(get_upload_operation); |
1181 kTestGDataAuthToken, kTestUserAgent, | |
1182 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1183 MessageLoop::current()->Run(); | 1160 MessageLoop::current()->Run(); |
1184 | 1161 |
1185 // METHOD_PUT should be used to upload data. | 1162 // METHOD_PUT should be used to upload data. |
1186 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1163 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1187 // Request should go to the upload URL. | 1164 // Request should go to the upload URL. |
1188 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1165 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
1189 // Content-Range header should be added. | 1166 // Content-Range header should be added. |
1190 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), | 1167 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), |
1191 http_request_.headers["Content-Range"]); | 1168 http_request_.headers["Content-Range"]); |
1192 EXPECT_TRUE(http_request_.has_content); | 1169 EXPECT_TRUE(http_request_.has_content); |
(...skipping 20 matching lines...) Expand all Loading... |
1213 const base::FilePath kTestFilePath = | 1190 const base::FilePath kTestFilePath = |
1214 temp_dir_.path().AppendASCII("empty_file.txt"); | 1191 temp_dir_.path().AppendASCII("empty_file.txt"); |
1215 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 1192 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
1216 | 1193 |
1217 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1194 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
1218 GURL upload_url; | 1195 GURL upload_url; |
1219 | 1196 |
1220 // 1) Get the upload URL for uploading a new file. | 1197 // 1) Get the upload URL for uploading a new file. |
1221 InitiateUploadNewFileOperation* initiate_operation = | 1198 InitiateUploadNewFileOperation* initiate_operation = |
1222 new InitiateUploadNewFileOperation( | 1199 new InitiateUploadNewFileOperation( |
1223 &operation_registry_, | 1200 operation_runner_.get(), |
1224 request_context_getter_.get(), | 1201 request_context_getter_.get(), |
1225 *url_generator_, | 1202 *url_generator_, |
1226 CreateComposedCallback( | 1203 CreateComposedCallback( |
1227 base::Bind(&test_util::RunAndQuit), | 1204 base::Bind(&test_util::RunAndQuit), |
1228 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1205 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
1229 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 1206 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
1230 "text/plain", | 1207 "text/plain", |
1231 kUploadContent.size(), | 1208 kUploadContent.size(), |
1232 "folder:id", | 1209 "folder:id", |
1233 "New file"); | 1210 "New file"); |
1234 | 1211 |
1235 initiate_operation->Start( | 1212 operation_runner_->StartOperationWithRetry(initiate_operation); |
1236 kTestGDataAuthToken, kTestUserAgent, | |
1237 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1238 MessageLoop::current()->Run(); | 1213 MessageLoop::current()->Run(); |
1239 | 1214 |
1240 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1215 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1241 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1216 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
1242 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 1217 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
1243 // convert=false should be passed as files should be uploaded as-is. | 1218 // convert=false should be passed as files should be uploaded as-is. |
1244 EXPECT_EQ( | 1219 EXPECT_EQ( |
1245 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" | 1220 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" |
1246 "?convert=false&v=3&alt=json&showroot=true", | 1221 "?convert=false&v=3&alt=json&showroot=true", |
1247 http_request_.relative_url); | 1222 http_request_.relative_url); |
1248 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1223 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1249 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 1224 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
1250 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1225 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1251 http_request_.headers["X-Upload-Content-Length"]); | 1226 http_request_.headers["X-Upload-Content-Length"]); |
1252 | 1227 |
1253 EXPECT_TRUE(http_request_.has_content); | 1228 EXPECT_TRUE(http_request_.has_content); |
1254 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 1229 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
1255 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 1230 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
1256 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 1231 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
1257 " <title>New file</title>\n" | 1232 " <title>New file</title>\n" |
1258 "</entry>\n", | 1233 "</entry>\n", |
1259 http_request_.content); | 1234 http_request_.content); |
1260 | 1235 |
1261 // 2) Upload the content to the upload URL. | 1236 // 2) Upload the content to the upload URL. |
1262 UploadRangeResponse response; | 1237 UploadRangeResponse response; |
1263 scoped_ptr<ResourceEntry> new_entry; | 1238 scoped_ptr<ResourceEntry> new_entry; |
1264 | 1239 |
1265 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1240 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
1266 &operation_registry_, | 1241 operation_runner_.get(), |
1267 request_context_getter_.get(), | 1242 request_context_getter_.get(), |
1268 CreateComposedCallback( | 1243 CreateComposedCallback( |
1269 base::Bind(&test_util::RunAndQuit), | 1244 base::Bind(&test_util::RunAndQuit), |
1270 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1245 test_util::CreateCopyResultCallback(&response, &new_entry)), |
1271 ProgressCallback(), | 1246 ProgressCallback(), |
1272 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | 1247 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), |
1273 upload_url, | 1248 upload_url, |
1274 0, // start_position | 1249 0, // start_position |
1275 kUploadContent.size(), // end_position (exclusive) | 1250 kUploadContent.size(), // end_position (exclusive) |
1276 kUploadContent.size(), // content_length, | 1251 kUploadContent.size(), // content_length, |
1277 "text/plain", // content_type | 1252 "text/plain", // content_type |
1278 kTestFilePath); | 1253 kTestFilePath); |
1279 | 1254 |
1280 resume_operation->Start( | 1255 operation_runner_->StartOperationWithRetry(resume_operation); |
1281 kTestGDataAuthToken, kTestUserAgent, | |
1282 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1283 MessageLoop::current()->Run(); | 1256 MessageLoop::current()->Run(); |
1284 | 1257 |
1285 // METHOD_PUT should be used to upload data. | 1258 // METHOD_PUT should be used to upload data. |
1286 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1259 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1287 // Request should go to the upload URL. | 1260 // Request should go to the upload URL. |
1288 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1261 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
1289 // Content-Range header should not exit if the content is empty. | 1262 // Content-Range header should not exit if the content is empty. |
1290 // We should not generate the header with an invalid value "bytes 0--1/0". | 1263 // We should not generate the header with an invalid value "bytes 0--1/0". |
1291 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); | 1264 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); |
1292 // The upload content should be set in the HTTP request. | 1265 // The upload content should be set in the HTTP request. |
(...skipping 14 matching lines...) Expand all Loading... |
1307 const base::FilePath kTestFilePath = | 1280 const base::FilePath kTestFilePath = |
1308 temp_dir_.path().AppendASCII("upload_file.txt"); | 1281 temp_dir_.path().AppendASCII("upload_file.txt"); |
1309 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 1282 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
1310 | 1283 |
1311 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1284 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
1312 GURL upload_url; | 1285 GURL upload_url; |
1313 | 1286 |
1314 // 1) Get the upload URL for uploading an existing file. | 1287 // 1) Get the upload URL for uploading an existing file. |
1315 InitiateUploadExistingFileOperation* initiate_operation = | 1288 InitiateUploadExistingFileOperation* initiate_operation = |
1316 new InitiateUploadExistingFileOperation( | 1289 new InitiateUploadExistingFileOperation( |
1317 &operation_registry_, | 1290 operation_runner_.get(), |
1318 request_context_getter_.get(), | 1291 request_context_getter_.get(), |
1319 *url_generator_, | 1292 *url_generator_, |
1320 CreateComposedCallback( | 1293 CreateComposedCallback( |
1321 base::Bind(&test_util::RunAndQuit), | 1294 base::Bind(&test_util::RunAndQuit), |
1322 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1295 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
1323 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | 1296 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), |
1324 "text/plain", | 1297 "text/plain", |
1325 kUploadContent.size(), | 1298 kUploadContent.size(), |
1326 "file:foo", | 1299 "file:foo", |
1327 std::string() /* etag */); | 1300 std::string() /* etag */); |
1328 | 1301 |
1329 initiate_operation->Start( | 1302 operation_runner_->StartOperationWithRetry(initiate_operation); |
1330 kTestGDataAuthToken, kTestUserAgent, | |
1331 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1332 MessageLoop::current()->Run(); | 1303 MessageLoop::current()->Run(); |
1333 | 1304 |
1334 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1305 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1335 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1306 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
1336 // For updating an existing file, METHOD_PUT should be used. | 1307 // For updating an existing file, METHOD_PUT should be used. |
1337 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1308 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1338 // convert=false should be passed as files should be uploaded as-is. | 1309 // convert=false should be passed as files should be uploaded as-is. |
1339 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" | 1310 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" |
1340 "?convert=false&v=3&alt=json&showroot=true", | 1311 "?convert=false&v=3&alt=json&showroot=true", |
1341 http_request_.relative_url); | 1312 http_request_.relative_url); |
1342 // Even though the body is empty, the content type should be set to | 1313 // Even though the body is empty, the content type should be set to |
1343 // "text/plain". | 1314 // "text/plain". |
1344 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1315 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
1345 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1316 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1346 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1317 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1347 http_request_.headers["X-Upload-Content-Length"]); | 1318 http_request_.headers["X-Upload-Content-Length"]); |
1348 // For updating an existing file, an empty body should be attached (PUT | 1319 // For updating an existing file, an empty body should be attached (PUT |
1349 // requires a body) | 1320 // requires a body) |
1350 EXPECT_TRUE(http_request_.has_content); | 1321 EXPECT_TRUE(http_request_.has_content); |
1351 EXPECT_EQ("", http_request_.content); | 1322 EXPECT_EQ("", http_request_.content); |
1352 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 1323 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
1353 | 1324 |
1354 // 2) Upload the content to the upload URL. | 1325 // 2) Upload the content to the upload URL. |
1355 UploadRangeResponse response; | 1326 UploadRangeResponse response; |
1356 scoped_ptr<ResourceEntry> new_entry; | 1327 scoped_ptr<ResourceEntry> new_entry; |
1357 | 1328 |
1358 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1329 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
1359 &operation_registry_, | 1330 operation_runner_.get(), |
1360 request_context_getter_.get(), | 1331 request_context_getter_.get(), |
1361 CreateComposedCallback( | 1332 CreateComposedCallback( |
1362 base::Bind(&test_util::RunAndQuit), | 1333 base::Bind(&test_util::RunAndQuit), |
1363 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1334 test_util::CreateCopyResultCallback(&response, &new_entry)), |
1364 ProgressCallback(), | 1335 ProgressCallback(), |
1365 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | 1336 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), |
1366 upload_url, | 1337 upload_url, |
1367 0, // start_position | 1338 0, // start_position |
1368 kUploadContent.size(), // end_position (exclusive) | 1339 kUploadContent.size(), // end_position (exclusive) |
1369 kUploadContent.size(), // content_length, | 1340 kUploadContent.size(), // content_length, |
1370 "text/plain", // content_type | 1341 "text/plain", // content_type |
1371 kTestFilePath); | 1342 kTestFilePath); |
1372 | 1343 |
1373 resume_operation->Start( | 1344 operation_runner_->StartOperationWithRetry(resume_operation); |
1374 kTestGDataAuthToken, kTestUserAgent, | |
1375 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1376 MessageLoop::current()->Run(); | 1345 MessageLoop::current()->Run(); |
1377 | 1346 |
1378 // METHOD_PUT should be used to upload data. | 1347 // METHOD_PUT should be used to upload data. |
1379 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1348 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1380 // Request should go to the upload URL. | 1349 // Request should go to the upload URL. |
1381 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1350 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
1382 // Content-Range header should be added. | 1351 // Content-Range header should be added. |
1383 EXPECT_EQ("bytes 0-" + | 1352 EXPECT_EQ("bytes 0-" + |
1384 base::Int64ToString(kUploadContent.size() -1) + "/" + | 1353 base::Int64ToString(kUploadContent.size() -1) + "/" + |
1385 base::Int64ToString(kUploadContent.size()), | 1354 base::Int64ToString(kUploadContent.size()), |
(...skipping 16 matching lines...) Expand all Loading... |
1402 const base::FilePath kTestFilePath = | 1371 const base::FilePath kTestFilePath = |
1403 temp_dir_.path().AppendASCII("upload_file.txt"); | 1372 temp_dir_.path().AppendASCII("upload_file.txt"); |
1404 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 1373 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
1405 | 1374 |
1406 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1375 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
1407 GURL upload_url; | 1376 GURL upload_url; |
1408 | 1377 |
1409 // 1) Get the upload URL for uploading an existing file. | 1378 // 1) Get the upload URL for uploading an existing file. |
1410 InitiateUploadExistingFileOperation* initiate_operation = | 1379 InitiateUploadExistingFileOperation* initiate_operation = |
1411 new InitiateUploadExistingFileOperation( | 1380 new InitiateUploadExistingFileOperation( |
1412 &operation_registry_, | 1381 operation_runner_.get(), |
1413 request_context_getter_.get(), | 1382 request_context_getter_.get(), |
1414 *url_generator_, | 1383 *url_generator_, |
1415 CreateComposedCallback( | 1384 CreateComposedCallback( |
1416 base::Bind(&test_util::RunAndQuit), | 1385 base::Bind(&test_util::RunAndQuit), |
1417 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1386 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
1418 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | 1387 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), |
1419 "text/plain", | 1388 "text/plain", |
1420 kUploadContent.size(), | 1389 kUploadContent.size(), |
1421 "file:foo", | 1390 "file:foo", |
1422 kTestETag); | 1391 kTestETag); |
1423 | 1392 |
1424 initiate_operation->Start( | 1393 operation_runner_->StartOperationWithRetry(initiate_operation); |
1425 kTestGDataAuthToken, kTestUserAgent, | |
1426 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1427 MessageLoop::current()->Run(); | 1394 MessageLoop::current()->Run(); |
1428 | 1395 |
1429 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1396 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1430 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1397 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
1431 // For updating an existing file, METHOD_PUT should be used. | 1398 // For updating an existing file, METHOD_PUT should be used. |
1432 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1399 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1433 // convert=false should be passed as files should be uploaded as-is. | 1400 // convert=false should be passed as files should be uploaded as-is. |
1434 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" | 1401 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" |
1435 "?convert=false&v=3&alt=json&showroot=true", | 1402 "?convert=false&v=3&alt=json&showroot=true", |
1436 http_request_.relative_url); | 1403 http_request_.relative_url); |
1437 // Even though the body is empty, the content type should be set to | 1404 // Even though the body is empty, the content type should be set to |
1438 // "text/plain". | 1405 // "text/plain". |
1439 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1406 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
1440 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1407 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1441 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1408 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1442 http_request_.headers["X-Upload-Content-Length"]); | 1409 http_request_.headers["X-Upload-Content-Length"]); |
1443 // For updating an existing file, an empty body should be attached (PUT | 1410 // For updating an existing file, an empty body should be attached (PUT |
1444 // requires a body) | 1411 // requires a body) |
1445 EXPECT_TRUE(http_request_.has_content); | 1412 EXPECT_TRUE(http_request_.has_content); |
1446 EXPECT_EQ("", http_request_.content); | 1413 EXPECT_EQ("", http_request_.content); |
1447 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); | 1414 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); |
1448 | 1415 |
1449 // 2) Upload the content to the upload URL. | 1416 // 2) Upload the content to the upload URL. |
1450 UploadRangeResponse response; | 1417 UploadRangeResponse response; |
1451 scoped_ptr<ResourceEntry> new_entry; | 1418 scoped_ptr<ResourceEntry> new_entry; |
1452 | 1419 |
1453 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( | 1420 ResumeUploadOperation* resume_operation = new ResumeUploadOperation( |
1454 &operation_registry_, | 1421 operation_runner_.get(), |
1455 request_context_getter_.get(), | 1422 request_context_getter_.get(), |
1456 CreateComposedCallback( | 1423 CreateComposedCallback( |
1457 base::Bind(&test_util::RunAndQuit), | 1424 base::Bind(&test_util::RunAndQuit), |
1458 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1425 test_util::CreateCopyResultCallback(&response, &new_entry)), |
1459 ProgressCallback(), | 1426 ProgressCallback(), |
1460 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | 1427 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), |
1461 upload_url, | 1428 upload_url, |
1462 0, // start_position | 1429 0, // start_position |
1463 kUploadContent.size(), // end_position (exclusive) | 1430 kUploadContent.size(), // end_position (exclusive) |
1464 kUploadContent.size(), // content_length, | 1431 kUploadContent.size(), // content_length, |
1465 "text/plain", // content_type | 1432 "text/plain", // content_type |
1466 kTestFilePath); | 1433 kTestFilePath); |
1467 | 1434 |
1468 resume_operation->Start( | 1435 operation_runner_->StartOperationWithRetry(resume_operation); |
1469 kTestGDataAuthToken, kTestUserAgent, | |
1470 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1471 MessageLoop::current()->Run(); | 1436 MessageLoop::current()->Run(); |
1472 | 1437 |
1473 // METHOD_PUT should be used to upload data. | 1438 // METHOD_PUT should be used to upload data. |
1474 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1439 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1475 // Request should go to the upload URL. | 1440 // Request should go to the upload URL. |
1476 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1441 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
1477 // Content-Range header should be added. | 1442 // Content-Range header should be added. |
1478 EXPECT_EQ("bytes 0-" + | 1443 EXPECT_EQ("bytes 0-" + |
1479 base::Int64ToString(kUploadContent.size() -1) + "/" + | 1444 base::Int64ToString(kUploadContent.size() -1) + "/" + |
1480 base::Int64ToString(kUploadContent.size()), | 1445 base::Int64ToString(kUploadContent.size()), |
(...skipping 12 matching lines...) Expand all Loading... |
1493 // This test exercises InitiateUploadExistingFileOperation for a scenario of | 1458 // This test exercises InitiateUploadExistingFileOperation for a scenario of |
1494 // confliction on updating an existing file. | 1459 // confliction on updating an existing file. |
1495 TEST_F(GDataWapiOperationsTest, UploadExistingFileWithETagConflict) { | 1460 TEST_F(GDataWapiOperationsTest, UploadExistingFileWithETagConflict) { |
1496 const std::string kUploadContent = "hello"; | 1461 const std::string kUploadContent = "hello"; |
1497 const std::string kWrongETag = "wrong_etag"; | 1462 const std::string kWrongETag = "wrong_etag"; |
1498 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1463 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
1499 GURL upload_url; | 1464 GURL upload_url; |
1500 | 1465 |
1501 InitiateUploadExistingFileOperation* initiate_operation = | 1466 InitiateUploadExistingFileOperation* initiate_operation = |
1502 new InitiateUploadExistingFileOperation( | 1467 new InitiateUploadExistingFileOperation( |
1503 &operation_registry_, | 1468 operation_runner_.get(), |
1504 request_context_getter_.get(), | 1469 request_context_getter_.get(), |
1505 *url_generator_, | 1470 *url_generator_, |
1506 CreateComposedCallback( | 1471 CreateComposedCallback( |
1507 base::Bind(&test_util::RunAndQuit), | 1472 base::Bind(&test_util::RunAndQuit), |
1508 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1473 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
1509 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | 1474 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), |
1510 "text/plain", | 1475 "text/plain", |
1511 kUploadContent.size(), | 1476 kUploadContent.size(), |
1512 "file:foo", | 1477 "file:foo", |
1513 kWrongETag); | 1478 kWrongETag); |
1514 | 1479 |
1515 initiate_operation->Start( | 1480 operation_runner_->StartOperationWithRetry(initiate_operation); |
1516 kTestGDataAuthToken, kTestUserAgent, | |
1517 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | |
1518 MessageLoop::current()->Run(); | 1481 MessageLoop::current()->Run(); |
1519 | 1482 |
1520 EXPECT_EQ(HTTP_PRECONDITION, result_code); | 1483 EXPECT_EQ(HTTP_PRECONDITION, result_code); |
1521 // For updating an existing file, METHOD_PUT should be used. | 1484 // For updating an existing file, METHOD_PUT should be used. |
1522 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1485 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1523 // convert=false should be passed as files should be uploaded as-is. | 1486 // convert=false should be passed as files should be uploaded as-is. |
1524 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" | 1487 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" |
1525 "?convert=false&v=3&alt=json&showroot=true", | 1488 "?convert=false&v=3&alt=json&showroot=true", |
1526 http_request_.relative_url); | 1489 http_request_.relative_url); |
1527 // Even though the body is empty, the content type should be set to | 1490 // Even though the body is empty, the content type should be set to |
1528 // "text/plain". | 1491 // "text/plain". |
1529 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1492 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
1530 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1493 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1531 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1494 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1532 http_request_.headers["X-Upload-Content-Length"]); | 1495 http_request_.headers["X-Upload-Content-Length"]); |
1533 // For updating an existing file, an empty body should be attached (PUT | 1496 // For updating an existing file, an empty body should be attached (PUT |
1534 // requires a body) | 1497 // requires a body) |
1535 EXPECT_TRUE(http_request_.has_content); | 1498 EXPECT_TRUE(http_request_.has_content); |
1536 EXPECT_EQ("", http_request_.content); | 1499 EXPECT_EQ("", http_request_.content); |
1537 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); | 1500 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); |
1538 } | 1501 } |
1539 | 1502 |
1540 } // namespace google_apis | 1503 } // namespace google_apis |
OLD | NEW |