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

Side by Side Diff: chrome/browser/google_apis/gdata_wapi_operations_unittest.cc

Issue 15069003: Rename the embedded test server to EmbeddedTestServer in net::test_server namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/google_apis/gdata_wapi_operations.h" 17 #include "chrome/browser/google_apis/gdata_wapi_operations.h"
18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
19 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" 19 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
20 #include "chrome/browser/google_apis/operation_registry.h" 20 #include "chrome/browser/google_apis/operation_registry.h"
21 #include "chrome/browser/google_apis/task_util.h" 21 #include "chrome/browser/google_apis/task_util.h"
22 #include "chrome/browser/google_apis/test_util.h" 22 #include "chrome/browser/google_apis/test_util.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
26 #include "net/base/escape.h" 26 #include "net/base/escape.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h"
27 #include "net/test/embedded_test_server/http_request.h" 28 #include "net/test/embedded_test_server/http_request.h"
28 #include "net/test/embedded_test_server/http_response.h" 29 #include "net/test/embedded_test_server/http_response.h"
29 #include "net/test/embedded_test_server/http_server.h"
30 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 32
33 namespace google_apis { 33 namespace google_apis {
34 34
35 namespace { 35 namespace {
36 36
37 const char kTestGDataAuthToken[] = "testtoken"; 37 const char kTestGDataAuthToken[] = "testtoken";
38 const char kTestUserAgent[] = "test-user-agent"; 38 const char kTestUserAgent[] = "test-user-agent";
39 const char kTestETag[] = "test_etag"; 39 const char kTestETag[] = "test_etag";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 content_length_ = 0; 82 content_length_ = 0;
83 } 83 }
84 84
85 virtual void TearDown() OVERRIDE { 85 virtual void TearDown() OVERRIDE {
86 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); 86 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete());
87 request_context_getter_ = NULL; 87 request_context_getter_ = NULL;
88 } 88 }
89 89
90 protected: 90 protected:
91 // Handles a request for fetching a resource feed. 91 // Handles a request for fetching a resource feed.
92 scoped_ptr<test_server::HttpResponse> HandleResourceFeedRequest( 92 scoped_ptr<net::test_server::HttpResponse> HandleResourceFeedRequest(
93 const test_server::HttpRequest& request) { 93 const net::test_server::HttpRequest& request) {
94 http_request_ = request; 94 http_request_ = request;
95 95
96 const GURL absolute_url = test_server_.GetURL(request.relative_url); 96 const GURL absolute_url = test_server_.GetURL(request.relative_url);
97 std::string remaining_path; 97 std::string remaining_path;
98 if (absolute_url.path() == "/feeds/default/private/full" && 98 if (absolute_url.path() == "/feeds/default/private/full" &&
99 request.method == test_server::METHOD_POST) { 99 request.method == net::test_server::METHOD_POST) {
100 // This is a request for copying a document. 100 // This is a request for copying a document.
101 // TODO(satorux): we should generate valid JSON data for the newly 101 // TODO(satorux): we should generate valid JSON data for the newly
102 // copied document but for now, just return "file_entry.json" 102 // copied document but for now, just return "file_entry.json"
103 return test_util::CreateHttpResponseFromFile( 103 return test_util::CreateHttpResponseFromFile(
104 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); 104 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"));
105 } 105 }
106 106
107 if (!test_util::RemovePrefix(absolute_url.path(), 107 if (!test_util::RemovePrefix(absolute_url.path(),
108 "/feeds/default/private/full", 108 "/feeds/default/private/full",
109 &remaining_path)) { 109 &remaining_path)) {
110 return scoped_ptr<test_server::HttpResponse>(); 110 return scoped_ptr<net::test_server::HttpResponse>();
111 } 111 }
112 112
113 if (remaining_path.empty()) { 113 if (remaining_path.empty()) {
114 // Process the default feed. 114 // Process the default feed.
115 return test_util::CreateHttpResponseFromFile( 115 return test_util::CreateHttpResponseFromFile(
116 test_util::GetTestFilePath("chromeos/gdata/root_feed.json")); 116 test_util::GetTestFilePath("chromeos/gdata/root_feed.json"));
117 } else { 117 } else {
118 // Process a feed for a single resource ID. 118 // Process a feed for a single resource ID.
119 const std::string resource_id = net::UnescapeURLComponent( 119 const std::string resource_id = net::UnescapeURLComponent(
120 remaining_path.substr(1), net::UnescapeRule::URL_SPECIAL_CHARS); 120 remaining_path.substr(1), net::UnescapeRule::URL_SPECIAL_CHARS);
121 if (resource_id == "file:2_file_resource_id") { 121 if (resource_id == "file:2_file_resource_id") {
122 return test_util::CreateHttpResponseFromFile( 122 return test_util::CreateHttpResponseFromFile(
123 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); 123 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"));
124 } else if (resource_id == "folder:root/contents" && 124 } else if (resource_id == "folder:root/contents" &&
125 request.method == test_server::METHOD_POST) { 125 request.method == net::test_server::METHOD_POST) {
126 // This is a request for creating a directory in the root directory. 126 // This is a request for creating a directory in the root directory.
127 // TODO(satorux): we should generate valid JSON data for the newly 127 // TODO(satorux): we should generate valid JSON data for the newly
128 // created directory but for now, just return "directory_entry.json" 128 // created directory but for now, just return "directory_entry.json"
129 return test_util::CreateHttpResponseFromFile( 129 return test_util::CreateHttpResponseFromFile(
130 test_util::GetTestFilePath("chromeos/gdata/directory_entry.json")); 130 test_util::GetTestFilePath("chromeos/gdata/directory_entry.json"));
131 } else if (resource_id == 131 } else if (resource_id ==
132 "folder:root/contents/file:2_file_resource_id" && 132 "folder:root/contents/file:2_file_resource_id" &&
133 request.method == test_server::METHOD_DELETE) { 133 request.method == net::test_server::METHOD_DELETE) {
134 // This is a request for deleting a file from the root directory. 134 // This is a request for deleting a file from the root directory.
135 // TODO(satorux): Investigate what's returned from the server, and 135 // TODO(satorux): Investigate what's returned from the server, and
136 // copy it. For now, just return a random file, as the contents don't 136 // copy it. For now, just return a random file, as the contents don't
137 // matter. 137 // matter.
138 return test_util::CreateHttpResponseFromFile( 138 return test_util::CreateHttpResponseFromFile(
139 test_util::GetTestFilePath("chromeos/gdata/testfile.txt")); 139 test_util::GetTestFilePath("chromeos/gdata/testfile.txt"));
140 } else if (resource_id == "invalid_resource_id") { 140 } else if (resource_id == "invalid_resource_id") {
141 // Check if this is an authorization request for an app. 141 // Check if this is an authorization request for an app.
142 // This emulates to return invalid formatted result from the server. 142 // This emulates to return invalid formatted result from the server.
143 if (request.method == test_server::METHOD_PUT && 143 if (request.method == net::test_server::METHOD_PUT &&
144 request.content.find("<docs:authorizedApp>") != std::string::npos) { 144 request.content.find("<docs:authorizedApp>") != std::string::npos) {
145 return test_util::CreateHttpResponseFromFile( 145 return test_util::CreateHttpResponseFromFile(
146 test_util::GetTestFilePath("chromeos/gdata/testfile.txt")); 146 test_util::GetTestFilePath("chromeos/gdata/testfile.txt"));
147 } 147 }
148 } 148 }
149 } 149 }
150 150
151 return scoped_ptr<test_server::HttpResponse>(); 151 return scoped_ptr<net::test_server::HttpResponse>();
152 } 152 }
153 153
154 // Handles a request for fetching a metadata feed. 154 // Handles a request for fetching a metadata feed.
155 scoped_ptr<test_server::HttpResponse> HandleMetadataRequest( 155 scoped_ptr<net::test_server::HttpResponse> HandleMetadataRequest(
156 const test_server::HttpRequest& request) { 156 const net::test_server::HttpRequest& request) {
157 http_request_ = request; 157 http_request_ = request;
158 158
159 const GURL absolute_url = test_server_.GetURL(request.relative_url); 159 const GURL absolute_url = test_server_.GetURL(request.relative_url);
160 if (absolute_url.path() != "/feeds/metadata/default") 160 if (absolute_url.path() != "/feeds/metadata/default")
161 return scoped_ptr<test_server::HttpResponse>(); 161 return scoped_ptr<net::test_server::HttpResponse>();
162 162
163 scoped_ptr<test_server::HttpResponse> result( 163 scoped_ptr<net::test_server::HttpResponse> result(
164 test_util::CreateHttpResponseFromFile( 164 test_util::CreateHttpResponseFromFile(
165 test_util::GetTestFilePath( 165 test_util::GetTestFilePath(
166 "chromeos/gdata/account_metadata.json"))); 166 "chromeos/gdata/account_metadata.json")));
167 if (absolute_url.query().find("include-installed-apps=true") == 167 if (absolute_url.query().find("include-installed-apps=true") ==
168 string::npos) { 168 string::npos) {
169 // Exclude the list of installed apps. 169 // Exclude the list of installed apps.
170 scoped_ptr<base::Value> parsed_content( 170 scoped_ptr<base::Value> parsed_content(
171 base::JSONReader::Read(result->content(), base::JSON_PARSE_RFC)); 171 base::JSONReader::Read(result->content(), base::JSON_PARSE_RFC));
172 CHECK(parsed_content); 172 CHECK(parsed_content);
173 173
174 // Remove the install apps node. 174 // Remove the install apps node.
175 base::DictionaryValue* dictionary_value; 175 base::DictionaryValue* dictionary_value;
176 CHECK(parsed_content->GetAsDictionary(&dictionary_value)); 176 CHECK(parsed_content->GetAsDictionary(&dictionary_value));
177 dictionary_value->Remove("entry.docs$installedApp", NULL); 177 dictionary_value->Remove("entry.docs$installedApp", NULL);
178 178
179 // Write back it as the content of the result. 179 // Write back it as the content of the result.
180 std::string content; 180 std::string content;
181 base::JSONWriter::Write(parsed_content.get(), &content); 181 base::JSONWriter::Write(parsed_content.get(), &content);
182 result->set_content(content); 182 result->set_content(content);
183 } 183 }
184 184
185 return result.Pass(); 185 return result.Pass();
186 } 186 }
187 187
188 // Handles a request for creating a session for uploading. 188 // Handles a request for creating a session for uploading.
189 scoped_ptr<test_server::HttpResponse> HandleCreateSessionRequest( 189 scoped_ptr<net::test_server::HttpResponse> HandleCreateSessionRequest(
190 const test_server::HttpRequest& request) { 190 const net::test_server::HttpRequest& request) {
191 http_request_ = request; 191 http_request_ = request;
192 192
193 const GURL absolute_url = test_server_.GetURL(request.relative_url); 193 const GURL absolute_url = test_server_.GetURL(request.relative_url);
194 if (StartsWithASCII(absolute_url.path(), 194 if (StartsWithASCII(absolute_url.path(),
195 "/feeds/upload/create-session/default/private/full", 195 "/feeds/upload/create-session/default/private/full",
196 true)) { // case sensitive 196 true)) { // case sensitive
197 // This is an initiating upload URL. 197 // This is an initiating upload URL.
198 scoped_ptr<test_server::HttpResponse> http_response( 198 scoped_ptr<net::test_server::HttpResponse> http_response(
199 new test_server::HttpResponse); 199 new net::test_server::HttpResponse);
200 200
201 // Check an ETag. 201 // Check an ETag.
202 std::map<std::string, std::string>::const_iterator found = 202 std::map<std::string, std::string>::const_iterator found =
203 request.headers.find("If-Match"); 203 request.headers.find("If-Match");
204 if (found != request.headers.end() && 204 if (found != request.headers.end() &&
205 found->second != "*" && 205 found->second != "*" &&
206 found->second != kTestETag) { 206 found->second != kTestETag) {
207 http_response->set_code(test_server::PRECONDITION); 207 http_response->set_code(net::test_server::PRECONDITION);
208 return http_response.Pass(); 208 return http_response.Pass();
209 } 209 }
210 210
211 // Check if the X-Upload-Content-Length is present. If yes, store the 211 // Check if the X-Upload-Content-Length is present. If yes, store the
212 // length of the file. 212 // length of the file.
213 found = request.headers.find("X-Upload-Content-Length"); 213 found = request.headers.find("X-Upload-Content-Length");
214 if (found == request.headers.end() || 214 if (found == request.headers.end() ||
215 !base::StringToInt64(found->second, &content_length_)) { 215 !base::StringToInt64(found->second, &content_length_)) {
216 return scoped_ptr<test_server::HttpResponse>(); 216 return scoped_ptr<net::test_server::HttpResponse>();
217 } 217 }
218 received_bytes_ = 0; 218 received_bytes_ = 0;
219 219
220 http_response->set_code(test_server::SUCCESS); 220 http_response->set_code(net::test_server::SUCCESS);
221 GURL upload_url; 221 GURL upload_url;
222 // POST is used for a new file, and PUT is used for an existing file. 222 // POST is used for a new file, and PUT is used for an existing file.
223 if (request.method == test_server::METHOD_POST) { 223 if (request.method == net::test_server::METHOD_POST) {
224 upload_url = test_server_.GetURL("/upload_new_file"); 224 upload_url = test_server_.GetURL("/upload_new_file");
225 } else if (request.method == test_server::METHOD_PUT) { 225 } else if (request.method == net::test_server::METHOD_PUT) {
226 upload_url = test_server_.GetURL("/upload_existing_file"); 226 upload_url = test_server_.GetURL("/upload_existing_file");
227 } else { 227 } else {
228 return scoped_ptr<test_server::HttpResponse>(); 228 return scoped_ptr<net::test_server::HttpResponse>();
229 } 229 }
230 http_response->AddCustomHeader("Location", upload_url.spec()); 230 http_response->AddCustomHeader("Location", upload_url.spec());
231 return http_response.Pass(); 231 return http_response.Pass();
232 } 232 }
233 233
234 return scoped_ptr<test_server::HttpResponse>(); 234 return scoped_ptr<net::test_server::HttpResponse>();
235 } 235 }
236 236
237 // Handles a request for uploading content. 237 // Handles a request for uploading content.
238 scoped_ptr<test_server::HttpResponse> HandleUploadRequest( 238 scoped_ptr<net::test_server::HttpResponse> HandleUploadRequest(
239 const test_server::HttpRequest& request) { 239 const net::test_server::HttpRequest& request) {
240 http_request_ = request; 240 http_request_ = request;
241 241
242 const GURL absolute_url = test_server_.GetURL(request.relative_url); 242 const GURL absolute_url = test_server_.GetURL(request.relative_url);
243 if (absolute_url.path() != "/upload_new_file" && 243 if (absolute_url.path() != "/upload_new_file" &&
244 absolute_url.path() != "/upload_existing_file") { 244 absolute_url.path() != "/upload_existing_file") {
245 return scoped_ptr<test_server::HttpResponse>(); 245 return scoped_ptr<net::test_server::HttpResponse>();
246 } 246 }
247 247
248 // TODO(satorux): We should create a correct JSON data for the uploaded 248 // TODO(satorux): We should create a correct JSON data for the uploaded
249 // file, but for now, just return file_entry.json. 249 // file, but for now, just return file_entry.json.
250 scoped_ptr<test_server::HttpResponse> response = 250 scoped_ptr<net::test_server::HttpResponse> response =
251 test_util::CreateHttpResponseFromFile( 251 test_util::CreateHttpResponseFromFile(
252 test_util::GetTestFilePath("chromeos/gdata/file_entry.json")); 252 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"));
253 // response.code() is set to SUCCESS. Change it to CREATED if it's a new 253 // response.code() is set to SUCCESS. Change it to CREATED if it's a new
254 // file. 254 // file.
255 if (absolute_url.path() == "/upload_new_file") 255 if (absolute_url.path() == "/upload_new_file")
256 response->set_code(test_server::CREATED); 256 response->set_code(net::test_server::CREATED);
257 257
258 // Check if the Content-Range header is present. This must be present if 258 // Check if the Content-Range header is present. This must be present if
259 // the request body is not empty. 259 // the request body is not empty.
260 if (!request.content.empty()) { 260 if (!request.content.empty()) {
261 std::map<std::string, std::string>::const_iterator iter = 261 std::map<std::string, std::string>::const_iterator iter =
262 request.headers.find("Content-Range"); 262 request.headers.find("Content-Range");
263 if (iter == request.headers.end()) 263 if (iter == request.headers.end())
264 return scoped_ptr<test_server::HttpResponse>(); 264 return scoped_ptr<net::test_server::HttpResponse>();
265 int64 length = 0; 265 int64 length = 0;
266 int64 start_position = 0; 266 int64 start_position = 0;
267 int64 end_position = 0; 267 int64 end_position = 0;
268 if (!test_util::ParseContentRangeHeader(iter->second, 268 if (!test_util::ParseContentRangeHeader(iter->second,
269 &start_position, 269 &start_position,
270 &end_position, 270 &end_position,
271 &length)) { 271 &length)) {
272 return scoped_ptr<test_server::HttpResponse>(); 272 return scoped_ptr<net::test_server::HttpResponse>();
273 } 273 }
274 EXPECT_EQ(start_position, received_bytes_); 274 EXPECT_EQ(start_position, received_bytes_);
275 EXPECT_EQ(length, content_length_); 275 EXPECT_EQ(length, content_length_);
276 // end_position is inclusive, but so +1 to change the range to byte size. 276 // end_position is inclusive, but so +1 to change the range to byte size.
277 received_bytes_ = end_position + 1; 277 received_bytes_ = end_position + 1;
278 } 278 }
279 279
280 // Add Range header to the response, based on the values of 280 // Add Range header to the response, based on the values of
281 // Content-Range header in the request. 281 // Content-Range header in the request.
282 // The header is annotated only when at least one byte is received. 282 // The header is annotated only when at least one byte is received.
283 if (received_bytes_ > 0) { 283 if (received_bytes_ > 0) {
284 response->AddCustomHeader( 284 response->AddCustomHeader(
285 "Range", 285 "Range",
286 "bytes=0-" + base::Int64ToString(received_bytes_ - 1)); 286 "bytes=0-" + base::Int64ToString(received_bytes_ - 1));
287 } 287 }
288 288
289 // Change the code to RESUME_INCOMPLETE if upload is not complete. 289 // Change the code to RESUME_INCOMPLETE if upload is not complete.
290 if (received_bytes_ < content_length_) 290 if (received_bytes_ < content_length_)
291 response->set_code(test_server::RESUME_INCOMPLETE); 291 response->set_code(net::test_server::RESUME_INCOMPLETE);
292 292
293 return response.Pass(); 293 return response.Pass();
294 } 294 }
295 295
296 MessageLoopForUI message_loop_; 296 MessageLoopForUI message_loop_;
297 content::TestBrowserThread ui_thread_; 297 content::TestBrowserThread ui_thread_;
298 content::TestBrowserThread file_thread_; 298 content::TestBrowserThread file_thread_;
299 content::TestBrowserThread io_thread_; 299 content::TestBrowserThread io_thread_;
300 test_server::HttpServer test_server_; 300 net::test_server::EmbeddedTestServer test_server_;
301 scoped_ptr<TestingProfile> profile_; 301 scoped_ptr<TestingProfile> profile_;
302 OperationRegistry operation_registry_; 302 OperationRegistry operation_registry_;
303 scoped_ptr<GDataWapiUrlGenerator> url_generator_; 303 scoped_ptr<GDataWapiUrlGenerator> url_generator_;
304 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; 304 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
305 305
306 // These fields are used to keep the current upload state during a 306 // These fields are used to keep the current upload state during a
307 // test case. These values are updated by the request from 307 // test case. These values are updated by the request from
308 // ResumeUploadOperation, and used to construct the response for 308 // ResumeUploadOperation, and used to construct the response for
309 // both ResumeUploadOperation and GetUploadStatusOperation, to emulate 309 // both ResumeUploadOperation and GetUploadStatusOperation, to emulate
310 // the WAPI server. 310 // the WAPI server.
311 int64 received_bytes_; 311 int64 received_bytes_;
312 int64 content_length_; 312 int64 content_length_;
313 313
314 // The incoming HTTP request is saved so tests can verify the request 314 // The incoming HTTP request is saved so tests can verify the request
315 // parameters like HTTP method (ex. some operations should use DELETE 315 // parameters like HTTP method (ex. some operations should use DELETE
316 // instead of GET). 316 // instead of GET).
317 test_server::HttpRequest http_request_; 317 net::test_server::HttpRequest http_request_;
318 }; 318 };
319 319
320 } // namespace 320 } // namespace
321 321
322 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_DefaultFeed) { 322 TEST_F(GDataWapiOperationsTest, GetResourceListOperation_DefaultFeed) {
323 GDataErrorCode result_code = GDATA_OTHER_ERROR; 323 GDataErrorCode result_code = GDATA_OTHER_ERROR;
324 scoped_ptr<ResourceList> result_data; 324 scoped_ptr<ResourceList> result_data;
325 325
326 GetResourceListOperation* operation = new GetResourceListOperation( 326 GetResourceListOperation* operation = new GetResourceListOperation(
327 &operation_registry_, 327 &operation_registry_,
328 request_context_getter_.get(), 328 request_context_getter_.get(),
329 *url_generator_, 329 *url_generator_,
330 GURL(), // Pass an empty URL to use the default feed 330 GURL(), // Pass an empty URL to use the default feed
331 0, // start changestamp 331 0, // start changestamp
332 std::string(), // search string 332 std::string(), // search string
333 std::string(), // directory resource ID 333 std::string(), // directory resource ID
334 CreateComposedCallback( 334 CreateComposedCallback(
335 base::Bind(&test_util::RunAndQuit), 335 base::Bind(&test_util::RunAndQuit),
336 test_util::CreateCopyResultCallback(&result_code, &result_data))); 336 test_util::CreateCopyResultCallback(&result_code, &result_data)));
337 operation->Start(kTestGDataAuthToken, kTestUserAgent, 337 operation->Start(kTestGDataAuthToken, kTestUserAgent,
338 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 338 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
339 MessageLoop::current()->Run(); 339 MessageLoop::current()->Run();
340 340
341 EXPECT_EQ(HTTP_SUCCESS, result_code); 341 EXPECT_EQ(HTTP_SUCCESS, result_code);
342 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 342 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
343 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" 343 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&"
344 "showfolders=true&include-shared=true&max-results=500", 344 "showfolders=true&include-shared=true&max-results=500",
345 http_request_.relative_url); 345 http_request_.relative_url);
346 346
347 // Sanity check of the result. 347 // Sanity check of the result.
348 scoped_ptr<ResourceList> expected( 348 scoped_ptr<ResourceList> expected(
349 ResourceList::ExtractAndParse( 349 ResourceList::ExtractAndParse(
350 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); 350 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json")));
351 ASSERT_TRUE(result_data); 351 ASSERT_TRUE(result_data);
352 EXPECT_EQ(expected->title(), result_data->title()); 352 EXPECT_EQ(expected->title(), result_data->title());
(...skipping 12 matching lines...) Expand all
365 std::string(), // search string 365 std::string(), // search string
366 std::string(), // directory resource ID 366 std::string(), // directory resource ID
367 CreateComposedCallback( 367 CreateComposedCallback(
368 base::Bind(&test_util::RunAndQuit), 368 base::Bind(&test_util::RunAndQuit),
369 test_util::CreateCopyResultCallback(&result_code, &result_data))); 369 test_util::CreateCopyResultCallback(&result_code, &result_data)));
370 operation->Start(kTestGDataAuthToken, kTestUserAgent, 370 operation->Start(kTestGDataAuthToken, kTestUserAgent,
371 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 371 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
372 MessageLoop::current()->Run(); 372 MessageLoop::current()->Run();
373 373
374 EXPECT_EQ(HTTP_SUCCESS, result_code); 374 EXPECT_EQ(HTTP_SUCCESS, result_code);
375 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 375 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
376 EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&" 376 EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&"
377 "showfolders=true&include-shared=true&max-results=500", 377 "showfolders=true&include-shared=true&max-results=500",
378 http_request_.relative_url); 378 http_request_.relative_url);
379 379
380 scoped_ptr<ResourceList> expected( 380 scoped_ptr<ResourceList> expected(
381 ResourceList::ExtractAndParse( 381 ResourceList::ExtractAndParse(
382 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); 382 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json")));
383 ASSERT_TRUE(result_data); 383 ASSERT_TRUE(result_data);
384 EXPECT_EQ(expected->title(), result_data->title()); 384 EXPECT_EQ(expected->title(), result_data->title());
385 } 385 }
(...skipping 13 matching lines...) Expand all
399 std::string(), // search string 399 std::string(), // search string
400 std::string(), // directory resource ID 400 std::string(), // directory resource ID
401 CreateComposedCallback( 401 CreateComposedCallback(
402 base::Bind(&test_util::RunAndQuit), 402 base::Bind(&test_util::RunAndQuit),
403 test_util::CreateCopyResultCallback(&result_code, &result_data))); 403 test_util::CreateCopyResultCallback(&result_code, &result_data)));
404 operation->Start(kTestGDataAuthToken, kTestUserAgent, 404 operation->Start(kTestGDataAuthToken, kTestUserAgent,
405 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 405 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
406 MessageLoop::current()->Run(); 406 MessageLoop::current()->Run();
407 407
408 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); 408 EXPECT_EQ(GDATA_PARSE_ERROR, result_code);
409 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 409 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
410 EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&" 410 EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&"
411 "showfolders=true&include-shared=true&max-results=500", 411 "showfolders=true&include-shared=true&max-results=500",
412 http_request_.relative_url); 412 http_request_.relative_url);
413 EXPECT_FALSE(result_data); 413 EXPECT_FALSE(result_data);
414 } 414 }
415 415
416 TEST_F(GDataWapiOperationsTest, SearchByTitleOperation) { 416 TEST_F(GDataWapiOperationsTest, SearchByTitleOperation) {
417 GDataErrorCode result_code = GDATA_OTHER_ERROR; 417 GDataErrorCode result_code = GDATA_OTHER_ERROR;
418 scoped_ptr<ResourceList> result_data; 418 scoped_ptr<ResourceList> result_data;
419 419
420 SearchByTitleOperation* operation = new SearchByTitleOperation( 420 SearchByTitleOperation* operation = new SearchByTitleOperation(
421 &operation_registry_, 421 &operation_registry_,
422 request_context_getter_.get(), 422 request_context_getter_.get(),
423 *url_generator_, 423 *url_generator_,
424 "search-title", 424 "search-title",
425 std::string(), // directory resource id 425 std::string(), // directory resource id
426 CreateComposedCallback( 426 CreateComposedCallback(
427 base::Bind(&test_util::RunAndQuit), 427 base::Bind(&test_util::RunAndQuit),
428 test_util::CreateCopyResultCallback(&result_code, &result_data))); 428 test_util::CreateCopyResultCallback(&result_code, &result_data)));
429 operation->Start(kTestGDataAuthToken, kTestUserAgent, 429 operation->Start(kTestGDataAuthToken, kTestUserAgent,
430 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 430 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
431 MessageLoop::current()->Run(); 431 MessageLoop::current()->Run();
432 432
433 EXPECT_EQ(HTTP_SUCCESS, result_code); 433 EXPECT_EQ(HTTP_SUCCESS, result_code);
434 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 434 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
435 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" 435 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&"
436 "showfolders=true&include-shared=true&max-results=500" 436 "showfolders=true&include-shared=true&max-results=500"
437 "&title=search-title&title-exact=true", 437 "&title=search-title&title-exact=true",
438 http_request_.relative_url); 438 http_request_.relative_url);
439 EXPECT_TRUE(result_data); 439 EXPECT_TRUE(result_data);
440 } 440 }
441 441
442 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_ValidResourceId) { 442 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_ValidResourceId) {
443 GDataErrorCode result_code = GDATA_OTHER_ERROR; 443 GDataErrorCode result_code = GDATA_OTHER_ERROR;
444 scoped_ptr<base::Value> result_data; 444 scoped_ptr<base::Value> result_data;
445 445
446 GetResourceEntryOperation* operation = new GetResourceEntryOperation( 446 GetResourceEntryOperation* operation = new GetResourceEntryOperation(
447 &operation_registry_, 447 &operation_registry_,
448 request_context_getter_.get(), 448 request_context_getter_.get(),
449 *url_generator_, 449 *url_generator_,
450 "file:2_file_resource_id", // resource ID 450 "file:2_file_resource_id", // resource ID
451 CreateComposedCallback( 451 CreateComposedCallback(
452 base::Bind(&test_util::RunAndQuit), 452 base::Bind(&test_util::RunAndQuit),
453 test_util::CreateCopyResultCallback(&result_code, &result_data))); 453 test_util::CreateCopyResultCallback(&result_code, &result_data)));
454 operation->Start(kTestGDataAuthToken, kTestUserAgent, 454 operation->Start(kTestGDataAuthToken, kTestUserAgent,
455 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 455 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
456 MessageLoop::current()->Run(); 456 MessageLoop::current()->Run();
457 457
458 EXPECT_EQ(HTTP_SUCCESS, result_code); 458 EXPECT_EQ(HTTP_SUCCESS, result_code);
459 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 459 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
460 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" 460 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id"
461 "?v=3&alt=json&showroot=true", 461 "?v=3&alt=json&showroot=true",
462 http_request_.relative_url); 462 http_request_.relative_url);
463 EXPECT_TRUE(test_util::VerifyJsonData( 463 EXPECT_TRUE(test_util::VerifyJsonData(
464 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"), 464 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"),
465 result_data.get())); 465 result_data.get()));
466 } 466 }
467 467
468 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_InvalidResourceId) { 468 TEST_F(GDataWapiOperationsTest, GetResourceEntryOperation_InvalidResourceId) {
469 GDataErrorCode result_code = GDATA_OTHER_ERROR; 469 GDataErrorCode result_code = GDATA_OTHER_ERROR;
470 scoped_ptr<base::Value> result_data; 470 scoped_ptr<base::Value> result_data;
471 471
472 GetResourceEntryOperation* operation = new GetResourceEntryOperation( 472 GetResourceEntryOperation* operation = new GetResourceEntryOperation(
473 &operation_registry_, 473 &operation_registry_,
474 request_context_getter_.get(), 474 request_context_getter_.get(),
475 *url_generator_, 475 *url_generator_,
476 "<invalid>", // resource ID 476 "<invalid>", // resource ID
477 CreateComposedCallback( 477 CreateComposedCallback(
478 base::Bind(&test_util::RunAndQuit), 478 base::Bind(&test_util::RunAndQuit),
479 test_util::CreateCopyResultCallback(&result_code, &result_data))); 479 test_util::CreateCopyResultCallback(&result_code, &result_data)));
480 operation->Start(kTestGDataAuthToken, kTestUserAgent, 480 operation->Start(kTestGDataAuthToken, kTestUserAgent,
481 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 481 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
482 MessageLoop::current()->Run(); 482 MessageLoop::current()->Run();
483 483
484 EXPECT_EQ(HTTP_NOT_FOUND, result_code); 484 EXPECT_EQ(HTTP_NOT_FOUND, result_code);
485 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 485 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
486 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json" 486 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json"
487 "&showroot=true", 487 "&showroot=true",
488 http_request_.relative_url); 488 http_request_.relative_url);
489 ASSERT_FALSE(result_data); 489 ASSERT_FALSE(result_data);
490 } 490 }
491 491
492 TEST_F(GDataWapiOperationsTest, GetAccountMetadataOperation) { 492 TEST_F(GDataWapiOperationsTest, GetAccountMetadataOperation) {
493 GDataErrorCode result_code = GDATA_OTHER_ERROR; 493 GDataErrorCode result_code = GDATA_OTHER_ERROR;
494 scoped_ptr<AccountMetadata> result_data; 494 scoped_ptr<AccountMetadata> result_data;
495 495
496 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation( 496 GetAccountMetadataOperation* operation = new GetAccountMetadataOperation(
497 &operation_registry_, 497 &operation_registry_,
498 request_context_getter_.get(), 498 request_context_getter_.get(),
499 *url_generator_, 499 *url_generator_,
500 CreateComposedCallback( 500 CreateComposedCallback(
501 base::Bind(&test_util::RunAndQuit), 501 base::Bind(&test_util::RunAndQuit),
502 test_util::CreateCopyResultCallback(&result_code, &result_data)), 502 test_util::CreateCopyResultCallback(&result_code, &result_data)),
503 true); // Include installed apps. 503 true); // Include installed apps.
504 operation->Start(kTestGDataAuthToken, kTestUserAgent, 504 operation->Start(kTestGDataAuthToken, kTestUserAgent,
505 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 505 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
506 MessageLoop::current()->Run(); 506 MessageLoop::current()->Run();
507 507
508 EXPECT_EQ(HTTP_SUCCESS, result_code); 508 EXPECT_EQ(HTTP_SUCCESS, result_code);
509 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 509 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
510 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true" 510 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true"
511 "&include-installed-apps=true", 511 "&include-installed-apps=true",
512 http_request_.relative_url); 512 http_request_.relative_url);
513 513
514 scoped_ptr<AccountMetadata> expected( 514 scoped_ptr<AccountMetadata> expected(
515 AccountMetadata::CreateFrom( 515 AccountMetadata::CreateFrom(
516 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"))); 516 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json")));
517 517
518 ASSERT_TRUE(result_data.get()); 518 ASSERT_TRUE(result_data.get());
519 EXPECT_EQ(expected->largest_changestamp(), 519 EXPECT_EQ(expected->largest_changestamp(),
(...skipping 19 matching lines...) Expand all
539 *url_generator_, 539 *url_generator_,
540 CreateComposedCallback( 540 CreateComposedCallback(
541 base::Bind(&test_util::RunAndQuit), 541 base::Bind(&test_util::RunAndQuit),
542 test_util::CreateCopyResultCallback(&result_code, &result_data)), 542 test_util::CreateCopyResultCallback(&result_code, &result_data)),
543 false); // Exclude installed apps. 543 false); // Exclude installed apps.
544 operation->Start(kTestGDataAuthToken, kTestUserAgent, 544 operation->Start(kTestGDataAuthToken, kTestUserAgent,
545 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 545 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
546 MessageLoop::current()->Run(); 546 MessageLoop::current()->Run();
547 547
548 EXPECT_EQ(HTTP_SUCCESS, result_code); 548 EXPECT_EQ(HTTP_SUCCESS, result_code);
549 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 549 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
550 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true", 550 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true",
551 http_request_.relative_url); 551 http_request_.relative_url);
552 552
553 scoped_ptr<AccountMetadata> expected( 553 scoped_ptr<AccountMetadata> expected(
554 AccountMetadata::CreateFrom( 554 AccountMetadata::CreateFrom(
555 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"))); 555 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json")));
556 556
557 ASSERT_TRUE(result_data.get()); 557 ASSERT_TRUE(result_data.get());
558 EXPECT_EQ(expected->largest_changestamp(), 558 EXPECT_EQ(expected->largest_changestamp(),
559 result_data->largest_changestamp()); 559 result_data->largest_changestamp());
(...skipping 16 matching lines...) Expand all
576 CreateComposedCallback(base::Bind(&test_util::RunAndQuit), 576 CreateComposedCallback(base::Bind(&test_util::RunAndQuit),
577 test_util::CreateCopyResultCallback(&result_code)), 577 test_util::CreateCopyResultCallback(&result_code)),
578 "file:2_file_resource_id", 578 "file:2_file_resource_id",
579 std::string()); 579 std::string());
580 580
581 operation->Start(kTestGDataAuthToken, kTestUserAgent, 581 operation->Start(kTestGDataAuthToken, kTestUserAgent,
582 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 582 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
583 MessageLoop::current()->Run(); 583 MessageLoop::current()->Run();
584 584
585 EXPECT_EQ(HTTP_SUCCESS, result_code); 585 EXPECT_EQ(HTTP_SUCCESS, result_code);
586 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); 586 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
587 EXPECT_EQ( 587 EXPECT_EQ(
588 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" 588 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json"
589 "&showroot=true", 589 "&showroot=true",
590 http_request_.relative_url); 590 http_request_.relative_url);
591 EXPECT_EQ("*", http_request_.headers["If-Match"]); 591 EXPECT_EQ("*", http_request_.headers["If-Match"]);
592 } 592 }
593 593
594 TEST_F(GDataWapiOperationsTest, DeleteResourceOperationWithETag) { 594 TEST_F(GDataWapiOperationsTest, DeleteResourceOperationWithETag) {
595 GDataErrorCode result_code = GDATA_OTHER_ERROR; 595 GDataErrorCode result_code = GDATA_OTHER_ERROR;
596 596
597 DeleteResourceOperation* operation = new DeleteResourceOperation( 597 DeleteResourceOperation* operation = new DeleteResourceOperation(
598 &operation_registry_, 598 &operation_registry_,
599 request_context_getter_.get(), 599 request_context_getter_.get(),
600 *url_generator_, 600 *url_generator_,
601 CreateComposedCallback( 601 CreateComposedCallback(
602 base::Bind(&test_util::RunAndQuit), 602 base::Bind(&test_util::RunAndQuit),
603 test_util::CreateCopyResultCallback(&result_code)), 603 test_util::CreateCopyResultCallback(&result_code)),
604 "file:2_file_resource_id", 604 "file:2_file_resource_id",
605 "etag"); 605 "etag");
606 606
607 operation->Start(kTestGDataAuthToken, kTestUserAgent, 607 operation->Start(kTestGDataAuthToken, kTestUserAgent,
608 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 608 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
609 MessageLoop::current()->Run(); 609 MessageLoop::current()->Run();
610 610
611 EXPECT_EQ(HTTP_SUCCESS, result_code); 611 EXPECT_EQ(HTTP_SUCCESS, result_code);
612 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); 612 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
613 EXPECT_EQ( 613 EXPECT_EQ(
614 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" 614 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json"
615 "&showroot=true", 615 "&showroot=true",
616 http_request_.relative_url); 616 http_request_.relative_url);
617 EXPECT_EQ("etag", http_request_.headers["If-Match"]); 617 EXPECT_EQ("etag", http_request_.headers["If-Match"]);
618 } 618 }
619 619
620 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) { 620 TEST_F(GDataWapiOperationsTest, CreateDirectoryOperation) {
621 GDataErrorCode result_code = GDATA_OTHER_ERROR; 621 GDataErrorCode result_code = GDATA_OTHER_ERROR;
622 scoped_ptr<base::Value> result_data; 622 scoped_ptr<base::Value> result_data;
623 623
624 // Create "new directory" in the root directory. 624 // Create "new directory" in the root directory.
625 CreateDirectoryOperation* operation = new CreateDirectoryOperation( 625 CreateDirectoryOperation* operation = new CreateDirectoryOperation(
626 &operation_registry_, 626 &operation_registry_,
627 request_context_getter_.get(), 627 request_context_getter_.get(),
628 *url_generator_, 628 *url_generator_,
629 CreateComposedCallback( 629 CreateComposedCallback(
630 base::Bind(&test_util::RunAndQuit), 630 base::Bind(&test_util::RunAndQuit),
631 test_util::CreateCopyResultCallback(&result_code, &result_data)), 631 test_util::CreateCopyResultCallback(&result_code, &result_data)),
632 "folder:root", 632 "folder:root",
633 "new directory"); 633 "new directory");
634 634
635 operation->Start(kTestGDataAuthToken, kTestUserAgent, 635 operation->Start(kTestGDataAuthToken, kTestUserAgent,
636 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 636 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
637 MessageLoop::current()->Run(); 637 MessageLoop::current()->Run();
638 638
639 EXPECT_EQ(HTTP_SUCCESS, result_code); 639 EXPECT_EQ(HTTP_SUCCESS, result_code);
640 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 640 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
641 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" 641 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json"
642 "&showroot=true", 642 "&showroot=true",
643 http_request_.relative_url); 643 http_request_.relative_url);
644 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 644 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
645 645
646 EXPECT_TRUE(http_request_.has_content); 646 EXPECT_TRUE(http_request_.has_content);
647 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 647 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
648 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 648 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
649 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " 649 " <category scheme=\"http://schemas.google.com/g/2005#kind\" "
650 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" 650 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n"
(...skipping 15 matching lines...) Expand all
666 base::Bind(&test_util::RunAndQuit), 666 base::Bind(&test_util::RunAndQuit),
667 test_util::CreateCopyResultCallback(&result_code, &result_data)), 667 test_util::CreateCopyResultCallback(&result_code, &result_data)),
668 "document:5_document_resource_id", // source resource ID 668 "document:5_document_resource_id", // source resource ID
669 "New Document"); 669 "New Document");
670 670
671 operation->Start(kTestGDataAuthToken, kTestUserAgent, 671 operation->Start(kTestGDataAuthToken, kTestUserAgent,
672 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 672 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
673 MessageLoop::current()->Run(); 673 MessageLoop::current()->Run();
674 674
675 EXPECT_EQ(HTTP_SUCCESS, result_code); 675 EXPECT_EQ(HTTP_SUCCESS, result_code);
676 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 676 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
677 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true", 677 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true",
678 http_request_.relative_url); 678 http_request_.relative_url);
679 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 679 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
680 680
681 EXPECT_TRUE(http_request_.has_content); 681 EXPECT_TRUE(http_request_.has_content);
682 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 682 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
683 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 683 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
684 " <id>document:5_document_resource_id</id>\n" 684 " <id>document:5_document_resource_id</id>\n"
685 " <title>New Document</title>\n" 685 " <title>New Document</title>\n"
686 "</entry>\n", 686 "</entry>\n",
(...skipping 12 matching lines...) Expand all
699 base::Bind(&test_util::RunAndQuit), 699 base::Bind(&test_util::RunAndQuit),
700 test_util::CreateCopyResultCallback(&result_code)), 700 test_util::CreateCopyResultCallback(&result_code)),
701 "file:2_file_resource_id", 701 "file:2_file_resource_id",
702 "New File"); 702 "New File");
703 703
704 operation->Start(kTestGDataAuthToken, kTestUserAgent, 704 operation->Start(kTestGDataAuthToken, kTestUserAgent,
705 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 705 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
706 MessageLoop::current()->Run(); 706 MessageLoop::current()->Run();
707 707
708 EXPECT_EQ(HTTP_SUCCESS, result_code); 708 EXPECT_EQ(HTTP_SUCCESS, result_code);
709 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 709 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
710 EXPECT_EQ( 710 EXPECT_EQ(
711 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" 711 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json"
712 "&showroot=true", 712 "&showroot=true",
713 http_request_.relative_url); 713 http_request_.relative_url);
714 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 714 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
715 EXPECT_EQ("*", http_request_.headers["If-Match"]); 715 EXPECT_EQ("*", http_request_.headers["If-Match"]);
716 716
717 EXPECT_TRUE(http_request_.has_content); 717 EXPECT_TRUE(http_request_.has_content);
718 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 718 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
719 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 719 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
(...skipping 15 matching lines...) Expand all
735 base::Bind(&test_util::RunAndQuit), 735 base::Bind(&test_util::RunAndQuit),
736 test_util::CreateCopyResultCallback(&result_code, &result_data)), 736 test_util::CreateCopyResultCallback(&result_code, &result_data)),
737 "file:2_file_resource_id", 737 "file:2_file_resource_id",
738 "APP_ID"); 738 "APP_ID");
739 739
740 operation->Start(kTestGDataAuthToken, kTestUserAgent, 740 operation->Start(kTestGDataAuthToken, kTestUserAgent,
741 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 741 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
742 MessageLoop::current()->Run(); 742 MessageLoop::current()->Run();
743 743
744 EXPECT_EQ(HTTP_SUCCESS, result_code); 744 EXPECT_EQ(HTTP_SUCCESS, result_code);
745 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 745 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
746 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" 746 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id"
747 "?v=3&alt=json&showroot=true", 747 "?v=3&alt=json&showroot=true",
748 http_request_.relative_url); 748 http_request_.relative_url);
749 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 749 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
750 EXPECT_EQ("*", http_request_.headers["If-Match"]); 750 EXPECT_EQ("*", http_request_.headers["If-Match"]);
751 751
752 EXPECT_TRUE(http_request_.has_content); 752 EXPECT_TRUE(http_request_.has_content);
753 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 753 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
754 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 754 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
755 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 755 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
(...skipping 15 matching lines...) Expand all
771 base::Bind(&test_util::RunAndQuit), 771 base::Bind(&test_util::RunAndQuit),
772 test_util::CreateCopyResultCallback(&result_code, &result_data)), 772 test_util::CreateCopyResultCallback(&result_code, &result_data)),
773 "invalid_resource_id", 773 "invalid_resource_id",
774 "APP_ID"); 774 "APP_ID");
775 775
776 operation->Start(kTestGDataAuthToken, kTestUserAgent, 776 operation->Start(kTestGDataAuthToken, kTestUserAgent,
777 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 777 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
778 MessageLoop::current()->Run(); 778 MessageLoop::current()->Run();
779 779
780 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); 780 EXPECT_EQ(GDATA_PARSE_ERROR, result_code);
781 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 781 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
782 EXPECT_EQ("/feeds/default/private/full/invalid_resource_id" 782 EXPECT_EQ("/feeds/default/private/full/invalid_resource_id"
783 "?v=3&alt=json&showroot=true", 783 "?v=3&alt=json&showroot=true",
784 http_request_.relative_url); 784 http_request_.relative_url);
785 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 785 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
786 EXPECT_EQ("*", http_request_.headers["If-Match"]); 786 EXPECT_EQ("*", http_request_.headers["If-Match"]);
787 787
788 EXPECT_TRUE(http_request_.has_content); 788 EXPECT_TRUE(http_request_.has_content);
789 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 789 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
790 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 790 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
791 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 791 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
(...skipping 15 matching lines...) Expand all
807 base::Bind(&test_util::RunAndQuit), 807 base::Bind(&test_util::RunAndQuit),
808 test_util::CreateCopyResultCallback(&result_code)), 808 test_util::CreateCopyResultCallback(&result_code)),
809 "folder:root", 809 "folder:root",
810 "file:2_file_resource_id"); 810 "file:2_file_resource_id");
811 811
812 operation->Start(kTestGDataAuthToken, kTestUserAgent, 812 operation->Start(kTestGDataAuthToken, kTestUserAgent,
813 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 813 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
814 MessageLoop::current()->Run(); 814 MessageLoop::current()->Run();
815 815
816 EXPECT_EQ(HTTP_SUCCESS, result_code); 816 EXPECT_EQ(HTTP_SUCCESS, result_code);
817 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 817 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
818 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" 818 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json"
819 "&showroot=true", 819 "&showroot=true",
820 http_request_.relative_url); 820 http_request_.relative_url);
821 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 821 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
822 822
823 EXPECT_TRUE(http_request_.has_content); 823 EXPECT_TRUE(http_request_.has_content);
824 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 824 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
825 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 825 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
826 " <id>http://127.0.0.1:8040/feeds/default/private/full/" 826 " <id>http://127.0.0.1:8040/feeds/default/private/full/"
827 "file%3A2_file_resource_id</id>\n" 827 "file%3A2_file_resource_id</id>\n"
(...skipping 15 matching lines...) Expand all
843 test_util::CreateCopyResultCallback(&result_code)), 843 test_util::CreateCopyResultCallback(&result_code)),
844 "folder:root", 844 "folder:root",
845 "file:2_file_resource_id"); 845 "file:2_file_resource_id");
846 846
847 operation->Start(kTestGDataAuthToken, kTestUserAgent, 847 operation->Start(kTestGDataAuthToken, kTestUserAgent,
848 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 848 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
849 MessageLoop::current()->Run(); 849 MessageLoop::current()->Run();
850 850
851 EXPECT_EQ(HTTP_SUCCESS, result_code); 851 EXPECT_EQ(HTTP_SUCCESS, result_code);
852 // DELETE method should be used, without the body content. 852 // DELETE method should be used, without the body content.
853 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); 853 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
854 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/" 854 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/"
855 "file%3A2_file_resource_id?v=3&alt=json&showroot=true", 855 "file%3A2_file_resource_id?v=3&alt=json&showroot=true",
856 http_request_.relative_url); 856 http_request_.relative_url);
857 EXPECT_EQ("*", http_request_.headers["If-Match"]); 857 EXPECT_EQ("*", http_request_.headers["If-Match"]);
858 EXPECT_FALSE(http_request_.has_content); 858 EXPECT_FALSE(http_request_.has_content);
859 } 859 }
860 860
861 // This test exercises InitiateUploadNewFileOperation and 861 // This test exercises InitiateUploadNewFileOperation and
862 // ResumeUploadOperation for a scenario of uploading a new file. 862 // ResumeUploadOperation for a scenario of uploading a new file.
863 TEST_F(GDataWapiOperationsTest, UploadNewFile) { 863 TEST_F(GDataWapiOperationsTest, UploadNewFile) {
(...skipping 16 matching lines...) Expand all
880 "folder:id", 880 "folder:id",
881 "New file"); 881 "New file");
882 882
883 initiate_operation->Start( 883 initiate_operation->Start(
884 kTestGDataAuthToken, kTestUserAgent, 884 kTestGDataAuthToken, kTestUserAgent,
885 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 885 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
886 MessageLoop::current()->Run(); 886 MessageLoop::current()->Run();
887 887
888 EXPECT_EQ(HTTP_SUCCESS, result_code); 888 EXPECT_EQ(HTTP_SUCCESS, result_code);
889 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); 889 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url);
890 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 890 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
891 // convert=false should be passed as files should be uploaded as-is. 891 // convert=false should be passed as files should be uploaded as-is.
892 EXPECT_EQ( 892 EXPECT_EQ(
893 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" 893 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents"
894 "?convert=false&v=3&alt=json&showroot=true", 894 "?convert=false&v=3&alt=json&showroot=true",
895 http_request_.relative_url); 895 http_request_.relative_url);
896 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 896 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
897 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 897 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
898 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 898 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
899 http_request_.headers["X-Upload-Content-Length"]); 899 http_request_.headers["X-Upload-Content-Length"]);
900 900
(...skipping 26 matching lines...) Expand all
927 kUploadContent.size(), // content_length, 927 kUploadContent.size(), // content_length,
928 "text/plain", // content_type 928 "text/plain", // content_type
929 buffer); 929 buffer);
930 930
931 resume_operation->Start( 931 resume_operation->Start(
932 kTestGDataAuthToken, kTestUserAgent, 932 kTestGDataAuthToken, kTestUserAgent,
933 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 933 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
934 MessageLoop::current()->Run(); 934 MessageLoop::current()->Run();
935 935
936 // METHOD_PUT should be used to upload data. 936 // METHOD_PUT should be used to upload data.
937 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 937 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
938 // Request should go to the upload URL. 938 // Request should go to the upload URL.
939 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 939 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
940 // Content-Range header should be added. 940 // Content-Range header should be added.
941 EXPECT_EQ("bytes 0-" + 941 EXPECT_EQ("bytes 0-" +
942 base::Int64ToString(kUploadContent.size() -1) + "/" + 942 base::Int64ToString(kUploadContent.size() -1) + "/" +
943 base::Int64ToString(kUploadContent.size()), 943 base::Int64ToString(kUploadContent.size()),
944 http_request_.headers["Content-Range"]); 944 http_request_.headers["Content-Range"]);
945 // The upload content should be set in the HTTP request. 945 // The upload content should be set in the HTTP request.
946 EXPECT_TRUE(http_request_.has_content); 946 EXPECT_TRUE(http_request_.has_content);
947 EXPECT_EQ(kUploadContent, http_request_.content); 947 EXPECT_EQ(kUploadContent, http_request_.content);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 "folder:id", 982 "folder:id",
983 "New file"); 983 "New file");
984 984
985 initiate_operation->Start( 985 initiate_operation->Start(
986 kTestGDataAuthToken, kTestUserAgent, 986 kTestGDataAuthToken, kTestUserAgent,
987 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 987 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
988 MessageLoop::current()->Run(); 988 MessageLoop::current()->Run();
989 989
990 EXPECT_EQ(HTTP_SUCCESS, result_code); 990 EXPECT_EQ(HTTP_SUCCESS, result_code);
991 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); 991 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url);
992 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 992 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
993 // convert=false should be passed as files should be uploaded as-is. 993 // convert=false should be passed as files should be uploaded as-is.
994 EXPECT_EQ( 994 EXPECT_EQ(
995 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" 995 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents"
996 "?convert=false&v=3&alt=json&showroot=true", 996 "?convert=false&v=3&alt=json&showroot=true",
997 http_request_.relative_url); 997 http_request_.relative_url);
998 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 998 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
999 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 999 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
1000 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1000 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1001 http_request_.headers["X-Upload-Content-Length"]); 1001 http_request_.headers["X-Upload-Content-Length"]);
1002 1002
(...skipping 23 matching lines...) Expand all
1026 UPLOAD_NEW_FILE, 1026 UPLOAD_NEW_FILE,
1027 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), 1027 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"),
1028 upload_url, 1028 upload_url,
1029 kUploadContent.size()); 1029 kUploadContent.size());
1030 get_upload_status_operation->Start( 1030 get_upload_status_operation->Start(
1031 kTestGDataAuthToken, kTestUserAgent, 1031 kTestGDataAuthToken, kTestUserAgent,
1032 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1032 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1033 MessageLoop::current()->Run(); 1033 MessageLoop::current()->Run();
1034 1034
1035 // METHOD_PUT should be used to upload data. 1035 // METHOD_PUT should be used to upload data.
1036 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1036 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1037 // Request should go to the upload URL. 1037 // Request should go to the upload URL.
1038 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1038 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1039 // Content-Range header should be added. 1039 // Content-Range header should be added.
1040 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), 1040 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()),
1041 http_request_.headers["Content-Range"]); 1041 http_request_.headers["Content-Range"]);
1042 EXPECT_TRUE(http_request_.has_content); 1042 EXPECT_TRUE(http_request_.has_content);
1043 EXPECT_TRUE(http_request_.content.empty()); 1043 EXPECT_TRUE(http_request_.content.empty());
1044 1044
1045 // Check the response. 1045 // Check the response.
1046 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1046 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 kUploadContent.size(), // content_length, 1082 kUploadContent.size(), // content_length,
1083 "text/plain", // content_type 1083 "text/plain", // content_type
1084 buffer); 1084 buffer);
1085 1085
1086 resume_operation->Start( 1086 resume_operation->Start(
1087 kTestGDataAuthToken, kTestUserAgent, 1087 kTestGDataAuthToken, kTestUserAgent,
1088 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1088 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1089 MessageLoop::current()->Run(); 1089 MessageLoop::current()->Run();
1090 1090
1091 // METHOD_PUT should be used to upload data. 1091 // METHOD_PUT should be used to upload data.
1092 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1092 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1093 // Request should go to the upload URL. 1093 // Request should go to the upload URL.
1094 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1094 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1095 // Content-Range header should be added. 1095 // Content-Range header should be added.
1096 EXPECT_EQ("bytes " + 1096 EXPECT_EQ("bytes " +
1097 base::Int64ToString(start_position) + "-" + 1097 base::Int64ToString(start_position) + "-" +
1098 base::Int64ToString(end_position - 1) + "/" + 1098 base::Int64ToString(end_position - 1) + "/" +
1099 base::Int64ToString(kUploadContent.size()), 1099 base::Int64ToString(kUploadContent.size()),
1100 http_request_.headers["Content-Range"]); 1100 http_request_.headers["Content-Range"]);
1101 // The upload content should be set in the HTTP request. 1101 // The upload content should be set in the HTTP request.
1102 EXPECT_TRUE(http_request_.has_content); 1102 EXPECT_TRUE(http_request_.has_content);
(...skipping 26 matching lines...) Expand all
1129 UPLOAD_NEW_FILE, 1129 UPLOAD_NEW_FILE,
1130 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), 1130 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"),
1131 upload_url, 1131 upload_url,
1132 kUploadContent.size()); 1132 kUploadContent.size());
1133 get_upload_status_operation->Start( 1133 get_upload_status_operation->Start(
1134 kTestGDataAuthToken, kTestUserAgent, 1134 kTestGDataAuthToken, kTestUserAgent,
1135 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1135 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1136 MessageLoop::current()->Run(); 1136 MessageLoop::current()->Run();
1137 1137
1138 // METHOD_PUT should be used to upload data. 1138 // METHOD_PUT should be used to upload data.
1139 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1139 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1140 // Request should go to the upload URL. 1140 // Request should go to the upload URL.
1141 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1141 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1142 // Content-Range header should be added. 1142 // Content-Range header should be added.
1143 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), 1143 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()),
1144 http_request_.headers["Content-Range"]); 1144 http_request_.headers["Content-Range"]);
1145 EXPECT_TRUE(http_request_.has_content); 1145 EXPECT_TRUE(http_request_.has_content);
1146 EXPECT_TRUE(http_request_.content.empty()); 1146 EXPECT_TRUE(http_request_.content.empty());
1147 1147
1148 // Check the response. 1148 // Check the response.
1149 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1149 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
(...skipping 30 matching lines...) Expand all
1180 "folder:id", 1180 "folder:id",
1181 "New file"); 1181 "New file");
1182 1182
1183 initiate_operation->Start( 1183 initiate_operation->Start(
1184 kTestGDataAuthToken, kTestUserAgent, 1184 kTestGDataAuthToken, kTestUserAgent,
1185 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1185 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1186 MessageLoop::current()->Run(); 1186 MessageLoop::current()->Run();
1187 1187
1188 EXPECT_EQ(HTTP_SUCCESS, result_code); 1188 EXPECT_EQ(HTTP_SUCCESS, result_code);
1189 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); 1189 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url);
1190 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 1190 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
1191 // convert=false should be passed as files should be uploaded as-is. 1191 // convert=false should be passed as files should be uploaded as-is.
1192 EXPECT_EQ( 1192 EXPECT_EQ(
1193 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" 1193 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents"
1194 "?convert=false&v=3&alt=json&showroot=true", 1194 "?convert=false&v=3&alt=json&showroot=true",
1195 http_request_.relative_url); 1195 http_request_.relative_url);
1196 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1196 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1197 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 1197 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
1198 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1198 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1199 http_request_.headers["X-Upload-Content-Length"]); 1199 http_request_.headers["X-Upload-Content-Length"]);
1200 1200
(...skipping 26 matching lines...) Expand all
1227 kUploadContent.size(), // content_length, 1227 kUploadContent.size(), // content_length,
1228 "text/plain", // content_type 1228 "text/plain", // content_type
1229 buffer); 1229 buffer);
1230 1230
1231 resume_operation->Start( 1231 resume_operation->Start(
1232 kTestGDataAuthToken, kTestUserAgent, 1232 kTestGDataAuthToken, kTestUserAgent,
1233 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1233 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1234 MessageLoop::current()->Run(); 1234 MessageLoop::current()->Run();
1235 1235
1236 // METHOD_PUT should be used to upload data. 1236 // METHOD_PUT should be used to upload data.
1237 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1237 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1238 // Request should go to the upload URL. 1238 // Request should go to the upload URL.
1239 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1239 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1240 // Content-Range header should not exit if the content is empty. 1240 // Content-Range header should not exit if the content is empty.
1241 // We should not generate the header with an invalid value "bytes 0--1/0". 1241 // We should not generate the header with an invalid value "bytes 0--1/0".
1242 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); 1242 EXPECT_EQ(0U, http_request_.headers.count("Content-Range"));
1243 // The upload content should be set in the HTTP request. 1243 // The upload content should be set in the HTTP request.
1244 EXPECT_TRUE(http_request_.has_content); 1244 EXPECT_TRUE(http_request_.has_content);
1245 EXPECT_EQ(kUploadContent, http_request_.content); 1245 EXPECT_EQ(kUploadContent, http_request_.content);
1246 1246
1247 // Check the response. 1247 // Check the response.
(...skipping 26 matching lines...) Expand all
1274 std::string() /* etag */); 1274 std::string() /* etag */);
1275 1275
1276 initiate_operation->Start( 1276 initiate_operation->Start(
1277 kTestGDataAuthToken, kTestUserAgent, 1277 kTestGDataAuthToken, kTestUserAgent,
1278 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1278 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1279 MessageLoop::current()->Run(); 1279 MessageLoop::current()->Run();
1280 1280
1281 EXPECT_EQ(HTTP_SUCCESS, result_code); 1281 EXPECT_EQ(HTTP_SUCCESS, result_code);
1282 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); 1282 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url);
1283 // For updating an existing file, METHOD_PUT should be used. 1283 // For updating an existing file, METHOD_PUT should be used.
1284 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1284 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1285 // convert=false should be passed as files should be uploaded as-is. 1285 // convert=false should be passed as files should be uploaded as-is.
1286 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" 1286 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo"
1287 "?convert=false&v=3&alt=json&showroot=true", 1287 "?convert=false&v=3&alt=json&showroot=true",
1288 http_request_.relative_url); 1288 http_request_.relative_url);
1289 // Even though the body is empty, the content type should be set to 1289 // Even though the body is empty, the content type should be set to
1290 // "text/plain". 1290 // "text/plain".
1291 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); 1291 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]);
1292 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1292 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1293 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1293 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1294 http_request_.headers["X-Upload-Content-Length"]); 1294 http_request_.headers["X-Upload-Content-Length"]);
(...skipping 24 matching lines...) Expand all
1319 kUploadContent.size(), // content_length, 1319 kUploadContent.size(), // content_length,
1320 "text/plain", // content_type 1320 "text/plain", // content_type
1321 buffer); 1321 buffer);
1322 1322
1323 resume_operation->Start( 1323 resume_operation->Start(
1324 kTestGDataAuthToken, kTestUserAgent, 1324 kTestGDataAuthToken, kTestUserAgent,
1325 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1325 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1326 MessageLoop::current()->Run(); 1326 MessageLoop::current()->Run();
1327 1327
1328 // METHOD_PUT should be used to upload data. 1328 // METHOD_PUT should be used to upload data.
1329 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1329 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1330 // Request should go to the upload URL. 1330 // Request should go to the upload URL.
1331 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1331 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1332 // Content-Range header should be added. 1332 // Content-Range header should be added.
1333 EXPECT_EQ("bytes 0-" + 1333 EXPECT_EQ("bytes 0-" +
1334 base::Int64ToString(kUploadContent.size() -1) + "/" + 1334 base::Int64ToString(kUploadContent.size() -1) + "/" +
1335 base::Int64ToString(kUploadContent.size()), 1335 base::Int64ToString(kUploadContent.size()),
1336 http_request_.headers["Content-Range"]); 1336 http_request_.headers["Content-Range"]);
1337 // The upload content should be set in the HTTP request. 1337 // The upload content should be set in the HTTP request.
1338 EXPECT_TRUE(http_request_.has_content); 1338 EXPECT_TRUE(http_request_.has_content);
1339 EXPECT_EQ(kUploadContent, http_request_.content); 1339 EXPECT_EQ(kUploadContent, http_request_.content);
(...skipping 28 matching lines...) Expand all
1368 kTestETag); 1368 kTestETag);
1369 1369
1370 initiate_operation->Start( 1370 initiate_operation->Start(
1371 kTestGDataAuthToken, kTestUserAgent, 1371 kTestGDataAuthToken, kTestUserAgent,
1372 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1372 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1373 MessageLoop::current()->Run(); 1373 MessageLoop::current()->Run();
1374 1374
1375 EXPECT_EQ(HTTP_SUCCESS, result_code); 1375 EXPECT_EQ(HTTP_SUCCESS, result_code);
1376 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); 1376 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url);
1377 // For updating an existing file, METHOD_PUT should be used. 1377 // For updating an existing file, METHOD_PUT should be used.
1378 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1378 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1379 // convert=false should be passed as files should be uploaded as-is. 1379 // convert=false should be passed as files should be uploaded as-is.
1380 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" 1380 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo"
1381 "?convert=false&v=3&alt=json&showroot=true", 1381 "?convert=false&v=3&alt=json&showroot=true",
1382 http_request_.relative_url); 1382 http_request_.relative_url);
1383 // Even though the body is empty, the content type should be set to 1383 // Even though the body is empty, the content type should be set to
1384 // "text/plain". 1384 // "text/plain".
1385 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); 1385 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]);
1386 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1386 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1387 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1387 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1388 http_request_.headers["X-Upload-Content-Length"]); 1388 http_request_.headers["X-Upload-Content-Length"]);
(...skipping 24 matching lines...) Expand all
1413 kUploadContent.size(), // content_length, 1413 kUploadContent.size(), // content_length,
1414 "text/plain", // content_type 1414 "text/plain", // content_type
1415 buffer); 1415 buffer);
1416 1416
1417 resume_operation->Start( 1417 resume_operation->Start(
1418 kTestGDataAuthToken, kTestUserAgent, 1418 kTestGDataAuthToken, kTestUserAgent,
1419 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1419 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1420 MessageLoop::current()->Run(); 1420 MessageLoop::current()->Run();
1421 1421
1422 // METHOD_PUT should be used to upload data. 1422 // METHOD_PUT should be used to upload data.
1423 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1423 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1424 // Request should go to the upload URL. 1424 // Request should go to the upload URL.
1425 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1425 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1426 // Content-Range header should be added. 1426 // Content-Range header should be added.
1427 EXPECT_EQ("bytes 0-" + 1427 EXPECT_EQ("bytes 0-" +
1428 base::Int64ToString(kUploadContent.size() -1) + "/" + 1428 base::Int64ToString(kUploadContent.size() -1) + "/" +
1429 base::Int64ToString(kUploadContent.size()), 1429 base::Int64ToString(kUploadContent.size()),
1430 http_request_.headers["Content-Range"]); 1430 http_request_.headers["Content-Range"]);
1431 // The upload content should be set in the HTTP request. 1431 // The upload content should be set in the HTTP request.
1432 EXPECT_TRUE(http_request_.has_content); 1432 EXPECT_TRUE(http_request_.has_content);
1433 EXPECT_EQ(kUploadContent, http_request_.content); 1433 EXPECT_EQ(kUploadContent, http_request_.content);
(...skipping 27 matching lines...) Expand all
1461 "file:foo", 1461 "file:foo",
1462 kWrongETag); 1462 kWrongETag);
1463 1463
1464 initiate_operation->Start( 1464 initiate_operation->Start(
1465 kTestGDataAuthToken, kTestUserAgent, 1465 kTestGDataAuthToken, kTestUserAgent,
1466 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 1466 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
1467 MessageLoop::current()->Run(); 1467 MessageLoop::current()->Run();
1468 1468
1469 EXPECT_EQ(HTTP_PRECONDITION, result_code); 1469 EXPECT_EQ(HTTP_PRECONDITION, result_code);
1470 // For updating an existing file, METHOD_PUT should be used. 1470 // For updating an existing file, METHOD_PUT should be used.
1471 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1471 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1472 // convert=false should be passed as files should be uploaded as-is. 1472 // convert=false should be passed as files should be uploaded as-is.
1473 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" 1473 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo"
1474 "?convert=false&v=3&alt=json&showroot=true", 1474 "?convert=false&v=3&alt=json&showroot=true",
1475 http_request_.relative_url); 1475 http_request_.relative_url);
1476 // Even though the body is empty, the content type should be set to 1476 // Even though the body is empty, the content type should be set to
1477 // "text/plain". 1477 // "text/plain".
1478 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); 1478 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]);
1479 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1479 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1480 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1480 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1481 http_request_.headers["X-Upload-Content-Length"]); 1481 http_request_.headers["X-Upload-Content-Length"]);
1482 // For updating an existing file, an empty body should be attached (PUT 1482 // For updating an existing file, an empty body should be attached (PUT
1483 // requires a body) 1483 // requires a body)
1484 EXPECT_TRUE(http_request_.has_content); 1484 EXPECT_TRUE(http_request_.has_content);
1485 EXPECT_EQ("", http_request_.content); 1485 EXPECT_EQ("", http_request_.content);
1486 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); 1486 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]);
1487 } 1487 }
1488 1488
1489 } // namespace google_apis 1489 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_operations_unittest.cc ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698