2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "core/page/scrolling/ScrollingCoordinator.h"
28 #include "core/layout/LayoutPart.h"
29 #include "core/layout/LayoutView.h"
30 #include "core/layout/compositing/CompositedDeprecatedPaintLayerMapping.h"
31 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h"
32 #include "core/page/Page.h"
33 #include "platform/graphics/GraphicsLayer.h"
34 #include "platform/testing/URLTestHelpers.h"
35 #include "public/platform/Platform.h"
36 #include "public/platform/WebLayer.h"
37 #include "public/platform/WebLayerPositionConstraint.h"
38 #include "public/platform/WebLayerTreeView.h"
39 #include "public/platform/WebUnitTestSupport.h"
40 #include "public/web/WebSettings.h"
41 #include "public/web/WebViewClient.h"
42 #include "web/WebLocalFrameImpl.h"
43 #include "web/WebViewImpl.h"
44 #include "web/tests/FrameTestHelpers.h"
45 #include <gtest/gtest.h>
49 class ScrollingCoordinatorTest
: public testing::Test
{
51 ScrollingCoordinatorTest()
52 : m_baseURL("http://www.test.com/")
54 m_helper
.initialize(true, 0, &m_mockWebViewClient
, &configureSettings
);
55 webViewImpl()->resize(IntSize(320, 240));
57 // OSX attaches main frame scrollbars to the VisualViewport so the VisualViewport layers need
59 webViewImpl()->layout();
60 webViewImpl()->setRootGraphicsLayer(
61 webViewImpl()->mainFrameImpl()->frame()->view()->layoutView()->compositor()->rootGraphicsLayer());
64 ~ScrollingCoordinatorTest() override
66 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
69 void navigateTo(const std::string
& url
)
71 FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url
);
74 void forceFullCompositingUpdate()
76 webViewImpl()->layout();
79 void registerMockedHttpURLLoad(const std::string
& fileName
)
81 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL
.c_str()), WebString::fromUTF8(fileName
.c_str()));
84 WebLayer
* getRootScrollLayer()
86 DeprecatedPaintLayerCompositor
* compositor
= frame()->contentLayoutObject()->compositor();
88 ASSERT(compositor
->scrollLayer());
90 WebLayer
* webScrollLayer
= compositor
->scrollLayer()->platformLayer();
91 return webScrollLayer
;
94 WebViewImpl
* webViewImpl() const { return m_helper
.webViewImpl(); }
95 LocalFrame
* frame() const { return m_helper
.webViewImpl()->mainFrameImpl()->frame(); }
98 std::string m_baseURL
;
99 FrameTestHelpers::TestWebViewClient m_mockWebViewClient
;
102 static void configureSettings(WebSettings
* settings
)
104 settings
->setJavaScriptEnabled(true);
105 settings
->setAcceleratedCompositingEnabled(true);
106 settings
->setPreferCompositingToLCDTextEnabled(true);
109 FrameTestHelpers::WebViewHelper m_helper
;
112 TEST_F(ScrollingCoordinatorTest
, fastScrollingByDefault
)
114 navigateTo("about:blank");
115 forceFullCompositingUpdate();
117 // Make sure the scrolling coordinator is active.
118 FrameView
* frameView
= frame()->view();
119 Page
* page
= frame()->page();
120 ASSERT_TRUE(page
->scrollingCoordinator());
121 ASSERT_TRUE(page
->scrollingCoordinator()->coordinatesScrollingForFrameView(frameView
));
123 // Fast scrolling should be enabled by default.
124 WebLayer
* rootScrollLayer
= getRootScrollLayer();
125 ASSERT_TRUE(rootScrollLayer
->scrollable());
126 ASSERT_FALSE(rootScrollLayer
->shouldScrollOnMainThread());
127 ASSERT_FALSE(rootScrollLayer
->haveWheelEventHandlers());
130 TEST_F(ScrollingCoordinatorTest
, fastScrollingCanBeDisabledWithSetting
)
132 navigateTo("about:blank");
133 webViewImpl()->settings()->setThreadedScrollingEnabled(false);
134 forceFullCompositingUpdate();
136 // Make sure the scrolling coordinator is active.
137 FrameView
* frameView
= frame()->view();
138 Page
* page
= frame()->page();
139 ASSERT_TRUE(page
->scrollingCoordinator());
140 ASSERT_TRUE(page
->scrollingCoordinator()->coordinatesScrollingForFrameView(frameView
));
142 // Main scrolling should be enabled with the setting override.
143 WebLayer
* rootScrollLayer
= getRootScrollLayer();
144 ASSERT_TRUE(rootScrollLayer
->scrollable());
145 ASSERT_TRUE(rootScrollLayer
->shouldScrollOnMainThread());
149 TEST_F(ScrollingCoordinatorTest
, fastFractionalScrollingDiv
)
151 registerMockedHttpURLLoad("fractional-scroll-div.html");
152 navigateTo(m_baseURL
+ "fractional-scroll-div.html");
153 forceFullCompositingUpdate();
155 Document
* document
= frame()->document();
156 Element
* scrollableElement
= document
->getElementById("scroller");
157 ASSERT(scrollableElement
);
159 scrollableElement
->setScrollTop(1.0);
160 scrollableElement
->setScrollLeft(1.0);
161 forceFullCompositingUpdate();
163 // Make sure the fractional scroll offset change 1.0 -> 1.2 gets propagated
165 scrollableElement
->setScrollTop(1.2);
166 scrollableElement
->setScrollLeft(1.2);
167 forceFullCompositingUpdate();
169 LayoutObject
* layoutObject
= scrollableElement
->layoutObject();
170 ASSERT_TRUE(layoutObject
->isBox());
171 LayoutBox
* box
= toLayoutBox(layoutObject
);
172 ASSERT_TRUE(box
->usesCompositedScrolling());
173 CompositedDeprecatedPaintLayerMapping
* compositedDeprecatedPaintLayerMapping
= box
->layer()->compositedDeprecatedPaintLayerMapping();
174 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->hasScrollingLayer());
175 ASSERT(compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer());
176 WebLayer
* webScrollLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer()->platformLayer();
177 ASSERT_TRUE(webScrollLayer
);
178 ASSERT_NEAR(1.2, webScrollLayer
->scrollPositionDouble().x
, 0.01);
179 ASSERT_NEAR(1.2, webScrollLayer
->scrollPositionDouble().y
, 0.01);
182 static WebLayer
* webLayerFromElement(Element
* element
)
186 LayoutObject
* layoutObject
= element
->layoutObject();
187 if (!layoutObject
|| !layoutObject
->isBoxModelObject())
189 DeprecatedPaintLayer
* layer
= toLayoutBoxModelObject(layoutObject
)->layer();
192 if (!layer
->hasCompositedDeprecatedPaintLayerMapping())
194 CompositedDeprecatedPaintLayerMapping
* compositedDeprecatedPaintLayerMapping
= layer
->compositedDeprecatedPaintLayerMapping();
195 GraphicsLayer
* graphicsLayer
= compositedDeprecatedPaintLayerMapping
->mainGraphicsLayer();
198 return graphicsLayer
->platformLayer();
202 TEST_F(ScrollingCoordinatorTest
, fractionalScrollingNonLayerFixedPosition
)
204 registerMockedHttpURLLoad("fractional-scroll-fixed-position.html");
205 navigateTo(m_baseURL
+ "fractional-scroll-fixed-position.html");
206 // Prevent fixed-position element from getting its own layer.
207 webViewImpl()->settings()->setPreferCompositingToLCDTextEnabled(false);
208 forceFullCompositingUpdate();
210 FrameView
* frameView
= frame()->view();
211 frameView
->scrollTo(DoublePoint(1.5, 1.5));
212 WebLayer
* rootScrollLayer
= getRootScrollLayer();
213 // Scroll on main if there is non-composited fixed position element.
214 // And the containing scroll layer should not get fractional scroll offset.
215 ASSERT_TRUE(rootScrollLayer
->shouldScrollOnMainThread());
216 ASSERT_EQ(1.0, rootScrollLayer
->scrollPositionDouble().x
);
217 ASSERT_EQ(1.0, rootScrollLayer
->scrollPositionDouble().y
);
218 ASSERT_EQ(0.0, rootScrollLayer
->position().x
);
219 ASSERT_EQ(0.0, rootScrollLayer
->position().y
);
222 TEST_F(ScrollingCoordinatorTest
, fastScrollingForFixedPosition
)
224 registerMockedHttpURLLoad("fixed-position.html");
225 navigateTo(m_baseURL
+ "fixed-position.html");
226 forceFullCompositingUpdate();
228 // Fixed position should not fall back to main thread scrolling.
229 WebLayer
* rootScrollLayer
= getRootScrollLayer();
230 ASSERT_FALSE(rootScrollLayer
->shouldScrollOnMainThread());
232 Document
* document
= frame()->document();
234 Element
* element
= document
->getElementById("div-tl");
235 ASSERT_TRUE(element
);
236 WebLayer
* layer
= webLayerFromElement(element
);
238 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
239 ASSERT_TRUE(constraint
.isFixedPosition
);
240 ASSERT_TRUE(!constraint
.isFixedToRightEdge
&& !constraint
.isFixedToBottomEdge
);
243 Element
* element
= document
->getElementById("div-tr");
244 ASSERT_TRUE(element
);
245 WebLayer
* layer
= webLayerFromElement(element
);
247 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
248 ASSERT_TRUE(constraint
.isFixedPosition
);
249 ASSERT_TRUE(constraint
.isFixedToRightEdge
&& !constraint
.isFixedToBottomEdge
);
252 Element
* element
= document
->getElementById("div-bl");
253 ASSERT_TRUE(element
);
254 WebLayer
* layer
= webLayerFromElement(element
);
256 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
257 ASSERT_TRUE(constraint
.isFixedPosition
);
258 ASSERT_TRUE(!constraint
.isFixedToRightEdge
&& constraint
.isFixedToBottomEdge
);
261 Element
* element
= document
->getElementById("div-br");
262 ASSERT_TRUE(element
);
263 WebLayer
* layer
= webLayerFromElement(element
);
265 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
266 ASSERT_TRUE(constraint
.isFixedPosition
);
267 ASSERT_TRUE(constraint
.isFixedToRightEdge
&& constraint
.isFixedToBottomEdge
);
270 Element
* element
= document
->getElementById("span-tl");
271 ASSERT_TRUE(element
);
272 WebLayer
* layer
= webLayerFromElement(element
);
274 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
275 ASSERT_TRUE(constraint
.isFixedPosition
);
276 ASSERT_TRUE(!constraint
.isFixedToRightEdge
&& !constraint
.isFixedToBottomEdge
);
279 Element
* element
= document
->getElementById("span-tr");
280 ASSERT_TRUE(element
);
281 WebLayer
* layer
= webLayerFromElement(element
);
283 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
284 ASSERT_TRUE(constraint
.isFixedPosition
);
285 ASSERT_TRUE(constraint
.isFixedToRightEdge
&& !constraint
.isFixedToBottomEdge
);
288 Element
* element
= document
->getElementById("span-bl");
289 ASSERT_TRUE(element
);
290 WebLayer
* layer
= webLayerFromElement(element
);
292 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
293 ASSERT_TRUE(constraint
.isFixedPosition
);
294 ASSERT_TRUE(!constraint
.isFixedToRightEdge
&& constraint
.isFixedToBottomEdge
);
297 Element
* element
= document
->getElementById("span-br");
298 ASSERT_TRUE(element
);
299 WebLayer
* layer
= webLayerFromElement(element
);
301 WebLayerPositionConstraint constraint
= layer
->positionConstraint();
302 ASSERT_TRUE(constraint
.isFixedPosition
);
303 ASSERT_TRUE(constraint
.isFixedToRightEdge
&& constraint
.isFixedToBottomEdge
);
307 TEST_F(ScrollingCoordinatorTest
, wheelEventHandler
)
309 registerMockedHttpURLLoad("wheel-event-handler.html");
310 navigateTo(m_baseURL
+ "wheel-event-handler.html");
311 forceFullCompositingUpdate();
313 WebLayer
* rootScrollLayer
= getRootScrollLayer();
314 ASSERT_TRUE(rootScrollLayer
->haveWheelEventHandlers());
317 TEST_F(ScrollingCoordinatorTest
, scrollEventHandler
)
319 registerMockedHttpURLLoad("scroll-event-handler.html");
320 navigateTo(m_baseURL
+ "scroll-event-handler.html");
321 forceFullCompositingUpdate();
323 WebLayer
* rootScrollLayer
= getRootScrollLayer();
324 ASSERT_TRUE(rootScrollLayer
->haveScrollEventHandlers());
327 TEST_F(ScrollingCoordinatorTest
, updateEventHandlersDuringTeardown
)
329 registerMockedHttpURLLoad("scroll-event-handler-window.html");
330 navigateTo(m_baseURL
+ "scroll-event-handler-window.html");
331 forceFullCompositingUpdate();
333 // Simulate detaching the document from its DOM window. This should not
334 // cause a crash when the WebViewImpl is closed by the test runner.
335 frame()->document()->detach();
338 TEST_F(ScrollingCoordinatorTest
, clippedBodyTest
)
340 registerMockedHttpURLLoad("clipped-body.html");
341 navigateTo(m_baseURL
+ "clipped-body.html");
342 forceFullCompositingUpdate();
344 WebLayer
* rootScrollLayer
= getRootScrollLayer();
345 ASSERT_EQ(0u, rootScrollLayer
->nonFastScrollableRegion().size());
348 TEST_F(ScrollingCoordinatorTest
, overflowScrolling
)
350 registerMockedHttpURLLoad("overflow-scrolling.html");
351 navigateTo(m_baseURL
+ "overflow-scrolling.html");
352 forceFullCompositingUpdate();
354 // Verify the properties of the accelerated scrolling element starting from the LayoutObject
355 // all the way to the WebLayer.
356 Element
* scrollableElement
= frame()->document()->getElementById("scrollable");
357 ASSERT(scrollableElement
);
359 LayoutObject
* layoutObject
= scrollableElement
->layoutObject();
360 ASSERT_TRUE(layoutObject
->isBox());
361 ASSERT_TRUE(layoutObject
->hasLayer());
363 LayoutBox
* box
= toLayoutBox(layoutObject
);
364 ASSERT_TRUE(box
->usesCompositedScrolling());
365 ASSERT_EQ(PaintsIntoOwnBacking
, box
->layer()->compositingState());
367 CompositedDeprecatedPaintLayerMapping
* compositedDeprecatedPaintLayerMapping
= box
->layer()->compositedDeprecatedPaintLayerMapping();
368 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->hasScrollingLayer());
369 ASSERT(compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer());
371 GraphicsLayer
* graphicsLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer();
372 ASSERT_EQ(box
->layer()->scrollableArea(), graphicsLayer
->scrollableArea());
374 WebLayer
* webScrollLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer()->platformLayer();
375 ASSERT_TRUE(webScrollLayer
->scrollable());
376 ASSERT_TRUE(webScrollLayer
->userScrollableHorizontal());
377 ASSERT_TRUE(webScrollLayer
->userScrollableVertical());
380 // Now verify we've attached impl-side scrollbars onto the scrollbar layers
381 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->layerForHorizontalScrollbar());
382 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->layerForHorizontalScrollbar()->hasContentsLayer());
383 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->layerForVerticalScrollbar());
384 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->layerForVerticalScrollbar()->hasContentsLayer());
388 TEST_F(ScrollingCoordinatorTest
, overflowHidden
)
390 registerMockedHttpURLLoad("overflow-hidden.html");
391 navigateTo(m_baseURL
+ "overflow-hidden.html");
392 forceFullCompositingUpdate();
394 // Verify the properties of the accelerated scrolling element starting from the LayoutObject
395 // all the way to the WebLayer.
396 Element
* overflowElement
= frame()->document()->getElementById("unscrollable-y");
397 ASSERT(overflowElement
);
399 LayoutObject
* layoutObject
= overflowElement
->layoutObject();
400 ASSERT_TRUE(layoutObject
->isBox());
401 ASSERT_TRUE(layoutObject
->hasLayer());
403 LayoutBox
* box
= toLayoutBox(layoutObject
);
404 ASSERT_TRUE(box
->usesCompositedScrolling());
405 ASSERT_EQ(PaintsIntoOwnBacking
, box
->layer()->compositingState());
407 CompositedDeprecatedPaintLayerMapping
* compositedDeprecatedPaintLayerMapping
= box
->layer()->compositedDeprecatedPaintLayerMapping();
408 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->hasScrollingLayer());
409 ASSERT(compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer());
411 GraphicsLayer
* graphicsLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer();
412 ASSERT_EQ(box
->layer()->scrollableArea(), graphicsLayer
->scrollableArea());
414 WebLayer
* webScrollLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer()->platformLayer();
415 ASSERT_TRUE(webScrollLayer
->scrollable());
416 ASSERT_TRUE(webScrollLayer
->userScrollableHorizontal());
417 ASSERT_FALSE(webScrollLayer
->userScrollableVertical());
419 overflowElement
= frame()->document()->getElementById("unscrollable-x");
420 ASSERT(overflowElement
);
422 layoutObject
= overflowElement
->layoutObject();
423 ASSERT_TRUE(layoutObject
->isBox());
424 ASSERT_TRUE(layoutObject
->hasLayer());
426 box
= toLayoutBox(layoutObject
);
427 ASSERT_TRUE(box
->scrollableArea()->usesCompositedScrolling());
428 ASSERT_EQ(PaintsIntoOwnBacking
, box
->layer()->compositingState());
430 compositedDeprecatedPaintLayerMapping
= box
->layer()->compositedDeprecatedPaintLayerMapping();
431 ASSERT_TRUE(compositedDeprecatedPaintLayerMapping
->hasScrollingLayer());
432 ASSERT(compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer());
434 graphicsLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer();
435 ASSERT_EQ(box
->layer()->scrollableArea(), graphicsLayer
->scrollableArea());
437 webScrollLayer
= compositedDeprecatedPaintLayerMapping
->scrollingContentsLayer()->platformLayer();
438 ASSERT_TRUE(webScrollLayer
->scrollable());
439 ASSERT_FALSE(webScrollLayer
->userScrollableHorizontal());
440 ASSERT_TRUE(webScrollLayer
->userScrollableVertical());
443 TEST_F(ScrollingCoordinatorTest
, iframeScrolling
)
445 registerMockedHttpURLLoad("iframe-scrolling.html");
446 registerMockedHttpURLLoad("iframe-scrolling-inner.html");
447 navigateTo(m_baseURL
+ "iframe-scrolling.html");
448 forceFullCompositingUpdate();
450 // Verify the properties of the accelerated scrolling element starting from the LayoutObject
451 // all the way to the WebLayer.
452 Element
* scrollableFrame
= frame()->document()->getElementById("scrollable");
453 ASSERT_TRUE(scrollableFrame
);
455 LayoutObject
* layoutObject
= scrollableFrame
->layoutObject();
456 ASSERT_TRUE(layoutObject
);
457 ASSERT_TRUE(layoutObject
->isLayoutPart());
459 LayoutPart
* layoutPart
= toLayoutPart(layoutObject
);
460 ASSERT_TRUE(layoutPart
);
461 ASSERT_TRUE(layoutPart
->widget());
462 ASSERT_TRUE(layoutPart
->widget()->isFrameView());
464 FrameView
* innerFrameView
= toFrameView(layoutPart
->widget());
465 LayoutView
* innerLayoutView
= innerFrameView
->layoutView();
466 ASSERT_TRUE(innerLayoutView
);
468 DeprecatedPaintLayerCompositor
* innerCompositor
= innerLayoutView
->compositor();
469 ASSERT_TRUE(innerCompositor
->inCompositingMode());
470 ASSERT_TRUE(innerCompositor
->scrollLayer());
472 GraphicsLayer
* scrollLayer
= innerCompositor
->scrollLayer();
473 ASSERT_EQ(innerFrameView
, scrollLayer
->scrollableArea());
475 WebLayer
* webScrollLayer
= scrollLayer
->platformLayer();
476 ASSERT_TRUE(webScrollLayer
->scrollable());
479 // Now verify we've attached impl-side scrollbars onto the scrollbar layers
480 ASSERT_TRUE(innerCompositor
->layerForHorizontalScrollbar());
481 ASSERT_TRUE(innerCompositor
->layerForHorizontalScrollbar()->hasContentsLayer());
482 ASSERT_TRUE(innerCompositor
->layerForVerticalScrollbar());
483 ASSERT_TRUE(innerCompositor
->layerForVerticalScrollbar()->hasContentsLayer());
487 TEST_F(ScrollingCoordinatorTest
, rtlIframe
)
489 registerMockedHttpURLLoad("rtl-iframe.html");
490 registerMockedHttpURLLoad("rtl-iframe-inner.html");
491 navigateTo(m_baseURL
+ "rtl-iframe.html");
492 forceFullCompositingUpdate();
494 // Verify the properties of the accelerated scrolling element starting from the LayoutObject
495 // all the way to the WebLayer.
496 Element
* scrollableFrame
= frame()->document()->getElementById("scrollable");
497 ASSERT_TRUE(scrollableFrame
);
499 LayoutObject
* layoutObject
= scrollableFrame
->layoutObject();
500 ASSERT_TRUE(layoutObject
);
501 ASSERT_TRUE(layoutObject
->isLayoutPart());
503 LayoutPart
* layoutPart
= toLayoutPart(layoutObject
);
504 ASSERT_TRUE(layoutPart
);
505 ASSERT_TRUE(layoutPart
->widget());
506 ASSERT_TRUE(layoutPart
->widget()->isFrameView());
508 FrameView
* innerFrameView
= toFrameView(layoutPart
->widget());
509 LayoutView
* innerLayoutView
= innerFrameView
->layoutView();
510 ASSERT_TRUE(innerLayoutView
);
512 DeprecatedPaintLayerCompositor
* innerCompositor
= innerLayoutView
->compositor();
513 ASSERT_TRUE(innerCompositor
->inCompositingMode());
514 ASSERT_TRUE(innerCompositor
->scrollLayer());
516 GraphicsLayer
* scrollLayer
= innerCompositor
->scrollLayer();
517 ASSERT_EQ(innerFrameView
, scrollLayer
->scrollableArea());
519 WebLayer
* webScrollLayer
= scrollLayer
->platformLayer();
520 ASSERT_TRUE(webScrollLayer
->scrollable());
522 int expectedScrollPosition
= 958 + (innerFrameView
->verticalScrollbar()->isOverlayScrollbar() ? 0 : 15);
523 ASSERT_EQ(expectedScrollPosition
, webScrollLayer
->scrollPositionDouble().x
);
526 TEST_F(ScrollingCoordinatorTest
, setupScrollbarLayerShouldNotCrash
)
528 registerMockedHttpURLLoad("setup_scrollbar_layer_crash.html");
529 navigateTo(m_baseURL
+ "setup_scrollbar_layer_crash.html");
530 forceFullCompositingUpdate();
531 // This test document setup an iframe with scrollbars, then switch to
532 // an empty document by javascript.
535 TEST_F(ScrollingCoordinatorTest
, scrollbarsForceMainThreadOrHaveWebScrollbarLayer
)
537 blink::FrameTestHelpers::UseMockScrollbarSettings mockScrollbarSettings
;
539 registerMockedHttpURLLoad("trivial-scroller.html");
540 navigateTo(m_baseURL
+ "trivial-scroller.html");
541 forceFullCompositingUpdate();
543 Document
* document
= frame()->document();
544 Element
* scrollableElement
= document
->getElementById("scroller");
545 ASSERT(scrollableElement
);
547 LayoutObject
* layoutObject
= scrollableElement
->layoutObject();
548 ASSERT_TRUE(layoutObject
->isBox());
549 LayoutBox
* box
= toLayoutBox(layoutObject
);
550 ASSERT_TRUE(box
->usesCompositedScrolling());
551 CompositedDeprecatedPaintLayerMapping
* compositedDeprecatedPaintLayerMapping
= box
->layer()->compositedDeprecatedPaintLayerMapping();
552 GraphicsLayer
* scrollbarGraphicsLayer
= compositedDeprecatedPaintLayerMapping
->layerForVerticalScrollbar();
553 ASSERT_TRUE(scrollbarGraphicsLayer
);
555 bool hasWebScrollbarLayer
= !scrollbarGraphicsLayer
->drawsContent();
556 ASSERT_TRUE(hasWebScrollbarLayer
|| scrollbarGraphicsLayer
->platformLayer()->shouldScrollOnMainThread());
559 #if OS(MACOSX) || OS(ANDROID)
560 TEST_F(ScrollingCoordinatorTest
, DISABLED_setupScrollbarLayerShouldSetScrollLayerOpaque
)
562 TEST_F(ScrollingCoordinatorTest
, setupScrollbarLayerShouldSetScrollLayerOpaque
)
565 registerMockedHttpURLLoad("wide_document.html");
566 navigateTo(m_baseURL
+ "wide_document.html");
567 forceFullCompositingUpdate();
569 FrameView
* frameView
= frame()->view();
570 ASSERT_TRUE(frameView
);
572 GraphicsLayer
* scrollbarGraphicsLayer
= frameView
->layerForHorizontalScrollbar();
573 ASSERT_TRUE(scrollbarGraphicsLayer
);
575 WebLayer
* platformLayer
= scrollbarGraphicsLayer
->platformLayer();
576 ASSERT_TRUE(platformLayer
);
578 WebLayer
* contentsLayer
= scrollbarGraphicsLayer
->contentsLayer();
579 ASSERT_TRUE(contentsLayer
);
581 // After scrollableAreaScrollbarLayerDidChange,
582 // if the main frame's scrollbarLayer is opaque,
583 // contentsLayer should be opaque too.
584 ASSERT_EQ(platformLayer
->opaque(), contentsLayer
->opaque());
587 TEST_F(ScrollingCoordinatorTest
, FixedPositionLosingBackingShouldTriggerMainThreadScroll
)
589 webViewImpl()->settings()->setPreferCompositingToLCDTextEnabled(false);
590 registerMockedHttpURLLoad("fixed-position-losing-backing.html");
591 navigateTo(m_baseURL
+ "fixed-position-losing-backing.html");
592 forceFullCompositingUpdate();
594 WebLayer
* scrollLayer
= frame()->page()->deprecatedLocalMainFrame()->view()->layerForScrolling()->platformLayer();
595 Document
* document
= frame()->document();
596 Element
* fixedPos
= document
->getElementById("fixed");
598 EXPECT_TRUE(static_cast<LayoutBoxModelObject
*>(fixedPos
->layoutObject())->layer()->hasCompositedDeprecatedPaintLayerMapping());
599 EXPECT_FALSE(scrollLayer
->shouldScrollOnMainThread());
601 fixedPos
->setInlineStyleProperty(CSSPropertyTransform
, CSSValueNone
);
602 forceFullCompositingUpdate();
604 EXPECT_FALSE(static_cast<LayoutBoxModelObject
*>(fixedPos
->layoutObject())->layer()->hasCompositedDeprecatedPaintLayerMapping());
605 EXPECT_TRUE(scrollLayer
->shouldScrollOnMainThread());