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 26 matching lines...) Expand all Loading... |
37 // The temporary directory used to contain the test operations. | 37 // The temporary directory used to contain the test operations. |
38 base::ScopedTempDir test_dir_; | 38 base::ScopedTempDir test_dir_; |
39 | 39 |
40 private: | 40 private: |
41 DISALLOW_COPY_AND_ASSIGN(HostConfigTest); | 41 DISALLOW_COPY_AND_ASSIGN(HostConfigTest); |
42 }; | 42 }; |
43 | 43 |
44 TEST_F(HostConfigTest, InvalidFile) { | 44 TEST_F(HostConfigTest, InvalidFile) { |
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_.GetPath().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_.GetPath().AppendASCII("read.json"); |
54 WriteTestFile(test_file); | 54 WriteTestFile(test_file); |
55 std::unique_ptr<base::DictionaryValue> target( | 55 std::unique_ptr<base::DictionaryValue> target( |
56 HostConfigFromJsonFile(test_file)); | 56 HostConfigFromJsonFile(test_file)); |
57 ASSERT_TRUE(target); | 57 ASSERT_TRUE(target); |
58 | 58 |
59 std::string value; | 59 std::string value; |
60 EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); | 60 EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); |
61 EXPECT_EQ("test@gmail.com", value); | 61 EXPECT_EQ("test@gmail.com", value); |
62 EXPECT_TRUE(target->GetString(kOAuthRefreshTokenConfigPath, &value)); | 62 EXPECT_TRUE(target->GetString(kOAuthRefreshTokenConfigPath, &value)); |
63 EXPECT_EQ("TEST_REFRESH_TOKEN", value); | 63 EXPECT_EQ("TEST_REFRESH_TOKEN", value); |
64 EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); | 64 EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); |
65 EXPECT_EQ("TEST_HOST_ID", value); | 65 EXPECT_EQ("TEST_HOST_ID", value); |
66 EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); | 66 EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); |
67 EXPECT_EQ("TEST_MACHINE_NAME", value); | 67 EXPECT_EQ("TEST_MACHINE_NAME", value); |
68 EXPECT_TRUE(target->GetString(kPrivateKeyConfigPath, &value)); | 68 EXPECT_TRUE(target->GetString(kPrivateKeyConfigPath, &value)); |
69 EXPECT_EQ("TEST_PRIVATE_KEY", value); | 69 EXPECT_EQ("TEST_PRIVATE_KEY", value); |
70 | 70 |
71 EXPECT_FALSE(target->GetString("non_existent_value", &value)); | 71 EXPECT_FALSE(target->GetString("non_existent_value", &value)); |
72 } | 72 } |
73 | 73 |
74 TEST_F(HostConfigTest, Write) { | 74 TEST_F(HostConfigTest, Write) { |
75 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 75 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
76 | 76 |
77 base::FilePath test_file = test_dir_.path().AppendASCII("write.json"); | 77 base::FilePath test_file = test_dir_.GetPath().AppendASCII("write.json"); |
78 WriteTestFile(test_file); | 78 WriteTestFile(test_file); |
79 std::unique_ptr<base::DictionaryValue> target( | 79 std::unique_ptr<base::DictionaryValue> target( |
80 HostConfigFromJsonFile(test_file)); | 80 HostConfigFromJsonFile(test_file)); |
81 ASSERT_TRUE(target); | 81 ASSERT_TRUE(target); |
82 | 82 |
83 std::string new_refresh_token_value = "NEW_REFRESH_TOKEN"; | 83 std::string new_refresh_token_value = "NEW_REFRESH_TOKEN"; |
84 target->SetString(kOAuthRefreshTokenConfigPath, new_refresh_token_value); | 84 target->SetString(kOAuthRefreshTokenConfigPath, new_refresh_token_value); |
85 ASSERT_TRUE(HostConfigToJsonFile(*target, test_file)); | 85 ASSERT_TRUE(HostConfigToJsonFile(*target, test_file)); |
86 | 86 |
87 // 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. |
88 std::unique_ptr<base::DictionaryValue> reader( | 88 std::unique_ptr<base::DictionaryValue> reader( |
89 HostConfigFromJsonFile(test_file)); | 89 HostConfigFromJsonFile(test_file)); |
90 ASSERT_TRUE(reader); | 90 ASSERT_TRUE(reader); |
91 | 91 |
92 std::string value; | 92 std::string value; |
93 EXPECT_TRUE(reader->GetString(kXmppLoginConfigPath, &value)); | 93 EXPECT_TRUE(reader->GetString(kXmppLoginConfigPath, &value)); |
94 EXPECT_EQ("test@gmail.com", value); | 94 EXPECT_EQ("test@gmail.com", value); |
95 EXPECT_TRUE(reader->GetString(kOAuthRefreshTokenConfigPath, &value)); | 95 EXPECT_TRUE(reader->GetString(kOAuthRefreshTokenConfigPath, &value)); |
96 EXPECT_EQ(new_refresh_token_value, value); | 96 EXPECT_EQ(new_refresh_token_value, value); |
97 EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); | 97 EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); |
98 EXPECT_EQ("TEST_HOST_ID", value); | 98 EXPECT_EQ("TEST_HOST_ID", value); |
99 EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); | 99 EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); |
100 EXPECT_EQ("TEST_MACHINE_NAME", value); | 100 EXPECT_EQ("TEST_MACHINE_NAME", value); |
101 EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); | 101 EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); |
102 EXPECT_EQ("TEST_PRIVATE_KEY", value); | 102 EXPECT_EQ("TEST_PRIVATE_KEY", value); |
103 } | 103 } |
104 | 104 |
105 } // namespace remoting | 105 } // namespace remoting |
OLD | NEW |