browser_test_oopif_reconstruct.js (2596B)
1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* vim: set sts=2 sw=2 et tw=80: */ 3 /* This test is based on 4 https://searchfox.org/mozilla-central/rev/25d26b0a62cc5bb4aa3bb90a11f3b0b7c52859c4/gfx/layers/apz/test/mochitest/browser_test_position_sticky.js 5 */ 6 7 "use strict"; 8 9 requestLongerTimeout(2); 10 11 Services.scriptloader.loadSubScript( 12 "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js", 13 this 14 ); 15 16 Services.scriptloader.loadSubScript( 17 "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js", 18 this 19 ); 20 21 async function runOneTest(filename) { 22 function httpURL(sfilename) { 23 let chromeURL = getRootDirectory(gTestPath) + sfilename; 24 return chromeURL.replace( 25 "chrome://mochitests/content/", 26 "http://mochi.test:8888/" 27 ); 28 } 29 30 const url = httpURL(filename); 31 const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); 32 33 const { rect } = await SpecialPowers.spawn( 34 tab.linkedBrowser, 35 [], 36 async () => { 37 const container = content.document.getElementById("container"); 38 39 // Get the area in the screen coords where the position:sticky element is. 40 let containerRect = container.getBoundingClientRect(); 41 containerRect.x += content.window.mozInnerScreenX; 42 containerRect.y += content.window.mozInnerScreenY; 43 44 await content.wrappedJSObject.promiseApzFlushedRepaints(); 45 await content.wrappedJSObject.waitUntilApzStable(); 46 47 let w = {}, 48 h = {}; 49 SpecialPowers.DOMWindowUtils.getScrollbarSizes( 50 content.document.documentElement, 51 w, 52 h 53 ); 54 55 // Reduce the scrollbar width from the sticky area. 56 containerRect.width -= w.value; 57 return { 58 rect: containerRect, 59 }; 60 } 61 ); 62 63 const reference = await getSnapshot({ 64 x: rect.x, 65 y: rect.y, 66 width: rect.width, 67 height: rect.height, 68 }); 69 70 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 71 // start the toggling the position on a setInterval which triggers the bug 72 content.wrappedJSObject.doTest(); 73 }); 74 75 // have to try many times to capture the bug 76 for (let i = 0; i < 100; i++) { 77 let snapshot = await getSnapshot({ 78 x: rect.x, 79 y: rect.y, 80 width: rect.width, 81 height: rect.height, 82 }); 83 84 is(snapshot, reference, "should be same " + filename); 85 } 86 87 BrowserTestUtils.removeTab(tab); 88 } 89 90 add_task(async () => { 91 await runOneTest("helper_oopif_reconstruct.html"); 92 await runOneTest("helper_oopif_reconstruct_nested.html"); 93 });