4 <title>Viewport: Scroll Event
</title>
6 <meta name=
"viewport" content=
"width=device-width, minimum-scale=1">
7 <script src=
"/resources/testharness.js"></script>
8 <script src=
"/resources/testharnessreport.js"></script>
9 <script src=
"viewport_support.js"></script>
11 setup({explicit_timeout
: true, explicit_done
: true})
21 <h1>Viewport: Scroll Event
</h1>
23 Test Description: This test checks that a scroll event is fired against
24 the window.visualViewport object when the viewport is scrolled.
26 <h2 style=
"color: red">THIS IS A MANUAL TEST
</h2>
28 <button id=
"skipbtn" onclick=
"skipManualTest();">Skip Test
</button>
31 <p id=
"instruction"></p>
32 <button id=
"continue">Start Test
</button>
36 var continueBtn
= document
.getElementById("continue");
38 function continueTest() {
39 nextStep(function(instructionText
) {
40 var instruction
= document
.getElementById("instruction");
41 continueBtn
.innerText
= "Continue";
42 instruction
.innerText
= instructionText
;
46 continueBtn
.addEventListener('click', continueTest
);
48 var didGetScrollEvent
= false;
49 var cancelable
= undefined;
50 var bubbles
= undefined;
52 function resetValues() {
53 didGetScrollEvent
= false;
54 cancelable
= undefined;
60 window
.visualViewport
.addEventListener('scroll', function(e
) {
61 didGetScrollEvent
= true;
62 cancelable
= e
.cancelable
;
65 document
.documentElement
.style
.overflow
= "hidden";
68 '1. Pinch-zoom a little near the "Continue" button but don\'t ' +
69 'perform any scrolling.');
73 requestAnimationFrame(continueTest
);
74 assert_true(didGetScrollEvent
, "Got event");
75 assert_false(cancelable
, "Event is not cancelable");
76 assert_false(bubbles
, "Event does not bubble");
78 'Got scroll event while pinch-zooming',
84 '2. Scroll in any direction.');
88 requestAnimationFrame(continueTest
);
89 assert_true(didGetScrollEvent
, "Got event");
90 assert_false(cancelable
, "Event is not cancelable");
91 assert_false(bubbles
, "Event does not bubble");
93 'Panning viewport fires a scroll event',
98 continueBtn
.style
.position
= "absolute";
99 continueBtn
.style
.right
= "10px";
100 continueBtn
.style
.bottom
= "10px";
103 '3. Scroll fully to the bottom right and click the continue ' +
111 document
.documentElement
.style
.overflow
= "";
112 document
.body
.style
.width
= "500%";
113 document
.body
.style
.height
= "500%";
114 continueBtn
.style
.position
= "";
115 continueBtn
.style
.left
= "";
116 continueBtn
.style
.top
= "";
118 offsetLeft
= window
.visualViewport
.offsetLeft
;
119 offsetTop
= window
.visualViewport
.offsetTop
;
121 // The visual viewport should be fully scrolled so even if
122 // scrollTo does normally "push" the layout viewport with the
123 // visual, there should be no change to either offsetValue
124 window
.scrollTo(10000, 10000);
126 requestAnimationFrame(continueTest
);
127 assert_equals(window
.visualViewport
.offsetLeft
, offsetLeft
,
128 "OffsetLeft Unchanged");
129 assert_equals(window
.visualViewport
.offsetTop
, offsetTop
,
130 "OffsetTop Unchanged");
131 assert_false(didGetScrollEvent
,
132 "Should not get view scroll event");
134 'scrollTo down and right on a fully scrolled visual viewport ' +
135 'shouldn\'t change offsets',
140 requestAnimationFrame(continueTest
);
141 assert_false(didGetScrollEvent
,
142 "Should not get view scroll event");
145 'scrollTo without changing offsets shouldn\'t fire scroll event ' +
151 requestAnimationFrame(continueTest
);
153 window
.scrollTo(0, 0);
160 // How scrollTo behaves in this case isn't fully spec'd but
161 // make sure it's at least rational if it does change the
163 var scrollChangedOffset
=
164 offsetLeft
!= window
.visualViewport
.offsetLeft
||
165 offsetTop
!= window
.visualViewport
.offsetTop
;
167 document
.body
.style
.width
= "";
168 document
.body
.style
.height
= "";
170 assert_equals(didGetScrollEvent
, scrollChangedOffset
,
171 'If the scrollTo changed offsets it must have fired a ' +
174 'scrollTo must fire scroll event if it changes visualViewport.offsetLeft|Top',
175 '6. Pinch-zoom out fully');
178 function() { continueBtn
.remove(); },