| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/scroll/ScrollbarThemeAura.h" | 5 #include "platform/scroll/ScrollbarThemeAura.h" |
| 6 | 6 |
| 7 #include "platform/scroll/ScrollbarTestSuite.h" | 7 #include "platform/scroll/ScrollbarTestSuite.h" |
| 8 #include "platform/testing/TestingPlatformSupport.h" |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 11 using testing::Return; | 12 using testing::Return; |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 class ScrollbarThemeAuraButtonOverride final : public ScrollbarThemeAura { | 16 class ScrollbarThemeAuraButtonOverride final : public ScrollbarThemeAura { |
| 16 public: | 17 public: |
| 17 ScrollbarThemeAuraButtonOverride() : m_hasScrollbarButtons(true) {} | 18 ScrollbarThemeAuraButtonOverride() : m_hasScrollbarButtons(true) {} |
| 18 | 19 |
| 19 void setHasScrollbarButtons(bool value) { m_hasScrollbarButtons = value; } | 20 void setHasScrollbarButtons(bool value) { m_hasScrollbarButtons = value; } |
| 20 | 21 |
| 21 bool hasScrollbarButtons(ScrollbarOrientation unused) const override { | 22 bool hasScrollbarButtons(ScrollbarOrientation unused) const override { |
| 22 return m_hasScrollbarButtons; | 23 return m_hasScrollbarButtons; |
| 23 } | 24 } |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 bool m_hasScrollbarButtons; | 27 bool m_hasScrollbarButtons; |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 class ScrollbarThemeAuraTest : public ScrollbarTestSuite {}; | 32 using ScrollbarThemeAuraTest = testing::Test; |
| 32 | 33 |
| 33 TEST_F(ScrollbarThemeAuraTest, ButtonSizeHorizontal) { | 34 TEST_F(ScrollbarThemeAuraTest, ButtonSizeHorizontal) { |
| 34 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, | 35 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 35 const TestingPlatformSupport::Config&> | 36 platform; |
| 36 platform(m_config); | |
| 37 | 37 |
| 38 MockScrollableArea* mockScrollableArea = MockScrollableArea::create(); | 38 MockScrollableArea* mockScrollableArea = MockScrollableArea::create(); |
| 39 ScrollbarThemeMock mockTheme; | 39 ScrollbarThemeMock mockTheme; |
| 40 Scrollbar* scrollbar = Scrollbar::createForTesting( | 40 Scrollbar* scrollbar = Scrollbar::createForTesting( |
| 41 mockScrollableArea, HorizontalScrollbar, RegularScrollbar, &mockTheme); | 41 mockScrollableArea, HorizontalScrollbar, RegularScrollbar, &mockTheme); |
| 42 ScrollbarThemeAuraButtonOverride theme; | 42 ScrollbarThemeAuraButtonOverride theme; |
| 43 | 43 |
| 44 IntRect scrollbarSizeNormalDimensions(11, 22, 444, 66); | 44 IntRect scrollbarSizeNormalDimensions(11, 22, 444, 66); |
| 45 scrollbar->setFrameRect(scrollbarSizeNormalDimensions); | 45 scrollbar->setFrameRect(scrollbarSizeNormalDimensions); |
| 46 IntSize size1 = theme.buttonSize(*scrollbar); | 46 IntSize size1 = theme.buttonSize(*scrollbar); |
| 47 EXPECT_EQ(66, size1.width()); | 47 EXPECT_EQ(66, size1.width()); |
| 48 EXPECT_EQ(66, size1.height()); | 48 EXPECT_EQ(66, size1.height()); |
| 49 | 49 |
| 50 IntRect scrollbarSizeSquashedDimensions(11, 22, 444, 666); | 50 IntRect scrollbarSizeSquashedDimensions(11, 22, 444, 666); |
| 51 scrollbar->setFrameRect(scrollbarSizeSquashedDimensions); | 51 scrollbar->setFrameRect(scrollbarSizeSquashedDimensions); |
| 52 IntSize size2 = theme.buttonSize(*scrollbar); | 52 IntSize size2 = theme.buttonSize(*scrollbar); |
| 53 EXPECT_EQ(222, size2.width()); | 53 EXPECT_EQ(222, size2.width()); |
| 54 EXPECT_EQ(666, size2.height()); | 54 EXPECT_EQ(666, size2.height()); |
| 55 | 55 |
| 56 ThreadState::current()->collectAllGarbage(); | 56 ThreadState::current()->collectAllGarbage(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST_F(ScrollbarThemeAuraTest, ButtonSizeVertical) { | 59 TEST_F(ScrollbarThemeAuraTest, ButtonSizeVertical) { |
| 60 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, | 60 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 61 const TestingPlatformSupport::Config&> | 61 platform; |
| 62 platform(m_config); | |
| 63 | 62 |
| 64 MockScrollableArea* mockScrollableArea = MockScrollableArea::create(); | 63 MockScrollableArea* mockScrollableArea = MockScrollableArea::create(); |
| 65 ScrollbarThemeMock mockTheme; | 64 ScrollbarThemeMock mockTheme; |
| 66 Scrollbar* scrollbar = Scrollbar::createForTesting( | 65 Scrollbar* scrollbar = Scrollbar::createForTesting( |
| 67 mockScrollableArea, VerticalScrollbar, RegularScrollbar, &mockTheme); | 66 mockScrollableArea, VerticalScrollbar, RegularScrollbar, &mockTheme); |
| 68 ScrollbarThemeAuraButtonOverride theme; | 67 ScrollbarThemeAuraButtonOverride theme; |
| 69 | 68 |
| 70 IntRect scrollbarSizeNormalDimensions(11, 22, 44, 666); | 69 IntRect scrollbarSizeNormalDimensions(11, 22, 44, 666); |
| 71 scrollbar->setFrameRect(scrollbarSizeNormalDimensions); | 70 scrollbar->setFrameRect(scrollbarSizeNormalDimensions); |
| 72 IntSize size1 = theme.buttonSize(*scrollbar); | 71 IntSize size1 = theme.buttonSize(*scrollbar); |
| 73 EXPECT_EQ(44, size1.width()); | 72 EXPECT_EQ(44, size1.width()); |
| 74 EXPECT_EQ(44, size1.height()); | 73 EXPECT_EQ(44, size1.height()); |
| 75 | 74 |
| 76 IntRect scrollbarSizeSquashedDimensions(11, 22, 444, 666); | 75 IntRect scrollbarSizeSquashedDimensions(11, 22, 444, 666); |
| 77 scrollbar->setFrameRect(scrollbarSizeSquashedDimensions); | 76 scrollbar->setFrameRect(scrollbarSizeSquashedDimensions); |
| 78 IntSize size2 = theme.buttonSize(*scrollbar); | 77 IntSize size2 = theme.buttonSize(*scrollbar); |
| 79 EXPECT_EQ(444, size2.width()); | 78 EXPECT_EQ(444, size2.width()); |
| 80 EXPECT_EQ(333, size2.height()); | 79 EXPECT_EQ(333, size2.height()); |
| 81 | 80 |
| 82 ThreadState::current()->collectAllGarbage(); | 81 ThreadState::current()->collectAllGarbage(); |
| 83 } | 82 } |
| 84 | 83 |
| 85 TEST_F(ScrollbarThemeAuraTest, NoButtonsReturnsSize0) { | 84 TEST_F(ScrollbarThemeAuraTest, NoButtonsReturnsSize0) { |
| 86 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler, | 85 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 87 const TestingPlatformSupport::Config&> | 86 platform; |
| 88 platform(m_config); | |
| 89 | 87 |
| 90 MockScrollableArea* mockScrollableArea = MockScrollableArea::create(); | 88 MockScrollableArea* mockScrollableArea = MockScrollableArea::create(); |
| 91 ScrollbarThemeMock mockTheme; | 89 ScrollbarThemeMock mockTheme; |
| 92 Scrollbar* scrollbar = Scrollbar::createForTesting( | 90 Scrollbar* scrollbar = Scrollbar::createForTesting( |
| 93 mockScrollableArea, VerticalScrollbar, RegularScrollbar, &mockTheme); | 91 mockScrollableArea, VerticalScrollbar, RegularScrollbar, &mockTheme); |
| 94 ScrollbarThemeAuraButtonOverride theme; | 92 ScrollbarThemeAuraButtonOverride theme; |
| 95 theme.setHasScrollbarButtons(false); | 93 theme.setHasScrollbarButtons(false); |
| 96 | 94 |
| 97 scrollbar->setFrameRect(IntRect(1, 2, 3, 4)); | 95 scrollbar->setFrameRect(IntRect(1, 2, 3, 4)); |
| 98 IntSize size = theme.buttonSize(*scrollbar); | 96 IntSize size = theme.buttonSize(*scrollbar); |
| 99 EXPECT_EQ(0, size.width()); | 97 EXPECT_EQ(0, size.width()); |
| 100 EXPECT_EQ(0, size.height()); | 98 EXPECT_EQ(0, size.height()); |
| 101 | 99 |
| 102 ThreadState::current()->collectAllGarbage(); | 100 ThreadState::current()->collectAllGarbage(); |
| 103 } | 101 } |
| 104 | 102 |
| 105 } // namespace blink | 103 } // namespace blink |
| OLD | NEW |