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

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

Issue 12500008: Eliminate CopyResultsFromDownloadActionCallback(AndQuit). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google_apis/base_operations_server_unittest.cc
diff --git a/chrome/browser/google_apis/base_operations_server_unittest.cc b/chrome/browser/google_apis/base_operations_server_unittest.cc
index a701ff126de1cf93c37833d7feb29260451e64ac..65f0513b2d980492e7c94471f67242b069eff5e6 100644
--- a/chrome/browser/google_apis/base_operations_server_unittest.cc
+++ b/chrome/browser/google_apis/base_operations_server_unittest.cc
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/google_apis/operation_registry.h"
#include "chrome/browser/google_apis/operation_runner.h"
+#include "chrome/browser/google_apis/task_util.h"
#include "chrome/browser/google_apis/test_server/http_request.h"
#include "chrome/browser/google_apis/test_server/http_response.h"
#include "chrome/browser/google_apis/test_server/http_server.h"
@@ -27,20 +28,6 @@ namespace {
const char kTestAuthToken[] = "testtoken";
const char kTestUserAgent[] = "test-user-agent";
-// Copies the results from DownloadActionCallback and quit the message loop.
-// The contents of the download cache file are copied to a string, and the
-// file is removed.
-void CopyResultsFromDownloadActionCallbackAndQuit(
- GDataErrorCode* out_result_code,
- std::string* contents,
- GDataErrorCode result_code,
- const base::FilePath& cache_file_path) {
- *out_result_code = result_code;
- file_util::ReadFileToString(cache_file_path, contents);
- file_util::Delete(cache_file_path, false);
- MessageLoop::current()->Quit();
-}
-
} // namespace
class BaseOperationsServerTest : public testing::Test {
@@ -94,13 +81,13 @@ class BaseOperationsServerTest : public testing::Test {
TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) {
GDataErrorCode result_code = GDATA_OTHER_ERROR;
- std::string contents;
+ base::FilePath temp_file;
DownloadFileOperation* operation = new DownloadFileOperation(
&operation_registry_,
request_context_getter_.get(),
- base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit,
- &result_code,
- &contents),
+ CreateComposedCallback(
+ base::Bind(&test_util::RunAndQuit),
+ test_util::CreateCopyResultCallback(&result_code, &temp_file)),
GetContentCallback(),
test_server_.GetURL("/files/chromeos/gdata/testfile.txt"),
base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"),
@@ -110,6 +97,10 @@ TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) {
base::Bind(&test_util::DoNothingForReAuthenticateCallback));
MessageLoop::current()->Run();
+ std::string contents;
+ file_util::ReadFileToString(temp_file, &contents);
+ file_util::Delete(temp_file, false);
+
EXPECT_EQ(HTTP_SUCCESS, result_code);
EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
EXPECT_EQ("/files/chromeos/gdata/testfile.txt", http_request_.relative_url);
@@ -125,13 +116,13 @@ TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) {
TEST_F(BaseOperationsServerTest,
DISABLED_DownloadFileOperation_NonExistentFile) {
GDataErrorCode result_code = GDATA_OTHER_ERROR;
- std::string contents;
+ base::FilePath temp_file;
DownloadFileOperation* operation = new DownloadFileOperation(
&operation_registry_,
request_context_getter_.get(),
- base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit,
- &result_code,
- &contents),
+ CreateComposedCallback(
+ base::Bind(&test_util::RunAndQuit),
+ test_util::CreateCopyResultCallback(&result_code, &temp_file)),
GetContentCallback(),
test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"),
base::FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"),
@@ -141,6 +132,10 @@ TEST_F(BaseOperationsServerTest,
base::Bind(&test_util::DoNothingForReAuthenticateCallback));
MessageLoop::current()->Run();
+ std::string contents;
+ file_util::ReadFileToString(temp_file, &contents);
+ file_util::Delete(temp_file, false);
+
EXPECT_EQ(HTTP_NOT_FOUND, result_code);
EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt",
« no previous file with comments | « chrome/browser/chromeos/drive/drive_scheduler_unittest.cc ('k') | chrome/browser/google_apis/fake_drive_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698