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

Unified Diff: components/scheduler/child/task_queue_manager_unittest.cc

Issue 1252143002: scheduler: Don't run multiple tasks per batch in a nested run loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fix. Created 5 years, 5 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 | « components/scheduler/child/task_queue_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/scheduler/child/task_queue_manager_unittest.cc
diff --git a/components/scheduler/child/task_queue_manager_unittest.cc b/components/scheduler/child/task_queue_manager_unittest.cc
index 382660a843c130537438675a2928f786b71be486..d9eb15416ca36ee2dac0f1c65dfbaaf036046099 100644
--- a/components/scheduler/child/task_queue_manager_unittest.cc
+++ b/components/scheduler/child/task_queue_manager_unittest.cc
@@ -5,6 +5,7 @@
#include "components/scheduler/child/task_queue_manager.h"
#include "base/location.h"
+#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/thread.h"
@@ -997,4 +998,35 @@ TEST_F(TaskQueueManagerTest, DelayedTaskWithAbsoluteRunTime) {
EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4));
}
+void CheckIsNested(bool* is_nested) {
+ *is_nested = base::MessageLoop::current()->IsNested();
+}
+
+void PostAndQuitFromNestedRunloop(base::RunLoop* run_loop,
+ base::SingleThreadTaskRunner* runner,
+ bool* was_nested) {
+ base::MessageLoop::ScopedNestableTaskAllower allow(
+ base::MessageLoop::current());
+ runner->PostTask(FROM_HERE, run_loop->QuitClosure());
+ runner->PostTask(FROM_HERE, base::Bind(&CheckIsNested, was_nested));
+ run_loop->Run();
+}
+
+TEST_F(TaskQueueManagerTest, QuitWhileNested) {
+ // This test makes sure we don't continue running a work batch after a nested
+ // run loop has been exited in the middle of the batch.
+ InitializeWithRealMessageLoop(1u);
+ manager_->SetWorkBatchSize(2);
+
+ bool was_nested = true;
+ base::RunLoop run_loop;
+ runners_[0]->PostTask(
+ FROM_HERE,
+ base::Bind(&PostAndQuitFromNestedRunloop, base::Unretained(&run_loop),
+ runners_[0], base::Unretained(&was_nested)));
+
+ message_loop_->RunUntilIdle();
+ EXPECT_FALSE(was_nested);
+}
+
} // namespace scheduler
« no previous file with comments | « components/scheduler/child/task_queue_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698