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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_manager_unittest.cc

Issue 2818533003: Make nesting/running states a RunLoop rather than a MessageLoop concept. (Closed)
Patch Set: still need to check MessageLoop::current() in Mojo's RunLoopNestingObserver::GetForThread() 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 unified diff | Download patch
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 "platform/scheduler/base/task_queue_manager.h" 5 #include "platform/scheduler/base/task_queue_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 using TaskQueueManager::NextTaskDelay; 53 using TaskQueueManager::NextTaskDelay;
54 }; 54 };
55 55
56 class MessageLoopTaskRunner : public TaskQueueManagerDelegateForTest { 56 class MessageLoopTaskRunner : public TaskQueueManagerDelegateForTest {
57 public: 57 public:
58 static scoped_refptr<MessageLoopTaskRunner> Create( 58 static scoped_refptr<MessageLoopTaskRunner> Create(
59 std::unique_ptr<base::TickClock> tick_clock) { 59 std::unique_ptr<base::TickClock> tick_clock) {
60 return make_scoped_refptr(new MessageLoopTaskRunner(std::move(tick_clock))); 60 return make_scoped_refptr(new MessageLoopTaskRunner(std::move(tick_clock)));
61 } 61 }
62 62
63 // NestableTaskRunner implementation. 63 // TaskQueueManagerDelegateForTest:
64 bool IsNested() const override { 64 bool IsNested() const override {
65 return base::MessageLoop::current()->IsNested(); 65 DCHECK(RunsTasksOnCurrentThread());
66 return base::RunLoop::IsNestedOnCurrentThread();
66 } 67 }
67 68
68 void AddNestingObserver( 69 void AddNestingObserver(base::RunLoop::NestingObserver* observer) override {
69 base::MessageLoop::NestingObserver* observer) override { 70 base::RunLoop::AddNestingObserverOnCurrentThread(observer);
70 base::MessageLoop::current()->AddNestingObserver(observer);
71 } 71 }
72 72
73 void RemoveNestingObserver( 73 void RemoveNestingObserver(
74 base::MessageLoop::NestingObserver* observer) override { 74 base::RunLoop::NestingObserver* observer) override {
75 base::MessageLoop::current()->RemoveNestingObserver(observer); 75 base::RunLoop::RemoveNestingObserverOnCurrentThread(observer);
76 } 76 }
77 77
78 private: 78 private:
79 explicit MessageLoopTaskRunner(std::unique_ptr<base::TickClock> tick_clock) 79 explicit MessageLoopTaskRunner(std::unique_ptr<base::TickClock> tick_clock)
80 : TaskQueueManagerDelegateForTest(base::ThreadTaskRunnerHandle::Get(), 80 : TaskQueueManagerDelegateForTest(base::ThreadTaskRunnerHandle::Get(),
81 std::move(tick_clock)) {} 81 std::move(tick_clock)) {}
82 ~MessageLoopTaskRunner() override {} 82 ~MessageLoopTaskRunner() override {}
83 }; 83 };
84 84
85 class TaskQueueManagerTest : public testing::Test { 85 class TaskQueueManagerTest : public testing::Test {
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 runners_[1]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order), 1244 runners_[1]->PostDelayedTask(FROM_HERE, base::Bind(&TestTask, 2, &run_order),
1245 delay2); 1245 delay2);
1246 1246
1247 now_src_->Advance(delay1 * 2); 1247 now_src_->Advance(delay1 * 2);
1248 test_task_runner_->RunUntilIdle(); 1248 test_task_runner_->RunUntilIdle();
1249 1249
1250 EXPECT_THAT(run_order, ElementsAre(2, 1)); 1250 EXPECT_THAT(run_order, ElementsAre(2, 1));
1251 } 1251 }
1252 1252
1253 void CheckIsNested(bool* is_nested) { 1253 void CheckIsNested(bool* is_nested) {
1254 *is_nested = base::MessageLoop::current()->IsNested(); 1254 *is_nested = base::RunLoop::IsNestedOnCurrentThread();
1255 } 1255 }
1256 1256
1257 void PostAndQuitFromNestedRunloop(base::RunLoop* run_loop, 1257 void PostAndQuitFromNestedRunloop(base::RunLoop* run_loop,
1258 base::SingleThreadTaskRunner* runner, 1258 base::SingleThreadTaskRunner* runner,
1259 bool* was_nested) { 1259 bool* was_nested) {
1260 base::MessageLoop::ScopedNestableTaskAllower allow( 1260 base::MessageLoop::ScopedNestableTaskAllower allow(
1261 base::MessageLoop::current()); 1261 base::MessageLoop::current());
1262 runner->PostTask(FROM_HERE, run_loop->QuitClosure()); 1262 runner->PostTask(FROM_HERE, run_loop->QuitClosure());
1263 runner->PostTask(FROM_HERE, base::Bind(&CheckIsNested, was_nested)); 1263 runner->PostTask(FROM_HERE, base::Bind(&CheckIsNested, was_nested));
1264 run_loop->Run(); 1264 run_loop->Run();
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after
2908 manager_->RegisterTimeDomain(domain.get()); 2908 manager_->RegisterTimeDomain(domain.get());
2909 runners_[0]->SetTimeDomain(domain.get()); 2909 runners_[0]->SetTimeDomain(domain.get());
2910 2910
2911 // Tidy up. 2911 // Tidy up.
2912 runners_[0]->UnregisterTaskQueue(); 2912 runners_[0]->UnregisterTaskQueue();
2913 manager_->UnregisterTimeDomain(domain.get()); 2913 manager_->UnregisterTimeDomain(domain.get());
2914 } 2914 }
2915 2915
2916 } // namespace scheduler 2916 } // namespace scheduler
2917 } // namespace blink 2917 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698