browser_scroll.js (3182B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * This test is checking that keyboard scrolling of content in RDM 8 * behaves correctly, both with and without touch simulation enabled. 9 */ 10 11 const PAINT_LISTENER_JS_URL = 12 URL_ROOT + "../../../../../../tests/SimpleTest/paint_listener.js"; 13 14 const APZ_TEST_UTILS_JS_URL = 15 URL_ROOT + "../../../../../gfx/layers/apz/test/mochitest/apz_test_utils.js"; 16 17 const TEST_URL = 18 "data:text/html;charset=utf-8," + 19 '<head><meta name="viewport" content="width=100, height=100"/>' + 20 '<script src="' + 21 PAINT_LISTENER_JS_URL + 22 '"></script>' + 23 '<script src="' + 24 APZ_TEST_UTILS_JS_URL + 25 '"></script>' + 26 "</head>" + 27 '<div style="background:blue; width:200px; height:200px"></div>'; 28 29 addRDMTask(TEST_URL, async function ({ ui, manager }) { 30 await setViewportSize(ui, manager, 50, 50); 31 const browser = ui.getViewportBrowser(); 32 33 for (const mv in [true, false]) { 34 await ui.updateTouchSimulation(mv); 35 36 info("Setting focus on the browser."); 37 browser.focus(); 38 39 await SpecialPowers.spawn(browser, [], async () => { 40 // First of all, cancel any async scroll animation if there is. If there's 41 // an on-going async scroll animation triggered by synthesizeKey, below 42 // scrollTo call scrolls to a position nearby (0, 0) so that this test 43 // won't work as expected. 44 await content.wrappedJSObject.cancelScrollAnimation( 45 content.document.scrollingElement, 46 content 47 ); 48 49 content.scrollTo(0, 0); 50 }); 51 52 info("Testing scroll behavior with touch simulation " + mv + "."); 53 await testScrollingOfContent(ui); 54 } 55 }); 56 57 async function testScrollingOfContent(ui) { 58 let scroll; 59 60 info("Checking initial scroll conditions."); 61 const viewportScroll = await getViewportScroll(ui); 62 is(viewportScroll.x, 0, "Content should load with scrollX 0."); 63 is(viewportScroll.y, 0, "Content should load with scrollY 0."); 64 65 /** 66 * Here we're going to send off some arrow key events to trigger scrolling. 67 * What we would like to be able to do is to await the scroll event and then 68 * check the scroll position to confirm the amount of scrolling that has 69 * happened. Unfortunately, APZ makes the scrolling happen asynchronously on 70 * the compositor thread, and it's very difficult to await the end state of 71 * the APZ animation -- see the tests in /gfx/layers/apz/test/mochitest for 72 * an example. For our purposes, it's sufficient to test that the scroll 73 * event is fired at all, and not worry about the amount of scrolling that 74 * has occurred at the time of the event. If the key events don't trigger 75 * scrolling, then no event will be fired and the test will time out. 76 */ 77 scroll = waitForViewportScroll(ui); 78 info("Synthesizing an arrow key down."); 79 EventUtils.synthesizeKey("KEY_ArrowDown"); 80 await scroll; 81 info("Scroll event was fired after arrow key down."); 82 83 scroll = waitForViewportScroll(ui); 84 info("Synthesizing an arrow key right."); 85 EventUtils.synthesizeKey("KEY_ArrowRight"); 86 await scroll; 87 info("Scroll event was fired after arrow key right."); 88 }