| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 if (remaining_path.empty()) { | 110 if (remaining_path.empty()) { |
| 111 // Process the default feed. | 111 // Process the default feed. |
| 112 return test_util::CreateHttpResponseFromFile( | 112 return test_util::CreateHttpResponseFromFile( |
| 113 test_util::GetTestFilePath("chromeos/gdata/root_feed.json")); | 113 test_util::GetTestFilePath("chromeos/gdata/root_feed.json")); |
| 114 } else { | 114 } else { |
| 115 // Process a feed for a single resource ID. | 115 // Process a feed for a single resource ID. |
| 116 const std::string resource_id = net::UnescapeURLComponent( | 116 const std::string resource_id = net::UnescapeURLComponent( |
| 117 remaining_path.substr(1), net::UnescapeRule::URL_SPECIAL_CHARS); | 117 remaining_path.substr(1), net::UnescapeRule::URL_SPECIAL_CHARS); |
| 118 if (resource_id == "file:2_file_resource_id") { | 118 if (resource_id == "file:2_file_resource_id") { |
| 119 // Check if this is an authorization request for an app. | |
| 120 if (request.method == test_server::METHOD_PUT && | |
| 121 request.content.find("<docs:authorizedApp>") != std::string::npos) { | |
| 122 return test_util::CreateHttpResponseFromFile( | |
| 123 test_util::GetTestFilePath("chromeos/gdata/basic_feed.json")); | |
| 124 } | |
| 125 | |
| 126 return test_util::CreateHttpResponseFromFile( | 119 return test_util::CreateHttpResponseFromFile( |
| 127 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); | 120 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); |
| 128 } else if (resource_id == "folder:root/contents" && | 121 } else if (resource_id == "folder:root/contents" && |
| 129 request.method == test_server::METHOD_POST) { | 122 request.method == test_server::METHOD_POST) { |
| 130 // This is a request for creating a directory in the root directory. | 123 // This is a request for creating a directory in the root directory. |
| 131 // TODO(satorux): we should generate valid JSON data for the newly | 124 // TODO(satorux): we should generate valid JSON data for the newly |
| 132 // created directory but for now, just return "directory_entry.json" | 125 // created directory but for now, just return "directory_entry.json" |
| 133 return test_util::CreateHttpResponseFromFile( | 126 return test_util::CreateHttpResponseFromFile( |
| 134 test_util::GetTestFilePath("chromeos/gdata/directory_entry.json")); | 127 test_util::GetTestFilePath("chromeos/gdata/directory_entry.json")); |
| 135 } else if (resource_id == | 128 } else if (resource_id == |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 EXPECT_TRUE(http_request_.has_content); | 688 EXPECT_TRUE(http_request_.has_content); |
| 696 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 689 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 697 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 690 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
| 698 " <title>New File</title>\n" | 691 " <title>New File</title>\n" |
| 699 "</entry>\n", | 692 "</entry>\n", |
| 700 http_request_.content); | 693 http_request_.content); |
| 701 } | 694 } |
| 702 | 695 |
| 703 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { | 696 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { |
| 704 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 697 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 705 scoped_ptr<base::Value> result_data; | 698 GURL result_data; |
| 706 | 699 |
| 707 // Authorize an app with APP_ID to access to a document. | 700 // Authorize an app with APP_ID to access to a document. |
| 708 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 701 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
| 709 &operation_registry_, | 702 &operation_registry_, |
| 710 request_context_getter_.get(), | 703 request_context_getter_.get(), |
| 711 *url_generator_, | 704 *url_generator_, |
| 712 CreateComposedCallback( | 705 CreateComposedCallback( |
| 713 base::Bind(&test_util::RunAndQuit), | 706 base::Bind(&test_util::RunAndQuit), |
| 714 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 707 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
| 715 "file:2_file_resource_id", | 708 "file:2_file_resource_id", |
| (...skipping 15 matching lines...) Expand all Loading... |
| 731 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 724 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 732 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 725 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
| 733 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 726 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
| 734 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" | 727 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" |
| 735 "</entry>\n", | 728 "</entry>\n", |
| 736 http_request_.content); | 729 http_request_.content); |
| 737 } | 730 } |
| 738 | 731 |
| 739 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { | 732 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { |
| 740 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 733 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 741 scoped_ptr<base::Value> result_data; | 734 GURL result_data; |
| 742 | 735 |
| 743 // Authorize an app with APP_ID to access to a document but an invalid feed. | 736 // Authorize an app with APP_ID to access to a document but an invalid feed. |
| 744 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 737 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
| 745 &operation_registry_, | 738 &operation_registry_, |
| 746 request_context_getter_.get(), | 739 request_context_getter_.get(), |
| 747 *url_generator_, | 740 *url_generator_, |
| 748 CreateComposedCallback( | 741 CreateComposedCallback( |
| 749 base::Bind(&test_util::RunAndQuit), | 742 base::Bind(&test_util::RunAndQuit), |
| 750 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 743 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
| 751 "invalid_resource_id", | 744 "invalid_resource_id", |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1446 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
| 1454 http_request_.headers["X-Upload-Content-Length"]); | 1447 http_request_.headers["X-Upload-Content-Length"]); |
| 1455 // For updating an existing file, an empty body should be attached (PUT | 1448 // For updating an existing file, an empty body should be attached (PUT |
| 1456 // requires a body) | 1449 // requires a body) |
| 1457 EXPECT_TRUE(http_request_.has_content); | 1450 EXPECT_TRUE(http_request_.has_content); |
| 1458 EXPECT_EQ("", http_request_.content); | 1451 EXPECT_EQ("", http_request_.content); |
| 1459 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); | 1452 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); |
| 1460 } | 1453 } |
| 1461 | 1454 |
| 1462 } // namespace google_apis | 1455 } // namespace google_apis |
| OLD | NEW |