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 "remoting/host/host_config.h" | 5 #include "remoting/host/host_config.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 45 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
46 base::FilePath non_existent_file = | 46 base::FilePath non_existent_file = |
47 test_dir_.path().AppendASCII("non_existent.json"); | 47 test_dir_.path().AppendASCII("non_existent.json"); |
48 EXPECT_FALSE(HostConfigFromJsonFile(non_existent_file)); | 48 EXPECT_FALSE(HostConfigFromJsonFile(non_existent_file)); |
49 } | 49 } |
50 | 50 |
51 TEST_F(HostConfigTest, Read) { | 51 TEST_F(HostConfigTest, Read) { |
52 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 52 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
53 base::FilePath test_file = test_dir_.path().AppendASCII("read.json"); | 53 base::FilePath test_file = test_dir_.path().AppendASCII("read.json"); |
54 WriteTestFile(test_file); | 54 WriteTestFile(test_file); |
55 scoped_ptr<base::DictionaryValue> target(HostConfigFromJsonFile(test_file)); | 55 std::unique_ptr<base::DictionaryValue> target( |
| 56 HostConfigFromJsonFile(test_file)); |
56 ASSERT_TRUE(target); | 57 ASSERT_TRUE(target); |
57 | 58 |
58 std::string value; | 59 std::string value; |
59 EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); | 60 EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); |
60 EXPECT_EQ("test@gmail.com", value); | 61 EXPECT_EQ("test@gmail.com", value); |
61 EXPECT_TRUE(target->GetString(kOAuthRefreshTokenConfigPath, &value)); | 62 EXPECT_TRUE(target->GetString(kOAuthRefreshTokenConfigPath, &value)); |
62 EXPECT_EQ("TEST_REFRESH_TOKEN", value); | 63 EXPECT_EQ("TEST_REFRESH_TOKEN", value); |
63 EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); | 64 EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); |
64 EXPECT_EQ("TEST_HOST_ID", value); | 65 EXPECT_EQ("TEST_HOST_ID", value); |
65 EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); | 66 EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); |
66 EXPECT_EQ("TEST_MACHINE_NAME", value); | 67 EXPECT_EQ("TEST_MACHINE_NAME", value); |
67 EXPECT_TRUE(target->GetString(kPrivateKeyConfigPath, &value)); | 68 EXPECT_TRUE(target->GetString(kPrivateKeyConfigPath, &value)); |
68 EXPECT_EQ("TEST_PRIVATE_KEY", value); | 69 EXPECT_EQ("TEST_PRIVATE_KEY", value); |
69 | 70 |
70 EXPECT_FALSE(target->GetString("non_existent_value", &value)); | 71 EXPECT_FALSE(target->GetString("non_existent_value", &value)); |
71 } | 72 } |
72 | 73 |
73 TEST_F(HostConfigTest, Write) { | 74 TEST_F(HostConfigTest, Write) { |
74 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 75 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
75 | 76 |
76 base::FilePath test_file = test_dir_.path().AppendASCII("write.json"); | 77 base::FilePath test_file = test_dir_.path().AppendASCII("write.json"); |
77 WriteTestFile(test_file); | 78 WriteTestFile(test_file); |
78 scoped_ptr<base::DictionaryValue> target(HostConfigFromJsonFile(test_file)); | 79 std::unique_ptr<base::DictionaryValue> target( |
| 80 HostConfigFromJsonFile(test_file)); |
79 ASSERT_TRUE(target); | 81 ASSERT_TRUE(target); |
80 | 82 |
81 std::string new_refresh_token_value = "NEW_REFRESH_TOKEN"; | 83 std::string new_refresh_token_value = "NEW_REFRESH_TOKEN"; |
82 target->SetString(kOAuthRefreshTokenConfigPath, new_refresh_token_value); | 84 target->SetString(kOAuthRefreshTokenConfigPath, new_refresh_token_value); |
83 ASSERT_TRUE(HostConfigToJsonFile(*target, test_file)); | 85 ASSERT_TRUE(HostConfigToJsonFile(*target, test_file)); |
84 | 86 |
85 // Now read the file again and check that the value has been written. | 87 // Now read the file again and check that the value has been written. |
86 scoped_ptr<base::DictionaryValue> reader(HostConfigFromJsonFile(test_file)); | 88 std::unique_ptr<base::DictionaryValue> reader( |
| 89 HostConfigFromJsonFile(test_file)); |
87 ASSERT_TRUE(reader); | 90 ASSERT_TRUE(reader); |
88 | 91 |
89 std::string value; | 92 std::string value; |
90 EXPECT_TRUE(reader->GetString(kXmppLoginConfigPath, &value)); | 93 EXPECT_TRUE(reader->GetString(kXmppLoginConfigPath, &value)); |
91 EXPECT_EQ("test@gmail.com", value); | 94 EXPECT_EQ("test@gmail.com", value); |
92 EXPECT_TRUE(reader->GetString(kOAuthRefreshTokenConfigPath, &value)); | 95 EXPECT_TRUE(reader->GetString(kOAuthRefreshTokenConfigPath, &value)); |
93 EXPECT_EQ(new_refresh_token_value, value); | 96 EXPECT_EQ(new_refresh_token_value, value); |
94 EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); | 97 EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); |
95 EXPECT_EQ("TEST_HOST_ID", value); | 98 EXPECT_EQ("TEST_HOST_ID", value); |
96 EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); | 99 EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); |
97 EXPECT_EQ("TEST_MACHINE_NAME", value); | 100 EXPECT_EQ("TEST_MACHINE_NAME", value); |
98 EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); | 101 EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); |
99 EXPECT_EQ("TEST_PRIVATE_KEY", value); | 102 EXPECT_EQ("TEST_PRIVATE_KEY", value); |
100 } | 103 } |
101 | 104 |
102 } // namespace remoting | 105 } // namespace remoting |
OLD | NEW |