diff --git a/editor/libeditor/tests/mochitest.ini b/editor/libeditor/tests/mochitest.ini index fbb5aa82994c1..f3751ec2dd6da 100644 --- a/editor/libeditor/tests/mochitest.ini +++ b/editor/libeditor/tests/mochitest.ini @@ -23,6 +23,7 @@ support-files = file_select_all_without_body.html green.png spellcheck.js + !/gfx/layers/apz/test/mochitest/apz_test_utils.js [test_bug46555.html] [test_bug200416.html] diff --git a/editor/libeditor/tests/test_bug549262.html b/editor/libeditor/tests/test_bug549262.html index c7f2dacb0566e..faf79ee2040bb 100644 --- a/editor/libeditor/tests/test_bug549262.html +++ b/editor/libeditor/tests/test_bug549262.html @@ -8,6 +8,7 @@ + Mozilla Bug 549262 @@ -24,31 +25,56 @@ var win = window.open("file_bug549262.html", "_blank", "width=600,height=600,scrollbars=yes"); -// grab the timer right at the start -var cwu = SpecialPowers.getDOMWindowUtils(win); -function step() { - cwu.advanceTimeAndRefresh(100); +function waitForScrollEvent(aWindow) { + return new Promise(resolve => { + aWindow.addEventListener("scroll", () => { SimpleTest.executeSoon(resolve); }, {once: true, capture: true}); + }); } + +function waitAndCheckNoScrollEvent(aWindow) { + let gotScroll = false; + function recordScroll() { + gotScroll = true; + } + aWindow.addEventListener("scroll", recordScroll, {capture: true}); + return new Promise(resolve => {aWindow.requestAnimationFrame(() => { aWindow.requestAnimationFrame( + () => { flushApzRepaints( + function() { + aWindow.removeEventListener("scroll", recordScroll, {capture: true}); + is(gotScroll, false, "check that we didn't get a scroll"); + resolve(); + }, aWindow + ); } + ); }); }); +} + +function waitToClearOutAnyPotentialScrolls(aWindow) { + return new Promise(resolve => {aWindow.requestAnimationFrame(() => { aWindow.requestAnimationFrame(() => { flushApzRepaints(resolve, aWindow); }); }); }); +} + SimpleTest.waitForFocus(function() { SpecialPowers.pushPrefEnv({"set": [[smoothScrollPref, false]]}, startTest); }, win); -function startTest() { +async function startTest() { // Make sure that pressing Space when a contenteditable element is not focused // will scroll the page. var ed = win.document.getElementById("editor"); var sc = win.document.querySelector("a"); sc.focus(); + await waitToClearOutAnyPotentialScrolls(win); is(win.scrollY, 0, "Sanity check"); + let waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForScrolling; isnot(win.scrollY, 0, "Page is scrolled down"); is(ed.textContent, "abc", "The content of the editable element has not changed"); var oldY = win.scrollY; + waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {shiftKey: true}, win); - step(); + await waitForScrolling; ok(win.scrollY < oldY, "Page is scrolled up"); is(ed.textContent, "abc", "The content of the editable element has not changed"); @@ -57,25 +83,31 @@ // will not scroll the page, and will edit the element. ed.focus(); win.getSelection().collapse(ed.firstChild, 1); + await waitToClearOutAnyPotentialScrolls(win); oldY = win.scrollY; + let waitForNoScroll = waitAndCheckNoScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForNoScroll; ok(win.scrollY <= oldY, "Page is not scrolled down"); is(ed.textContent, "a bc", "The content of the editable element has changed"); sc.focus(); + await waitToClearOutAnyPotentialScrolls(win); + waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForScrolling; isnot(win.scrollY, 0, "Page is scrolled down"); is(ed.textContent, "a bc", "The content of the editable element has not changed"); ed.focus(); win.getSelection().collapse(ed.firstChild, 3); + await waitToClearOutAnyPotentialScrolls(win); + waitForNoScroll = waitAndCheckNoScrollEvent(win); synthesizeKey(" ", {shiftKey: true}, win); - step(); + await waitForNoScroll; isnot(win.scrollY, 0, "Page is not scrolled up"); is(ed.textContent, "a b c", "The content of the editable element has changed"); @@ -83,45 +115,50 @@ // Now let's test the down/up keys sc = document.body; - step(); - ed.blur(); sc.focus(); + await waitToClearOutAnyPotentialScrolls(win); oldY = win.scrollY; + waitForScrolling = waitForScrollEvent(win); synthesizeKey("VK_UP", {}, win); - step(); + await waitForScrolling; ok(win.scrollY < oldY, "Page is scrolled up"); oldY = win.scrollY; ed.focus(); win.getSelection().collapse(ed.firstChild, 3); + await waitToClearOutAnyPotentialScrolls(win); + waitForNoScroll = waitAndCheckNoScrollEvent(win); synthesizeKey("VK_UP", {}, win); - step(); + await waitForNoScroll; is(win.scrollY, oldY, "Page is not scrolled up"); is(win.getSelection().focusNode, ed.firstChild, "Correct element selected"); is(win.getSelection().focusOffset, 0, "Selection should be moved to the beginning"); win.getSelection().removeAllRanges(); + await waitToClearOutAnyPotentialScrolls(win); + waitForScrolling = waitForScrollEvent(win); synthesizeMouse(sc, 300, 300, {}, win); synthesizeKey("VK_DOWN", {}, win); - step(); + await waitForScrolling; ok(win.scrollY > oldY, "Page is scrolled down"); ed.focus(); win.getSelection().collapse(ed.firstChild, 3); + await waitToClearOutAnyPotentialScrolls(win); oldY = win.scrollY; + waitForNoScroll = waitAndCheckNoScrollEvent(win); synthesizeKey("VK_DOWN", {}, win); - step(); + await waitForNoScroll; is(win.scrollY, oldY, "Page is not scrolled down"); is(win.getSelection().focusNode, ed.firstChild, "Correct element selected"); is(win.getSelection().focusOffset, ed.textContent.length, "Selection should be moved to the end"); - cwu.restoreNormalRefresh(); win.close(); SimpleTest.finish(); diff --git a/editor/libeditor/tests/test_bug915962.html b/editor/libeditor/tests/test_bug915962.html index 59281b6392395..eae46beb03ba0 100644 --- a/editor/libeditor/tests/test_bug915962.html +++ b/editor/libeditor/tests/test_bug915962.html @@ -8,6 +8,7 @@ + Mozilla Bug 915962 @@ -24,71 +25,99 @@ var win = window.open("file_bug915962.html", "_blank", "width=600,height=600,scrollbars=yes"); -// grab the timer right at the start -var cwu = SpecialPowers.getDOMWindowUtils(win); -function step() { - cwu.advanceTimeAndRefresh(100); + +function waitForScrollEvent(aWindow) { + return new Promise(resolve => { + aWindow.addEventListener("scroll", () => { SimpleTest.executeSoon(resolve); }, {once: true, capture: true}); + }); +} + +function waitAndCheckNoScrollEvent(aWindow) { + let gotScroll = false; + function recordScroll() { + gotScroll = true; + } + aWindow.addEventListener("scroll", recordScroll, {capture: true}); + return new Promise(resolve => {aWindow.requestAnimationFrame(() => { aWindow.requestAnimationFrame( + () => { flushApzRepaints( + function() { + aWindow.removeEventListener("scroll", recordScroll, {capture: true}); + is(gotScroll, false, "check that we didn't get a scroll"); + resolve(); + }, aWindow + ); } + ); }); }); } + +function waitToClearOutAnyPotentialScrolls(aWindow) { + return new Promise(resolve => {aWindow.requestAnimationFrame(() => { aWindow.requestAnimationFrame(() => { flushApzRepaints(resolve, aWindow); }); }); }); +} + SimpleTest.waitForFocus(function() { SpecialPowers.pushPrefEnv({"set": [[smoothScrollPref, false]]}, startTest); }, win); -function startTest() { +async function startTest() { // Make sure that pressing Space when a tabindex=-1 element is focused // will scroll the page. var button = win.document.querySelector("button"); var sc = win.document.querySelector("div"); sc.focus(); + await waitToClearOutAnyPotentialScrolls(win); is(win.scrollY, 0, "Sanity check"); + let waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForScrolling; isnot(win.scrollY, 0, "Page is scrolled down"); var oldY = win.scrollY; + waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {shiftKey: true}, win); - step(); + await waitForScrolling; ok(win.scrollY < oldY, "Page is scrolled up"); // Make sure that pressing Space when a tabindex=-1 element is focused // will not scroll the page, and will activate the element. button.focus(); + await waitToClearOutAnyPotentialScrolls(win); var clicked = false; button.onclick = () => clicked = true; oldY = win.scrollY; + let waitForNoScroll = waitAndCheckNoScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForNoScroll; ok(win.scrollY <= oldY, "Page is not scrolled down"); ok(clicked, "The button should be clicked"); synthesizeKey("VK_TAB", {}, win); - step(); + await waitToClearOutAnyPotentialScrolls(win); oldY = win.scrollY; + waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForScrolling; ok(win.scrollY >= oldY, "Page is scrolled down"); - cwu.restoreNormalRefresh(); win.close(); win = window.open("file_bug915962.html", "_blank", "width=600,height=600,scrollbars=yes"); - cwu = SpecialPowers.getDOMWindowUtils(win); - SimpleTest.waitForFocus(function() { + + SimpleTest.waitForFocus(async function() { is(win.scrollY, 0, "Sanity check"); + waitForScrolling = waitForScrollEvent(win); synthesizeKey(" ", {}, win); - step(); + await waitForScrolling; isnot(win.scrollY, 0, "Page is scrolled down without crashing"); - cwu.restoreNormalRefresh(); win.close(); SimpleTest.finish(); diff --git a/editor/libeditor/tests/test_selection_move_commands.html b/editor/libeditor/tests/test_selection_move_commands.html index b0207da0cfa28..b5c0fdb63c658 100644 --- a/editor/libeditor/tests/test_selection_move_commands.html +++ b/editor/libeditor/tests/test_selection_move_commands.html @@ -2,19 +2,16 @@ Test for nsSelectionMoveCommands + Mozilla Bug 454004 diff --git a/layout/base/tests/mochitest.ini b/layout/base/tests/mochitest.ini index 21cc65b11a584..b170c0f26c146 100644 --- a/layout/base/tests/mochitest.ini +++ b/layout/base/tests/mochitest.ini @@ -7,6 +7,7 @@ support-files = file_bug842853.sjs selection-utils.js ../../../dom/plugins/test/mochitest/plugin-utils.js + !/gfx/layers/apz/test/mochitest/apz_test_utils.js [test_after_paint_pref.html] skip-if = (os == 'win' && asan) # Bug 1459682 diff --git a/layout/base/tests/test_bug1120705.html b/layout/base/tests/test_bug1120705.html index 23b949bb17081..381f3c3b8f7e0 100644 --- a/layout/base/tests/test_bug1120705.html +++ b/layout/base/tests/test_bug1120705.html @@ -4,6 +4,7 @@ Test for Bug 1120705 + @@ -50,6 +51,16 @@ { type: "mouseup" }); } +function waitToClearOutAnyPotentialScrolls(aWindow) { + return new Promise(resolve => {aWindow.requestAnimationFrame(() => { aWindow.requestAnimationFrame(() => { flushApzRepaints(resolve, aWindow); }); }); }); +} + +function waitForScrollEvent(aWindow) { + return new Promise(resolve => { + aWindow.addEventListener("scroll", () => { SimpleTest.executeSoon(resolve); }, {once: true, capture: true}); + }); +} + SimpleTest.waitForExplicitFinish(); @@ -57,24 +68,30 @@ SpecialPowers.pushPrefEnv({ "set": [["general.smoothScroll", false], ["toolkit.scrollbox.verticalScrollDistance", 3]]}, - function() { + async function() { var sel = document.getElementById("sel"); sel.size = 2; sel.scrollTo(0, 0); + await waitToClearOutAnyPotentialScrolls(window); + is(sel.scrollTop, 0, "sanity check that we start scrolling from 0"); + let waitForScrolling = waitForScrollEvent(window); + clickDownButton(); + await waitForScrolling; + var restricted_top = sel.scrollTop; + isnot(restricted_top, 0, + "Expected to scroll when clicking scrollbar button"); + sel.size = 10; + sel.scrollTo(0, 0); + await waitToClearOutAnyPotentialScrolls(window); + is(sel.scrollTop, 0, "sanity check that we start scrolling from 0"); + waitForScrolling = waitForScrollEvent(window); clickDownButton(); - window.requestAnimationFrame(function() { - var restricted_top = sel.scrollTop; - isnot(restricted_top, 0, - "Expected to scroll when clicking scrollbar button"); - sel.size = 10; - sel.scrollTo(0, 0); - clickDownButton(); - window.requestAnimationFrame(function() { - isnot(sel.scrollTop, restricted_top, - "Scrollbar button scrolling should be limited by page size"); - SimpleTest.finish(); - }); - }); + await waitForScrolling; + isnot(sel.scrollTop, 0, + "Expected to scroll when clicking scrollbar button"); + isnot(sel.scrollTop, restricted_top, + "Scrollbar button scrolling should be limited by page size"); + SimpleTest.finish(); }); }); diff --git a/layout/base/tests/test_scroll_per_page.html b/layout/base/tests/test_scroll_per_page.html index 49a42cf244061..02a8362d05c58 100644 --- a/layout/base/tests/test_scroll_per_page.html +++ b/layout/base/tests/test_scroll_per_page.html @@ -4,6 +4,7 @@ Test for scroll per page + @@ -61,6 +62,10 @@ }); } + function waitToClearOutAnyPotentialScrolls() { + return new Promise(resolve => {aWindow.requestAnimationFrame(() => { aWindow.requestAnimationFrame(() => { flushApzRepaints(resolve, aWindow); }); }); }); + } + async function doPageDown() { let waitForScrolling = waitForScrollEvent(); if (kUseKeyboardEvent) { @@ -97,6 +102,7 @@ container = doc.documentElement; let editor = doc.getElementById("editor"); editor.focus(); + await waitToClearOutAnyPotentialScrolls(); let description = "PageDown in non-scrollable editing host: "; let previousScrollTop = container.scrollTop; @@ -135,6 +141,7 @@ editor = doc.getElementById("editor"); container = editor; editor.focus(); + await waitToClearOutAnyPotentialScrolls(); description = "PageDown in scrollable editing host: "; previousScrollTop = container.scrollTop; @@ -165,6 +172,7 @@ editor = doc.getElementById("editor"); container = doc.documentElement; editor.focus(); + await waitToClearOutAnyPotentialScrolls(); description = "PageDown in too large editing host: "; previousScrollTop = container.scrollTop; @@ -176,6 +184,8 @@ selection.selectAllChildren(editor); selection.collapseToEnd(); + await waitToClearOutAnyPotentialScrolls(); + description = "PageUp in too large editing host: "; container.scrollTop = container.scrollHeight; previousScrollTop = container.scrollTop; @@ -188,6 +198,7 @@ editor = doc.getElementById("editor"); container = editor; editor.focus(); + await waitToClearOutAnyPotentialScrolls(); description = "PageDown in scrollable editing host"; previousScrollTop = container.scrollTop; @@ -214,6 +225,7 @@ container = doc.documentElement; editor.focus(); selection.collapse(editor.firstChild); + await waitToClearOutAnyPotentialScrolls(); description = "PageDown in too high non-scrollable editing host"; previousScrollTop = container.scrollTop; diff --git a/layout/generic/test/page_scroll_with_fixed_pos_window.html b/layout/generic/test/page_scroll_with_fixed_pos_window.html index 8647e7252dea9..9c2b6586c4f49 100644 --- a/layout/generic/test/page_scroll_with_fixed_pos_window.html +++ b/layout/generic/test/page_scroll_with_fixed_pos_window.html @@ -27,6 +27,7 @@ for (var i = 0; i < elements.length; ++i) { elements[i].style.display = show ? '' : 'none'; } + document.documentElement.getBoundingClientRect(); } function showFixedPosElements(show) { showElements(show, "fp"); @@ -44,8 +45,18 @@ } } +function resetScrollAndScrollDownOnePageWithContinuation(cont) { + if (document.documentElement.scrollTop != 0) { + document.documentElement.scrollTop = 0; + nextCont = function() { + setTimeout(function() { scrollDownOnePageWithContinuation(cont) }, 0); + }; + } else { + scrollDownOnePageWithContinuation(cont); + } +} + function scrollDownOnePageWithContinuation(cont) { - document.documentElement.scrollTop = 0; nextCont = cont; window.scrollByPages(1); } @@ -58,42 +69,42 @@ function runTest() { showFixedPosElements(false); showFixedPosElements2(false); - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { var fullPageScrollDown = document.documentElement.scrollTop; showFixedPosElements(true); - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { var fullPageScrollDownWithHeaderAndFooter = document.documentElement.scrollTop; is(fullPageScrollDownWithHeaderAndFooter, fullPageScrollDown - (10 + 13), "Reduce scroll distance by size of small header and footer"); document.getElementById("bottom").style.height = (window.innerHeight - 20) + "px"; - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { is(document.documentElement.scrollTop, fullPageScrollDown - 10, "Ignore really big elements when reducing scroll size"); document.getElementById("bottom").style.height = "13px"; document.getElementById("top").style.width = "100px"; - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { is(document.documentElement.scrollTop, fullPageScrollDown - 13, "Ignore elements that don't span the entire viewport side"); document.getElementById("top").style.width = "100%"; showFixedPosElements2(true); - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { is(document.documentElement.scrollTop, fullPageScrollDown - (10 + 11 + 9 + 12), "Combine multiple overlapping elements"); showFixedPosElements2(false); document.getElementById("top").style.width = "400px"; - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { is(document.documentElement.scrollTop, fullPageScrollDown - (10 + 13), "Don't ignore elements that span more than half the viewport side"); document.getElementById("top").style.width = "100%"; document.getElementById("top").style.top = "-40px"; document.getElementById("top").style.transform = "translateY(38px)"; - scrollDownOnePageWithContinuation(function() { + resetScrollAndScrollDownOnePageWithContinuation(function() { is(document.documentElement.scrollTop, fullPageScrollDown - (10 + 13 - 40 + 38), "Account for offset and transform"); diff --git a/layout/generic/test/test_bug633762.html b/layout/generic/test/test_bug633762.html index 17525ea429f51..79ed0b97cbcc3 100644 --- a/layout/generic/test/test_bug633762.html +++ b/layout/generic/test/test_bug633762.html @@ -7,6 +7,7 @@ Test for Bug 633762 + @@ -20,7 +21,7 @@ var doc; -function runTests() { +async function runTests() { var i = document.getElementById("i"); doc = i.contentDocument; var win = i.contentWindow; @@ -30,12 +31,22 @@ doc.documentElement.offsetLeft; // focus on the iframe win.focus(); + + // clear out any potential scroll events so we can listen for the one we want without false positives + await new Promise(resolve => {window.requestAnimationFrame(() => { window.requestAnimationFrame(() => { flushApzRepaints(resolve, window); }); }); }); + step2(); +} + +function step2() { + var i = document.getElementById("i"); + doc = i.contentDocument; + var win = i.contentWindow; // record scrolltop scrollTopBefore = doc.body.scrollTop; // send up arrow key event sendKey("UP"); - window.requestAnimationFrame(finish); + win.addEventListener("scroll", finish, {once: true, capture: true}); } function finish() {