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

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

Issue 19579005: Move ReadFileToString to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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) 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/json/json_reader.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); 86 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error));
87 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value() 87 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value()
88 << ": " << error; 88 << ": " << error;
89 return value.Pass(); 89 return value.Pass();
90 } 90 }
91 91
92 // Returns a HttpResponse created from the given file path. 92 // Returns a HttpResponse created from the given file path.
93 scoped_ptr<net::test_server::BasicHttpResponse> CreateHttpResponseFromFile( 93 scoped_ptr<net::test_server::BasicHttpResponse> CreateHttpResponseFromFile(
94 const base::FilePath& file_path) { 94 const base::FilePath& file_path) {
95 std::string content; 95 std::string content;
96 if (!file_util::ReadFileToString(file_path, &content)) 96 if (!base::ReadFileToString(file_path, &content))
97 return scoped_ptr<net::test_server::BasicHttpResponse>(); 97 return scoped_ptr<net::test_server::BasicHttpResponse>();
98 98
99 std::string content_type = "text/plain"; 99 std::string content_type = "text/plain";
100 if (EndsWith(file_path.AsUTF8Unsafe(), ".json", true /* case sensitive */)) 100 if (EndsWith(file_path.AsUTF8Unsafe(), ".json", true /* case sensitive */))
101 content_type = "application/json"; 101 content_type = "application/json";
102 102
103 scoped_ptr<net::test_server::BasicHttpResponse> http_response( 103 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
104 new net::test_server::BasicHttpResponse); 104 new net::test_server::BasicHttpResponse);
105 http_response->set_code(net::HTTP_OK); 105 http_response->set_code(net::HTTP_OK);
106 http_response->set_content(content); 106 http_response->set_content(content);
(...skipping 16 matching lines...) Expand all
123 } 123 }
124 124
125 bool VerifyJsonData(const base::FilePath& expected_json_file_path, 125 bool VerifyJsonData(const base::FilePath& expected_json_file_path,
126 const base::Value* json_data) { 126 const base::Value* json_data) {
127 if (!json_data) { 127 if (!json_data) {
128 LOG(ERROR) << "json_data is NULL"; 128 LOG(ERROR) << "json_data is NULL";
129 return false; 129 return false;
130 } 130 }
131 131
132 std::string expected_content; 132 std::string expected_content;
133 if (!file_util::ReadFileToString( 133 if (!base::ReadFileToString(expected_json_file_path, &expected_content)) {
134 expected_json_file_path, &expected_content)) {
135 LOG(ERROR) << "Failed to read file: " << expected_json_file_path.value(); 134 LOG(ERROR) << "Failed to read file: " << expected_json_file_path.value();
136 return false; 135 return false;
137 } 136 }
138 137
139 scoped_ptr<base::Value> expected_json_data( 138 scoped_ptr<base::Value> expected_json_data(
140 base::JSONReader::Read(expected_content)); 139 base::JSONReader::Read(expected_content));
141 if (!base::Value::Equals(expected_json_data.get(), json_data)) { 140 if (!base::Value::Equals(expected_json_data.get(), json_data)) {
142 LOG(ERROR) 141 LOG(ERROR)
143 << "The value of json_data is different from the file's content."; 142 << "The value of json_data is different from the file's content.";
144 return false; 143 return false;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return result; 198 return result;
200 } 199 }
201 200
202 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, 201 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error,
203 scoped_ptr<std::string> data) { 202 scoped_ptr<std::string> data) {
204 data_.push_back(data.release()); 203 data_.push_back(data.release());
205 } 204 }
206 205
207 } // namespace test_util 206 } // namespace test_util
208 } // namespace google_apis 207 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/gdata_wapi_requests_unittest.cc ('k') | chrome/browser/history/expire_history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698