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

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

Issue 11824023: Add unittest for google_apis::GetAboutOperation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Get rid of EXPECT_X creation. Move the verification method to test_util to share it with gdata_wapi… Created 7 years, 11 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 | « chrome/browser/google_apis/test_util.h ('k') | chrome/chrome_tests_unit.gypi » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/test_util.h" 5 #include "chrome/browser/google_apis/test_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/json/json_reader.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 15 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
15 #include "chrome/browser/google_apis/test_server/http_server.h" 16 #include "chrome/browser/google_apis/test_server/http_server.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 84 }
84 85
85 void CopyResultsFromGetDataCallback(GDataErrorCode* error_out, 86 void CopyResultsFromGetDataCallback(GDataErrorCode* error_out,
86 scoped_ptr<base::Value>* value_out, 87 scoped_ptr<base::Value>* value_out,
87 GDataErrorCode error_in, 88 GDataErrorCode error_in,
88 scoped_ptr<base::Value> value_in) { 89 scoped_ptr<base::Value> value_in) {
89 value_out->swap(value_in); 90 value_out->swap(value_in);
90 *error_out = error_in; 91 *error_out = error_in;
91 } 92 }
92 93
94 void CopyResultsFromGetDataCallbackAndQuit(GDataErrorCode* error_out,
95 scoped_ptr<base::Value>* value_out,
96 GDataErrorCode error_in,
97 scoped_ptr<base::Value> value_in) {
98 *error_out = error_in;
99 *value_out = value_in.Pass();
100 MessageLoop::current()->Quit();
101 }
102
93 void CopyResultsFromGetResourceEntryCallback( 103 void CopyResultsFromGetResourceEntryCallback(
94 GDataErrorCode* error_out, 104 GDataErrorCode* error_out,
95 scoped_ptr<ResourceEntry>* resource_entry_out, 105 scoped_ptr<ResourceEntry>* resource_entry_out,
96 GDataErrorCode error_in, 106 GDataErrorCode error_in,
97 scoped_ptr<ResourceEntry> resource_entry_in) { 107 scoped_ptr<ResourceEntry> resource_entry_in) {
98 resource_entry_out->swap(resource_entry_in); 108 resource_entry_out->swap(resource_entry_in);
99 *error_out = error_in; 109 *error_out = error_in;
100 } 110 }
101 111
102 void CopyResultsFromGetResourceListCallback( 112 void CopyResultsFromGetResourceListCallback(
(...skipping 29 matching lines...) Expand all
132 } 142 }
133 143
134 scoped_ptr<test_server::HttpResponse> http_response( 144 scoped_ptr<test_server::HttpResponse> http_response(
135 new test_server::HttpResponse); 145 new test_server::HttpResponse);
136 http_response->set_code(test_server::SUCCESS); 146 http_response->set_code(test_server::SUCCESS);
137 http_response->set_content(content); 147 http_response->set_content(content);
138 http_response->set_content_type(content_type); 148 http_response->set_content_type(content_type);
139 return http_response.Pass(); 149 return http_response.Pass();
140 } 150 }
141 151
152 void DoNothingForReAuthenticateCallback(
153 AuthenticatedOperationInterface* /* operation */) {
154 NOTREACHED();
155 }
156
157 bool VerifyJsonData(const FilePath& expected_json_file_path,
158 const base::Value* json_data) {
159 if (!json_data) {
160 LOG(ERROR) << "json_data is NULL";
161 return false;
162 }
163
164 std::string expected_content;
165 if (!file_util::ReadFileToString(
166 expected_json_file_path, &expected_content)) {
167 LOG(ERROR) << "Failed to read file: " << expected_json_file_path.value();
168 return false;
169 }
170
171 scoped_ptr<base::Value> expected_json_data(
172 base::JSONReader::Read(expected_content));
173 if (!base::Value::Equals(expected_json_data.get(), json_data)) {
174 LOG(ERROR)
175 << "The value of json_data is different from the file's content.";
176 return false;
177 }
178
179 return true;
180 }
181
142 } // namespace test_util 182 } // namespace test_util
143 } // namespace google_apis 183 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/test_util.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698