OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/config_file_watcher.h" | 5 #include "remoting/host/config_file_watcher.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 void ConfigFileWatcherTest::TearDown() { | 90 void ConfigFileWatcherTest::TearDown() { |
91 // Delete the test file. | 91 // Delete the test file. |
92 if (!config_file_.empty()) | 92 if (!config_file_.empty()) |
93 base::DeleteFile(config_file_, false); | 93 base::DeleteFile(config_file_, false); |
94 } | 94 } |
95 | 95 |
96 // Verifies that the initial notification is delivered. | 96 // Verifies that the initial notification is delivered. |
97 TEST_F(ConfigFileWatcherTest, Basic) { | 97 TEST_F(ConfigFileWatcherTest, Basic) { |
98 std::string data("test"); | 98 std::string data("test"); |
99 EXPECT_NE(file_util::WriteFile(config_file_, data.c_str(), | 99 EXPECT_NE(base::WriteFile(config_file_, data.c_str(), |
100 static_cast<int>(data.size())), -1); | 100 static_cast<int>(data.size())), -1); |
101 | 101 |
102 EXPECT_CALL(delegate_, OnConfigUpdated(_)) | 102 EXPECT_CALL(delegate_, OnConfigUpdated(_)) |
103 .Times(1) | 103 .Times(1) |
104 .WillOnce(InvokeWithoutArgs(this, &ConfigFileWatcherTest::StopWatcher)); | 104 .WillOnce(InvokeWithoutArgs(this, &ConfigFileWatcherTest::StopWatcher)); |
105 EXPECT_CALL(delegate_, OnConfigWatcherError()) | 105 EXPECT_CALL(delegate_, OnConfigWatcherError()) |
106 .Times(0); | 106 .Times(0); |
107 | 107 |
108 watcher_->Watch(&delegate_); | 108 watcher_->Watch(&delegate_); |
109 run_loop_.Run(); | 109 run_loop_.Run(); |
110 } | 110 } |
111 | 111 |
112 MATCHER_P(EqualsString, s, "") { | 112 MATCHER_P(EqualsString, s, "") { |
113 return arg == s; | 113 return arg == s; |
114 } | 114 } |
115 | 115 |
116 // Verifies that an update notification is sent when the file is changed. | 116 // Verifies that an update notification is sent when the file is changed. |
117 TEST_F(ConfigFileWatcherTest, Update) { | 117 TEST_F(ConfigFileWatcherTest, Update) { |
118 EXPECT_CALL(delegate_, OnConfigUpdated(EqualsString("test"))) | 118 EXPECT_CALL(delegate_, OnConfigUpdated(EqualsString("test"))) |
119 .Times(1) | 119 .Times(1) |
120 .WillOnce(InvokeWithoutArgs(this, &ConfigFileWatcherTest::StopWatcher)); | 120 .WillOnce(InvokeWithoutArgs(this, &ConfigFileWatcherTest::StopWatcher)); |
121 EXPECT_CALL(delegate_, OnConfigWatcherError()) | 121 EXPECT_CALL(delegate_, OnConfigWatcherError()) |
122 .Times(0); | 122 .Times(0); |
123 | 123 |
124 watcher_->Watch(&delegate_); | 124 watcher_->Watch(&delegate_); |
125 | 125 |
126 // Modify the watched file. | 126 // Modify the watched file. |
127 std::string data("test"); | 127 std::string data("test"); |
128 EXPECT_NE(file_util::WriteFile(config_file_, data.c_str(), | 128 EXPECT_NE(base::WriteFile(config_file_, data.c_str(), |
129 static_cast<int>(data.size())), -1); | 129 static_cast<int>(data.size())), -1); |
130 | 130 |
131 run_loop_.Run(); | 131 run_loop_.Run(); |
132 } | 132 } |
133 | 133 |
134 } // namespace remoting | 134 } // namespace remoting |
OLD | NEW |