browser_test_background_tab_scroll.js (2836B)
1 add_setup(async function () { 2 await SpecialPowers.pushPrefEnv({ 3 set: [["test.wait300msAfterTabSwitch", true]], 4 }); 5 }); 6 7 add_task(async function test_main() { 8 // Load page in the background. This will cause the first-paint of the 9 // tab (which has ScrollPositionUpdate instances) to get sent to the 10 // compositor, but the parent process RefLayer won't be pointing to this 11 // tab so APZ never sees the ScrollPositionUpdate instances. 12 13 let url = 14 "http://mochi.test:8888/browser/gfx/layers/apz/test/mochitest/helper_background_tab_scroll.html#scrolltarget"; 15 let backgroundTab = BrowserTestUtils.addTab(gBrowser, url); 16 let browser = backgroundTab.linkedBrowser; 17 await BrowserTestUtils.browserLoaded(browser, false, url); 18 dump("Done loading background tab\n"); 19 20 // Switch to the foreground, to let the APZ tree get built. 21 await BrowserTestUtils.switchTab(gBrowser, backgroundTab); 22 dump("Switched background tab to foreground\n"); 23 24 // Verify main-thread scroll position is where we expect 25 let scrollPos = await ContentTask.spawn(browser, null, function () { 26 return content.window.scrollY; 27 }); 28 is(scrollPos, 5000, "Expected background tab to be at scroll pos 5000"); 29 30 // Trigger an APZ-side scroll via native wheel event, followed by some code 31 // to ensure APZ's repaint requests to arrive at the main-thread. If 32 // things are working properly, the main thread will accept the repaint 33 // requests and update the main-thread scroll position. If the APZ side 34 // is sending incorrect scroll generations in the repaint request, then 35 // the main thread will fail to clear the main-thread scroll origin (which 36 // was set by the scroll to the #scrolltarget anchor), and so will not 37 // accept APZ's scroll position updates. 38 let contentScrollFunction = async function () { 39 await content.window.wrappedJSObject.promiseNativeWheelAndWaitForWheelEvent( 40 content.window, 41 100, 42 100, 43 0, 44 200 45 ); 46 47 // Advance some/all frames of the APZ wheel animation 48 let utils = content.window.SpecialPowers.getDOMWindowUtils(content.window); 49 for (var i = 0; i < 10; i++) { 50 utils.advanceTimeAndRefresh(16); 51 } 52 utils.restoreNormalRefresh(); 53 // Flush pending APZ repaints, then read the main-thread scroll 54 // position 55 await content.window.wrappedJSObject.promiseOnlyApzControllerFlushed( 56 content.window 57 ); 58 return content.window.scrollY; 59 }; 60 scrollPos = await ContentTask.spawn(browser, null, contentScrollFunction); 61 62 // Verify main-thread scroll position has changed 63 ok( 64 scrollPos < 5000, 65 `Expected background tab to have scrolled up, is at ${scrollPos}` 66 ); 67 68 // Cleanup 69 let tabClosed = BrowserTestUtils.waitForTabClosing(backgroundTab); 70 BrowserTestUtils.removeTab(backgroundTab); 71 await tabClosed; 72 });