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

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

Issue 12387021: Move the responsibility to convert from JSON to FileResource into drive_api_operations. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor fix to address review comments. Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/google_apis/drive_api_operations.h" 9 #include "chrome/browser/google_apis/drive_api_operations.h"
10 #include "chrome/browser/google_apis/drive_api_parser.h" 10 #include "chrome/browser/google_apis/drive_api_parser.h"
(...skipping 25 matching lines...) Expand all
36 void CopyResultsFromGetAboutResourceCallbackAndQuit( 36 void CopyResultsFromGetAboutResourceCallbackAndQuit(
37 GDataErrorCode* error_out, 37 GDataErrorCode* error_out,
38 scoped_ptr<AboutResource>* about_resource_out, 38 scoped_ptr<AboutResource>* about_resource_out,
39 const GDataErrorCode error_in, 39 const GDataErrorCode error_in,
40 scoped_ptr<AboutResource> about_resource_in) { 40 scoped_ptr<AboutResource> about_resource_in) {
41 *error_out = error_in; 41 *error_out = error_in;
42 *about_resource_out = about_resource_in.Pass(); 42 *about_resource_out = about_resource_in.Pass();
43 MessageLoop::current()->Quit(); 43 MessageLoop::current()->Quit();
44 } 44 }
45 45
46 void CopyResultsFromFileResourceCallbackAndQuit(
47 GDataErrorCode* error_out,
48 scoped_ptr<FileResource>* file_resource_out,
49 const GDataErrorCode error_in,
50 scoped_ptr<FileResource> file_resource_in) {
51 *error_out = error_in;
52 *file_resource_out = file_resource_in.Pass();
53 MessageLoop::current()->Quit();
54 }
55
46 } // namespace 56 } // namespace
47 57
48 class DriveApiOperationsTest : public testing::Test { 58 class DriveApiOperationsTest : public testing::Test {
49 public: 59 public:
50 DriveApiOperationsTest() 60 DriveApiOperationsTest()
51 : ui_thread_(content::BrowserThread::UI, &message_loop_), 61 : ui_thread_(content::BrowserThread::UI, &message_loop_),
52 file_thread_(content::BrowserThread::FILE), 62 file_thread_(content::BrowserThread::FILE),
53 io_thread_(content::BrowserThread::IO) { 63 io_thread_(content::BrowserThread::IO) {
54 } 64 }
55 65
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 232 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
223 EXPECT_FALSE(feed_data.get()); 233 EXPECT_FALSE(feed_data.get());
224 } 234 }
225 235
226 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) { 236 TEST_F(DriveApiOperationsTest, CreateDirectoryOperation) {
227 // Set an expected data file containing the directory's entry data. 237 // Set an expected data file containing the directory's entry data.
228 expected_data_file_path_ = 238 expected_data_file_path_ =
229 test_util::GetTestFilePath("drive/directory_entry.json"); 239 test_util::GetTestFilePath("drive/directory_entry.json");
230 240
231 GDataErrorCode error = GDATA_OTHER_ERROR; 241 GDataErrorCode error = GDATA_OTHER_ERROR;
232 scoped_ptr<base::Value> feed_data; 242 scoped_ptr<FileResource> feed_data;
233 243
234 // Create "new directory" in the root directory. 244 // Create "new directory" in the root directory.
235 drive::CreateDirectoryOperation* operation = 245 drive::CreateDirectoryOperation* operation =
236 new drive::CreateDirectoryOperation( 246 new drive::CreateDirectoryOperation(
237 &operation_registry_, 247 &operation_registry_,
238 request_context_getter_.get(), 248 request_context_getter_.get(),
239 *url_generator_, 249 *url_generator_,
240 "root", 250 "root",
241 "new directory", 251 "new directory",
242 base::Bind(&test_util::CopyResultsFromGetDataCallbackAndQuit, 252 base::Bind(&CopyResultsFromFileResourceCallbackAndQuit,
243 &error, &feed_data)); 253 &error, &feed_data));
244 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, 254 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
245 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 255 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
246 MessageLoop::current()->Run(); 256 MessageLoop::current()->Run();
247 257
248 EXPECT_EQ(HTTP_SUCCESS, error); 258 EXPECT_EQ(HTTP_SUCCESS, error);
249 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); 259 EXPECT_EQ(test_server::METHOD_POST, http_request_.method);
250 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); 260 EXPECT_EQ("/drive/v2/files", http_request_.relative_url);
251 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 261 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
252 262
253 EXPECT_TRUE(http_request_.has_content); 263 EXPECT_TRUE(http_request_.has_content);
254 264
255 EXPECT_EQ("{\"mimeType\":\"application/vnd.google-apps.folder\"," 265 scoped_ptr<FileResource> expected(
256 "\"parents\":[{\"id\":\"root\"}]," 266 FileResource::CreateFrom(
257 "\"title\":\"new directory\"}", 267 *test_util::LoadJSONFile("drive/directory_entry.json")));
258 http_request_.content); 268
269 // Sanity check.
270 ASSERT_TRUE(feed_data.get());
271
272 EXPECT_EQ(expected->file_id(), feed_data->file_id());
273 EXPECT_EQ(expected->title(), feed_data->title());
274 EXPECT_EQ(expected->mime_type(), feed_data->mime_type());
275 EXPECT_EQ(expected->parents().size(), feed_data->parents().size());
259 } 276 }
260 277
261 TEST_F(DriveApiOperationsTest, RenameResourceOperation) { 278 TEST_F(DriveApiOperationsTest, RenameResourceOperation) {
262 // Set an expected data file containing the directory's entry data. 279 // Set an expected data file containing the directory's entry data.
263 // It'd be returned if we rename a directory. 280 // It'd be returned if we rename a directory.
264 expected_data_file_path_ = 281 expected_data_file_path_ =
265 test_util::GetTestFilePath("drive/directory_entry.json"); 282 test_util::GetTestFilePath("drive/directory_entry.json");
266 283
267 GDataErrorCode error = GDATA_OTHER_ERROR; 284 GDataErrorCode error = GDATA_OTHER_ERROR;
268 285
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 MessageLoop::current()->Run(); 385 MessageLoop::current()->Run();
369 386
370 EXPECT_EQ(HTTP_NO_CONTENT, error); 387 EXPECT_EQ(HTTP_NO_CONTENT, error);
371 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method); 388 EXPECT_EQ(test_server::METHOD_DELETE, http_request_.method);
372 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id", 389 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id",
373 http_request_.relative_url); 390 http_request_.relative_url);
374 EXPECT_FALSE(http_request_.has_content); 391 EXPECT_FALSE(http_request_.has_content);
375 } 392 }
376 393
377 } // namespace google_apis 394 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_operations.cc ('k') | chrome/browser/google_apis/drive_api_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698