| 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<net::test_server::HttpResponse> CreateHttpResponseFromFile( | 129 scoped_ptr<net::test_server::BasicHttpResponse> 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<net::test_server::HttpResponse>(); | 133 return scoped_ptr<net::test_server::BasicHttpResponse>(); |
| 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<net::test_server::HttpResponse> http_response( | 142 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| 143 new net::test_server::HttpResponse); | 143 new net::test_server::BasicHttpResponse); |
| 144 http_response->set_code(net::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 scoped_ptr<net::test_server::HttpResponse> HandleDownloadRequest( | 150 scoped_ptr<net::test_server::HttpResponse> HandleDownloadRequest( |
| 151 const GURL& base_url, | 151 const GURL& base_url, |
| 152 net::test_server::HttpRequest* out_request, | 152 net::test_server::HttpRequest* out_request, |
| 153 const net::test_server::HttpRequest& request) { | 153 const net::test_server::HttpRequest& request) { |
| 154 *out_request = request; | 154 *out_request = request; |
| 155 | 155 |
| 156 GURL absolute_url = base_url.Resolve(request.relative_url); | 156 GURL absolute_url = base_url.Resolve(request.relative_url); |
| 157 std::string remaining_path; | 157 std::string remaining_path; |
| 158 if (!RemovePrefix(absolute_url.path(), "/files/", &remaining_path)) | 158 if (!RemovePrefix(absolute_url.path(), "/files/", &remaining_path)) |
| 159 return scoped_ptr<net::test_server::HttpResponse>(); | 159 return scoped_ptr<net::test_server::HttpResponse>(); |
| 160 return CreateHttpResponseFromFile(GetTestFilePath(remaining_path)); | 160 return CreateHttpResponseFromFile( |
| 161 GetTestFilePath(remaining_path)).PassAs<net::test_server::HttpResponse>(); |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool VerifyJsonData(const base::FilePath& expected_json_file_path, | 164 bool VerifyJsonData(const base::FilePath& expected_json_file_path, |
| 164 const base::Value* json_data) { | 165 const base::Value* json_data) { |
| 165 if (!json_data) { | 166 if (!json_data) { |
| 166 LOG(ERROR) << "json_data is NULL"; | 167 LOG(ERROR) << "json_data is NULL"; |
| 167 return false; | 168 return false; |
| 168 } | 169 } |
| 169 | 170 |
| 170 std::string expected_content; | 171 std::string expected_content; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 return result; | 238 return result; |
| 238 } | 239 } |
| 239 | 240 |
| 240 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, | 241 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, |
| 241 scoped_ptr<std::string> data) { | 242 scoped_ptr<std::string> data) { |
| 242 data_.push_back(data.release()); | 243 data_.push_back(data.release()); |
| 243 } | 244 } |
| 244 | 245 |
| 245 } // namespace test_util | 246 } // namespace test_util |
| 246 } // namespace google_apis | 247 } // namespace google_apis |
| OLD | NEW |