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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/scheduler/child/task_queue_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/scheduler/child/task_queue_manager.h" 5 #include "components/scheduler/child/task_queue_manager.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
9 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
10 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
11 #include "cc/test/ordered_simple_task_runner.h" 12 #include "cc/test/ordered_simple_task_runner.h"
12 #include "components/scheduler/child/nestable_task_runner_for_test.h" 13 #include "components/scheduler/child/nestable_task_runner_for_test.h"
13 #include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" 14 #include "components/scheduler/child/scheduler_task_runner_delegate_impl.h"
14 #include "components/scheduler/child/task_queue_impl.h" 15 #include "components/scheduler/child/task_queue_impl.h"
15 #include "components/scheduler/child/task_queue_selector.h" 16 #include "components/scheduler/child/task_queue_selector.h"
16 #include "components/scheduler/child/task_queue_sets.h" 17 #include "components/scheduler/child/task_queue_sets.h"
17 #include "components/scheduler/child/test_time_source.h" 18 #include "components/scheduler/child/test_time_source.h"
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 FROM_HERE, base::Bind(&TestTask, 3, &run_order), runTime3); 991 FROM_HERE, base::Bind(&TestTask, 3, &run_order), runTime3);
991 runners_[0]->PostDelayedTaskAt( 992 runners_[0]->PostDelayedTaskAt(
992 FROM_HERE, base::Bind(&TestTask, 4, &run_order), runTime4); 993 FROM_HERE, base::Bind(&TestTask, 4, &run_order), runTime4);
993 994
994 now_src_->Advance(2 * delay); 995 now_src_->Advance(2 * delay);
995 test_task_runner_->RunUntilIdle(); 996 test_task_runner_->RunUntilIdle();
996 997
997 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4)); 998 EXPECT_THAT(run_order, ElementsAre(1, 2, 3, 4));
998 } 999 }
999 1000
1001 void CheckIsNested(bool* is_nested) {
1002 *is_nested = base::MessageLoop::current()->IsNested();
1003 }
1004
1005 void PostAndQuitFromNestedRunloop(base::RunLoop* run_loop,
1006 base::SingleThreadTaskRunner* runner,
1007 bool* was_nested) {
1008 base::MessageLoop::ScopedNestableTaskAllower allow(
1009 base::MessageLoop::current());
1010 runner->PostTask(FROM_HERE, run_loop->QuitClosure());
1011 runner->PostTask(FROM_HERE, base::Bind(&CheckIsNested, was_nested));
1012 run_loop->Run();
1013 }
1014
1015 TEST_F(TaskQueueManagerTest, QuitWhileNested) {
1016 // This test makes sure we don't continue running a work batch after a nested
1017 // run loop has been exited in the middle of the batch.
1018 InitializeWithRealMessageLoop(1u);
1019 manager_->SetWorkBatchSize(2);
1020
1021 bool was_nested = true;
1022 base::RunLoop run_loop;
1023 runners_[0]->PostTask(
1024 FROM_HERE,
1025 base::Bind(&PostAndQuitFromNestedRunloop, base::Unretained(&run_loop),
1026 runners_[0], base::Unretained(&was_nested)));
1027
1028 message_loop_->RunUntilIdle();
1029 EXPECT_FALSE(was_nested);
1030 }
1031
1000 } // namespace scheduler 1032 } // namespace scheduler
OLDNEW
« 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