diff options
author | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-05 12:52:34 +0000 |
---|---|---|
committer | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-05 12:52:34 +0000 |
commit | 6cd6108ca878209c2a530ba455aaff9961cbbbd9 (patch) | |
tree | 6bf8ed170df2f33df860f11f66f184e34efde214 /chrome/browser/google_apis | |
parent | 95046339c81e410b8b82f0712a6200e8f4f6f1b0 (diff) | |
download | chromium_src-6cd6108ca878209c2a530ba455aaff9961cbbbd9.zip chromium_src-6cd6108ca878209c2a530ba455aaff9961cbbbd9.tar.gz chromium_src-6cd6108ca878209c2a530ba455aaff9961cbbbd9.tar.bz2 |
Implement url generation for file.copy method on Drive API v2.
This is preparation to implement CopyHostedDocument. The newly introduced
method is not used yet, and will be used in following CLs.
BUG=179838
TEST=Ran unit_tests
Review URL: https://chromiumcodereview.appspot.com/12409005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google_apis')
3 files changed, 28 insertions, 0 deletions
diff --git a/chrome/browser/google_apis/drive_api_url_generator.cc b/chrome/browser/google_apis/drive_api_url_generator.cc index b1c95ca..d102802 100644 --- a/chrome/browser/google_apis/drive_api_url_generator.cc +++ b/chrome/browser/google_apis/drive_api_url_generator.cc @@ -22,6 +22,7 @@ const char kDriveV2FileUrlPrefix[] = "/drive/v2/files/"; const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children"; const char kDriveV2ChildrenUrlForRemovalFormat[] = "/drive/v2/files/%s/children/%s"; +const char kDriveV2FileCopyUrlFormat[] = "/drive/v2/files/%s/copy"; const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash"; const char kDriveV2InitiateUploadNewFileUrl[] = "/upload/drive/v2/files"; const char kDriveV2InitiateUploadExistingFileUrlPrefix[] = @@ -82,6 +83,13 @@ GURL DriveApiUrlGenerator::GetFileUrl(const std::string& file_id) const { return base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id)); } +GURL DriveApiUrlGenerator::GetFileCopyUrl( + const std::string& resource_id) const { + return base_url_.Resolve( + base::StringPrintf(kDriveV2FileCopyUrlFormat, + net::EscapePath(resource_id).c_str())); +} + GURL DriveApiUrlGenerator::GetFileTrashUrl(const std::string& file_id) const { return base_url_.Resolve( base::StringPrintf(kDriveV2FileTrashUrlFormat, diff --git a/chrome/browser/google_apis/drive_api_url_generator.h b/chrome/browser/google_apis/drive_api_url_generator.h index 4aeb5c8..dc23041 100644 --- a/chrome/browser/google_apis/drive_api_url_generator.h +++ b/chrome/browser/google_apis/drive_api_url_generator.h @@ -48,6 +48,9 @@ class DriveApiUrlGenerator { // Returns a URL to fetch a file content. GURL GetFileUrl(const std::string& file_id) const; + // Returns a URL to copy a file specified by |resource_id|. + GURL GetFileCopyUrl(const std::string& resource_id) const; + // Returns a URL to trash a resource with the given |resource_id|. // Note that the |resource_id| is corresponding to the "file id" in the // document: https://developers.google.com/drive/v2/reference/files/trash diff --git a/chrome/browser/google_apis/drive_api_url_generator_unittest.cc b/chrome/browser/google_apis/drive_api_url_generator_unittest.cc index bac3326..818fb2d 100644 --- a/chrome/browser/google_apis/drive_api_url_generator_unittest.cc +++ b/chrome/browser/google_apis/drive_api_url_generator_unittest.cc @@ -110,6 +110,23 @@ TEST_F(DriveApiUrlGeneratorTest, GetFileUrl) { test_url_generator_.GetFileUrl("file:file_id").spec()); } +TEST_F(DriveApiUrlGeneratorTest, GetFileCopyUrl) { + // |file_id| should be embedded into the url. + EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/copy", + url_generator_.GetFileCopyUrl("0ADK06pfg").spec()); + EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/copy", + url_generator_.GetFileCopyUrl("0Bz0bd074").spec()); + EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id/copy", + url_generator_.GetFileCopyUrl("file:file_id").spec()); + + EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/copy", + test_url_generator_.GetFileCopyUrl("0ADK06pfg").spec()); + EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/copy", + test_url_generator_.GetFileCopyUrl("0Bz0bd074").spec()); + EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id/copy", + test_url_generator_.GetFileCopyUrl("file:file_id").spec()); +} + TEST_F(DriveApiUrlGeneratorTest, GetChildrenUrl) { // |file_id| should be embedded into the url. EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/children", |