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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 9 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
10 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 10 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 &remaining_path)) { | 198 &remaining_path)) { |
199 return scoped_ptr<test_server::HttpResponse>(); | 199 return scoped_ptr<test_server::HttpResponse>(); |
200 } | 200 } |
201 | 201 |
202 if (remaining_path == "-/mine") { | 202 if (remaining_path == "-/mine") { |
203 // Process the default feed. | 203 // Process the default feed. |
204 return CreateHttpResponseFromFile( | 204 return CreateHttpResponseFromFile( |
205 test_util::GetTestFilePath("gdata/root_feed.json")); | 205 test_util::GetTestFilePath("gdata/root_feed.json")); |
206 } else { | 206 } else { |
207 // Process a feed for a single resource ID. | 207 // Process a feed for a single resource ID. |
208 // For now, we only support a resource feed for a particular entry. | |
209 const std::string resource_id = net::UnescapeURLComponent( | 208 const std::string resource_id = net::UnescapeURLComponent( |
210 remaining_path, net::UnescapeRule::URL_SPECIAL_CHARS); | 209 remaining_path, net::UnescapeRule::URL_SPECIAL_CHARS); |
211 if (resource_id != "file:2_file_resource_id") | 210 if (resource_id == "file:2_file_resource_id") { |
212 return scoped_ptr<test_server::HttpResponse>(); | 211 return CreateHttpResponseFromFile( |
213 | 212 test_util::GetTestFilePath("gdata/file_entry.json")); |
214 return CreateHttpResponseFromFile( | 213 } else if (resource_id == "folder:root" && |
215 test_util::GetTestFilePath("gdata/file_entry.json")); | 214 request.method == test_server::METHOD_POST) { |
| 215 // This is a request for creating a directory in the root directory. |
| 216 // TODO(satorux): we should generate valid JSON data for the newly |
| 217 // created directory but for now, just return "directory_entry.json" |
| 218 return CreateHttpResponseFromFile( |
| 219 test_util::GetTestFilePath("gdata/directory_entry.json")); |
| 220 } |
216 } | 221 } |
217 | 222 |
218 NOTREACHED(); | |
219 return scoped_ptr<test_server::HttpResponse>(); | 223 return scoped_ptr<test_server::HttpResponse>(); |
220 } | 224 } |
221 | 225 |
222 // Handles a request for fetching a metadata feed. | 226 // Handles a request for fetching a metadata feed. |
223 scoped_ptr<test_server::HttpResponse> HandleMetadataFeedRequest( | 227 scoped_ptr<test_server::HttpResponse> HandleMetadataFeedRequest( |
224 const test_server::HttpRequest& request) { | 228 const test_server::HttpRequest& request) { |
225 http_request_ = request; | 229 http_request_ = request; |
226 | 230 |
227 const GURL absolute_url = test_server_.GetURL(request.relative_url); | 231 const GURL absolute_url = test_server_.GetURL(request.relative_url); |
228 if (absolute_url.path() != "/feeds/metadata/default") | 232 if (absolute_url.path() != "/feeds/metadata/default") |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 "/feeds/default/private/full/file:2_file_resource_id")); | 450 "/feeds/default/private/full/file:2_file_resource_id")); |
447 | 451 |
448 operation->Start(kTestGDataAuthToken, kTestUserAgent); | 452 operation->Start(kTestGDataAuthToken, kTestUserAgent); |
449 MessageLoop::current()->Run(); | 453 MessageLoop::current()->Run(); |
450 | 454 |
451 EXPECT_EQ(HTTP_SUCCESS, result_code); | 455 EXPECT_EQ(HTTP_SUCCESS, result_code); |
452 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); | 456 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); |
453 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 457 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
454 } | 458 } |
455 | 459 |
456 // TODO(satorux): Write tests for CreateDirectoryOperation. | 460 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { |
457 // crbug.com/162348 | 461 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 462 scoped_ptr<base::Value> result_data; |
| 463 |
| 464 // Create "new directory" in the root directory. |
| 465 CreateDirectoryOperation* operation = new CreateDirectoryOperation( |
| 466 &operation_registry_, |
| 467 *url_generator_, |
| 468 base::Bind(&CopyResultsFromGetDataCallbackAndQuit, |
| 469 &result_code, |
| 470 &result_data), |
| 471 test_server_.GetURL("/feeds/default/private/full/folder%3Aroot"), |
| 472 FILE_PATH_LITERAL("new directory")); |
| 473 |
| 474 operation->Start(kTestGDataAuthToken, kTestUserAgent); |
| 475 MessageLoop::current()->Run(); |
| 476 |
| 477 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 478 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
| 479 EXPECT_TRUE(http_request_.has_content); |
| 480 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 481 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" |
| 482 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " |
| 483 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" |
| 484 " <title>new directory</title>\n" |
| 485 "</entry>\n", |
| 486 http_request_.content); |
| 487 } |
458 | 488 |
459 // TODO(satorux): Write tests for CopyDocumentOperation. | 489 // TODO(satorux): Write tests for CopyDocumentOperation. |
460 // crbug.com/162348 | 490 // crbug.com/162348 |
461 | 491 |
462 // TODO(satorux): Write tests for RenameResourceOperation. | 492 // TODO(satorux): Write tests for RenameResourceOperation. |
463 // crbug.com/162348 | 493 // crbug.com/162348 |
464 | 494 |
465 // TODO(satorux): Write tests for AuthorizeAppsOperation. | 495 // TODO(satorux): Write tests for AuthorizeAppsOperation. |
466 // crbug.com/162348 | 496 // crbug.com/162348 |
467 | 497 |
468 // TODO(satorux): Write tests for AddResourceToDirectoryOperation. | 498 // TODO(satorux): Write tests for AddResourceToDirectoryOperation. |
469 // crbug.com/162348 | 499 // crbug.com/162348 |
470 | 500 |
471 // TODO(satorux): Write tests for RemoveResourceFromDirectoryOperation. | 501 // TODO(satorux): Write tests for RemoveResourceFromDirectoryOperation. |
472 // crbug.com/162348 | 502 // crbug.com/162348 |
473 | 503 |
474 // TODO(satorux): Write tests for InitiateUploadOperation. | 504 // TODO(satorux): Write tests for InitiateUploadOperation. |
475 // crbug.com/162348 | 505 // crbug.com/162348 |
476 | 506 |
477 // TODO(satorux): Write tests for ResumeUploadOperation. | 507 // TODO(satorux): Write tests for ResumeUploadOperation. |
478 // crbug.com/162348 | 508 // crbug.com/162348 |
479 | 509 |
480 } // namespace google_apis | 510 } // namespace google_apis |
OLD | NEW |