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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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"
11 #include "public/platform/WebViewScheduler.h" 11 #include "public/platform/WebViewScheduler.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "wtf/PtrUtil.h"
15 #include "wtf/RefCounted.h" 14 #include "wtf/RefCounted.h"
16 #include <memory>
17 #include <queue> 15 #include <queue>
18 16
19 using testing::ElementsAre; 17 using testing::ElementsAre;
20 18
21 namespace blink { 19 namespace blink {
22 namespace { 20 namespace {
23 double gCurrentTimeSecs = 0.0; 21 double gCurrentTimeSecs = 0.0;
24 22
25 // This class exists because gcc doesn't know how to move an std::unique_ptr. 23 // This class exists because gcc doesn't know how to move an OwnPtr.
26 class RefCountedTaskContainer : public RefCounted<RefCountedTaskContainer> { 24 class RefCountedTaskContainer : public RefCounted<RefCountedTaskContainer> {
27 public: 25 public:
28 explicit RefCountedTaskContainer(WebTaskRunner::Task* task) : m_task(wrapUni que(task)) { } 26 explicit RefCountedTaskContainer(WebTaskRunner::Task* task) : m_task(adoptPt r(task)) { }
29 27
30 ~RefCountedTaskContainer() { } 28 ~RefCountedTaskContainer() { }
31 29
32 void run() 30 void run()
33 { 31 {
34 m_task->run(); 32 m_task->run();
35 } 33 }
36 34
37 private: 35 private:
38 std::unique_ptr<WebTaskRunner::Task> m_task; 36 OwnPtr<WebTaskRunner::Task> m_task;
39 }; 37 };
40 38
41 class DelayedTask { 39 class DelayedTask {
42 public: 40 public:
43 DelayedTask(WebTaskRunner::Task* task, double delaySeconds) 41 DelayedTask(WebTaskRunner::Task* task, double delaySeconds)
44 : m_task(adoptRef(new RefCountedTaskContainer(task))) 42 : m_task(adoptRef(new RefCountedTaskContainer(task)))
45 , m_runTimeSeconds(gCurrentTimeSecs + delaySeconds) 43 , m_runTimeSeconds(gCurrentTimeSecs + delaySeconds)
46 , m_delaySeconds(delaySeconds) 44 , m_delaySeconds(delaySeconds)
47 { 45 {
48 } 46 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void removePendingNavigation(WebScheduler::NavigatingFrameType) override { } 193 void removePendingNavigation(WebScheduler::NavigatingFrameType) override { }
196 void onNavigationStarted() override { } 194 void onNavigationStarted() override { }
197 195
198 private: 196 private:
199 std::priority_queue<DelayedTask> m_timerTasks; 197 std::priority_queue<DelayedTask> m_timerTasks;
200 MockWebTaskRunner m_timerWebTaskRunner; 198 MockWebTaskRunner m_timerWebTaskRunner;
201 }; 199 };
202 200
203 class FakeWebThread : public WebThread { 201 class FakeWebThread : public WebThread {
204 public: 202 public:
205 FakeWebThread() : m_webScheduler(wrapUnique(new MockWebScheduler())) { } 203 FakeWebThread() : m_webScheduler(adoptPtr(new MockWebScheduler())) { }
206 ~FakeWebThread() override { } 204 ~FakeWebThread() override { }
207 205
208 virtual bool isCurrentThread() const 206 virtual bool isCurrentThread() const
209 { 207 {
210 ASSERT_NOT_REACHED(); 208 ASSERT_NOT_REACHED();
211 return true; 209 return true;
212 } 210 }
213 211
214 virtual PlatformThreadId threadId() const 212 virtual PlatformThreadId threadId() const
215 { 213 {
(...skipping 16 matching lines...) Expand all
232 { 230 {
233 ASSERT_NOT_REACHED(); 231 ASSERT_NOT_REACHED();
234 } 232 }
235 233
236 virtual void exitRunLoop() 234 virtual void exitRunLoop()
237 { 235 {
238 ASSERT_NOT_REACHED(); 236 ASSERT_NOT_REACHED();
239 } 237 }
240 238
241 private: 239 private:
242 std::unique_ptr<MockWebScheduler> m_webScheduler; 240 OwnPtr<MockWebScheduler> m_webScheduler;
243 }; 241 };
244 242
245 class TimerTestPlatform : public TestingPlatformSupport { 243 class TimerTestPlatform : public TestingPlatformSupport {
246 public: 244 public:
247 TimerTestPlatform() 245 TimerTestPlatform()
248 : m_webThread(wrapUnique(new FakeWebThread())) { } 246 : m_webThread(adoptPtr(new FakeWebThread())) { }
249 ~TimerTestPlatform() override { } 247 ~TimerTestPlatform() override { }
250 248
251 WebThread* currentThread() override 249 WebThread* currentThread() override
252 { 250 {
253 return m_webThread.get(); 251 return m_webThread.get();
254 } 252 }
255 253
256 void runUntilIdle() 254 void runUntilIdle()
257 { 255 {
258 mockScheduler()->runUntilIdle(); 256 mockScheduler()->runUntilIdle();
(...skipping 18 matching lines...) Expand all
277 { 275 {
278 return mockScheduler()->nextTimerTaskDelaySecs(); 276 return mockScheduler()->nextTimerTaskDelaySecs();
279 } 277 }
280 278
281 private: 279 private:
282 MockWebScheduler* mockScheduler() const 280 MockWebScheduler* mockScheduler() const
283 { 281 {
284 return static_cast<MockWebScheduler*>(m_webThread->scheduler()); 282 return static_cast<MockWebScheduler*>(m_webThread->scheduler());
285 } 283 }
286 284
287 std::unique_ptr<FakeWebThread> m_webThread; 285 OwnPtr<FakeWebThread> m_webThread;
288 }; 286 };
289 287
290 class TimerTest : public testing::Test { 288 class TimerTest : public testing::Test {
291 public: 289 public:
292 void SetUp() override 290 void SetUp() override
293 { 291 {
294 m_runTimes.clear(); 292 m_runTimes.clear();
295 gCurrentTimeSecs = 10.0; 293 gCurrentTimeSecs = 10.0;
296 m_startTime = gCurrentTimeSecs; 294 m_startTime = gCurrentTimeSecs;
297 } 295 }
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner); 776 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner);
779 timer.startOneShot(0, BLINK_FROM_HERE); 777 timer.startOneShot(0, BLINK_FROM_HERE);
780 778
781 // Make sure the task was posted on taskRunner. 779 // Make sure the task was posted on taskRunner.
782 EXPECT_FALSE(timerTasks.empty()); 780 EXPECT_FALSE(timerTasks.empty());
783 } 781 }
784 782
785 783
786 } // namespace 784 } // namespace
787 } // namespace blink 785 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/SharedBufferTest.cpp ('k') | third_party/WebKit/Source/platform/TraceEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698