| OLD | NEW |
| 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 "core/layout/ScrollAnchor.h" | 5 #include "core/layout/ScrollAnchor.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutBox.h" | 7 #include "core/layout/LayoutBox.h" |
| 8 #include "core/layout/LayoutTestHelper.h" | 8 #include "core/layout/LayoutTestHelper.h" |
| 9 #include "core/paint/PaintLayerScrollableArea.h" | 9 #include "core/paint/PaintLayerScrollableArea.h" |
| 10 #include "platform/testing/HistogramTester.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 using Corner = ScrollAnchor::Corner; | 14 using Corner = ScrollAnchor::Corner; |
| 14 | 15 |
| 15 class ScrollAnchorTest : public RenderingTest { | 16 class ScrollAnchorTest : public RenderingTest { |
| 16 public: | 17 public: |
| 17 ScrollAnchorTest() { RuntimeEnabledFeatures::setScrollAnchoringEnabled(true)
; } | 18 ScrollAnchorTest() { RuntimeEnabledFeatures::setScrollAnchoringEnabled(true)
; } |
| 18 ~ScrollAnchorTest() { RuntimeEnabledFeatures::setScrollAnchoringEnabled(fals
e); } | 19 ~ScrollAnchorTest() { RuntimeEnabledFeatures::setScrollAnchoringEnabled(fals
e); } |
| 19 | 20 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 77 |
| 77 EXPECT_EQ(250, viewport->scrollPosition().y()); | 78 EXPECT_EQ(250, viewport->scrollPosition().y()); |
| 78 EXPECT_EQ(document().getElementById("block2")->layoutObject(), | 79 EXPECT_EQ(document().getElementById("block2")->layoutObject(), |
| 79 scrollAnchor(viewport).anchorObject()); | 80 scrollAnchor(viewport).anchorObject()); |
| 80 | 81 |
| 81 // ScrollableArea::userScroll should clear the anchor. | 82 // ScrollableArea::userScroll should clear the anchor. |
| 82 viewport->userScroll(ScrollByPrecisePixel, FloatSize(0, 100)); | 83 viewport->userScroll(ScrollByPrecisePixel, FloatSize(0, 100)); |
| 83 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); | 84 EXPECT_EQ(nullptr, scrollAnchor(viewport).anchorObject()); |
| 84 } | 85 } |
| 85 | 86 |
| 87 TEST_F(ScrollAnchorTest, UMAMetricUpdated) |
| 88 { |
| 89 HistogramTester histogramTester; |
| 90 setBodyInnerHTML( |
| 91 "<style> body { height: 1000px } div { height: 100px } </style>" |
| 92 "<div id='block1'>abc</div>" |
| 93 "<div id='block2'>def</div>"); |
| 94 |
| 95 ScrollableArea* viewport = layoutViewport(); |
| 96 |
| 97 // Scroll position not adjusted, metric not updated. |
| 98 scrollLayoutViewport(DoubleSize(0, 150)); |
| 99 histogramTester.expectTotalCount( |
| 100 "Layout.ScrollAnchor.AdjustedScrollOffset", 0); |
| 101 |
| 102 // Height changed, verify metric updated once. |
| 103 setHeight(document().getElementById("block1"), 200); |
| 104 histogramTester.expectUniqueSample( |
| 105 "Layout.ScrollAnchor.AdjustedScrollOffset", 1, 1); |
| 106 |
| 107 EXPECT_EQ(250, viewport->scrollPosition().y()); |
| 108 EXPECT_EQ(document().getElementById("block2")->layoutObject(), |
| 109 scrollAnchor(viewport).anchorObject()); |
| 110 } |
| 111 |
| 86 TEST_F(ScrollAnchorTest, AnchorWithLayerInScrollingDiv) | 112 TEST_F(ScrollAnchorTest, AnchorWithLayerInScrollingDiv) |
| 87 { | 113 { |
| 88 setBodyInnerHTML( | 114 setBodyInnerHTML( |
| 89 "<style>" | 115 "<style>" |
| 90 " #scroller { overflow: scroll; width: 500px; height: 400px; }" | 116 " #scroller { overflow: scroll; width: 500px; height: 400px; }" |
| 91 " div { height: 100px }" | 117 " div { height: 100px }" |
| 92 " #block2 { overflow: hidden }" | 118 " #block2 { overflow: hidden }" |
| 93 " #space { height: 1000px; }" | 119 " #space { height: 1000px; }" |
| 94 "</style>" | 120 "</style>" |
| 95 "<div id='scroller'><div id='space'>" | 121 "<div id='scroller'><div id='space'>" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 "<div id=c></div>" | 292 "<div id=c></div>" |
| 267 "<div id=d></div>"); | 293 "<div id=d></div>"); |
| 268 | 294 |
| 269 checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(+400
, +300)); | 295 checkCorner("a", Corner::BottomRight, DoublePoint(20, 20), DoubleSize(+400
, +300)); |
| 270 checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(-400
, +300)); | 296 checkCorner("b", Corner::BottomLeft, DoublePoint(420, 20), DoubleSize(-400
, +300)); |
| 271 checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(+400
, -300)); | 297 checkCorner("c", Corner::TopRight, DoublePoint(20, 320), DoubleSize(+400
, -300)); |
| 272 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400
, -300)); | 298 checkCorner("d", Corner::TopLeft, DoublePoint(420, 320), DoubleSize(-400
, -300)); |
| 273 } | 299 } |
| 274 | 300 |
| 275 } | 301 } |
| OLD | NEW |