Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../../resources/js-test.js"></script> | |
| 3 <style> | |
| 4 body { | |
| 5 height: 2000px; | |
| 6 width: 2000px; | |
| 7 } | |
| 8 </style> | |
| 9 | |
| 10 <script> | |
| 11 window.jsTestIsAsync = true; | |
| 12 var numCalls = 0; | |
| 13 | |
| 14 description("This test verifies that that visualviewportchanged event gets \ | |
| 15 fired when the visual viewport is scaled or scrolled."); | |
| 16 | |
| 17 function verifySetViewportOffsets() { | |
| 18 // Set viewport offset. Listener called twice. | |
| 19 document.visualViewport.scrollTop = 20; | |
| 20 requestAnimationFrame(function() { | |
| 21 shouldBe("numCalls", "3"); | |
| 22 document.visualViewport.scrollLeft = 0; | |
| 23 requestAnimationFrame(function() { | |
| 24 shouldBe("numCalls", "4"); | |
| 25 finishJSTest(); | |
| 26 }); | |
| 27 }); | |
| 28 } | |
| 29 | |
| 30 function runTest() { | |
| 31 if (!window.eventSender || !window.internals) { | |
| 32 finishJSTest(); | |
| 33 return; | |
| 34 } | |
| 35 // Turn off smooth scrolling. | |
| 36 internals.settings.setScrollAnimatorEnabled(false); | |
| 37 | |
| 38 document.addEventListener('visualviewportchanged', function(e) { | |
| 39 numCalls++; | |
| 40 }); | |
| 41 | |
| 42 // visualviewportchanged is non-bubbling. | |
| 43 document.documentElement.addEventListener('visualviewportchanged', funct ion(event) { | |
| 44 debug("visualviewportchanged erroneously called on document"); | |
| 45 }) | |
| 46 | |
| 47 // Scroll both viewports. Listner not called. | |
|
bokan
2016/03/22 18:30:29
Check this in a rAF too please. Right now it could
ymalik
2016/03/22 21:28:19
Spoke to you offline. Don't need rAFs
| |
| 48 eventSender.mouseMoveTo(100, 100); | |
| 49 eventSender.continuousMouseScrollBy(100, 100); | |
| 50 | |
| 51 // Scale and scroll visual viewport. Listener called twice. | |
| 52 internals.setPageScaleFactor(2); | |
| 53 requestAnimationFrame(function() { | |
| 54 shouldBe("numCalls", "1"); | |
| 55 internals.setVisualViewportOffset(10, 10); | |
| 56 requestAnimationFrame(function() { | |
| 57 shouldBe("numCalls", "2"); | |
| 58 verifySetViewportOffsets(); | |
| 59 }); | |
| 60 }); | |
| 61 } | |
| 62 </script> | |
| 63 | |
| 64 <body onload="runTest()"></body> | |
| OLD | NEW |