OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ScopedTempDir test_dir_; | 47 ScopedTempDir test_dir_; |
48 // A message loop that we can use as the file thread message loop. | 48 // A message loop that we can use as the file thread message loop. |
49 MessageLoop message_loop_; | 49 MessageLoop message_loop_; |
50 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 50 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
51 }; | 51 }; |
52 | 52 |
53 TEST_F(JsonHostConfigTest, InvalidFile) { | 53 TEST_F(JsonHostConfigTest, InvalidFile) { |
54 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 54 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
55 FilePath non_existent_file = | 55 FilePath non_existent_file = |
56 test_dir_.path().AppendASCII("non_existent.json"); | 56 test_dir_.path().AppendASCII("non_existent.json"); |
57 scoped_refptr<JsonHostConfig> target = | 57 scoped_refptr<JsonHostConfig> target( |
58 new JsonHostConfig(non_existent_file, message_loop_proxy_.get()); | 58 new JsonHostConfig(non_existent_file, message_loop_proxy_.get())); |
59 EXPECT_FALSE(target->Read()); | 59 EXPECT_FALSE(target->Read()); |
60 } | 60 } |
61 | 61 |
62 TEST_F(JsonHostConfigTest, Read) { | 62 TEST_F(JsonHostConfigTest, Read) { |
63 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 63 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
64 FilePath test_file = test_dir_.path().AppendASCII("read.json"); | 64 FilePath test_file = test_dir_.path().AppendASCII("read.json"); |
65 WriteTestFile(test_file); | 65 WriteTestFile(test_file); |
66 scoped_refptr<JsonHostConfig> target = | 66 scoped_refptr<JsonHostConfig> target( |
67 new JsonHostConfig(test_file, message_loop_proxy_.get()); | 67 new JsonHostConfig(test_file, message_loop_proxy_.get())); |
68 ASSERT_TRUE(target->Read()); | 68 ASSERT_TRUE(target->Read()); |
69 | 69 |
70 std::string value; | 70 std::string value; |
71 EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); | 71 EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); |
72 EXPECT_EQ("test@gmail.com", value); | 72 EXPECT_EQ("test@gmail.com", value); |
73 EXPECT_TRUE(target->GetString(kXmppAuthTokenConfigPath, &value)); | 73 EXPECT_TRUE(target->GetString(kXmppAuthTokenConfigPath, &value)); |
74 EXPECT_EQ("TEST_AUTH_TOKEN", value); | 74 EXPECT_EQ("TEST_AUTH_TOKEN", value); |
75 EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); | 75 EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); |
76 EXPECT_EQ("TEST_HOST_ID", value); | 76 EXPECT_EQ("TEST_HOST_ID", value); |
77 EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); | 77 EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 EXPECT_EQ(new_auth_token_value, value); | 112 EXPECT_EQ(new_auth_token_value, value); |
113 EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); | 113 EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); |
114 EXPECT_EQ("TEST_HOST_ID", value); | 114 EXPECT_EQ("TEST_HOST_ID", value); |
115 EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); | 115 EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); |
116 EXPECT_EQ("TEST_MACHINE_NAME", value); | 116 EXPECT_EQ("TEST_MACHINE_NAME", value); |
117 EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); | 117 EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); |
118 EXPECT_EQ("TEST_PRIVATE_KEY", value); | 118 EXPECT_EQ("TEST_PRIVATE_KEY", value); |
119 } | 119 } |
120 | 120 |
121 } | 121 } |
OLD | NEW |