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

Side by Side Diff: Source/platform/scroll/ScrollableAreaTest.cpp

Issue 1134523002: Implement timers by posting delayed tasks (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Gyp tweak. Created 5 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 | Annotate | Revision Log
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 "config.h" 5 #include "config.h"
6 6
7 #include "platform/scroll/ScrollableArea.h" 7 #include "platform/scroll/ScrollableArea.h"
8 8
9 #include "platform/TestingPlatformSupport.h"
10 #include "public/platform/Platform.h"
11 #include "public/platform/WebScheduler.h"
12 #include "public/platform/WebThread.h"
9 #include <gmock/gmock.h> 13 #include <gmock/gmock.h>
10 #include <gtest/gtest.h> 14 #include <gtest/gtest.h>
11 15
12 using namespace blink; 16 using namespace blink;
13 17
14 namespace { 18 namespace {
15 19
16 class MockScrollableArea : public ScrollableArea { 20 class MockScrollableArea : public ScrollableArea {
17 public: 21 public:
18 MockScrollableArea(const IntPoint& maximumScrollPosition) 22 MockScrollableArea(const IntPoint& maximumScrollPosition)
(...skipping 21 matching lines...) Expand all
40 virtual int visibleHeight() const override { return 768; } 44 virtual int visibleHeight() const override { return 768; }
41 virtual int visibleWidth() const override { return 1024; } 45 virtual int visibleWidth() const override { return 1024; }
42 virtual bool scrollAnimatorEnabled() const override { return false; } 46 virtual bool scrollAnimatorEnabled() const override { return false; }
43 virtual int pageStep(ScrollbarOrientation) const override { return 0; } 47 virtual int pageStep(ScrollbarOrientation) const override { return 0; }
44 48
45 private: 49 private:
46 IntPoint m_scrollPosition; 50 IntPoint m_scrollPosition;
47 IntPoint m_maximumScrollPosition; 51 IntPoint m_maximumScrollPosition;
48 }; 52 };
49 53
50 TEST(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) 54 class FakeWebThread : public WebThread {
55 public:
56 FakeWebThread() { }
57 ~FakeWebThread() override { }
58
59 void postTask(const WebTraceLocation&, Task*) override
60 {
61 ASSERT_NOT_REACHED();
62 }
63
64 void postDelayedTask(const WebTraceLocation&, Task*, long long) override
65 {
66 ASSERT_NOT_REACHED();
67 }
68
69 bool isCurrentThread() const override
70 {
71 ASSERT_NOT_REACHED();
72 return true;
73 }
74
75 WebScheduler* scheduler() const override
76 {
77 return nullptr;
78 }
79 };
80
81 // The FakePlatform is needed because ScrollAnimatorMac's constructor creates se veral timers.
82 // We need just enough scaffolding for the Timer constructor to not segfault.
83 class FakePlatform : public TestingPlatformSupport {
84 public:
85 FakePlatform() : TestingPlatformSupport(TestingPlatformSupport::Config()) { }
86 ~FakePlatform() override { }
87
88 WebThread* currentThread() override
89 {
90 return &m_webThread;
91 }
92
93 private:
94 FakeWebThread m_webThread;
95 };
96
97 class ScrollableAreaTest : public testing::Test {
98 public:
99 ScrollableAreaTest() : m_oldPlatform(nullptr) { }
100
101 void SetUp() override
102 {
103 m_oldPlatform = Platform::current();
104 Platform::initialize(&m_fakePlatform);
105 }
106
107 void TearDown() override
108 {
109 Platform::initialize(m_oldPlatform);
110 }
111
112 private:
113 FakePlatform m_fakePlatform;
114 Platform* m_oldPlatform; // Not owned.
115 };
116
117 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync)
51 { 118 {
52 MockScrollableArea scrollableArea(IntPoint(0, 100)); 119 MockScrollableArea scrollableArea(IntPoint(0, 100));
53 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000)); 120 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000));
54 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); 121 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y());
55 } 122 }
56 123
57 } // unnamed namespace 124 } // unnamed namespace
58
59
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698