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

Side by Side Diff: third_party/WebKit/Source/platform/TimerTest.cpp

Issue 2123783002: Expose RunsTasksOnCurrentThread through WebTaskRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@00_fix_thread_affinity
Patch Set: rebase Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/Timer.h" 5 #include "platform/Timer.h"
6 6
7 #include "platform/testing/TestingPlatformSupport.h" 7 #include "platform/testing/TestingPlatformSupport.h"
8 #include "public/platform/Platform.h" 8 #include "public/platform/Platform.h"
9 #include "public/platform/WebScheduler.h" 9 #include "public/platform/WebScheduler.h"
10 #include "public/platform/WebThread.h" 10 #include "public/platform/WebThread.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void postTask(const WebTraceLocation&, Task* task) override 81 void postTask(const WebTraceLocation&, Task* task) override
82 { 82 {
83 m_timerTasks->push(DelayedTask(task, 0)); 83 m_timerTasks->push(DelayedTask(task, 0));
84 } 84 }
85 85
86 void postDelayedTask(const WebTraceLocation&, Task* task, double delayMs) ov erride 86 void postDelayedTask(const WebTraceLocation&, Task* task, double delayMs) ov erride
87 { 87 {
88 m_timerTasks->push(DelayedTask(task, delayMs * 0.001)); 88 m_timerTasks->push(DelayedTask(task, delayMs * 0.001));
89 } 89 }
90 90
91 bool runsTasksOnCurrentThread() override
92 {
93 NOTREACHED();
94 return true;
95 }
96
91 WebTaskRunner* clone() override 97 WebTaskRunner* clone() override
92 { 98 {
93 ASSERT_NOT_REACHED(); 99 NOTREACHED();
94 return nullptr; 100 return nullptr;
95 } 101 }
96 102
97 double virtualTimeSeconds() const override 103 double virtualTimeSeconds() const override
98 { 104 {
99 ASSERT_NOT_REACHED(); 105 NOTREACHED();
100 return 0.0; 106 return 0.0;
101 } 107 }
102 108
103 double monotonicallyIncreasingVirtualTimeSeconds() const override 109 double monotonicallyIncreasingVirtualTimeSeconds() const override
104 { 110 {
105 return gCurrentTimeSecs; 111 return gCurrentTimeSecs;
106 } 112 }
107 113
108 std::priority_queue<DelayedTask>* m_timerTasks; // NOT OWNED 114 std::priority_queue<DelayedTask>* m_timerTasks; // NOT OWNED
109 }; 115 };
(...skipping 25 matching lines...) Expand all
135 { 141 {
136 } 142 }
137 143
138 WebTaskRunner* timerTaskRunner() override 144 WebTaskRunner* timerTaskRunner() override
139 { 145 {
140 return &m_timerWebTaskRunner; 146 return &m_timerWebTaskRunner;
141 } 147 }
142 148
143 WebTaskRunner* loadingTaskRunner() override 149 WebTaskRunner* loadingTaskRunner() override
144 { 150 {
145 ASSERT_NOT_REACHED(); 151 NOTREACHED();
146 return nullptr; 152 return nullptr;
147 } 153 }
148 154
149 void runUntilIdle() 155 void runUntilIdle()
150 { 156 {
151 while (m_timerTasks.size()) { 157 while (m_timerTasks.size()) {
152 gCurrentTimeSecs = m_timerTasks.top().runTimeSeconds(); 158 gCurrentTimeSecs = m_timerTasks.top().runTimeSeconds();
153 m_timerTasks.top().run(); 159 m_timerTasks.top().run();
154 m_timerTasks.pop(); 160 m_timerTasks.pop();
155 } 161 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 MockWebTaskRunner m_timerWebTaskRunner; 206 MockWebTaskRunner m_timerWebTaskRunner;
201 }; 207 };
202 208
203 class FakeWebThread : public WebThread { 209 class FakeWebThread : public WebThread {
204 public: 210 public:
205 FakeWebThread() : m_webScheduler(wrapUnique(new MockWebScheduler())) { } 211 FakeWebThread() : m_webScheduler(wrapUnique(new MockWebScheduler())) { }
206 ~FakeWebThread() override { } 212 ~FakeWebThread() override { }
207 213
208 virtual bool isCurrentThread() const 214 virtual bool isCurrentThread() const
209 { 215 {
210 ASSERT_NOT_REACHED(); 216 NOTREACHED();
211 return true; 217 return true;
212 } 218 }
213 219
214 virtual PlatformThreadId threadId() const 220 virtual PlatformThreadId threadId() const
215 { 221 {
216 ASSERT_NOT_REACHED(); 222 NOTREACHED();
217 return 0; 223 return 0;
218 } 224 }
219 225
220 WebTaskRunner* getWebTaskRunner() override 226 WebTaskRunner* getWebTaskRunner() override
221 { 227 {
222 ASSERT_NOT_REACHED(); 228 NOTREACHED();
223 return nullptr; 229 return nullptr;
224 } 230 }
225 231
226 WebScheduler* scheduler() const override 232 WebScheduler* scheduler() const override
227 { 233 {
228 return m_webScheduler.get(); 234 return m_webScheduler.get();
229 } 235 }
230 236
231 virtual void enterRunLoop() 237 virtual void enterRunLoop()
232 { 238 {
233 ASSERT_NOT_REACHED(); 239 NOTREACHED();
234 } 240 }
235 241
236 virtual void exitRunLoop() 242 virtual void exitRunLoop()
237 { 243 {
238 ASSERT_NOT_REACHED(); 244 NOTREACHED();
239 } 245 }
240 246
241 private: 247 private:
242 std::unique_ptr<MockWebScheduler> m_webScheduler; 248 std::unique_ptr<MockWebScheduler> m_webScheduler;
243 }; 249 };
244 250
245 class TimerTestPlatform : public TestingPlatformSupport { 251 class TimerTestPlatform : public TestingPlatformSupport {
246 public: 252 public:
247 TimerTestPlatform() 253 TimerTestPlatform()
248 : m_webThread(wrapUnique(new FakeWebThread())) { } 254 : m_webThread(wrapUnique(new FakeWebThread())) { }
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner); 784 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner);
779 timer.startOneShot(0, BLINK_FROM_HERE); 785 timer.startOneShot(0, BLINK_FROM_HERE);
780 786
781 // Make sure the task was posted on taskRunner. 787 // Make sure the task was posted on taskRunner.
782 EXPECT_FALSE(timerTasks.empty()); 788 EXPECT_FALSE(timerTasks.empty());
783 } 789 }
784 790
785 791
786 } // namespace 792 } // namespace
787 } // namespace blink 793 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698