| 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 "base/test/values_test_util.h" | 5 #include "base/test/values_test_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 void ExpectDictStringValue(const std::string& expected_value, | 49 void ExpectDictStringValue(const std::string& expected_value, |
| 50 const DictionaryValue& value, | 50 const DictionaryValue& value, |
| 51 const std::string& key) { | 51 const std::string& key) { |
| 52 std::string string_value; | 52 std::string string_value; |
| 53 EXPECT_TRUE(value.GetString(key, &string_value)) << key; | 53 EXPECT_TRUE(value.GetString(key, &string_value)) << key; |
| 54 EXPECT_EQ(expected_value, string_value) << key; | 54 EXPECT_EQ(expected_value, string_value) << key; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ExpectStringValue(const std::string& expected_str, Value* actual) { | 57 void ExpectStringValue(const std::string& expected_str, const Value& actual) { |
| 58 std::unique_ptr<Value> scoped_actual(actual); | 58 EXPECT_EQ(Value::Type::STRING, actual.type()); |
| 59 std::string actual_str; | 59 EXPECT_EQ(expected_str, actual.GetString()); |
| 60 EXPECT_TRUE(scoped_actual->GetAsString(&actual_str)); | |
| 61 EXPECT_EQ(expected_str, actual_str); | |
| 62 } | 60 } |
| 63 | 61 |
| 64 namespace test { | 62 namespace test { |
| 65 | 63 |
| 66 std::unique_ptr<Value> ParseJson(base::StringPiece json) { | 64 std::unique_ptr<Value> ParseJson(base::StringPiece json) { |
| 67 std::string error_msg; | 65 std::string error_msg; |
| 68 std::unique_ptr<Value> result = base::JSONReader::ReadAndReturnError( | 66 std::unique_ptr<Value> result = base::JSONReader::ReadAndReturnError( |
| 69 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); | 67 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); |
| 70 if (!result) { | 68 if (!result) { |
| 71 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg; | 69 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg; |
| 72 result = MakeUnique<Value>(); | 70 result = MakeUnique<Value>(); |
| 73 } | 71 } |
| 74 return result; | 72 return result; |
| 75 } | 73 } |
| 76 | 74 |
| 77 } // namespace test | 75 } // namespace test |
| 78 } // namespace base | 76 } // namespace base |
| OLD | NEW |