browser_test_paint_skip_in_popup.js (3899B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 Services.scriptloader.loadSubScript( 7 "chrome://mochikit/content/tests/SimpleTest/paint_listener.js", 8 this 9 ); 10 11 Services.scriptloader.loadSubScript( 12 new URL("apz_test_utils.js", gTestPath).href, 13 this 14 ); 15 16 /* import-globals-from helper_browser_test_utils.js */ 17 // For openSelectPopup. 18 Services.scriptloader.loadSubScript( 19 new URL("helper_browser_test_utils.js", gTestPath).href, 20 this 21 ); 22 23 // Cleanup for paint_listener.js. 24 add_task(() => { 25 registerCleanupFunction(() => { 26 delete window.waitForAllPaintsFlushed; 27 delete window.waitForAllPaints; 28 delete window.promiseAllPaintsDone; 29 }); 30 }); 31 32 // Setup preferences. 33 add_task(async () => { 34 await SpecialPowers.pushPrefEnv({ 35 set: [ 36 ["apz.popups.enabled", true], 37 ["apz.popups_without_remote.enabled", true], 38 ["apz.test.logging_enabled", true], 39 ["layout.disable-pixel-alignment", true], 40 ], 41 }); 42 }); 43 44 add_task(async () => { 45 function httpURL(filename) { 46 let chromeURL = getRootDirectory(gTestPath) + filename; 47 return chromeURL.replace( 48 "chrome://mochitests/content/", 49 "http://mochi.test:8888/" 50 ); 51 } 52 const url = httpURL("helper_paint_skip_in_popup.html"); 53 const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); 54 55 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 56 await content.wrappedJSObject.promiseApzFlushedRepaints(); 57 await content.wrappedJSObject.waitUntilApzStable(); 58 }); 59 60 // Focus to the select element. This stuff is necessary for `openSelectPopup()` 61 // since the function is triggered on the focused element. 62 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 63 const select = content.document.querySelector("select"); 64 const focusPromise = new Promise(resolve => { 65 select.addEventListener("focus", resolve, { once: true }); 66 }); 67 select.focus(); 68 await focusPromise; 69 }); 70 71 // Open the select popup. 72 const selectPopup = await openSelectPopup(); 73 74 const arrowscrollbox = selectPopup.shadowRoot.querySelector("arrowscrollbox"); 75 ok(arrowscrollbox, "There's <arrowscrollbox> inside the popup"); 76 77 const scrollbox = arrowscrollbox.shadowRoot.querySelector("scrollbox"); 78 ok(scrollbox, "There's <scrollbox> inside the popup"); 79 80 // Scroll down as much as possible to get the max scroll offset. 81 scrollbox.scrollTo(0, 100000); 82 const scrollMax = scrollbox.scrollTop; 83 ok(scrollMax, "The max scroll offset should not be zero"); 84 85 // Restore the scroll offset. 86 // Note that this restoring needs to be done in the same paint where the above scrollTo happened so that 87 // APZ will never sample the max scroll offset at this moment. 88 scrollbox.scrollTo(0, 0); 89 await promiseApzFlushedRepaints(selectPopup); 90 91 // Now scroll to a position which is close to the bottom. 92 scrollbox.scrollBy(0, scrollMax - 10); 93 await promiseApzFlushedRepaints(selectPopup); 94 95 // Try to scroll to the bottom with a `scrollBy` call, even if paint-skip 96 // is enabled, this scroll operation should be reflected to APZ. 97 scrollbox.scrollBy(0, 10); 98 99 // Wait a bit to make sure that APZ has sampled the new scroll offset. 100 await promiseApzFlushedRepaints(selectPopup); 101 await promiseApzFlushedRepaints(selectPopup); 102 103 is( 104 scrollbox.scrollTop, 105 scrollMax, 106 `The scroll offset: ${scrollbox.scrollTop} on the main-thread should be ${scrollMax}` 107 ); 108 109 const sampledData = collectSampledScrollOffsets(scrollbox, selectPopup); 110 ok(sampledData.length, "There should be at least one collected offsets"); 111 ok( 112 sampledData.some( 113 data => SpecialPowers.wrap(data).scrollOffsetY - scrollMax < 1.0 114 ), 115 `There should be ${scrollMax} in [${sampledData.map(data => SpecialPowers.wrap(data).scrollOffsetY)}]` 116 ); 117 118 BrowserTestUtils.removeTab(tab); 119 });