Chromium Code Reviews| Index: Source/web/tests/ScrollbarStateTransitionAnimatorTest.cpp |
| diff --git a/Source/web/tests/ScrollbarStateTransitionAnimatorTest.cpp b/Source/web/tests/ScrollbarStateTransitionAnimatorTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3418ec1ccc21110a8774b3a3b9f494801587b574 |
| --- /dev/null |
| +++ b/Source/web/tests/ScrollbarStateTransitionAnimatorTest.cpp |
| @@ -0,0 +1,193 @@ |
| +/* |
| + * Copyright (c) 2011, Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
|
abarth-chromium
2014/06/23 21:52:43
Please use new-style copyright blocks for new file
abarth-chromium
2014/06/23 21:52:43
Please use new-style copyright blocks for new file
|
| + |
| +#include "config.h" |
| + |
| +#include "platform/scroll/ScrollbarStateTransitionAnimator.h" |
| + |
| +#include "platform/Logging.h" |
| +#include "platform/geometry/FloatPoint.h" |
| +#include "platform/geometry/IntRect.h" |
| +#include "platform/scroll/ScrollableArea.h" |
| +#include "platform/scroll/ScrollbarThemeOverlayMock.h" |
|
abarth-chromium
2014/06/23 21:52:43
If all the code you're testing is in blink_platfor
|
| +#include <gmock/gmock.h> |
| +#include <gtest/gtest.h> |
| + |
| +using namespace std; |
| +using namespace WebCore; |
| + |
| +using testing::AtLeast; |
| +using testing::Return; |
| +using testing::_; |
| + |
| +class MockScrollbarStateTransitionAnimator; |
| +class MockScrollableAreaForAnimator : public ScrollableArea { |
| +public: |
| + MockScrollableAreaForAnimator(bool enabled) |
| + : m_scrollbarAnimatorEnabled(enabled) { } |
| + void setAnimator(MockScrollbarStateTransitionAnimator* animator) |
| + { |
| + m_scrollbarStateTransitionAnimator = animator; |
| + } |
| + void setAnimatorEnabled(bool enabled) |
| + { |
| + m_scrollbarAnimatorEnabled = enabled; |
| + } |
| + virtual bool hasOverlayScrollbars() const OVERRIDE |
| + { |
| + return m_scrollbarAnimatorEnabled; |
| + } |
| + virtual bool scheduleAnimation() OVERRIDE |
| + { |
| + return true; |
| + } |
| + |
| + MOCK_CONST_METHOD0(isActive, bool()); |
| + MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); |
| + MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); |
| + MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); |
| + MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); |
| + MOCK_METHOD1(setScrollOffset, void(const IntPoint&)); |
| + MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); |
| + MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); |
| + MOCK_METHOD1(setScrollOffsetFromAnimation, void(const IntPoint&)); |
| + MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); |
| + MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); |
| + MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint()); |
| + MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); |
| + MOCK_CONST_METHOD0(contentsSize, IntSize()); |
| + MOCK_CONST_METHOD0(overhangAmount, IntSize()); |
| + MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); |
| + MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); |
| + MOCK_CONST_METHOD0(scrollPosition, IntPoint()); |
| + MOCK_CONST_METHOD0(shouldPlaceVerticalScrollbarOnLeft, bool()); |
| + MOCK_CONST_METHOD1(userInputScrollable, bool(ScrollbarOrientation)); |
| + MOCK_CONST_METHOD0(visibleHeight, int()); |
| + MOCK_CONST_METHOD0(visibleWidth, int()); |
| + |
| +private: |
| + MockScrollbarStateTransitionAnimator* m_scrollbarStateTransitionAnimator; |
| + bool m_scrollbarAnimatorEnabled; |
| +}; |
| + |
| +class MockScrollbarStateTransitionAnimator : public ScrollbarStateTransitionAnimator { |
| +public: |
| + MockScrollbarStateTransitionAnimator(MockScrollableAreaForAnimator* scrollableArea) |
| + : ScrollbarStateTransitionAnimator(scrollableArea) { } |
| + |
| + void reset() |
| + { |
| + m_data.reset(); |
| + m_mockCurrentTime = 0; |
| + stopAnimationTimerIfNeeded(); |
| + } |
| + |
| + void setCurrentTime(double time) |
| + { |
| + m_mockCurrentTime = time; |
| + } |
| + virtual double currentTime() const OVERRIDE |
| + { |
| + return m_mockCurrentTime; |
| + } |
| + |
| +private: |
| + double m_mockCurrentTime; |
| +}; |
| + |
| +TEST(ScrollbarStateTransitionAnimatorEnabled, Enabled) |
| +{ |
| + MockScrollableAreaForAnimator scrollableArea(true); |
| + MockScrollbarStateTransitionAnimator scrollbarAnimator(&scrollableArea); |
| + scrollableArea.setAnimator(&scrollbarAnimator); |
| + |
| + scrollbarAnimator.reset(); |
| + scrollbarAnimator.setCurrentTime(1.0); |
| + scrollbarAnimator.mouseEnteredScrollbar(0); |
| + scrollbarAnimator.setCurrentTime(1.1); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_TRUE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + EXPECT_NE(0.f, scrollbarAnimator.stateTransitionProgress()); |
| + EXPECT_EQ(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransitionStartState()); |
| + EXPECT_EQ(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransitionEndState()); |
| + scrollbarAnimator.setCurrentTime(2.0); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + scrollbarAnimator.reset(); |
| + scrollbarAnimator.setCurrentTime(1.0); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + scrollbarAnimator.mouseExitedScrollbar(0); |
| + scrollbarAnimator.setCurrentTime(1.1); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_TRUE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + EXPECT_NE(0.f, scrollbarAnimator.stateTransitionProgress()); |
| + EXPECT_EQ(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransitionStartState()); |
| + EXPECT_EQ(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransitionEndState()); |
| + scrollbarAnimator.setCurrentTime(2.0); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + scrollbarAnimator.reset(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| +} |
| + |
| +TEST(ScrollbarStateTransitionAnimatorEnabled, Disabled) |
| +{ |
| + MockScrollableAreaForAnimator scrollableArea(false); |
| + MockScrollbarStateTransitionAnimator scrollbarAnimator(&scrollableArea); |
| + scrollableArea.setAnimator(&scrollbarAnimator); |
| + |
| + scrollbarAnimator.reset(); |
| + scrollbarAnimator.setCurrentTime(1.0); |
| + scrollbarAnimator.mouseEnteredScrollbar(0); |
| + scrollbarAnimator.setCurrentTime(1.1); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + EXPECT_EQ(0.f, scrollbarAnimator.stateTransitionProgress()); |
| + EXPECT_NE(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransitionStartState()); |
| + EXPECT_NE(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransitionEndState()); |
| + scrollbarAnimator.setCurrentTime(2.0); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + scrollbarAnimator.reset(); |
| + scrollbarAnimator.setCurrentTime(1.0); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + scrollbarAnimator.mouseExitedScrollbar(0); |
| + scrollbarAnimator.setCurrentTime(1.1); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + EXPECT_EQ(0.f, scrollbarAnimator.stateTransitionProgress()); |
| + EXPECT_NE(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransitionStartState()); |
| + EXPECT_NE(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransitionEndState()); |
| + scrollbarAnimator.setCurrentTime(2.0); |
| + scrollbarAnimator.serviceAnimations(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| + scrollbarAnimator.reset(); |
| + EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); |
| +} |