summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authortzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-12 12:00:06 +0000
committertzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-12 12:00:06 +0000
commit56fc130a8b04f83192d09bd838d290fe724a6838 (patch)
treecbca2de0a5c419078b8974bf13dcf1124dcd48ac /google_apis
parent165fad29acd06b872c5a757a4a626e033e01af1f (diff)
downloadchromium_src-56fc130a8b04f83192d09bd838d290fe724a6838.zip
chromium_src-56fc130a8b04f83192d09bd838d290fe724a6838.tar.gz
chromium_src-56fc130a8b04f83192d09bd838d290fe724a6838.tar.bz2
[Drive] Add DriveServiceInterface::DeleteResource
* Add DriveServiceInterface::DeleteResource * Implement DriveAPIService::DeleteResource BUG=240165 R=hashimoto@chromium.org Review URL: https://codereview.chromium.org/113803002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/drive_api_requests.cc21
-rw-r--r--google_apis/drive/drive_api_requests.h30
-rw-r--r--google_apis/drive/drive_api_requests_unittest.cc46
-rw-r--r--google_apis/drive/drive_api_url_generator.cc6
-rw-r--r--google_apis/drive/drive_api_url_generator.h3
-rw-r--r--google_apis/drive/drive_api_url_generator_unittest.cc17
6 files changed, 122 insertions, 1 deletions
diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc
index 67e3ac2..b524e6e 100644
--- a/google_apis/drive/drive_api_requests.cc
+++ b/google_apis/drive/drive_api_requests.cc
@@ -371,6 +371,27 @@ GURL FilesListNextPageRequest::GetURLInternal() const {
return next_link_;
}
+//============================ FilesDeleteRequest =============================
+
+FilesDeleteRequest::FilesDeleteRequest(
+ RequestSender* sender,
+ const DriveApiUrlGenerator& url_generator,
+ const EntryActionCallback& callback)
+ : EntryActionRequest(sender, callback),
+ url_generator_(url_generator) {
+ DCHECK(!callback.is_null());
+}
+
+FilesDeleteRequest::~FilesDeleteRequest() {}
+
+net::URLFetcher::RequestType FilesDeleteRequest::GetRequestType() const {
+ return net::URLFetcher::DELETE_REQUEST;
+}
+
+GURL FilesDeleteRequest::GetURL() const {
+ return url_generator_.GetFilesDeleteUrl(file_id_);
+}
+
//============================ FilesTrashRequest =============================
FilesTrashRequest::FilesTrashRequest(
diff --git a/google_apis/drive/drive_api_requests.h b/google_apis/drive/drive_api_requests.h
index 094ff4f..0e3e793 100644
--- a/google_apis/drive/drive_api_requests.h
+++ b/google_apis/drive/drive_api_requests.h
@@ -326,7 +326,35 @@ class FilesListNextPageRequest : public DriveApiDataRequest {
DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest);
};
-//============================= FilesTrashRequest =============================
+//============================= FilesDeleteRequest =============================
+
+// This class performs the request for deleting a resource.
+// This request is mapped to
+// https://developers.google.com/drive/v2/reference/files/delete
+class FilesDeleteRequest : public EntryActionRequest {
+ public:
+ FilesDeleteRequest(RequestSender* sender,
+ const DriveApiUrlGenerator& url_generator,
+ const EntryActionCallback& callback);
+ virtual ~FilesDeleteRequest();
+
+ // Required parameter.
+ const std::string& file_id() const { return file_id_; }
+ void set_file_id(const std::string& file_id) { file_id_ = file_id; }
+
+ protected:
+ // Overridden from UrlFetchRequestBase.
+ virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
+ virtual GURL GetURL() const OVERRIDE;
+
+ private:
+ const DriveApiUrlGenerator url_generator_;
+ std::string file_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(FilesDeleteRequest);
+};
+
+//============================= FilesTrashRequest ==============================
// This class performs the request for trashing a resource.
// This request is mapped to
diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc
index ba95adf..ecdefb5 100644
--- a/google_apis/drive/drive_api_requests_unittest.cc
+++ b/google_apis/drive/drive_api_requests_unittest.cc
@@ -75,6 +75,9 @@ class DriveApiRequestsTest : public testing::Test {
base::Bind(&DriveApiRequestsTest::HandleDataFileRequest,
base::Unretained(this)));
test_server_.RegisterRequestHandler(
+ base::Bind(&DriveApiRequestsTest::HandleDeleteRequest,
+ base::Unretained(this)));
+ test_server_.RegisterRequestHandler(
base::Bind(&DriveApiRequestsTest::HandlePreconditionFailedRequest,
base::Unretained(this)));
test_server_.RegisterRequestHandler(
@@ -176,6 +179,27 @@ class DriveApiRequestsTest : public testing::Test {
expected_data_file_path_).PassAs<net::test_server::HttpResponse>();
}
+ // Deletes the resource and returns no content with HTTP_NO_CONTENT status
+ // code.
+ scoped_ptr<net::test_server::HttpResponse> HandleDeleteRequest(
+ const net::test_server::HttpRequest& request) {
+ if (request.method != net::test_server::METHOD_DELETE ||
+ request.relative_url.find("/files/") == string::npos) {
+ // The file is not file deletion request. Delegate the processing to the
+ // next handler.
+ return scoped_ptr<net::test_server::HttpResponse>();
+ }
+
+ http_request_ = request;
+
+ scoped_ptr<net::test_server::BasicHttpResponse> response(
+ new net::test_server::BasicHttpResponse);
+ response->set_code(net::HTTP_NO_CONTENT);
+
+ return response.PassAs<net::test_server::HttpResponse>();
+ }
+
+
// Returns PRECONDITION_FAILED response for ETag mismatching with error JSON
// content specified by |expected_precondition_failed_file_path_|.
// To use this method, it is necessary to set the variable to the appropriate
@@ -761,6 +785,28 @@ TEST_F(DriveApiRequestsTest, FilesListNextPageRequest) {
EXPECT_TRUE(result);
}
+TEST_F(DriveApiRequestsTest, FilesDeleteRequest) {
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+
+ // Delete a resource with the given resource id.
+ {
+ base::RunLoop run_loop;
+ drive::FilesDeleteRequest* request = new drive::FilesDeleteRequest(
+ request_sender_.get(),
+ *url_generator_,
+ test_util::CreateQuitCallback(
+ &run_loop, test_util::CreateCopyResultCallback(&error)));
+ request->set_file_id("resource_id");
+ request_sender_->StartRequestWithRetry(request);
+ run_loop.Run();
+ }
+
+ EXPECT_EQ(HTTP_NO_CONTENT, error);
+ EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
+ EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url);
+ EXPECT_FALSE(http_request_.has_content);
+}
+
TEST_F(DriveApiRequestsTest, FilesTrashRequest) {
// Set data for the expected result. Directory entry should be returned
// if the trashing entry is a directory, so using it here should be fine.
diff --git a/google_apis/drive/drive_api_url_generator.cc b/google_apis/drive/drive_api_url_generator.cc
index 3be0f29..c12b947 100644
--- a/google_apis/drive/drive_api_url_generator.cc
+++ b/google_apis/drive/drive_api_url_generator.cc
@@ -24,6 +24,7 @@ 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 kDriveV2FileDeleteUrlFormat[] = "/drive/v2/files/%s";
const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash";
const char kDriveV2InitiateUploadNewFileUrl[] = "/upload/drive/v2/files";
const char kDriveV2InitiateUploadExistingFileUrlPrefix[] =
@@ -109,6 +110,11 @@ GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
return url;
}
+GURL DriveApiUrlGenerator::GetFilesDeleteUrl(const std::string& file_id) const {
+ return base_url_.Resolve(base::StringPrintf(
+ kDriveV2FileDeleteUrlFormat, net::EscapePath(file_id).c_str()));
+}
+
GURL DriveApiUrlGenerator::GetFilesTrashUrl(const std::string& file_id) const {
return base_url_.Resolve(base::StringPrintf(
kDriveV2FileTrashUrlFormat, net::EscapePath(file_id).c_str()));
diff --git a/google_apis/drive/drive_api_url_generator.h b/google_apis/drive/drive_api_url_generator.h
index a7e20a6..cf93edd 100644
--- a/google_apis/drive/drive_api_url_generator.h
+++ b/google_apis/drive/drive_api_url_generator.h
@@ -51,6 +51,9 @@ class DriveApiUrlGenerator {
const std::string& page_token,
const std::string& q) const;
+ // Returns a URL to delete a resource with the given |file_id|.
+ GURL GetFilesDeleteUrl(const std::string& file_id) const;
+
// Returns a URL to trash a resource with the given |file_id|.
GURL GetFilesTrashUrl(const std::string& file_id) const;
diff --git a/google_apis/drive/drive_api_url_generator_unittest.cc b/google_apis/drive/drive_api_url_generator_unittest.cc
index b9afb6f..343b279 100644
--- a/google_apis/drive/drive_api_url_generator_unittest.cc
+++ b/google_apis/drive/drive_api_url_generator_unittest.cc
@@ -186,6 +186,23 @@ TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) {
}
}
+TEST_F(DriveApiUrlGeneratorTest, GetFilesDeleteUrl) {
+ // |file_id| should be embedded into the url.
+ EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg",
+ url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec());
+ EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074",
+ url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec());
+ EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id",
+ url_generator_.GetFilesDeleteUrl("file:file_id").spec());
+
+ EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg",
+ test_url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec());
+ EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074",
+ test_url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec());
+ EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id",
+ test_url_generator_.GetFilesDeleteUrl("file:file_id").spec());
+}
+
TEST_F(DriveApiUrlGeneratorTest, GetFilesTrashUrl) {
// |file_id| should be embedded into the url.
EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/trash",