OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/animation/ScrollTimeline.h" |
| 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/animation/ScrollTimelineOptions.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "core/frame/FrameView.h" |
| 11 #include "core/layout/LayoutBoxModelObject.h" |
| 12 #include "core/paint/PaintLayerScrollableArea.h" |
| 13 #include "core/testing/DummyPageHolder.h" |
| 14 #include "platform/wtf/text/WTFString.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 class ScrollTimelineTest : public ::testing::Test { |
| 20 protected: |
| 21 void SetUp() override { page_holder_ = DummyPageHolder::Create(); } |
| 22 |
| 23 Document& GetDocument() { return page_holder_->GetDocument(); } |
| 24 |
| 25 void SetInnerHTML(const String& html) { |
| 26 GetDocument().documentElement()->setInnerHTML(html); |
| 27 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 28 } |
| 29 |
| 30 ScrollTimelineOptions CreateOptions(Element* scrollSource = nullptr, |
| 31 double time_range = 0, |
| 32 String orientation = "auto") { |
| 33 ScrollTimelineOptions options; |
| 34 options.setScrollSource(scrollSource); |
| 35 options.setTimeRange( |
| 36 DoubleOrScrollTimelineAutoKeyword::fromDouble(time_range)); |
| 37 options.setOrientation(orientation); |
| 38 return options; |
| 39 } |
| 40 |
| 41 private: |
| 42 std::unique_ptr<DummyPageHolder> page_holder_; |
| 43 }; |
| 44 |
| 45 TEST_F(ScrollTimelineTest, CreateScrollTimeline) { |
| 46 SetInnerHTML( |
| 47 "<style>#scroller { height: 100px; width: 100px; overflow: auto; }" |
| 48 "#content { height: 250px; width: 250px; }</style>" |
| 49 "<div id='scroller'><div id='content'></div></div>"); |
| 50 |
| 51 Element* scroller = GetDocument().getElementById("scroller"); |
| 52 ASSERT_TRUE(scroller); |
| 53 |
| 54 ScrollTimelineOptions options = CreateOptions(scroller, 100, "inline"); |
| 55 DummyExceptionStateForTesting exception_state; |
| 56 ScrollTimeline* scroll_timeline = |
| 57 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 58 ASSERT_TRUE(scroll_timeline); |
| 59 EXPECT_FALSE(exception_state.HadException()); |
| 60 |
| 61 EXPECT_EQ(scroller, scroll_timeline->scrollSource()); |
| 62 EXPECT_EQ("inline", scroll_timeline->orientation()); |
| 63 DoubleOrScrollTimelineAutoKeyword time_range; |
| 64 scroll_timeline->timeRange(time_range); |
| 65 EXPECT_TRUE(time_range.isDouble()); |
| 66 EXPECT_EQ(100, time_range.getAsDouble()); |
| 67 } |
| 68 |
| 69 TEST_F(ScrollTimelineTest, CreateScrollTimelineWithoutScrollingSource) { |
| 70 ScrollTimelineOptions options = CreateOptions(nullptr); |
| 71 DummyExceptionStateForTesting exception_state; |
| 72 ScrollTimeline* scroll_timeline = |
| 73 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 74 ASSERT_TRUE(scroll_timeline); |
| 75 EXPECT_FALSE(exception_state.HadException()); |
| 76 |
| 77 EXPECT_EQ(GetDocument().scrollingElement(), scroll_timeline->scrollSource()); |
| 78 } |
| 79 |
| 80 TEST_F(ScrollTimelineTest, CreateScrollTimelineWithInvalidOrientation) { |
| 81 ScrollTimelineOptions options = CreateOptions(nullptr, 100, "invalid"); |
| 82 DummyExceptionStateForTesting exception_state; |
| 83 EXPECT_FALSE(ScrollTimeline::Create(GetDocument(), options, exception_state)); |
| 84 EXPECT_TRUE(exception_state.HadException()); |
| 85 } |
| 86 |
| 87 // TODO(smcgruer): Remove once 'auto' timeRange is supported. |
| 88 TEST_F(ScrollTimelineTest, CreateScrollTimelineWithInvalidTimeRange) { |
| 89 ScrollTimelineOptions options; |
| 90 options.setTimeRange( |
| 91 DoubleOrScrollTimelineAutoKeyword::fromScrollTimelineAutoKeyword("auto")); |
| 92 DummyExceptionStateForTesting exception_state; |
| 93 EXPECT_FALSE(ScrollTimeline::Create(GetDocument(), options, exception_state)); |
| 94 EXPECT_TRUE(exception_state.HadException()); |
| 95 } |
| 96 |
| 97 TEST_F(ScrollTimelineTest, CurrentTimeCorrect) { |
| 98 SetInnerHTML( |
| 99 "<style>#scroller { height: 100px; width: 100px; overflow: auto; }" |
| 100 "#content { height: 250px; width: 250px; }</style>" |
| 101 "<div id='scroller'><div id='content'></div></div>"); |
| 102 |
| 103 Element* scroller = GetDocument().getElementById("scroller"); |
| 104 PaintLayerScrollableArea* scrollable_area = |
| 105 scroller->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 106 ASSERT_TRUE(scroller); |
| 107 ASSERT_TRUE(scrollable_area); |
| 108 |
| 109 DummyExceptionStateForTesting exception_state; |
| 110 |
| 111 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 112 // the value scrolled. We have a square scroller/contents, so can just compute |
| 113 // one edge and use it for inline and block. |
| 114 double scroller_size = scroller->scrollHeight() - scroller->clientHeight(); |
| 115 |
| 116 ScrollTimelineOptions block_options = |
| 117 CreateOptions(scroller, scroller_size, "block"); |
| 118 ScrollTimeline* block_timeline = |
| 119 ScrollTimeline::Create(GetDocument(), block_options, exception_state); |
| 120 EXPECT_TRUE(block_timeline); |
| 121 EXPECT_FALSE(exception_state.HadException()); |
| 122 |
| 123 ScrollTimelineOptions inline_options = |
| 124 CreateOptions(scroller, scroller_size, "inline"); |
| 125 ScrollTimeline* inline_timeline = |
| 126 ScrollTimeline::Create(GetDocument(), inline_options, exception_state); |
| 127 EXPECT_TRUE(inline_timeline); |
| 128 EXPECT_FALSE(exception_state.HadException()); |
| 129 |
| 130 // Unscrolled, both timelines should read a current time of 0. |
| 131 EXPECT_DOUBLE_EQ(0, block_timeline->currentTime()); |
| 132 EXPECT_DOUBLE_EQ(0, inline_timeline->currentTime()); |
| 133 |
| 134 // Now do some scrolling and make sure that the ScrollTimelines update. |
| 135 // |
| 136 // As noted above, we have mapped timeRange such that currentTime should just |
| 137 // be the scroll offset. |
| 138 scrollable_area->ScrollToAbsolutePosition(FloatPoint(75, 50)); |
| 139 ASSERT_EQ(75.0, scrollable_area->ScrollPosition().X()); |
| 140 ASSERT_EQ(50.0, scrollable_area->ScrollPosition().Y()); |
| 141 |
| 142 EXPECT_DOUBLE_EQ(50, block_timeline->currentTime()); |
| 143 EXPECT_DOUBLE_EQ(75, inline_timeline->currentTime()); |
| 144 } |
| 145 |
| 146 TEST_F(ScrollTimelineTest, CurrentTimeForInlineElementIsNaN) { |
| 147 SetInnerHTML( |
| 148 "<style>#scroller { height: 100px; width: 100px; overflow: auto; " |
| 149 "display: inline; }" |
| 150 "#content { height: 250px; width: 250px; }</style>" |
| 151 "<div id='scroller'><div id='content'></div></div>"); |
| 152 |
| 153 Element* scroller = GetDocument().getElementById("scroller"); |
| 154 ASSERT_TRUE(scroller); |
| 155 |
| 156 // We should still be able to create a timeline with an inline element as the |
| 157 // scrollSource. |
| 158 ScrollTimelineOptions options = CreateOptions(scroller); |
| 159 DummyExceptionStateForTesting exception_state; |
| 160 ScrollTimeline* scroll_timeline = |
| 161 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 162 EXPECT_TRUE(scroll_timeline); |
| 163 EXPECT_FALSE(exception_state.HadException()); |
| 164 |
| 165 // However it should return NaN for the currentTime. |
| 166 EXPECT_TRUE(std::isnan(scroll_timeline->currentTime())); |
| 167 } |
| 168 |
| 169 TEST_F(ScrollTimelineTest, CurrentTimeForDisplayNoneElementIsNaN) { |
| 170 SetInnerHTML( |
| 171 "<style>#scroller { height: 100px; width: 100px; overflow: auto; " |
| 172 "display: none; }" |
| 173 "#content { height: 250px; width: 250px; }</style>" |
| 174 "<div id='scroller'><div id='content'></div></div>"); |
| 175 |
| 176 Element* scroller = GetDocument().getElementById("scroller"); |
| 177 ASSERT_TRUE(scroller); |
| 178 |
| 179 // We should still be able to create a timeline with a display:none element as |
| 180 // the scrollSource. |
| 181 ScrollTimelineOptions options = CreateOptions(scroller); |
| 182 DummyExceptionStateForTesting exception_state; |
| 183 ScrollTimeline* scroll_timeline = |
| 184 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 185 EXPECT_TRUE(scroll_timeline); |
| 186 EXPECT_FALSE(exception_state.HadException()); |
| 187 |
| 188 // However it should return NaN for the currentTime. |
| 189 EXPECT_TRUE(std::isnan(scroll_timeline->currentTime())); |
| 190 } |
| 191 |
| 192 TEST_F(ScrollTimelineTest, CurrentTimeForNonAttachedElementIsNaN) { |
| 193 // We manually create an entire overflow element tree, but do not attach it to |
| 194 // the document. |
| 195 Element* scroller = GetDocument().createElement("div"); |
| 196 Element* content = GetDocument().createElement("div"); |
| 197 ASSERT_TRUE(scroller); |
| 198 ASSERT_TRUE(content); |
| 199 |
| 200 scroller->SetInlineStyleProperty(CSSPropertyOverflow, CSSValueAuto); |
| 201 scroller->SetInlineStyleProperty(CSSPropertyHeight, 100, |
| 202 CSSPrimitiveValue::UnitType::kPixels); |
| 203 scroller->SetInlineStyleProperty(CSSPropertyWidth, 100, |
| 204 CSSPrimitiveValue::UnitType::kPixels); |
| 205 content->SetInlineStyleProperty(CSSPropertyHeight, 250, |
| 206 CSSPrimitiveValue::UnitType::kPixels); |
| 207 content->SetInlineStyleProperty(CSSPropertyWidth, 250, |
| 208 CSSPrimitiveValue::UnitType::kPixels); |
| 209 scroller->AppendChild(content); |
| 210 |
| 211 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 212 |
| 213 // We should still be able to create a timeline with an unattached element as |
| 214 // the scrollSource. |
| 215 ScrollTimelineOptions options = CreateOptions(scroller); |
| 216 DummyExceptionStateForTesting exception_state; |
| 217 ScrollTimeline* scroll_timeline = |
| 218 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 219 EXPECT_TRUE(scroll_timeline); |
| 220 EXPECT_FALSE(exception_state.HadException()); |
| 221 |
| 222 // However it should return NaN for the currentTime. |
| 223 EXPECT_TRUE(std::isnan(scroll_timeline->currentTime())); |
| 224 } |
| 225 |
| 226 TEST_F(ScrollTimelineTest, CurrentTimeForNonScrollerIsNaN) { |
| 227 // The so-called scroller here is deliberately overflow: visible. |
| 228 SetInnerHTML( |
| 229 "<style>#scroller { height: 100px; width: 100px; overflow: visible; }" |
| 230 "#content { height: 250px; width: 250px; }</style>" |
| 231 "<div id='scroller'><div id='content'></div></div>"); |
| 232 |
| 233 Element* scroller = GetDocument().getElementById("scroller"); |
| 234 ASSERT_TRUE(scroller); |
| 235 |
| 236 // We should still be able to create a timeline with a non-scroller as the |
| 237 // scrollSource. |
| 238 ScrollTimelineOptions options = CreateOptions(scroller); |
| 239 DummyExceptionStateForTesting exception_state; |
| 240 ScrollTimeline* scroll_timeline = |
| 241 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 242 EXPECT_TRUE(scroll_timeline); |
| 243 EXPECT_FALSE(exception_state.HadException()); |
| 244 |
| 245 // However it should return NaN for the currentTime. |
| 246 EXPECT_TRUE(std::isnan(scroll_timeline->currentTime())); |
| 247 } |
| 248 |
| 249 TEST_F(ScrollTimelineTest, CurrentTimeSelectsCorrectAxisForAutoOrientation) { |
| 250 // This tests basic block/inline selection, ignoring writing mode. There are |
| 251 // writing-mode specific tests below for orientation. |
| 252 SetInnerHTML( |
| 253 "<style>#scroller1 { height: 100px; width: 100px; overflow-y: auto; }" |
| 254 "#scroller2 { height: 100px; width: 100px; overflow-x: auto; }" |
| 255 "#scroller3 { height: 100px; width: 100px; overflow: auto; }" |
| 256 "#content1 { height: 250px; width: 50px; }" |
| 257 "#content2 { height: 50px; width: 250px; }" |
| 258 "#content3 { height: 250px; width: 250px; }</style>" |
| 259 "<div id='scroller1'><div id='content1'></div></div>" |
| 260 "<div id='scroller2'><div id='content2'></div></div>" |
| 261 "<div id='scroller3'><div id='content3'></div></div>"); |
| 262 |
| 263 Element* scroller1 = GetDocument().getElementById("scroller1"); |
| 264 Element* scroller2 = GetDocument().getElementById("scroller2"); |
| 265 Element* scroller3 = GetDocument().getElementById("scroller3"); |
| 266 ASSERT_TRUE(scroller1); |
| 267 ASSERT_TRUE(scroller2); |
| 268 ASSERT_TRUE(scroller3); |
| 269 |
| 270 DummyExceptionStateForTesting exception_state; |
| 271 |
| 272 ScrollTimelineOptions options1 = CreateOptions( |
| 273 scroller1, scroller1->scrollHeight() - scroller1->clientHeight()); |
| 274 ScrollTimeline* scroll_timeline1 = |
| 275 ScrollTimeline::Create(GetDocument(), options1, exception_state); |
| 276 ASSERT_TRUE(scroll_timeline1); |
| 277 |
| 278 ScrollTimelineOptions options2 = CreateOptions( |
| 279 scroller2, scroller2->scrollWidth() - scroller2->clientWidth()); |
| 280 ScrollTimeline* scroll_timeline2 = |
| 281 ScrollTimeline::Create(GetDocument(), options2, exception_state); |
| 282 ASSERT_TRUE(scroll_timeline2); |
| 283 |
| 284 ScrollTimelineOptions options3 = CreateOptions( |
| 285 scroller3, scroller3->scrollHeight() - scroller3->clientHeight()); |
| 286 ScrollTimeline* scroll_timeline3 = |
| 287 ScrollTimeline::Create(GetDocument(), options3, exception_state); |
| 288 ASSERT_TRUE(scroll_timeline3); |
| 289 |
| 290 EXPECT_FALSE(exception_state.HadException()); |
| 291 |
| 292 PaintLayerScrollableArea* scrollable_area1 = |
| 293 scroller1->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 294 PaintLayerScrollableArea* scrollable_area2 = |
| 295 scroller2->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 296 PaintLayerScrollableArea* scrollable_area3 = |
| 297 scroller3->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 298 ASSERT_TRUE(scrollable_area1); |
| 299 ASSERT_TRUE(scrollable_area2); |
| 300 ASSERT_TRUE(scrollable_area3); |
| 301 |
| 302 // The first scroller is only scrollable in the block direction so the 'auto' |
| 303 // orientation should resolve to block. |
| 304 scrollable_area1->ScrollToAbsolutePosition(FloatPoint(0, 50)); |
| 305 ASSERT_EQ(0.0, scrollable_area1->ScrollPosition().X()); |
| 306 ASSERT_EQ(50.0, scrollable_area1->ScrollPosition().Y()); |
| 307 EXPECT_DOUBLE_EQ(50, scroll_timeline1->currentTime()); |
| 308 |
| 309 // The second scroller is only scrollable in the inline direction so the |
| 310 // 'auto' orientation should resolve to inline. |
| 311 scrollable_area2->ScrollToAbsolutePosition(FloatPoint(75, 0)); |
| 312 ASSERT_EQ(75.0, scrollable_area2->ScrollPosition().X()); |
| 313 ASSERT_EQ(0.0, scrollable_area2->ScrollPosition().Y()); |
| 314 EXPECT_DOUBLE_EQ(75, scroll_timeline2->currentTime()); |
| 315 |
| 316 // The third scroller is scrollable in both axes, so the 'auto' orientation |
| 317 // should resolve to block. |
| 318 scrollable_area3->ScrollToAbsolutePosition(FloatPoint(75, 50)); |
| 319 ASSERT_EQ(75.0, scrollable_area3->ScrollPosition().X()); |
| 320 ASSERT_EQ(50.0, scrollable_area3->ScrollPosition().Y()); |
| 321 EXPECT_DOUBLE_EQ(50, scroll_timeline3->currentTime()); |
| 322 } |
| 323 |
| 324 TEST_F(ScrollTimelineTest, CurrentTimeAdjustsForTimeRangeCorrectly) { |
| 325 // It is unfortunately difficult to calculate what scroll offset results in an |
| 326 // exact currentTime. Scrolling is caluclated in integers which allows for the |
| 327 // possibility of rounding, and scrollbar widths differ between platforms |
| 328 // which means it is not possible to ensure a divisible scroller size. |
| 329 // |
| 330 // Instead we make the scroller content big enough that a 1-pixel rounding |
| 331 // difference results in a negligible difference in the output value. |
| 332 SetInnerHTML( |
| 333 "<style>#scroller { height: 100px; width: 100px; overflow: auto; }" |
| 334 "#content { height: 1000px; width: 1000px; }</style>" |
| 335 "<div id='scroller'><div id='content'></div></div>"); |
| 336 |
| 337 Element* scroller = GetDocument().getElementById("scroller"); |
| 338 PaintLayerScrollableArea* scrollable_area = |
| 339 scroller->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 340 ASSERT_TRUE(scroller); |
| 341 ASSERT_TRUE(scrollable_area); |
| 342 |
| 343 ScrollTimelineOptions options = CreateOptions(scroller, 100); |
| 344 DummyExceptionStateForTesting exception_state; |
| 345 ScrollTimeline* scroll_timeline = |
| 346 ScrollTimeline::Create(GetDocument(), options, exception_state); |
| 347 ASSERT_TRUE(scroll_timeline); |
| 348 EXPECT_FALSE(exception_state.HadException()); |
| 349 |
| 350 // Mapping timeRange to 100 gives a form of 'percentage scrolled', so |
| 351 // calculate where the 50% scroll mark would be. |
| 352 double halfway_y = (scroller->scrollHeight() - scroller->clientHeight()) / 2.; |
| 353 scrollable_area->ScrollToAbsolutePosition( |
| 354 FloatPoint(0, std::round(halfway_y))); |
| 355 |
| 356 EXPECT_NEAR(50, scroll_timeline->currentTime(), 0.5); |
| 357 } |
| 358 |
| 359 TEST_F(ScrollTimelineTest, CurrentTimeHandlesRtlDirection) { |
| 360 SetInnerHTML( |
| 361 "<style>#scroller { height: 100px; width: 100px; overflow: auto; " |
| 362 "direction: rtl; }" |
| 363 "#content { height: 250px; width: 250px; }</style>" |
| 364 "<div id='scroller'><div id='content'></div></div>"); |
| 365 |
| 366 Element* scroller = GetDocument().getElementById("scroller"); |
| 367 PaintLayerScrollableArea* scrollable_area = |
| 368 scroller->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 369 ASSERT_TRUE(scroller); |
| 370 ASSERT_TRUE(scrollable_area); |
| 371 |
| 372 DummyExceptionStateForTesting exception_state; |
| 373 |
| 374 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 375 // the value scrolled. We have a square scroller/contents, so can just compute |
| 376 // one edge and use it for inline and block. |
| 377 double scroller_size = scroller->scrollHeight() - scroller->clientHeight(); |
| 378 |
| 379 ScrollTimelineOptions block_options = |
| 380 CreateOptions(scroller, scroller_size, "block"); |
| 381 ScrollTimeline* block_timeline = |
| 382 ScrollTimeline::Create(GetDocument(), block_options, exception_state); |
| 383 EXPECT_TRUE(block_timeline); |
| 384 EXPECT_FALSE(exception_state.HadException()); |
| 385 |
| 386 ScrollTimelineOptions inline_options = |
| 387 CreateOptions(scroller, scroller_size, "inline"); |
| 388 ScrollTimeline* inline_timeline = |
| 389 ScrollTimeline::Create(GetDocument(), inline_options, exception_state); |
| 390 EXPECT_TRUE(inline_timeline); |
| 391 EXPECT_FALSE(exception_state.HadException()); |
| 392 |
| 393 // Unscrolled, both timelines should read a current time of 0 even though the |
| 394 // X-axis will have started at the right hand side for rtl. |
| 395 EXPECT_DOUBLE_EQ(0, block_timeline->currentTime()); |
| 396 EXPECT_DOUBLE_EQ(0, inline_timeline->currentTime()); |
| 397 |
| 398 // Absolute position scroll ignores the writing mode, so the actual offset in |
| 399 // the inline direction should be inverted. The block direction should be |
| 400 // unaffected. |
| 401 scrollable_area->ScrollToAbsolutePosition(FloatPoint(75, 50)); |
| 402 ASSERT_EQ(75.0, scrollable_area->ScrollPosition().X()); |
| 403 ASSERT_EQ(50.0, scrollable_area->ScrollPosition().Y()); |
| 404 |
| 405 EXPECT_DOUBLE_EQ(50, block_timeline->currentTime()); |
| 406 EXPECT_DOUBLE_EQ(scroller_size - 75, inline_timeline->currentTime()); |
| 407 } |
| 408 |
| 409 TEST_F(ScrollTimelineTest, CurrentTimeHandlesVerticalRlWritingMode) { |
| 410 SetInnerHTML( |
| 411 "<style>#scroller { height: 100px; width: 100px; overflow: auto; " |
| 412 "writing-mode: vertical-rl; }" |
| 413 "#content { height: 250px; width: 250px; }</style>" |
| 414 "<div id='scroller'><div id='content'></div></div>"); |
| 415 |
| 416 Element* scroller = GetDocument().getElementById("scroller"); |
| 417 PaintLayerScrollableArea* scrollable_area = |
| 418 scroller->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 419 ASSERT_TRUE(scroller); |
| 420 ASSERT_TRUE(scrollable_area); |
| 421 |
| 422 DummyExceptionStateForTesting exception_state; |
| 423 |
| 424 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 425 // the value scrolled. We have a square scroller/contents, so can just compute |
| 426 // one edge and use it for inline and block. |
| 427 double scroller_size = scroller->scrollHeight() - scroller->clientHeight(); |
| 428 |
| 429 ScrollTimelineOptions block_options = |
| 430 CreateOptions(scroller, scroller_size, "block"); |
| 431 ScrollTimeline* block_timeline = |
| 432 ScrollTimeline::Create(GetDocument(), block_options, exception_state); |
| 433 EXPECT_TRUE(block_timeline); |
| 434 EXPECT_FALSE(exception_state.HadException()); |
| 435 |
| 436 ScrollTimelineOptions inline_options = |
| 437 CreateOptions(scroller, scroller_size, "inline"); |
| 438 ScrollTimeline* inline_timeline = |
| 439 ScrollTimeline::Create(GetDocument(), inline_options, exception_state); |
| 440 EXPECT_TRUE(inline_timeline); |
| 441 EXPECT_FALSE(exception_state.HadException()); |
| 442 |
| 443 ScrollTimelineOptions auto_options = |
| 444 CreateOptions(scroller, scroller_size, "auto"); |
| 445 ScrollTimeline* auto_timeline = |
| 446 ScrollTimeline::Create(GetDocument(), auto_options, exception_state); |
| 447 EXPECT_TRUE(auto_timeline); |
| 448 EXPECT_FALSE(exception_state.HadException()); |
| 449 |
| 450 // Unscrolled, all three timelines should read a current time of 0 even though |
| 451 // the X-axis will have started at the right hand side for vertical-rl. |
| 452 EXPECT_DOUBLE_EQ(0, block_timeline->currentTime()); |
| 453 EXPECT_DOUBLE_EQ(0, inline_timeline->currentTime()); |
| 454 EXPECT_DOUBLE_EQ(0, auto_timeline->currentTime()); |
| 455 |
| 456 // For vertical-rl, the X-axis starts on the right-hand-side and is the block |
| 457 // axis. The Y-axis is normal but is the inline axis. |
| 458 scrollable_area->ScrollToAbsolutePosition(FloatPoint(75, 50)); |
| 459 ASSERT_EQ(75.0, scrollable_area->ScrollPosition().X()); |
| 460 ASSERT_EQ(50.0, scrollable_area->ScrollPosition().Y()); |
| 461 |
| 462 EXPECT_DOUBLE_EQ(scroller_size - 75, block_timeline->currentTime()); |
| 463 EXPECT_DOUBLE_EQ(50, inline_timeline->currentTime()); |
| 464 // As both axes are scrollable, 'auto' should select the block axis. |
| 465 EXPECT_DOUBLE_EQ(scroller_size - 75, auto_timeline->currentTime()); |
| 466 } |
| 467 |
| 468 TEST_F(ScrollTimelineTest, CurrentTimeHandlesVerticalLrWritingMode) { |
| 469 SetInnerHTML( |
| 470 "<style>#scroller { height: 100px; width: 100px; overflow: auto; " |
| 471 "writing-mode: vertical-lr; }" |
| 472 "#content { height: 250px; width: 250px; }</style>" |
| 473 "<div id='scroller'><div id='content'></div></div>"); |
| 474 |
| 475 Element* scroller = GetDocument().getElementById("scroller"); |
| 476 PaintLayerScrollableArea* scrollable_area = |
| 477 scroller->GetLayoutBoxModelObject()->GetScrollableArea(); |
| 478 ASSERT_TRUE(scroller); |
| 479 ASSERT_TRUE(scrollable_area); |
| 480 |
| 481 DummyExceptionStateForTesting exception_state; |
| 482 |
| 483 // For simplicity, we set the timeRange such that currentTime maps directly to |
| 484 // the value scrolled. We have a square scroller/contents, so can just compute |
| 485 // one edge and use it for inline and block. |
| 486 double scroller_size = scroller->scrollHeight() - scroller->clientHeight(); |
| 487 |
| 488 ScrollTimelineOptions block_options = |
| 489 CreateOptions(scroller, scroller_size, "block"); |
| 490 ScrollTimeline* block_timeline = |
| 491 ScrollTimeline::Create(GetDocument(), block_options, exception_state); |
| 492 EXPECT_TRUE(block_timeline); |
| 493 EXPECT_FALSE(exception_state.HadException()); |
| 494 |
| 495 ScrollTimelineOptions inline_options = |
| 496 CreateOptions(scroller, scroller_size, "inline"); |
| 497 ScrollTimeline* inline_timeline = |
| 498 ScrollTimeline::Create(GetDocument(), inline_options, exception_state); |
| 499 EXPECT_TRUE(inline_timeline); |
| 500 EXPECT_FALSE(exception_state.HadException()); |
| 501 |
| 502 ScrollTimelineOptions auto_options = |
| 503 CreateOptions(scroller, scroller_size, "auto"); |
| 504 ScrollTimeline* auto_timeline = |
| 505 ScrollTimeline::Create(GetDocument(), auto_options, exception_state); |
| 506 EXPECT_TRUE(auto_timeline); |
| 507 EXPECT_FALSE(exception_state.HadException()); |
| 508 |
| 509 // Unscrolled, all three timelines should read a current time of 0. |
| 510 EXPECT_DOUBLE_EQ(0, block_timeline->currentTime()); |
| 511 EXPECT_DOUBLE_EQ(0, inline_timeline->currentTime()); |
| 512 EXPECT_DOUBLE_EQ(0, auto_timeline->currentTime()); |
| 513 |
| 514 // For vertical-rl, both axes start at their 'normal' positions but the X-axis |
| 515 // is the block direction and the Y-axis is the inline direction. |
| 516 scrollable_area->ScrollToAbsolutePosition(FloatPoint(75, 50)); |
| 517 ASSERT_EQ(75.0, scrollable_area->ScrollPosition().X()); |
| 518 ASSERT_EQ(50.0, scrollable_area->ScrollPosition().Y()); |
| 519 |
| 520 EXPECT_DOUBLE_EQ(75, block_timeline->currentTime()); |
| 521 EXPECT_DOUBLE_EQ(50, inline_timeline->currentTime()); |
| 522 // As both axes are scrollable, 'auto' should select the block axis. |
| 523 EXPECT_DOUBLE_EQ(75, auto_timeline->currentTime()); |
| 524 } |
| 525 |
| 526 } // namespace blink |
OLD | NEW |