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