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 @@