Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5289)

Unified Diff: chrome/browser/google_apis/gdata_wapi_requests_unittest.cc

Issue 18211008: Add resource ID based download requests in {GDataWapi/Drive} requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reorder parameters. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/google_apis/gdata_wapi_requests.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/google_apis/gdata_wapi_requests_unittest.cc
diff --git a/chrome/browser/google_apis/gdata_wapi_requests_unittest.cc b/chrome/browser/google_apis/gdata_wapi_requests_unittest.cc
index 9772754d48436daa9a99eaa29187d8f06dc48a8d..cbdd2fa351d275279b854ef6aaa102ea5c37e8f5 100644
--- a/chrome/browser/google_apis/gdata_wapi_requests_unittest.cc
+++ b/chrome/browser/google_apis/gdata_wapi_requests_unittest.cc
@@ -6,6 +6,7 @@
#include <map>
#include "base/bind.h"
+#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_reader.h"
@@ -37,6 +38,7 @@ namespace {
const char kTestGDataAuthToken[] = "testtoken";
const char kTestUserAgent[] = "test-user-agent";
const char kTestETag[] = "test_etag";
+const char kTestDownloadPathPrefix[] = "/download/";
class GDataWapiRequestsTest : public testing::Test {
public:
@@ -79,10 +81,13 @@ class GDataWapiRequestsTest : public testing::Test {
test_server_.RegisterRequestHandler(
base::Bind(&GDataWapiRequestsTest::HandleUploadRequest,
base::Unretained(this)));
+ test_server_.RegisterRequestHandler(
+ base::Bind(&GDataWapiRequestsTest::HandleDownloadRequest,
+ base::Unretained(this)));
GURL test_base_url = test_util::GetBaseUrlForTesting(test_server_.port());
url_generator_.reset(new GDataWapiUrlGenerator(
- test_base_url, test_base_url.Resolve("download/")));
+ test_base_url, test_base_url.Resolve(kTestDownloadPathPrefix)));
received_bytes_ = 0;
content_length_ = 0;
@@ -312,6 +317,28 @@ class GDataWapiRequestsTest : public testing::Test {
return response.PassAs<net::test_server::HttpResponse>();
}
+ // Handles a request for downloading a file.
+ scoped_ptr<net::test_server::HttpResponse> HandleDownloadRequest(
+ const net::test_server::HttpRequest& request) {
+ http_request_ = request;
+
+ const GURL absolute_url = test_server_.GetURL(request.relative_url);
+ std::string id;
+ if (!test_util::RemovePrefix(absolute_url.path(),
+ kTestDownloadPathPrefix,
+ &id)) {
+ return scoped_ptr<net::test_server::HttpResponse>();
+ }
+
+ // For testing, returns a text with |id| repeated 3 times.
+ scoped_ptr<net::test_server::BasicHttpResponse> response(
+ new net::test_server::BasicHttpResponse);
+ response->set_code(net::HTTP_OK);
+ response->set_content(id + id + id);
+ response->set_content_type("text/plain");
+ return response.PassAs<net::test_server::HttpResponse>();
+ }
+
content::TestBrowserThreadBundle thread_bundle_;
net::test_server::EmbeddedTestServer test_server_;
scoped_ptr<TestingProfile> profile_;
@@ -1542,4 +1569,41 @@ TEST_F(GDataWapiRequestsTest, UploadExistingFileWithETagConflict) {
EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]);
}
+TEST_F(GDataWapiRequestsTest, DownloadFileRequest) {
+ const base::FilePath kDownloadedFilePath =
+ temp_dir_.path().AppendASCII("cache_file");
+ const std::string kTestIdWithTypeLabel("file:dummyId");
+ const std::string kTestId("dummyId");
+
+ GDataErrorCode result_code = GDATA_OTHER_ERROR;
+ base::FilePath temp_file;
+ {
+ base::RunLoop run_loop;
+ DownloadFileRequest* request = new DownloadFileRequest(
+ request_sender_.get(),
+ *url_generator_,
+ test_util::CreateQuitCallback(
+ &run_loop,
+ test_util::CreateCopyResultCallback(&result_code, &temp_file)),
+ GetContentCallback(),
+ ProgressCallback(),
+ kTestIdWithTypeLabel,
+ kDownloadedFilePath);
+ request_sender_->StartRequestWithRetry(request);
+ run_loop.Run();
+ }
+
+ std::string contents;
+ file_util::ReadFileToString(temp_file, &contents);
+ base::Delete(temp_file, false);
+
+ EXPECT_EQ(HTTP_SUCCESS, result_code);
+ EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
+ EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url);
+ EXPECT_EQ(kDownloadedFilePath, temp_file);
+
+ const std::string expected_contents = kTestId + kTestId + kTestId;
+ EXPECT_EQ(expected_contents, contents);
+}
+
} // namespace google_apis
« no previous file with comments | « chrome/browser/google_apis/gdata_wapi_requests.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698