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

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

Issue 956333002: Refactor TimeBase to post tasks. Workers to use real Idle tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 8 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 | « Source/platform/blink_platform_tests.gyp ('k') | Source/web/tests/TextFinderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "public/platform/Platform.h"
10 #include "public/platform/WebScheduler.h"
11 #include "public/platform/WebThread.h"
9 #include <gmock/gmock.h> 12 #include <gmock/gmock.h>
10 #include <gtest/gtest.h> 13 #include <gtest/gtest.h>
11 14
12 using namespace blink; 15 using namespace blink;
13 16
14 namespace { 17 namespace {
15 18
16 class MockScrollableArea : public ScrollableArea { 19 class MockScrollableArea : public ScrollableArea {
17 public: 20 public:
18 MockScrollableArea(const IntPoint& maximumScrollPosition) 21 MockScrollableArea(const IntPoint& maximumScrollPosition)
(...skipping 21 matching lines...) Expand all
40 virtual int visibleHeight() const override { return 768; } 43 virtual int visibleHeight() const override { return 768; }
41 virtual int visibleWidth() const override { return 1024; } 44 virtual int visibleWidth() const override { return 1024; }
42 virtual bool scrollAnimatorEnabled() const override { return false; } 45 virtual bool scrollAnimatorEnabled() const override { return false; }
43 virtual int pageStep(ScrollbarOrientation) const override { return 0; } 46 virtual int pageStep(ScrollbarOrientation) const override { return 0; }
44 47
45 private: 48 private:
46 IntPoint m_scrollPosition; 49 IntPoint m_scrollPosition;
47 IntPoint m_maximumScrollPosition; 50 IntPoint m_maximumScrollPosition;
48 }; 51 };
49 52
53 class FakeWebThread : public WebThread {
54 public:
55 FakeWebThread() { }
56 ~FakeWebThread() override { }
57
58 void postTask(const WebTraceLocation&, Task*)
59 {
60 ASSERT_NOT_REACHED();
61 }
62
63 virtual void postDelayedTask(const WebTraceLocation&, Task*, long long)
64 {
65 ASSERT_NOT_REACHED();
66 }
67
68 virtual bool isCurrentThread() const
69 {
70 ASSERT_NOT_REACHED();
71 return true;
72 }
73
74 virtual PlatformThreadId threadId() const
75 {
76 ASSERT_NOT_REACHED();
77 return 0;
78 }
79
80 WebScheduler* scheduler() const override
81 {
82 return nullptr;
83 }
84
85 virtual void enterRunLoop()
86 {
87 ASSERT_NOT_REACHED();
88 }
89
90 virtual void exitRunLoop()
91 {
92 ASSERT_NOT_REACHED();
93 }
94 };
95
96 // The FakePlatform is needed on mac because ScrollAnimatorMac's constructor cre ates several timers.
97 // We need just enough scaffolding for the Timer constructor to not segfault.
98 class FakePlatform : public Platform {
99 public:
100 FakePlatform() { }
101 ~FakePlatform() override { }
102
103 WebThread* currentThread() override
104 {
105 return &m_webThread;
106 }
107
108 void cryptographicallyRandomValues(unsigned char*, size_t) override
109 {
110 ASSERT_NOT_REACHED();
111 }
112
113 const unsigned char* getTraceCategoryEnabledFlag(const char*) override
114 {
115 return reinterpret_cast<const unsigned char*>("");
116 }
117
118 private:
119 FakeWebThread m_webThread;
120 };
121
50 TEST(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) 122 TEST(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync)
51 { 123 {
124 Platform* oldPlatform = Platform::current();
125 FakePlatform fakePlatform;
126 Platform::initialize(&fakePlatform);
127
52 MockScrollableArea scrollableArea(IntPoint(0, 100)); 128 MockScrollableArea scrollableArea(IntPoint(0, 100));
53 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000)); 129 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000));
54 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); 130 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y());
131
132 Platform::initialize(oldPlatform);
55 } 133 }
56 134
57 } // unnamed namespace 135 } // unnamed namespace
58 136
59 137
OLDNEW
« no previous file with comments | « Source/platform/blink_platform_tests.gyp ('k') | Source/web/tests/TextFinderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698