17 .container
> div
> div {
20 background: linear-gradient(to bottom, red, white);
30 <section id='div'
style=
"display:none;">
31 <div class=
"to-show container">
33 <div class=
"to-hide container">
35 <div>This should not be visible.
</div>
40 <section id=
"iframe" style=
"display:none;">
41 <div class=
"to-show container">
43 <div class=
"to-hide container">
44 <iframe src=
"data:text/html;charset=utf-8,<div style='height:1000px; width:1000px; background: linear-gradient(to bottom, red, white);'>">
45 This should not be visible.
50 <p>Two squares should be visible and fully covered by green overlays.
</p>
52 <div id=
"console"></div>
54 <script src=
"../resources/js-test.js"></script>
55 <script src=
"../resources/run-after-layout-and-paint.js"></script>
56 <script src=
"resources/non-fast-scrollable-region-testing.js"></script>
58 window
.jsTestIsAsync
= true;
59 description('This test ensures that changing visibility of a non-fast ' +
60 'scrollable area correctly updates list of non-fast scrollable ' +
61 'areas (See http://crbug.com/434982). Two types of non-fast ' +
62 'scrollable regions are covered: div, and iframe.');
67 // type, bounding box of element to show, bounding box of element to hide
68 ['div', '[0, 50, 200, 200]', '[0, 350, 200, 200]'],
69 ['iframe', '[0, 50, 222, 222]', '[0, 350, 222, 222]']];
73 if (index
< testCases
.length
) {
74 var type
= testCases
[index
][0];
75 debug('running tests for non-fast scrollable ' + type
);
76 runTest
.apply(this, testCases
[index
]);
78 // Next 3 statements have no functional impact just visual
79 showSectionIf(function(){return true;});
80 runAfterLayoutAndPaint(function(){
81 drawNonFastScrollableRegionOverlays();
90 // Execute tests for given non-fast scrollable type.
91 function runTest(type
, elemToShowExpected
, elemToHideExpected
) {
92 // Hide all sections that are not relevant to this test to ensure
93 // |window.internals.nonFastScrollableRects| returns only the relevant non-
94 // fast scrollable regions.
95 showSectionIf(function(section
){return section
.id
== type
;});
97 runAfterLayoutAndPaint(function() {
98 shouldBeEqualToString('document.getElementById("' + type
+ '").style.display', 'block');
100 var elemToShow
= document
.querySelector('section#' + type
+ '> .to-show'),
101 elemToHide
= document
.querySelector('section#' + type
+ '> .to-hide');
103 nonFastScrollableRects
= internals
.nonFastScrollableRects(document
);
104 shouldBe('nonFastScrollableRects.length', '1');
105 shouldBeEqualToString('rectToString(nonFastScrollableRects[0])', elemToHideExpected
);
107 // Hide container before making it non-fast scrollable to ensure any
108 // layout occurs while it is invisible.
109 elemToShow
.style
.visibility
= 'hidden';
110 appendScrollable(elemToShow
, type
, function() {
111 // Change visibility (hidden -> visible), which should not cause any layout,
112 // and verify that non-fast scrollable areas are correctly updated.
113 elemToShow
.style
.visibility
= 'visible';
114 shouldBe('window.internals.needsLayoutCount()', '0');
116 runAfterLayoutAndPaint(function() {
117 nonFastScrollableRects
= internals
.nonFastScrollableRects(document
);
118 shouldBe('nonFastScrollableRects.length', '2');
119 shouldBeEqualToString('rectToString(nonFastScrollableRects[0])', elemToShowExpected
);
120 shouldBeEqualToString('rectToString(nonFastScrollableRects[1])', elemToHideExpected
);
122 // Change visibility (visible -> hidden)
123 elemToHide
.style
.visibility
= 'hidden';
124 shouldBe('window.internals.needsLayoutCount()', '0');
126 runAfterLayoutAndPaint(function() {
127 nonFastScrollableRects
= internals
.nonFastScrollableRects(document
);
128 shouldBe('nonFastScrollableRects.length', '1');
129 shouldBeEqualToString('rectToString(nonFastScrollableRects[0])', elemToShowExpected
);
137 // Appends to container an scrollable element of the given type.
138 // Note that because this layout test runs with --run-layout-test flag
139 // the appended scrollable is always non-fast even on HDPI platforms.
140 function appendScrollable(container
, type
, nextStep
) {
144 inner
= '<div><div>This should be covered by a green overlay.</div></div>';
147 window
.nextStep
= nextStep
;
148 inner
= '<iframe id="iframe" onload="runAfterLayoutAndPaint(window.nextStep)" src="data:text/html;charset=utf-8,<div style=\'height:1000px; width:1000px; background: linear-gradient(to bottom, red, white);\'>This should be covered by a green overlay.</div>"></iframe>';
151 container
.innerHTML
= inner
;
153 runAfterLayoutAndPaint(nextStep
);
156 // Shows sections that pass condition but hides others
157 function showSectionIf(condition
) {
158 var sections
= document
.querySelectorAll('section');
159 for (var i
= 0; i
< sections
.length
; i
++)
160 sections
[i
].style
.display
= condition(sections
[i
]) ? 'block' : 'none';