| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 virtual ~ConfigFileWatcherTest(); | 42 virtual ~ConfigFileWatcherTest(); |
| 43 | 43 |
| 44 // testing::Test overrides | 44 // testing::Test overrides |
| 45 virtual void SetUp() OVERRIDE; | 45 virtual void SetUp() OVERRIDE; |
| 46 virtual void TearDown() OVERRIDE; | 46 virtual void TearDown() OVERRIDE; |
| 47 | 47 |
| 48 // Stops the config file watcher. | 48 // Stops the config file watcher. |
| 49 void StopWatcher(); | 49 void StopWatcher(); |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 MessageLoop message_loop_; | 52 base::MessageLoop message_loop_; |
| 53 base::RunLoop run_loop_; | 53 base::RunLoop run_loop_; |
| 54 | 54 |
| 55 ConfigFileWatcherDelegate delegate_; | 55 ConfigFileWatcherDelegate delegate_; |
| 56 | 56 |
| 57 // Path to the configuration file used. | 57 // Path to the configuration file used. |
| 58 base::FilePath config_file_; | 58 base::FilePath config_file_; |
| 59 | 59 |
| 60 // The configuration file watcher that is being tested. | 60 // The configuration file watcher that is being tested. |
| 61 scoped_ptr<ConfigFileWatcher> watcher_; | 61 scoped_ptr<ConfigFileWatcher> watcher_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 | |
| 65 ConfigFileWatcherTest::ConfigFileWatcherTest() | 64 ConfigFileWatcherTest::ConfigFileWatcherTest() |
| 66 : message_loop_(MessageLoop::TYPE_UI) { | 65 : message_loop_(base::MessageLoop::TYPE_UI) { |
| 67 } | 66 } |
| 68 | 67 |
| 69 ConfigFileWatcherTest::~ConfigFileWatcherTest() { | 68 ConfigFileWatcherTest::~ConfigFileWatcherTest() { |
| 70 } | 69 } |
| 71 | 70 |
| 72 void ConfigFileWatcherTest::StopWatcher() { | 71 void ConfigFileWatcherTest::StopWatcher() { |
| 73 watcher_.reset(); | 72 watcher_.reset(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 void ConfigFileWatcherTest::SetUp() { | 75 void ConfigFileWatcherTest::SetUp() { |
| 77 // Arrange to run |message_loop_| until no components depend on it. | 76 // Arrange to run |message_loop_| until no components depend on it. |
| 78 scoped_refptr<AutoThreadTaskRunner> task_runner = new AutoThreadTaskRunner( | 77 scoped_refptr<AutoThreadTaskRunner> task_runner = new AutoThreadTaskRunner( |
| 79 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); | 78 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); |
| 80 | 79 |
| 81 scoped_refptr<AutoThreadTaskRunner> io_task_runner = | 80 scoped_refptr<AutoThreadTaskRunner> io_task_runner = |
| 82 AutoThread::CreateWithType("IPC thread", task_runner, | 81 AutoThread::CreateWithType( |
| 83 MessageLoop::TYPE_IO); | 82 "IPC thread", task_runner, base::MessageLoop::TYPE_IO); |
| 84 | 83 |
| 85 // Create an instance of the config watcher. | 84 // Create an instance of the config watcher. |
| 86 watcher_.reset( | 85 watcher_.reset( |
| 87 new ConfigFileWatcher(task_runner, io_task_runner, &delegate_)); | 86 new ConfigFileWatcher(task_runner, io_task_runner, &delegate_)); |
| 88 } | 87 } |
| 89 | 88 |
| 90 void ConfigFileWatcherTest::TearDown() { | 89 void ConfigFileWatcherTest::TearDown() { |
| 91 // Delete the test file. | 90 // Delete the test file. |
| 92 if (!config_file_.empty()) | 91 if (!config_file_.empty()) |
| 93 file_util::Delete(config_file_, false); | 92 file_util::Delete(config_file_, false); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 128 |
| 130 // Modify the watched file. | 129 // Modify the watched file. |
| 131 std::string data("test"); | 130 std::string data("test"); |
| 132 EXPECT_NE(file_util::WriteFile(config_file_, data.c_str(), | 131 EXPECT_NE(file_util::WriteFile(config_file_, data.c_str(), |
| 133 static_cast<int>(data.size())), -1); | 132 static_cast<int>(data.size())), -1); |
| 134 | 133 |
| 135 run_loop_.Run(); | 134 run_loop_.Run(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 } // namespace remoting | 137 } // namespace remoting |
| OLD | NEW |