Chromium Code Reviews| 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. | 119 // Check if this is an authorization request for an app. |
|
hashimoto
2013/03/25 12:11:24
nit: Do we need to maintain this comment?
hidehiko
2013/03/25 12:41:34
Oops. Good catch. Removed.
| |
| 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( | 120 return test_util::CreateHttpResponseFromFile( |
| 127 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); | 121 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); |
| 128 } else if (resource_id == "folder:root/contents" && | 122 } else if (resource_id == "folder:root/contents" && |
| 129 request.method == test_server::METHOD_POST) { | 123 request.method == test_server::METHOD_POST) { |
| 130 // This is a request for creating a directory in the root directory. | 124 // This is a request for creating a directory in the root directory. |
| 131 // TODO(satorux): we should generate valid JSON data for the newly | 125 // TODO(satorux): we should generate valid JSON data for the newly |
| 132 // created directory but for now, just return "directory_entry.json" | 126 // created directory but for now, just return "directory_entry.json" |
| 133 return test_util::CreateHttpResponseFromFile( | 127 return test_util::CreateHttpResponseFromFile( |
| 134 test_util::GetTestFilePath("chromeos/gdata/directory_entry.json")); | 128 test_util::GetTestFilePath("chromeos/gdata/directory_entry.json")); |
| 135 } else if (resource_id == | 129 } else if (resource_id == |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 EXPECT_TRUE(http_request_.has_content); | 689 EXPECT_TRUE(http_request_.has_content); |
| 696 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 690 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 697 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" | 691 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
| 698 " <title>New File</title>\n" | 692 " <title>New File</title>\n" |
| 699 "</entry>\n", | 693 "</entry>\n", |
| 700 http_request_.content); | 694 http_request_.content); |
| 701 } | 695 } |
| 702 | 696 |
| 703 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { | 697 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_ValidFeed) { |
| 704 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 698 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 705 scoped_ptr<base::Value> result_data; | 699 GURL result_data; |
| 706 | 700 |
| 707 // Authorize an app with APP_ID to access to a document. | 701 // Authorize an app with APP_ID to access to a document. |
| 708 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 702 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
| 709 &operation_registry_, | 703 &operation_registry_, |
| 710 request_context_getter_.get(), | 704 request_context_getter_.get(), |
| 711 *url_generator_, | 705 *url_generator_, |
| 712 CreateComposedCallback( | 706 CreateComposedCallback( |
| 713 base::Bind(&test_util::RunAndQuit), | 707 base::Bind(&test_util::RunAndQuit), |
| 714 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 708 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
| 715 "file:2_file_resource_id", | 709 "file:2_file_resource_id", |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 731 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 725 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 732 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 726 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
| 733 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 727 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
| 734 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" | 728 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" |
| 735 "</entry>\n", | 729 "</entry>\n", |
| 736 http_request_.content); | 730 http_request_.content); |
| 737 } | 731 } |
| 738 | 732 |
| 739 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { | 733 TEST_F(GDataWapiOperationsTest, AuthorizeAppOperation_InvalidFeed) { |
| 740 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 734 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 741 scoped_ptr<base::Value> result_data; | 735 GURL result_data; |
| 742 | 736 |
| 743 // Authorize an app with APP_ID to access to a document but an invalid feed. | 737 // Authorize an app with APP_ID to access to a document but an invalid feed. |
| 744 AuthorizeAppOperation* operation = new AuthorizeAppOperation( | 738 AuthorizeAppOperation* operation = new AuthorizeAppOperation( |
| 745 &operation_registry_, | 739 &operation_registry_, |
| 746 request_context_getter_.get(), | 740 request_context_getter_.get(), |
| 747 *url_generator_, | 741 *url_generator_, |
| 748 CreateComposedCallback( | 742 CreateComposedCallback( |
| 749 base::Bind(&test_util::RunAndQuit), | 743 base::Bind(&test_util::RunAndQuit), |
| 750 test_util::CreateCopyResultCallback(&result_code, &result_data)), | 744 test_util::CreateCopyResultCallback(&result_code, &result_data)), |
| 751 "invalid_resource_id", | 745 "invalid_resource_id", |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1453 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1447 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
| 1454 http_request_.headers["X-Upload-Content-Length"]); | 1448 http_request_.headers["X-Upload-Content-Length"]); |
| 1455 // For updating an existing file, an empty body should be attached (PUT | 1449 // For updating an existing file, an empty body should be attached (PUT |
| 1456 // requires a body) | 1450 // requires a body) |
| 1457 EXPECT_TRUE(http_request_.has_content); | 1451 EXPECT_TRUE(http_request_.has_content); |
| 1458 EXPECT_EQ("", http_request_.content); | 1452 EXPECT_EQ("", http_request_.content); |
| 1459 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); | 1453 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); |
| 1460 } | 1454 } |
| 1461 | 1455 |
| 1462 } // namespace google_apis | 1456 } // namespace google_apis |
| OLD | NEW |