| Index: gin/modules/timer_unittest.cc | 
| diff --git a/gin/modules/timer_unittest.cc b/gin/modules/timer_unittest.cc | 
| index bd4b3450f0ac3c3caf71408f8d8055200326a445..665ea4e788d56bebf4170217433b20ce9349cab0 100644 | 
| --- a/gin/modules/timer_unittest.cc | 
| +++ b/gin/modules/timer_unittest.cc | 
| @@ -67,12 +67,6 @@ struct TestHelper { | 
| result->GetWrapper(isolate).ToLocalChecked()); | 
| } | 
|  | 
| -  void QuitSoon(base::MessageLoop* message_loop) { | 
| -    message_loop->task_runner()->PostDelayedTask( | 
| -        FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 
| -        base::TimeDelta::FromMilliseconds(0)); | 
| -  } | 
| - | 
| ShellRunnerDelegate delegate; | 
| std::unique_ptr<ShellRunner> runner; | 
| Runner::Scope scope; | 
| @@ -94,8 +88,7 @@ TEST_F(TimerUnittest, OneShot) { | 
| helper.runner->Run(source, "script"); | 
| EXPECT_EQ(0, helper.result->count()); | 
|  | 
| -  helper.QuitSoon(&message_loop_); | 
| -  base::RunLoop().Run(); | 
| +  base::RunLoop().RunUntilIdle(); | 
| EXPECT_EQ(1, helper.result->count()); | 
| } | 
|  | 
| @@ -110,8 +103,7 @@ TEST_F(TimerUnittest, OneShotCancel) { | 
| helper.runner->Run(source, "script"); | 
| EXPECT_EQ(0, helper.result->count()); | 
|  | 
| -  helper.QuitSoon(&message_loop_); | 
| -  base::RunLoop().Run(); | 
| +  base::RunLoop().RunUntilIdle(); | 
| EXPECT_EQ(0, helper.result->count()); | 
| } | 
|  | 
| @@ -121,12 +113,15 @@ TEST_F(TimerUnittest, Repeating) { | 
| // TODO(aa): Cannot do: if (++result.count == 3) because of v8 bug. Create | 
| // test case and report. | 
| std::string source = | 
| -     "timer.createRepeating(0, function() {" | 
| -     "  result.count++;" | 
| -     "  if (result.count == 3) {" | 
| -     "    result.quit();" | 
| -     "  }" | 
| -     "});"; | 
| +      "var t = timer.createRepeating(0, function() {" | 
| +      "  result.count++;" | 
| +      "  if (result.count == 3) {" | 
| +      "    /* Cancel the timer to prevent a hang when ScopedTaskEnvironment " | 
| +      "       flushes main thread tasks. */" | 
| +      "    t.cancel();" | 
| +      "    result.quit();" | 
| +      "  }" | 
| +      "});"; | 
|  | 
| helper.runner->Run(source, "script"); | 
| EXPECT_EQ(0, helper.result->count()); | 
| @@ -146,9 +141,8 @@ TEST_F(TimerUnittest, TimerCallbackToDestroyedRunner) { | 
| EXPECT_EQ(0, helper.result->count()); | 
|  | 
| // Destroy runner, which should destroy the timer object we created. | 
| -  helper.QuitSoon(&message_loop_); | 
| helper.runner.reset(NULL); | 
| -  base::RunLoop().Run(); | 
| +  base::RunLoop().RunUntilIdle(); | 
|  | 
| // Timer should not have run because it was deleted. | 
| EXPECT_EQ(0, helper.result->count()); | 
|  |