Commit 38f52016 authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Implement GetInitiateUpload{New,Existing}FileUrl on Drive API v2.

These methods will be used to implement InitiateUpload{New,Existing}Operation
on Drive API v2.

BUG=148632
TEST=Ran unit_tests


Review URL: https://chromiumcodereview.appspot.com/12225101

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182215 0039d316-1c4b-4281-b951-d872f2087c98
parent b642922e
...@@ -23,6 +23,13 @@ const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children"; ...@@ -23,6 +23,13 @@ const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children";
const char kDriveV2ChildrenUrlForRemovalFormat[] = const char kDriveV2ChildrenUrlForRemovalFormat[] =
"/drive/v2/files/%s/children/%s"; "/drive/v2/files/%s/children/%s";
const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash"; const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash";
const char kDriveV2InitiateUploadNewFileUrl[] = "/upload/drive/v2/files";
const char kDriveV2InitiateUploadExistingFileUrlPrefix[] =
"/upload/drive/v2/files/";
GURL AddResumableUploadParam(const GURL& url) {
return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable");
}
} // namespace } // namespace
...@@ -96,4 +103,17 @@ GURL DriveApiUrlGenerator::GetChildrenUrlForRemoval( ...@@ -96,4 +103,17 @@ GURL DriveApiUrlGenerator::GetChildrenUrlForRemoval(
net::EscapePath(child_id).c_str())); net::EscapePath(child_id).c_str()));
} }
GURL DriveApiUrlGenerator::GetInitiateUploadNewFileUrl() const {
return AddResumableUploadParam(
base_url_.Resolve(kDriveV2InitiateUploadNewFileUrl));
}
GURL DriveApiUrlGenerator::GetInitiateUploadExistingFileUrl(
const std::string& resource_id) const {
const GURL& url = base_url_.Resolve(
kDriveV2InitiateUploadExistingFileUrlPrefix +
net::EscapePath(resource_id));
return AddResumableUploadParam(url);
}
} // namespace google_apis } // namespace google_apis
...@@ -68,6 +68,13 @@ class DriveApiUrlGenerator { ...@@ -68,6 +68,13 @@ class DriveApiUrlGenerator {
GURL GetChildrenUrlForRemoval(const std::string& folder_id, GURL GetChildrenUrlForRemoval(const std::string& folder_id,
const std::string& child_id) const; const std::string& child_id) const;
// Returns a URL to initiate uploading a new file.
GURL GetInitiateUploadNewFileUrl() const;
// Returns a URL to initiate uploading an existing file specified by
// |resource_id|.
GURL GetInitiateUploadExistingFileUrl(const std::string& resource_id) const;
private: private:
const GURL base_url_; const GURL base_url_;
......
...@@ -176,4 +176,46 @@ TEST_F(DriveApiUrlGeneratorTest, GetFileTrashUrl) { ...@@ -176,4 +176,46 @@ TEST_F(DriveApiUrlGeneratorTest, GetFileTrashUrl) {
test_url_generator_.GetFileTrashUrl("file:file_id").spec()); test_url_generator_.GetFileTrashUrl("file:file_id").spec());
} }
TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadNewFileUrl) {
EXPECT_EQ(
"https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable",
url_generator_.GetInitiateUploadNewFileUrl().spec());
EXPECT_EQ(
"http://127.0.0.1:12345/upload/drive/v2/files?uploadType=resumable",
test_url_generator_.GetInitiateUploadNewFileUrl().spec());
}
TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadExistingFileUrl) {
// |resource_id| should be embedded into the url.
EXPECT_EQ(
"https://www.googleapis.com/upload/drive/v2/files/0ADK06pfg"
"?uploadType=resumable",
url_generator_.GetInitiateUploadExistingFileUrl("0ADK06pfg").spec());
EXPECT_EQ(
"https://www.googleapis.com/upload/drive/v2/files/0Bz0bd074"
"?uploadType=resumable",
url_generator_.GetInitiateUploadExistingFileUrl("0Bz0bd074").spec());
EXPECT_EQ(
"https://www.googleapis.com/upload/drive/v2/files/file%3Afile_id"
"?uploadType=resumable",
url_generator_.GetInitiateUploadExistingFileUrl("file:file_id").spec());
EXPECT_EQ(
"http://127.0.0.1:12345/upload/drive/v2/files/0ADK06pfg"
"?uploadType=resumable",
test_url_generator_.GetInitiateUploadExistingFileUrl(
"0ADK06pfg").spec());
EXPECT_EQ(
"http://127.0.0.1:12345/upload/drive/v2/files/0Bz0bd074"
"?uploadType=resumable",
test_url_generator_.GetInitiateUploadExistingFileUrl(
"0Bz0bd074").spec());
EXPECT_EQ(
"http://127.0.0.1:12345/upload/drive/v2/files/file%3Afile_id"
"?uploadType=resumable",
test_url_generator_.GetInitiateUploadExistingFileUrl(
"file:file_id").spec());
}
} // namespace google_apis } // namespace google_apis
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment