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

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

Issue 12785003: Implement generic CreateCopyResultCallback and RunAndQuit. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update 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
« no previous file with comments | « no previous file | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/google_apis/drive_api_operations.h" 10 #include "chrome/browser/google_apis/drive_api_operations.h"
11 #include "chrome/browser/google_apis/drive_api_parser.h" 11 #include "chrome/browser/google_apis/drive_api_parser.h"
12 #include "chrome/browser/google_apis/drive_api_url_generator.h" 12 #include "chrome/browser/google_apis/drive_api_url_generator.h"
13 #include "chrome/browser/google_apis/operation_registry.h" 13 #include "chrome/browser/google_apis/operation_registry.h"
14 #include "chrome/browser/google_apis/task_util.h"
14 #include "chrome/browser/google_apis/test_server/http_request.h" 15 #include "chrome/browser/google_apis/test_server/http_request.h"
15 #include "chrome/browser/google_apis/test_server/http_response.h" 16 #include "chrome/browser/google_apis/test_server/http_response.h"
16 #include "chrome/browser/google_apis/test_server/http_server.h" 17 #include "chrome/browser/google_apis/test_server/http_server.h"
17 #include "chrome/browser/google_apis/test_util.h" 18 #include "chrome/browser/google_apis/test_util.h"
18 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
19 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace google_apis { 23 namespace google_apis {
23 24
24 namespace { 25 namespace {
25 26
26 const char kTestDriveApiAuthToken[] = "testtoken"; 27 const char kTestDriveApiAuthToken[] = "testtoken";
27 const char kTestETag[] = "test_etag"; 28 const char kTestETag[] = "test_etag";
28 const char kTestUserAgent[] = "test-user-agent"; 29 const char kTestUserAgent[] = "test-user-agent";
29 30
30 const char kTestChildrenResponse[] = 31 const char kTestChildrenResponse[] =
31 "{\n" 32 "{\n"
32 "\"kind\": \"drive#childReference\",\n" 33 "\"kind\": \"drive#childReference\",\n"
33 "\"id\": \"resource_id\",\n" 34 "\"id\": \"resource_id\",\n"
34 "\"selfLink\": \"self_link\",\n" 35 "\"selfLink\": \"self_link\",\n"
35 "\"childLink\": \"child_link\",\n" 36 "\"childLink\": \"child_link\",\n"
36 "}\n"; 37 "}\n";
37 38
38 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path"; 39 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path";
39 const char kTestUploadNewFilePath[] = "/upload/newfile/path"; 40 const char kTestUploadNewFilePath[] = "/upload/newfile/path";
40 41
41 void CopyResultsFromGetAboutResourceCallbackAndQuit(
42 GDataErrorCode* error_out,
43 scoped_ptr<AboutResource>* about_resource_out,
44 const GDataErrorCode error_in,
45 scoped_ptr<AboutResource> about_resource_in) {
46 *error_out = error_in;
47 *about_resource_out = about_resource_in.Pass();
48 MessageLoop::current()->Quit();
49 }
50
51 void CopyResultsFromFileResourceCallbackAndQuit( 42 void CopyResultsFromFileResourceCallbackAndQuit(
52 GDataErrorCode* error_out, 43 GDataErrorCode* error_out,
53 scoped_ptr<FileResource>* file_resource_out, 44 scoped_ptr<FileResource>* file_resource_out,
54 const GDataErrorCode error_in, 45 const GDataErrorCode error_in,
55 scoped_ptr<FileResource> file_resource_in) { 46 scoped_ptr<FileResource> file_resource_in) {
56 *error_out = error_in; 47 *error_out = error_in;
57 *file_resource_out = file_resource_in.Pass(); 48 *file_resource_out = file_resource_in.Pass();
58 MessageLoop::current()->Quit(); 49 MessageLoop::current()->Quit();
59 } 50 }
60 51
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 expected_data_file_path_ = test_util::GetTestFilePath( 323 expected_data_file_path_ = test_util::GetTestFilePath(
333 "chromeos/drive/about.json"); 324 "chromeos/drive/about.json");
334 325
335 GDataErrorCode error = GDATA_OTHER_ERROR; 326 GDataErrorCode error = GDATA_OTHER_ERROR;
336 scoped_ptr<AboutResource> feed_data; 327 scoped_ptr<AboutResource> feed_data;
337 328
338 GetAboutOperation* operation = new GetAboutOperation( 329 GetAboutOperation* operation = new GetAboutOperation(
339 &operation_registry_, 330 &operation_registry_,
340 request_context_getter_.get(), 331 request_context_getter_.get(),
341 *url_generator_, 332 *url_generator_,
342 base::Bind(&CopyResultsFromGetAboutResourceCallbackAndQuit, 333 CreateComposedCallback(
343 &error, &feed_data)); 334 base::Bind(&test_util::RunAndQuit),
335 test_util::CreateCopyResultCallback(&error, &feed_data)));
344 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, 336 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
345 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 337 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
346 MessageLoop::current()->Run(); 338 MessageLoop::current()->Run();
347 339
348 EXPECT_EQ(HTTP_SUCCESS, error); 340 EXPECT_EQ(HTTP_SUCCESS, error);
349 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 341 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
350 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 342 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
351 343
352 scoped_ptr<AboutResource> expected( 344 scoped_ptr<AboutResource> expected(
353 AboutResource::CreateFrom( 345 AboutResource::CreateFrom(
(...skipping 10 matching lines...) Expand all
364 expected_data_file_path_ = test_util::GetTestFilePath( 356 expected_data_file_path_ = test_util::GetTestFilePath(
365 "chromeos/gdata/testfile.txt"); 357 "chromeos/gdata/testfile.txt");
366 358
367 GDataErrorCode error = GDATA_OTHER_ERROR; 359 GDataErrorCode error = GDATA_OTHER_ERROR;
368 scoped_ptr<AboutResource> feed_data; 360 scoped_ptr<AboutResource> feed_data;
369 361
370 GetAboutOperation* operation = new GetAboutOperation( 362 GetAboutOperation* operation = new GetAboutOperation(
371 &operation_registry_, 363 &operation_registry_,
372 request_context_getter_.get(), 364 request_context_getter_.get(),
373 *url_generator_, 365 *url_generator_,
374 base::Bind(&CopyResultsFromGetAboutResourceCallbackAndQuit, 366 CreateComposedCallback(
375 &error, &feed_data)); 367 base::Bind(&test_util::RunAndQuit),
368 test_util::CreateCopyResultCallback(&error, &feed_data)));
376 operation->Start(kTestDriveApiAuthToken, kTestUserAgent, 369 operation->Start(kTestDriveApiAuthToken, kTestUserAgent,
377 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 370 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
378 MessageLoop::current()->Run(); 371 MessageLoop::current()->Run();
379 372
380 // "parse error" should be returned, and the feed should be NULL. 373 // "parse error" should be returned, and the feed should be NULL.
381 EXPECT_EQ(GDATA_PARSE_ERROR, error); 374 EXPECT_EQ(GDATA_PARSE_ERROR, error);
382 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 375 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
383 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 376 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
384 EXPECT_FALSE(feed_data.get()); 377 EXPECT_FALSE(feed_data.get());
385 } 378 }
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); 1064 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]);
1072 1065
1073 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); 1066 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method);
1074 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", 1067 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1075 http_request_.relative_url); 1068 http_request_.relative_url);
1076 EXPECT_TRUE(http_request_.has_content); 1069 EXPECT_TRUE(http_request_.has_content);
1077 EXPECT_TRUE(http_request_.content.empty()); 1070 EXPECT_TRUE(http_request_.content.empty());
1078 } 1071 }
1079 1072
1080 } // namespace google_apis 1073 } // namespace google_apis
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698