Add move constructor in ScopedClosureRunner.

With this change ScopedClosureRunner will be movable. This will
allow to store instances of that class in STL containers, e.g. to store
list of callbacks to be called when certain event happens.

Review-Url: https://codereview.chromium.org/2091503004
Cr-Commit-Position: refs/heads/master@{#402031}
diff --git a/base/callback_helpers_unittest.cc b/base/callback_helpers_unittest.cc
index 3b17a6b..0e42852 100644
--- a/base/callback_helpers_unittest.cc
+++ b/base/callback_helpers_unittest.cc
@@ -58,4 +58,47 @@
   EXPECT_EQ(1, run_count_3);
 }
 
+TEST(BindHelpersTest, TestScopedClosureRunnerMoveConstructor) {
+  int run_count = 0;
+  {
+    std::unique_ptr<base::ScopedClosureRunner> runner(
+        new base::ScopedClosureRunner(base::Bind(&Increment, &run_count)));
+    base::ScopedClosureRunner runner2(std::move(*runner));
+    runner.reset();
+    EXPECT_EQ(0, run_count);
+  }
+  EXPECT_EQ(1, run_count);
+}
+
+TEST(BindHelpersTest, TestScopedClosureRunnerMoveAssignment) {
+  int run_count = 0;
+  {
+    base::ScopedClosureRunner runner;
+    {
+      base::ScopedClosureRunner runner2(base::Bind(&Increment, &run_count));
+      runner = std::move(runner2);
+    }
+    EXPECT_EQ(0, run_count);
+  }
+  EXPECT_EQ(1, run_count);
+}
+
+TEST(BindHelpersTest, TestScopedClosureRunnerRunOnReplace) {
+  int run_count1 = 0;
+  int run_count2 = 0;
+  {
+    base::ScopedClosureRunner runner1(base::Bind(&Increment, &run_count1));
+    {
+      base::ScopedClosureRunner runner2(base::Bind(&Increment, &run_count2));
+      runner1 = std::move(runner2);
+      EXPECT_EQ(1, run_count1);
+      EXPECT_EQ(0, run_count2);
+    }
+    EXPECT_EQ(1, run_count1);
+    EXPECT_EQ(0, run_count2);
+  }
+  EXPECT_EQ(1, run_count1);
+  EXPECT_EQ(1, run_count2);
+}
+
 }  // namespace