Revert "[base] Use TaskRunner instead of MessageLoop in FileDescriptorWatcher"

This reverts commit fcce12fe035224e4574097f3f15398b766276ccd.

Reason for revert: base_unittests failures: crbug.com/899263.

Original change's description:
> [base] Use TaskRunner instead of MessageLoop in FileDescriptorWatcher
> 
> Do not use MessageLoopForIO as it is used to post tasks anyway.
> 
> R=​gab@chromium.org
> TBR=gab@chromium.org
> BUG=891670
> 
> Change-Id: Ib255c6a5a5dd55c2654eaa284d43d7f78f06b244
> Reviewed-on: https://chromium-review.googlesource.com/c/1299239
> Commit-Queue: Alexander Timin <altimin@chromium.org>
> Reviewed-by: Alexander Timin <altimin@chromium.org>
> Reviewed-by: Gabriel Charette <gab@chromium.org>
> Reviewed-by: François Doray <fdoray@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#603076}

TBR=gab@chromium.org,fdoray@chromium.org,altimin@chromium.org

Change-Id: I1185c518e8243837cafdbee68d163b0cfdf611fc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 891670
Reviewed-on: https://chromium-review.googlesource.com/c/1302013
Reviewed-by: Alexander Timin <altimin@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#603115}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 17956924e472a949e04668b18de0c0a93b0bc4be
diff --git a/BUILD.gn b/BUILD.gn
index 0c9e8ce..c6f4a12 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -23,7 +23,6 @@
   deps = [
     ":timers",
     "//base",
-    "//base/test:test_support",
     "//testing/gtest",
   ]
 }
diff --git a/alarm_timer_unittest.cc b/alarm_timer_unittest.cc
index 7863d77..868eb78 100644
--- a/alarm_timer_unittest.cc
+++ b/alarm_timer_unittest.cc
@@ -8,11 +8,12 @@
 
 #include "base/bind.h"
 #include "base/bind_helpers.h"
+#include "base/files/file_descriptor_watcher_posix.h"
 #include "base/location.h"
 #include "base/macros.h"
+#include "base/message_loop/message_loop.h"
 #include "base/run_loop.h"
 #include "base/single_thread_task_runner.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/threading/platform_thread.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "base/time/time.h"
@@ -95,8 +96,8 @@
 // that timers work properly in all configurations.
 
 TEST(AlarmTimerTest, SimpleAlarmTimer) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   base::RunLoop run_loop;
   bool did_run = false;
@@ -110,8 +111,8 @@
 }
 
 TEST(AlarmTimerTest, SimpleAlarmTimer_Cancel) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   bool did_run_a = false;
   AlarmTimerTester* a =
@@ -138,8 +139,8 @@
 // If underlying timer does not handle this properly, we will crash or fail
 // in full page heap environment.
 TEST(AlarmTimerTest, SelfDeletingAlarmTimer) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   base::RunLoop run_loop;
   bool did_run = false;
@@ -153,8 +154,8 @@
 }
 
 TEST(AlarmTimerTest, AlarmTimerZeroDelay) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   base::RunLoop run_loop;
   bool did_run = false;
@@ -168,8 +169,8 @@
 }
 
 TEST(AlarmTimerTest, AlarmTimerZeroDelay_Cancel) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   bool did_run_a = false;
   AlarmTimerTester* a =
@@ -200,9 +201,9 @@
   // if debug heap checking is enabled.
   bool did_run = false;
   {
-    base::test::ScopedTaskEnvironment task_environment(
-        base::test::ScopedTaskEnvironment::MainThreadType::IO);
-
+    auto loop = std::make_unique<base::MessageLoopForIO>();
+    auto file_descriptor_watcher =
+        std::make_unique<base::FileDescriptorWatcher>(loop.get());
     AlarmTimerTester a(&did_run, kTenMilliseconds, base::OnceClosure());
     AlarmTimerTester b(&did_run, kTenMilliseconds, base::OnceClosure());
     AlarmTimerTester c(&did_run, kTenMilliseconds, base::OnceClosure());
@@ -215,6 +216,9 @@
     // tasks posted by FileDescriptorWatcher::WatchReadable() are leaked.
     base::RunLoop().RunUntilIdle();
 
+    // MessageLoop and FileDescriptorWatcher destruct.
+    file_descriptor_watcher.reset();
+    loop.reset();
   }  // SimpleAlarmTimers destruct. SHOULD NOT CRASH, of course.
 
   EXPECT_FALSE(did_run);
@@ -222,9 +226,8 @@
 
 TEST(AlarmTimerTest, NonRepeatIsRunning) {
   {
-    base::test::ScopedTaskEnvironment task_environment(
-        base::test::ScopedTaskEnvironment::MainThreadType::IO);
-
+    base::MessageLoopForIO loop;
+    base::FileDescriptorWatcher file_descriptor_watcher(&loop);
     timers::SimpleAlarmTimer timer;
     EXPECT_FALSE(timer.IsRunning());
     timer.Start(FROM_HERE, base::TimeDelta::FromDays(1), base::DoNothing());
@@ -244,9 +247,8 @@
 }
 
 TEST(AlarmTimerTest, RetainNonRepeatIsRunning) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
-
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
   timers::SimpleAlarmTimer timer;
   EXPECT_FALSE(timer.IsRunning());
   timer.Start(FROM_HERE, base::TimeDelta::FromDays(1), base::DoNothing());
@@ -290,9 +292,8 @@
 
 TEST(AlarmTimerTest, ContinuationStopStart) {
   ClearAllCallbackHappened();
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
-
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
   timers::SimpleAlarmTimer timer;
   timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(10),
               base::BindRepeating(&SetCallbackHappened1,
@@ -311,8 +312,8 @@
 
 TEST(AlarmTimerTest, ContinuationReset) {
   ClearAllCallbackHappened();
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   base::RunLoop run_loop;
   timers::SimpleAlarmTimer timer;
@@ -328,9 +329,8 @@
 // Verify that no crash occurs if a timer is deleted while its callback is
 // running.
 TEST(AlarmTimerTest, DeleteTimerWhileCallbackIsRunning) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
-
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
   base::RunLoop run_loop;
 
   // Will be deleted by the callback.
@@ -350,8 +350,8 @@
 // Verify that no crash occurs if a zero-delay timer is deleted while its
 // callback is running.
 TEST(AlarmTimerTest, DeleteTimerWhileCallbackIsRunningZeroDelay) {
-  base::test::ScopedTaskEnvironment task_environment(
-      base::test::ScopedTaskEnvironment::MainThreadType::IO);
+  base::MessageLoopForIO loop;
+  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
   base::RunLoop run_loop;
 
   // Will be deleted by the callback.