| 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |