OLD | NEW |
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.h" | 10 #include "base/message_loop.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 std::string error; | 120 std::string error; |
121 JSONFileValueSerializer serializer(path); | 121 JSONFileValueSerializer serializer(path); |
122 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); | 122 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); |
123 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value() | 123 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value() |
124 << ": " << error; | 124 << ": " << error; |
125 return value.Pass(); | 125 return value.Pass(); |
126 } | 126 } |
127 | 127 |
128 // Returns a HttpResponse created from the given file path. | 128 // Returns a HttpResponse created from the given file path. |
129 scoped_ptr<test_server::HttpResponse> CreateHttpResponseFromFile( | 129 scoped_ptr<net::test_server::HttpResponse> CreateHttpResponseFromFile( |
130 const base::FilePath& file_path) { | 130 const base::FilePath& file_path) { |
131 std::string content; | 131 std::string content; |
132 if (!file_util::ReadFileToString(file_path, &content)) | 132 if (!file_util::ReadFileToString(file_path, &content)) |
133 return scoped_ptr<test_server::HttpResponse>(); | 133 return scoped_ptr<net::test_server::HttpResponse>(); |
134 | 134 |
135 std::string content_type = "text/plain"; | 135 std::string content_type = "text/plain"; |
136 if (EndsWith(file_path.AsUTF8Unsafe(), ".json", true /* case sensitive */)) { | 136 if (EndsWith(file_path.AsUTF8Unsafe(), ".json", true /* case sensitive */)) { |
137 content_type = "application/json"; | 137 content_type = "application/json"; |
138 } else if (EndsWith(file_path.AsUTF8Unsafe(), ".xml", true)) { | 138 } else if (EndsWith(file_path.AsUTF8Unsafe(), ".xml", true)) { |
139 content_type = "application/atom+xml"; | 139 content_type = "application/atom+xml"; |
140 } | 140 } |
141 | 141 |
142 scoped_ptr<test_server::HttpResponse> http_response( | 142 scoped_ptr<net::test_server::HttpResponse> http_response( |
143 new test_server::HttpResponse); | 143 new net::test_server::HttpResponse); |
144 http_response->set_code(test_server::SUCCESS); | 144 http_response->set_code(net::test_server::SUCCESS); |
145 http_response->set_content(content); | 145 http_response->set_content(content); |
146 http_response->set_content_type(content_type); | 146 http_response->set_content_type(content_type); |
147 return http_response.Pass(); | 147 return http_response.Pass(); |
148 } | 148 } |
149 | 149 |
150 void DoNothingForReAuthenticateCallback( | 150 void DoNothingForReAuthenticateCallback( |
151 AuthenticatedOperationInterface* /* operation */) { | 151 AuthenticatedOperationInterface* /* operation */) { |
152 NOTREACHED(); | 152 NOTREACHED(); |
153 } | 153 } |
154 | 154 |
155 scoped_ptr<test_server::HttpResponse> HandleDownloadRequest( | 155 scoped_ptr<net::test_server::HttpResponse> HandleDownloadRequest( |
156 const GURL& base_url, | 156 const GURL& base_url, |
157 test_server::HttpRequest* out_request, | 157 net::test_server::HttpRequest* out_request, |
158 const test_server::HttpRequest& request) { | 158 const net::test_server::HttpRequest& request) { |
159 *out_request = request; | 159 *out_request = request; |
160 | 160 |
161 GURL absolute_url = base_url.Resolve(request.relative_url); | 161 GURL absolute_url = base_url.Resolve(request.relative_url); |
162 std::string remaining_path; | 162 std::string remaining_path; |
163 if (!RemovePrefix(absolute_url.path(), "/files/", &remaining_path)) | 163 if (!RemovePrefix(absolute_url.path(), "/files/", &remaining_path)) |
164 return scoped_ptr<test_server::HttpResponse>(); | 164 return scoped_ptr<net::test_server::HttpResponse>(); |
165 return CreateHttpResponseFromFile(GetTestFilePath(remaining_path)); | 165 return CreateHttpResponseFromFile(GetTestFilePath(remaining_path)); |
166 } | 166 } |
167 | 167 |
168 bool VerifyJsonData(const base::FilePath& expected_json_file_path, | 168 bool VerifyJsonData(const base::FilePath& expected_json_file_path, |
169 const base::Value* json_data) { | 169 const base::Value* json_data) { |
170 if (!json_data) { | 170 if (!json_data) { |
171 LOG(ERROR) << "json_data is NULL"; | 171 LOG(ERROR) << "json_data is NULL"; |
172 return false; | 172 return false; |
173 } | 173 } |
174 | 174 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return result; | 242 return result; |
243 } | 243 } |
244 | 244 |
245 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, | 245 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, |
246 scoped_ptr<std::string> data) { | 246 scoped_ptr<std::string> data) { |
247 data_.push_back(data.release()); | 247 data_.push_back(data.release()); |
248 } | 248 } |
249 | 249 |
250 } // namespace test_util | 250 } // namespace test_util |
251 } // namespace google_apis | 251 } // namespace google_apis |
OLD | NEW |