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

Side by Side 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 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 "chrome/browser/google_apis/base_operations.h" 5 #include "chrome/browser/google_apis/base_operations.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/google_apis/operation_registry.h" 12 #include "chrome/browser/google_apis/operation_registry.h"
13 #include "chrome/browser/google_apis/operation_runner.h" 13 #include "chrome/browser/google_apis/operation_runner.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 "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
20 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace google_apis { 24 namespace google_apis {
24 25
25 namespace { 26 namespace {
26 27
27 const char kTestAuthToken[] = "testtoken"; 28 const char kTestAuthToken[] = "testtoken";
28 const char kTestUserAgent[] = "test-user-agent"; 29 const char kTestUserAgent[] = "test-user-agent";
29 30
30 // Copies the results from DownloadActionCallback and quit the message loop.
31 // The contents of the download cache file are copied to a string, and the
32 // file is removed.
33 void CopyResultsFromDownloadActionCallbackAndQuit(
34 GDataErrorCode* out_result_code,
35 std::string* contents,
36 GDataErrorCode result_code,
37 const base::FilePath& cache_file_path) {
38 *out_result_code = result_code;
39 file_util::ReadFileToString(cache_file_path, contents);
40 file_util::Delete(cache_file_path, false);
41 MessageLoop::current()->Quit();
42 }
43
44 } // namespace 31 } // namespace
45 32
46 class BaseOperationsServerTest : public testing::Test { 33 class BaseOperationsServerTest : public testing::Test {
47 protected: 34 protected:
48 BaseOperationsServerTest() 35 BaseOperationsServerTest()
49 : ui_thread_(content::BrowserThread::UI, &message_loop_), 36 : ui_thread_(content::BrowserThread::UI, &message_loop_),
50 file_thread_(content::BrowserThread::FILE), 37 file_thread_(content::BrowserThread::FILE),
51 io_thread_(content::BrowserThread::IO) { 38 io_thread_(content::BrowserThread::IO) {
52 } 39 }
53 40
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; 74 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
88 75
89 // The incoming HTTP request is saved so tests can verify the request 76 // The incoming HTTP request is saved so tests can verify the request
90 // parameters like HTTP method (ex. some operations should use DELETE 77 // parameters like HTTP method (ex. some operations should use DELETE
91 // instead of GET). 78 // instead of GET).
92 test_server::HttpRequest http_request_; 79 test_server::HttpRequest http_request_;
93 }; 80 };
94 81
95 TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) { 82 TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) {
96 GDataErrorCode result_code = GDATA_OTHER_ERROR; 83 GDataErrorCode result_code = GDATA_OTHER_ERROR;
97 std::string contents; 84 base::FilePath temp_file;
98 DownloadFileOperation* operation = new DownloadFileOperation( 85 DownloadFileOperation* operation = new DownloadFileOperation(
99 &operation_registry_, 86 &operation_registry_,
100 request_context_getter_.get(), 87 request_context_getter_.get(),
101 base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit, 88 CreateComposedCallback(
102 &result_code, 89 base::Bind(&test_util::RunAndQuit),
103 &contents), 90 test_util::CreateCopyResultCallback(&result_code, &temp_file)),
104 GetContentCallback(), 91 GetContentCallback(),
105 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), 92 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"),
106 base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), 93 base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"),
107 GetTestCachedFilePath( 94 GetTestCachedFilePath(
108 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); 95 base::FilePath::FromUTF8Unsafe("cached_testfile.txt")));
109 operation->Start(kTestAuthToken, kTestUserAgent, 96 operation->Start(kTestAuthToken, kTestUserAgent,
110 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 97 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
111 MessageLoop::current()->Run(); 98 MessageLoop::current()->Run();
112 99
100 std::string contents;
101 file_util::ReadFileToString(temp_file, &contents);
102 file_util::Delete(temp_file, false);
103
113 EXPECT_EQ(HTTP_SUCCESS, result_code); 104 EXPECT_EQ(HTTP_SUCCESS, result_code);
114 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 105 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
115 EXPECT_EQ("/files/chromeos/gdata/testfile.txt", http_request_.relative_url); 106 EXPECT_EQ("/files/chromeos/gdata/testfile.txt", http_request_.relative_url);
116 107
117 const base::FilePath expected_path = 108 const base::FilePath expected_path =
118 test_util::GetTestFilePath("chromeos/gdata/testfile.txt"); 109 test_util::GetTestFilePath("chromeos/gdata/testfile.txt");
119 std::string expected_contents; 110 std::string expected_contents;
120 file_util::ReadFileToString(expected_path, &expected_contents); 111 file_util::ReadFileToString(expected_path, &expected_contents);
121 EXPECT_EQ(expected_contents, contents); 112 EXPECT_EQ(expected_contents, contents);
122 } 113 }
123 114
124 // http://crbug.com/169588 115 // http://crbug.com/169588
125 TEST_F(BaseOperationsServerTest, 116 TEST_F(BaseOperationsServerTest,
126 DISABLED_DownloadFileOperation_NonExistentFile) { 117 DISABLED_DownloadFileOperation_NonExistentFile) {
127 GDataErrorCode result_code = GDATA_OTHER_ERROR; 118 GDataErrorCode result_code = GDATA_OTHER_ERROR;
128 std::string contents; 119 base::FilePath temp_file;
129 DownloadFileOperation* operation = new DownloadFileOperation( 120 DownloadFileOperation* operation = new DownloadFileOperation(
130 &operation_registry_, 121 &operation_registry_,
131 request_context_getter_.get(), 122 request_context_getter_.get(),
132 base::Bind(&CopyResultsFromDownloadActionCallbackAndQuit, 123 CreateComposedCallback(
133 &result_code, 124 base::Bind(&test_util::RunAndQuit),
134 &contents), 125 test_util::CreateCopyResultCallback(&result_code, &temp_file)),
135 GetContentCallback(), 126 GetContentCallback(),
136 test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"), 127 test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"),
137 base::FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"), 128 base::FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"),
138 GetTestCachedFilePath( 129 GetTestCachedFilePath(
139 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); 130 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt")));
140 operation->Start(kTestAuthToken, kTestUserAgent, 131 operation->Start(kTestAuthToken, kTestUserAgent,
141 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); 132 base::Bind(&test_util::DoNothingForReAuthenticateCallback));
142 MessageLoop::current()->Run(); 133 MessageLoop::current()->Run();
143 134
135 std::string contents;
136 file_util::ReadFileToString(temp_file, &contents);
137 file_util::Delete(temp_file, false);
138
144 EXPECT_EQ(HTTP_NOT_FOUND, result_code); 139 EXPECT_EQ(HTTP_NOT_FOUND, result_code);
145 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); 140 EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
146 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt", 141 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt",
147 http_request_.relative_url); 142 http_request_.relative_url);
148 // Do not verify the not found message. 143 // Do not verify the not found message.
149 } 144 }
150 145
151 } // namespace google_apis 146 } // namespace google_apis
OLDNEW
« 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