[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / chromeos / network / onc / onc_test_utils.cc
blob522a9ed338a8a0bf534d3574b645d37d3b39b53c
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
3 // found in the LICENSE file.
5 #include "chromeos/network/onc/onc_test_utils.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/json/json_file_value_serializer.h"
10 #include "base/logging.h"
11 #include "base/values.h"
12 #include "chromeos/chromeos_test_utils.h"
14 namespace chromeos {
15 namespace onc {
16 namespace test_utils {
18 namespace {
20 // The name of the component directory to get the test data from.
21 const char kNetworkComponentDirectory[] = "network";
23 } // namespace
25 std::string ReadTestData(const std::string& filename) {
26 base::FilePath path;
27 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory,
28 filename,
29 &path)) {
30 NOTREACHED() << "Unable to get test data path for "
31 << kNetworkComponentDirectory << "/" << filename;
32 return "";
34 std::string result;
35 base::ReadFileToString(path, &result);
36 return result;
39 scoped_ptr<base::DictionaryValue> ReadTestDictionary(
40 const std::string& filename) {
41 base::DictionaryValue* dict = NULL;
42 base::FilePath path;
43 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory,
44 filename,
45 &path)) {
46 NOTREACHED() << "Unable to get test dictionary path for "
47 << kNetworkComponentDirectory << "/" << filename;
48 return make_scoped_ptr(dict);
51 JSONFileValueDeserializer deserializer(path);
52 deserializer.set_allow_trailing_comma(true);
54 std::string error_message;
55 base::Value* content = deserializer.Deserialize(NULL, &error_message);
56 CHECK(content != NULL) << "Couldn't json-deserialize file '"
57 << filename << "': " << error_message;
59 CHECK(content->GetAsDictionary(&dict))
60 << "File '" << filename
61 << "' does not contain a dictionary as expected, but type "
62 << content->GetType();
63 return make_scoped_ptr(dict);
66 ::testing::AssertionResult Equals(const base::Value* expected,
67 const base::Value* actual) {
68 CHECK(expected != NULL);
69 if (actual == NULL)
70 return ::testing::AssertionFailure() << "Actual value pointer is NULL";
72 if (expected->Equals(actual))
73 return ::testing::AssertionSuccess() << "Values are equal";
75 return ::testing::AssertionFailure() << "Values are unequal.\n"
76 << "Expected value:\n" << *expected
77 << "Actual value:\n" << *actual;
80 } // namespace test_utils
81 } // namespace onc
82 } // namespace chromeos