|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<meta name="viewport" content="width=device-width,initial-scale=1"> |
| 4 | +<script src="/resources/testharness.js"></script> |
| 5 | +<script src="/resources/testharnessreport.js"></script> |
| 6 | +<script src="/resources/testdriver.js"></script> |
| 7 | +<script src="/resources/testdriver-actions.js"></script> |
| 8 | +<script src="/resources/testdriver-vendor.js"></script> |
| 9 | +<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1943865"> |
| 10 | +<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1943053"> |
| 11 | +<link rel="help" href="https://drafts.csswg.org/cssom-view/#perform-a-scroll"> |
| 12 | +<style> |
| 13 | +body { |
| 14 | + margin: 0px; |
| 15 | + padding: 0px; |
| 16 | +} |
| 17 | +</style> |
| 18 | +<div id="anchor"></div> |
| 19 | +<div style="position: fixed; bottom: 0;"> |
| 20 | + <div style="position: absolute; bottom: 0;"> |
| 21 | + <input type="text" id="name" /> |
| 22 | + </div> |
| 23 | +</div> |
| 24 | +<script> |
| 25 | +promise_test(async t => { |
| 26 | + assert_equals(window.scrollY, 0); |
| 27 | + assert_equals(visualViewport.scale, 1.0); |
| 28 | + assert_equals(visualViewport.pageTop, 0); |
| 29 | + |
| 30 | + // Pinch zoom in this document. |
| 31 | + await new test_driver.Actions() |
| 32 | + .addPointer("finger1", "touch") |
| 33 | + .addPointer("finger2", "touch") |
| 34 | + .pointerMove(parseInt(window.innerWidth / 2), |
| 35 | + parseInt(window.innerHeight / 2), |
| 36 | + {origin: "viewport", sourceName: "finger1"}) |
| 37 | + .pointerMove(parseInt(window.innerWidth / 2), |
| 38 | + parseInt(window.innerHeight / 2), |
| 39 | + {origin: "viewport", sourceName: "finger2"}) |
| 40 | + .pointerDown({sourceName: "finger1"}) |
| 41 | + .pointerDown({sourceName: "finger2"}) |
| 42 | + .pointerMove(parseInt(window.innerWidth / 3), |
| 43 | + parseInt(window.innerHeight / 3), |
| 44 | + {origin: "viewport", sourceName: "finger1"}) |
| 45 | + .pointerMove(parseInt(window.innerWidth / 3 * 2), |
| 46 | + parseInt(window.innerHeight / 3 * 2), |
| 47 | + {origin: "viewport", sourceName: "finger2"}) |
| 48 | + .pointerUp({sourceName: "finger1"}) |
| 49 | + .pointerUp({sourceName: "finger2"}) |
| 50 | + .send(); |
| 51 | + |
| 52 | + assert_greater_than(visualViewport.scale, 1.0); |
| 53 | + |
| 54 | + // Suppose that the pinch zoom-in gesture at the center of the document did |
| 55 | + // move the visual viewport offset. |
| 56 | + assert_greater_than(visualViewport.pageTop, 0); |
| 57 | + |
| 58 | + // Move to zero offset of the visual viewport. |
| 59 | + let scrollPromise = |
| 60 | + new Promise(resolve => visualViewport.addEventListener("scroll", resolve)); |
| 61 | + document.querySelector('#anchor').scrollIntoView({ behavior: "instant" }); |
| 62 | + await scrollPromise; |
| 63 | + |
| 64 | + assert_equals(visualViewport.pageTop, 0); |
| 65 | + |
| 66 | + // Now trigger a scrollIntoView call to an element inside a position:fixed element. |
| 67 | + scrollPromise = |
| 68 | + new Promise(resolve => visualViewport.addEventListener("scroll", resolve)); |
| 69 | + document.querySelector('#name').scrollIntoView({ behavior: "instant" }); |
| 70 | + await scrollPromise; |
| 71 | + |
| 72 | + assert_greater_than(visualViewport.pageTop, 0); |
| 73 | +}, "Element.scrollIntoView scrolls visually"); |
| 74 | +</script> |
0 commit comments