Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / remoting / host / config_file_watcher_unittest.cc
index 1d349a3..543f089 100644 (file)
@@ -4,8 +4,8 @@
 
 #include "remoting/host/config_file_watcher.h"
 
-#include "base/file_util.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/message_loop/message_loop.h"
 #include "base/run_loop.h"
 #include "remoting/base/auto_thread.h"
@@ -49,7 +49,7 @@ class ConfigFileWatcherTest : public testing::Test {
   void StopWatcher();
 
  protected:
-  base::MessageLoop message_loop_;
+  base::MessageLoopForUI message_loop_;
   base::RunLoop run_loop_;
 
   ConfigFileWatcherDelegate delegate_;
@@ -61,8 +61,7 @@ class ConfigFileWatcherTest : public testing::Test {
   scoped_ptr<ConfigFileWatcher> watcher_;
 };
 
-ConfigFileWatcherTest::ConfigFileWatcherTest()
-    : message_loop_(base::MessageLoop::TYPE_UI) {
+ConfigFileWatcherTest::ConfigFileWatcherTest() {
 }
 
 ConfigFileWatcherTest::~ConfigFileWatcherTest() {
@@ -73,6 +72,8 @@ void ConfigFileWatcherTest::StopWatcher() {
 }
 
 void ConfigFileWatcherTest::SetUp() {
+  EXPECT_TRUE(base::CreateTemporaryFile(&config_file_));
+
   // Arrange to run |message_loop_| until no components depend on it.
   scoped_refptr<AutoThreadTaskRunner> task_runner = new AutoThreadTaskRunner(
       message_loop_.message_loop_proxy(), run_loop_.QuitClosure());
@@ -83,7 +84,7 @@ void ConfigFileWatcherTest::SetUp() {
 
   // Create an instance of the config watcher.
   watcher_.reset(
-      new ConfigFileWatcher(task_runner, io_task_runner, &delegate_));
+      new ConfigFileWatcher(task_runner, io_task_runner, config_file_));
 }
 
 void ConfigFileWatcherTest::TearDown() {
@@ -94,10 +95,8 @@ void ConfigFileWatcherTest::TearDown() {
 
 // Verifies that the initial notification is delivered.
 TEST_F(ConfigFileWatcherTest, Basic) {
-  EXPECT_TRUE(file_util::CreateTemporaryFile(&config_file_));
-
   std::string data("test");
-  EXPECT_NE(file_util::WriteFile(config_file_, data.c_str(),
+  EXPECT_NE(base::WriteFile(config_file_, data.c_str(),
                                  static_cast<int>(data.size())), -1);
 
   EXPECT_CALL(delegate_, OnConfigUpdated(_))
@@ -106,7 +105,7 @@ TEST_F(ConfigFileWatcherTest, Basic) {
   EXPECT_CALL(delegate_, OnConfigWatcherError())
       .Times(0);
 
-  watcher_->Watch(config_file_);
+  watcher_->Watch(&delegate_);
   run_loop_.Run();
 }
 
@@ -116,19 +115,17 @@ MATCHER_P(EqualsString, s, "") {
 
 // Verifies that an update notification is sent when the file is changed.
 TEST_F(ConfigFileWatcherTest, Update) {
-  EXPECT_TRUE(file_util::CreateTemporaryFile(&config_file_));
-
   EXPECT_CALL(delegate_, OnConfigUpdated(EqualsString("test")))
       .Times(1)
       .WillOnce(InvokeWithoutArgs(this, &ConfigFileWatcherTest::StopWatcher));
   EXPECT_CALL(delegate_, OnConfigWatcherError())
       .Times(0);
 
-  watcher_->Watch(config_file_);
+  watcher_->Watch(&delegate_);
 
   // Modify the watched file.
   std::string data("test");
-  EXPECT_NE(file_util::WriteFile(config_file_, data.c_str(),
+  EXPECT_NE(base::WriteFile(config_file_, data.c_str(),
                                  static_cast<int>(data.size())), -1);
 
   run_loop_.Run();