| 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 "core/frame/FrameView.h" | |
| 6 #include "core/layout/LayoutView.h" | 5 #include "core/layout/LayoutView.h" |
| 7 #include "core/paint/PaintLayerScrollableArea.h" | 6 #include "core/paint/PaintLayerScrollableArea.h" |
| 8 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 7 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 9 #include "platform/testing/TestingPlatformSupport.h" | |
| 10 #include "platform/testing/UnitTestHelpers.h" | 8 #include "platform/testing/UnitTestHelpers.h" |
| 11 #include "public/platform/WebThemeEngine.h" | |
| 12 #include "public/web/WebScriptSource.h" | 9 #include "public/web/WebScriptSource.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "web/WebLocalFrameImpl.h" | 11 #include "web/WebLocalFrameImpl.h" |
| 15 #include "web/tests/sim/SimDisplayItemList.h" | 12 #include "web/tests/sim/SimDisplayItemList.h" |
| 16 #include "web/tests/sim/SimRequest.h" | 13 #include "web/tests/sim/SimRequest.h" |
| 17 #include "web/tests/sim/SimTest.h" | 14 #include "web/tests/sim/SimTest.h" |
| 18 | 15 |
| 19 namespace blink { | 16 namespace blink { |
| 20 | 17 |
| 21 namespace { | 18 namespace { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 38 | 35 |
| 39 // Forces recalc of LayoutView's computed style in Document::updateStyle, | 36 // Forces recalc of LayoutView's computed style in Document::updateStyle, |
| 40 // without invalidating layout. | 37 // without invalidating layout. |
| 41 mainFrame().executeScriptAndReturnValue(WebScriptSource( | 38 mainFrame().executeScriptAndReturnValue(WebScriptSource( |
| 42 "document.querySelector('style').sheet.insertRule('body {}', 1);")); | 39 "document.querySelector('style').sheet.insertRule('body {}', 1);")); |
| 43 | 40 |
| 44 compositor().beginFrame(); | 41 compositor().beginFrame(); |
| 45 ASSERT_TRUE(plsa->verticalScrollbar() && plsa->horizontalScrollbar()); | 42 ASSERT_TRUE(plsa->verticalScrollbar() && plsa->horizontalScrollbar()); |
| 46 } | 43 } |
| 47 | 44 |
| 48 typedef bool TestParamOverlayScrollbar; | |
| 49 class ScrollbarAppearanceTest | |
| 50 : public SimTest, | |
| 51 public ::testing::WithParamInterface<TestParamOverlayScrollbar> { | |
| 52 public: | |
| 53 // Use real scrollbars to ensure we're testing the real ScrollbarThemes. | |
| 54 ScrollbarAppearanceTest() : m_mockScrollbars(false, GetParam()) {} | |
| 55 | |
| 56 private: | |
| 57 FrameTestHelpers::UseMockScrollbarSettings m_mockScrollbars; | |
| 58 }; | |
| 59 | |
| 60 class StubWebThemeEngine : public WebThemeEngine { | |
| 61 public: | |
| 62 WebSize getSize(Part part) override { | |
| 63 switch (part) { | |
| 64 case PartScrollbarHorizontalThumb: | |
| 65 return blink::WebSize(kMinimumHorizontalLength, 15); | |
| 66 case PartScrollbarVerticalThumb: | |
| 67 return blink::WebSize(15, kMinimumVerticalLength); | |
| 68 default: | |
| 69 return WebSize(); | |
| 70 } | |
| 71 } | |
| 72 static constexpr int kMinimumHorizontalLength = 51; | |
| 73 static constexpr int kMinimumVerticalLength = 52; | |
| 74 }; | |
| 75 | |
| 76 constexpr int StubWebThemeEngine::kMinimumHorizontalLength; | |
| 77 constexpr int StubWebThemeEngine::kMinimumVerticalLength; | |
| 78 | |
| 79 class ScrollbarTestingPlatformSupport : public TestingPlatformSupport { | |
| 80 public: | |
| 81 WebThemeEngine* themeEngine() override { return &m_stubThemeEngine; } | |
| 82 | |
| 83 private: | |
| 84 StubWebThemeEngine m_stubThemeEngine; | |
| 85 }; | |
| 86 | |
| 87 // Test both overlay and non-overlay scrollbars. | |
| 88 INSTANTIATE_TEST_CASE_P(All, ScrollbarAppearanceTest, ::testing::Bool()); | |
| 89 | |
| 90 #if !OS(MACOSX) | |
| 91 // Ensure that the minimum length for a scrollbar thumb comes from the | |
| 92 // WebThemeEngine. Note, Mac scrollbars differ from all other platforms so this | |
| 93 // test doesn't apply there. https://crbug.com/682209. | |
| 94 TEST_P(ScrollbarAppearanceTest, ThemeEngineDefinesMinimumThumbLength) { | |
| 95 ScopedTestingPlatformSupport<ScrollbarTestingPlatformSupport> platform; | |
| 96 | |
| 97 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | |
| 98 webView().resize(WebSize(800, 600)); | |
| 99 SimRequest request("https://example.com/test.html", "text/html"); | |
| 100 loadURL("https://example.com/test.html"); | |
| 101 request.complete( | |
| 102 "<style> body { width: 1000000px; height: 1000000px; } </style>"); | |
| 103 ScrollableArea* scrollableArea = | |
| 104 document().view()->layoutViewportScrollableArea(); | |
| 105 | |
| 106 compositor().beginFrame(); | |
| 107 ASSERT_TRUE(scrollableArea->verticalScrollbar()); | |
| 108 ASSERT_TRUE(scrollableArea->horizontalScrollbar()); | |
| 109 | |
| 110 ScrollbarTheme& theme = scrollableArea->verticalScrollbar()->theme(); | |
| 111 EXPECT_EQ(StubWebThemeEngine::kMinimumHorizontalLength, | |
| 112 theme.thumbLength(*scrollableArea->horizontalScrollbar())); | |
| 113 EXPECT_EQ(StubWebThemeEngine::kMinimumVerticalLength, | |
| 114 theme.thumbLength(*scrollableArea->verticalScrollbar())); | |
| 115 } | |
| 116 #endif | |
| 117 | |
| 118 } // namespace | 45 } // namespace |
| 119 | 46 |
| 120 } // namespace blink | 47 } // namespace blink |
| OLD | NEW |