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/chromeos/network_settings/onc_test_utils.h" | 5 #include "chromeos/network/onc_test_utils.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chromeos/chromeos_test_utils.h" |
13 | 13 |
14 namespace chromeos { | 14 namespace chromeos { |
15 namespace onc { | 15 namespace onc { |
16 namespace test_utils { | 16 namespace test_utils { |
17 | 17 |
18 scoped_ptr<base::DictionaryValue> ReadTestDictionary( | 18 scoped_ptr<base::DictionaryValue> ReadTestDictionary( |
19 const std::string& filename) { | 19 const std::string& filename) { |
| 20 base::DictionaryValue* dict = NULL; |
20 FilePath path; | 21 FilePath path; |
21 PathService::Get(chrome::DIR_TEST_DATA, &path); | 22 if (!chromeos::test_utils::GetTestDataPath(filename, &path)) |
22 path = path.AppendASCII("chromeos").AppendASCII("network_settings"). | 23 return make_scoped_ptr(dict); |
23 Append(filename); | 24 |
24 JSONFileValueSerializer serializer(path); | 25 JSONFileValueSerializer serializer(path); |
25 serializer.set_allow_trailing_comma(true); | 26 serializer.set_allow_trailing_comma(true); |
26 | 27 |
27 std::string error_message; | 28 std::string error_message; |
28 base::Value* content = serializer.Deserialize(NULL, &error_message); | 29 base::Value* content = serializer.Deserialize(NULL, &error_message); |
29 CHECK(content != NULL) << "Couldn't json-deserialize file '" | 30 CHECK(content != NULL) << "Couldn't json-deserialize file '" |
30 << filename << "': " << error_message; | 31 << filename << "': " << error_message; |
31 | 32 |
32 base::DictionaryValue* dict = NULL; | |
33 CHECK(content->GetAsDictionary(&dict)) | 33 CHECK(content->GetAsDictionary(&dict)) |
34 << "File '" << filename | 34 << "File '" << filename |
35 << "' does not contain a dictionary as expected, but type " | 35 << "' does not contain a dictionary as expected, but type " |
36 << content->GetType(); | 36 << content->GetType(); |
37 return make_scoped_ptr(dict); | 37 return make_scoped_ptr(dict); |
38 } | 38 } |
39 | 39 |
40 ::testing::AssertionResult Equals(const base::DictionaryValue* expected, | 40 ::testing::AssertionResult Equals(const base::DictionaryValue* expected, |
41 const base::DictionaryValue* actual) { | 41 const base::DictionaryValue* actual) { |
42 CHECK(expected != NULL); | 42 CHECK(expected != NULL); |
43 if (actual == NULL) | 43 if (actual == NULL) |
44 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; | 44 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; |
45 | 45 |
46 if (expected->Equals(actual)) | 46 if (expected->Equals(actual)) |
47 return ::testing::AssertionSuccess() << "Dictionaries are equal"; | 47 return ::testing::AssertionSuccess() << "Dictionaries are equal"; |
48 | 48 |
49 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" | 49 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" |
50 << "Expected dictionary:\n" << *expected | 50 << "Expected dictionary:\n" << *expected |
51 << "Actual dictionary:\n" << *actual; | 51 << "Actual dictionary:\n" << *actual; |
52 } | 52 } |
53 | 53 |
54 } // namespace test_utils | 54 } // namespace test_utils |
55 } // namespace onc | 55 } // namespace onc |
56 } // namespace chromeos | 56 } // namespace chromeos |
OLD | NEW |