Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: gin/modules/timer_unittest.cc

Issue 2852373004: Use ScopedTaskEnvironment instead of MessageLoop in tests that use v8. (Closed)
Patch Set: Reset-RenderViewTest Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/BUILD.gn ('k') | gin/shell_runner_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « gin/BUILD.gn ('k') | gin/shell_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698