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

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

Issue 12246002: Implement GetUploadStatusOperation on GData WAPI. (Closed) Base URL: http://git.chromium.org/chromium/src.git@b148632_create_base_operation
Patch Set: Remove unknown content length support, which is not used. Created 7 years, 10 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
Index: chrome/browser/google_apis/gdata_wapi_operations_unittest.cc
diff --git a/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc b/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc
index 26397d9d35e9337fefcb1fa5c76aa04e66845132..73b20a9095ba48f6cb7f46881d3ddeea6e85d9c3 100644
--- a/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc
+++ b/chrome/browser/google_apis/gdata_wapi_operations_unittest.cc
@@ -127,6 +127,10 @@ class GDataWapiOperationsTest : public testing::Test {
url_generator_.reset(new GDataWapiUrlGenerator(
test_util::GetBaseUrlForTesting(test_server_.port())));
+
+ start_position_ = 0;
+ end_position_ = 0;
+ content_length_ = 0;
}
virtual void TearDown() OVERRIDE {
@@ -225,6 +229,7 @@ class GDataWapiOperationsTest : public testing::Test {
scoped_ptr<test_server::HttpResponse> http_response(
new test_server::HttpResponse);
+ // Check an ETag.
std::map<std::string, std::string>::const_iterator found =
request.headers.find("If-Match");
if (found != request.headers.end() &&
@@ -234,6 +239,16 @@ class GDataWapiOperationsTest : public testing::Test {
return http_response.Pass();
}
+ // Check if the X-Upload-Content-Length is present. If yes, store the
+ // length of the file.
+ found = request.headers.find("X-Upload-Content-Length");
+ if (found == request.headers.end() ||
+ !base::StringToInt64(found->second, &content_length_)) {
+ return scoped_ptr<test_server::HttpResponse>();
+ }
+ start_position_ = 0;
+ end_position_ = 0;
kinaba 2013/02/07 09:06:12 Theoretically, it should be end_position_ = -1, si
hidehiko 2013/02/08 09:17:00 Changed to use received_bytes_.
+
http_response->set_code(test_server::SUCCESS);
GURL upload_url;
// POST is used for a new file, and PUT is used for an existing file.
@@ -279,29 +294,28 @@ class GDataWapiOperationsTest : public testing::Test {
request.headers.find("Content-Range");
if (iter == request.headers.end())
return scoped_ptr<test_server::HttpResponse>();
- int64 start_position = 0;
- int64 end_position = 0;
int64 length = 0;
if (!ParseContentRangeHeader(iter->second,
- &start_position,
- &end_position,
+ &start_position_,
+ &end_position_,
&length)) {
return scoped_ptr<test_server::HttpResponse>();
}
-
- // Add Range header to the response, based on the values of
- // Content-Range header in the request.
- response->AddCustomHeader(
- "Range",
- "bytes=" +
- base::Int64ToString(start_position) + "-" +
- base::Int64ToString(end_position));
-
- // Change the code to RESUME_INCOMPLETE if upload is not complete.
- if (end_position + 1 < length)
- response->set_code(test_server::RESUME_INCOMPLETE);
+ EXPECT_EQ(length, content_length_);
}
+ // Add Range header to the response, based on the values of
+ // Content-Range header in the request.
+ response->AddCustomHeader(
+ "Range",
+ "bytes=" +
+ base::Int64ToString(start_position_) + "-" +
kinaba 2013/02/07 09:06:12 Correct me if I'm wrong, When data is uploaded, t
hidehiko 2013/02/08 09:17:00 The server will return no Range header, if there i
+ base::Int64ToString(end_position_));
+
+ // Change the code to RESUME_INCOMPLETE if upload is not complete.
+ if (end_position_ + 1 < content_length_)
+ response->set_code(test_server::RESUME_INCOMPLETE);
+
return response.Pass();
}
@@ -315,6 +329,15 @@ class GDataWapiOperationsTest : public testing::Test {
scoped_ptr<GDataWapiUrlGenerator> url_generator_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
+ // These fields are used to keep the current upload state during a
+ // test case. These values are updated by the request from
+ // ResumeUploadOperation, and used to construct the response for
+ // both ResumeUploadOperation and GetUploadStatusOperation, to emulate
+ // the WAPI server.
+ int64 start_position_;
+ int64 end_position_;
+ int64 content_length_;
+
// The incoming HTTP request is saved so tests can verify the request
// parameters like HTTP method (ex. some operations should use DELETE
// instead of GET).
@@ -866,7 +889,8 @@ TEST_F(GDataWapiOperationsTest, UploadNewFile) {
// This test exercises InitiateUploadOperation and ResumeUploadOperation for
// a scenario of uploading a new *large* file, which requires multiple requests
-// of ResumeUploadOperation.
+// of ResumeUploadOperation. GetUploadOperation is also tested in this test
+// case.
TEST_F(GDataWapiOperationsTest, UploadNewLargeFile) {
const size_t kMaxNumBytes = 10;
// This is big enough to cause multiple requests of ResumeUploadOperation
@@ -980,13 +1004,49 @@ TEST_F(GDataWapiOperationsTest, UploadNewLargeFile) {
// complete.
EXPECT_EQ(-1, response.start_position_received);
EXPECT_EQ(-1, response.end_position_received);
- } else {
- EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
- EXPECT_EQ(static_cast<int64>(start_position),
- response.start_position_received);
- EXPECT_EQ(static_cast<int64>(end_position),
- response.end_position_received);
+ // The upload process is completed, so exit from the loop.
+ break;
}
+
+ EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
+ EXPECT_EQ(static_cast<int64>(start_position),
+ response.start_position_received);
+ EXPECT_EQ(static_cast<int64>(end_position),
+ response.end_position_received);
+
+ // Check the response by GetUploadStatusOperation.
+ GetUploadStatusOperation* get_upload_status_operation =
+ new GetUploadStatusOperation(
+ &operation_registry_,
+ request_context_getter_.get(),
+ base::Bind(&CopyResultFromUploadRangeCallbackAndQuit,
+ &response,
+ &new_entry),
+ UPLOAD_NEW_FILE,
+ FilePath::FromUTF8Unsafe("drive/newfile.txt"),
+ upload_url,
+ kUploadContent.size());
+ get_upload_status_operation->Start(
+ kTestGDataAuthToken, kTestUserAgent,
+ base::Bind(&test_util::DoNothingForReAuthenticateCallback));
+ MessageLoop::current()->Run();
+
+ // METHOD_PUT should be used to upload data.
+ EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
+ // Request should go to the upload URL.
+ EXPECT_EQ(upload_url.path(), http_request_.relative_url);
+ // Content-Range header should be added.
+ EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()),
+ http_request_.headers["Content-Range"]);
+ EXPECT_TRUE(http_request_.has_content);
+ EXPECT_TRUE(http_request_.content.empty());
+
+ // Check the response.
+ EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
+ EXPECT_EQ(static_cast<int64>(start_position),
+ response.start_position_received);
+ EXPECT_EQ(static_cast<int64>(end_position),
+ response.end_position_received);
}
EXPECT_EQ(kUploadContent.size(), num_bytes_consumed);
« no previous file with comments | « chrome/browser/google_apis/gdata_wapi_operations.cc ('k') | chrome/browser/google_apis/gdata_wapi_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698