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

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

Issue 22909041: Refactor GetAboutRequest and GetApplistRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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) 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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 response->set_content(id + id + id); 338 response->set_content(id + id + id);
339 response->set_content_type("text/plain"); 339 response->set_content_type("text/plain");
340 return response.PassAs<net::test_server::HttpResponse>(); 340 return response.PassAs<net::test_server::HttpResponse>();
341 } 341 }
342 342
343 // These are for the current upload file status. 343 // These are for the current upload file status.
344 int64 received_bytes_; 344 int64 received_bytes_;
345 int64 content_length_; 345 int64 content_length_;
346 }; 346 };
347 347
348 TEST_F(DriveApiRequestsTest, GetAboutRequest_ValidJson) { 348 TEST_F(DriveApiRequestsTest, AboutGetRequest_ValidJson) {
349 // Set an expected data file containing valid result. 349 // Set an expected data file containing valid result.
350 expected_data_file_path_ = test_util::GetTestFilePath( 350 expected_data_file_path_ = test_util::GetTestFilePath(
351 "drive/about.json"); 351 "drive/about.json");
352 352
353 GDataErrorCode error = GDATA_OTHER_ERROR; 353 GDataErrorCode error = GDATA_OTHER_ERROR;
354 scoped_ptr<AboutResource> about_resource; 354 scoped_ptr<AboutResource> about_resource;
355 355
356 { 356 {
357 base::RunLoop run_loop; 357 base::RunLoop run_loop;
358 GetAboutRequest* request = new GetAboutRequest( 358 drive::AboutGetRequest* request = new drive::AboutGetRequest(
359 request_sender_.get(), 359 request_sender_.get(),
360 *url_generator_, 360 *url_generator_,
361 test_util::CreateQuitCallback( 361 test_util::CreateQuitCallback(
362 &run_loop, 362 &run_loop,
363 test_util::CreateCopyResultCallback(&error, &about_resource))); 363 test_util::CreateCopyResultCallback(&error, &about_resource)));
364 request_sender_->StartRequestWithRetry(request); 364 request_sender_->StartRequestWithRetry(request);
365 run_loop.Run(); 365 run_loop.Run();
366 } 366 }
367 367
368 EXPECT_EQ(HTTP_SUCCESS, error); 368 EXPECT_EQ(HTTP_SUCCESS, error);
369 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 369 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
370 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 370 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
371 371
372 scoped_ptr<AboutResource> expected( 372 scoped_ptr<AboutResource> expected(
373 AboutResource::CreateFrom( 373 AboutResource::CreateFrom(
374 *test_util::LoadJSONFile("drive/about.json"))); 374 *test_util::LoadJSONFile("drive/about.json")));
375 ASSERT_TRUE(about_resource.get()); 375 ASSERT_TRUE(about_resource.get());
376 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id()); 376 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id());
377 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total()); 377 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total());
378 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used()); 378 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used());
379 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id()); 379 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id());
380 } 380 }
381 381
382 TEST_F(DriveApiRequestsTest, GetAboutRequest_InvalidJson) { 382 TEST_F(DriveApiRequestsTest, AboutGetRequest_InvalidJson) {
383 // Set an expected data file containing invalid result. 383 // Set an expected data file containing invalid result.
384 expected_data_file_path_ = test_util::GetTestFilePath( 384 expected_data_file_path_ = test_util::GetTestFilePath(
385 "gdata/testfile.txt"); 385 "gdata/testfile.txt");
386 386
387 GDataErrorCode error = GDATA_OTHER_ERROR; 387 GDataErrorCode error = GDATA_OTHER_ERROR;
388 scoped_ptr<AboutResource> about_resource; 388 scoped_ptr<AboutResource> about_resource;
389 389
390 { 390 {
391 base::RunLoop run_loop; 391 base::RunLoop run_loop;
392 GetAboutRequest* request = new GetAboutRequest( 392 drive::AboutGetRequest* request = new drive::AboutGetRequest(
393 request_sender_.get(), 393 request_sender_.get(),
394 *url_generator_, 394 *url_generator_,
395 test_util::CreateQuitCallback( 395 test_util::CreateQuitCallback(
396 &run_loop, 396 &run_loop,
397 test_util::CreateCopyResultCallback(&error, &about_resource))); 397 test_util::CreateCopyResultCallback(&error, &about_resource)));
398 request_sender_->StartRequestWithRetry(request); 398 request_sender_->StartRequestWithRetry(request);
399 run_loop.Run(); 399 run_loop.Run();
400 } 400 }
401 401
402 // "parse error" should be returned, and the about resource should be NULL. 402 // "parse error" should be returned, and the about resource should be NULL.
403 EXPECT_EQ(GDATA_PARSE_ERROR, error); 403 EXPECT_EQ(GDATA_PARSE_ERROR, error);
404 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 404 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
405 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 405 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
406 EXPECT_FALSE(about_resource.get()); 406 EXPECT_FALSE(about_resource);
407 } 407 }
408 408
409 TEST_F(DriveApiRequestsTest, GetApplistRequest) { 409 TEST_F(DriveApiRequestsTest, AppsListRequest) {
410 // Set an expected data file containing valid result. 410 // Set an expected data file containing valid result.
411 expected_data_file_path_ = test_util::GetTestFilePath( 411 expected_data_file_path_ = test_util::GetTestFilePath(
412 "drive/applist.json"); 412 "drive/applist.json");
413 413
414 GDataErrorCode error = GDATA_OTHER_ERROR; 414 GDataErrorCode error = GDATA_OTHER_ERROR;
415 scoped_ptr<base::Value> result; 415 scoped_ptr<AppList> app_list;
416 416
417 { 417 {
418 base::RunLoop run_loop; 418 base::RunLoop run_loop;
419 GetApplistRequest* request = new GetApplistRequest( 419 drive::AppsListRequest* request = new drive::AppsListRequest(
420 request_sender_.get(), 420 request_sender_.get(),
421 *url_generator_, 421 *url_generator_,
422 test_util::CreateQuitCallback( 422 test_util::CreateQuitCallback(
423 &run_loop, 423 &run_loop,
424 test_util::CreateCopyResultCallback(&error, &result))); 424 test_util::CreateCopyResultCallback(&error, &app_list)));
425 request_sender_->StartRequestWithRetry(request); 425 request_sender_->StartRequestWithRetry(request);
426 run_loop.Run(); 426 run_loop.Run();
427 } 427 }
428 428
429 EXPECT_EQ(HTTP_SUCCESS, error); 429 EXPECT_EQ(HTTP_SUCCESS, error);
430 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 430 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
431 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url); 431 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url);
432 EXPECT_TRUE(result); 432 EXPECT_TRUE(app_list);
433 } 433 }
434 434
435 TEST_F(DriveApiRequestsTest, GetChangelistRequest) { 435 TEST_F(DriveApiRequestsTest, GetChangelistRequest) {
436 // Set an expected data file containing valid result. 436 // Set an expected data file containing valid result.
437 expected_data_file_path_ = test_util::GetTestFilePath( 437 expected_data_file_path_ = test_util::GetTestFilePath(
438 "drive/changelist.json"); 438 "drive/changelist.json");
439 439
440 GDataErrorCode error = GDATA_OTHER_ERROR; 440 GDataErrorCode error = GDATA_OTHER_ERROR;
441 scoped_ptr<base::Value> result; 441 scoped_ptr<base::Value> result;
442 442
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 EXPECT_EQ(HTTP_SUCCESS, result_code); 1549 EXPECT_EQ(HTTP_SUCCESS, result_code);
1550 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 1550 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
1551 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); 1551 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url);
1552 EXPECT_EQ(kDownloadedFilePath, temp_file); 1552 EXPECT_EQ(kDownloadedFilePath, temp_file);
1553 1553
1554 const std::string expected_contents = kTestId + kTestId + kTestId; 1554 const std::string expected_contents = kTestId + kTestId + kTestId;
1555 EXPECT_EQ(expected_contents, contents); 1555 EXPECT_EQ(expected_contents, contents);
1556 } 1556 }
1557 1557
1558 } // namespace google_apis 1558 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_requests.cc ('k') | chrome/browser/google_apis/drive_api_url_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698