Bug 1273654 - Extract a helper function to run continuation-style tests. r=botond

MozReview-Commit-ID: 67WYQr1d7YO
This commit is contained in:
Kartikaya Gupta 2016-05-25 15:31:52 -04:00
Родитель 52b50801d8
Коммит 1dbcbb831c
8 изменённых файлов: 131 добавлений и 160 удалений

Просмотреть файл

@ -233,3 +233,37 @@ function isApzEnabled() {
} }
return enabled; return enabled;
} }
// Despite what this function name says, this does not *directly* run the
// provided continuation testFunction. Instead, it returns a function that
// can be used to run the continuation. The extra level of indirection allows
// it to be more easily added to a promise chain, like so:
// waitUntilApzStable().then(runContinuation(myTest));
//
// If you want to run the continuation directly, outside of a promise chain,
// you can invoke the return value of this function, like so:
// runContinuation(myTest)();
function runContinuation(testFunction) {
// We need to wrap this in an extra function, so that the call site can
// be more readable without running the promise too early. In other words,
// if we didn't have this extra function, the promise would start running
// during construction of the promise chain, concurrently with the first
// promise in the chain.
return function() {
return new Promise(function(resolve, reject) {
var testContinuation = null;
function driveTest() {
if (!testContinuation) {
testContinuation = testFunction(driveTest);
}
var ret = testContinuation.next();
if (ret.done) {
resolve();
}
}
driveTest();
});
};
}

Просмотреть файл

@ -4,7 +4,7 @@
<script type="application/javascript" src="apz_test_utils.js"></script> <script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script> <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript"> <script type="application/javascript">
function* runTest() { function* test(testDriver) {
var scroller = document.getElementById('scroller'); var scroller = document.getElementById('scroller');
var scrollerPos = scroller.scrollTop; var scrollerPos = scroller.scrollTop;
var dx = 100, dy = 50; var dx = 100, dy = 50;
@ -12,38 +12,29 @@ function* runTest() {
is(window.scrollY, 0, "Initial page scroll position should be 0"); is(window.scrollY, 0, "Initial page scroll position should be 0");
is(scrollerPos, 0, "Initial scroller position should be 0"); is(scrollerPos, 0, "Initial scroller position should be 0");
yield synthesizeNativeMouseMoveAndWaitForMoveEvent(scroller, dx, dy, driveTest); yield synthesizeNativeMouseMoveAndWaitForMoveEvent(scroller, dx, dy, testDriver);
yield synthesizeNativeWheelAndWaitForScrollEvent(scroller, dx, dy, 0, -10, driveTest); yield synthesizeNativeWheelAndWaitForScrollEvent(scroller, dx, dy, 0, -10, testDriver);
is(window.scrollY, 0, "Page scroll position should still be 0"); is(window.scrollY, 0, "Page scroll position should still be 0");
ok(scroller.scrollTop > scrollerPos, "Scroller should have scrolled"); ok(scroller.scrollTop > scrollerPos, "Scroller should have scrolled");
// wait for it to layerize fully and then try again // wait for it to layerize fully and then try again
yield waitForAllPaints(function() { yield waitForAllPaints(function() {
flushApzRepaints(driveTest); flushApzRepaints(testDriver);
}); });
scrollerPos = scroller.scrollTop; scrollerPos = scroller.scrollTop;
// The mouse is already at the right position. If we call scrollWheelOver it // The mouse is already at the right position. If we call scrollWheelOver it
// hangs on windows waiting for the mouse-move, so instead we just synthesize // hangs on windows waiting for the mouse-move, so instead we just synthesize
// the wheel directly. // the wheel directly.
yield synthesizeNativeWheelAndWaitForScrollEvent(scroller, dx, dy, 0, -10, driveTest); yield synthesizeNativeWheelAndWaitForScrollEvent(scroller, dx, dy, 0, -10, testDriver);
is(window.scrollY, 0, "Page scroll position should still be 0 after layerization"); is(window.scrollY, 0, "Page scroll position should still be 0 after layerization");
ok(scroller.scrollTop > scrollerPos, "Scroller should have continued scrolling"); ok(scroller.scrollTop > scrollerPos, "Scroller should have continued scrolling");
} }
var gTestContinuation = null; waitUntilApzStable()
function driveTest() { .then(runContinuation(test))
if (!gTestContinuation) { .then(subtestDone);
gTestContinuation = runTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
subtestDone();
}
}
waitUntilApzStable().then(driveTest);
</script> </script>
<style> <style>

Просмотреть файл

@ -9,15 +9,15 @@
<script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script> <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript"> <script type="application/javascript">
function* runTest() { function* test(testDriver) {
document.addEventListener('click', clicked, false); document.addEventListener('click', clicked, false);
// mouse down, move it around, and release it near where it went down. this // mouse down, move it around, and release it near where it went down. this
// should generate a click at the release point // should generate a click at the release point
yield synthesizeNativeMouseEvent(document.getElementById('b'), 5, 5, nativeMouseDownEventMsg(), driveTest); yield synthesizeNativeMouseEvent(document.getElementById('b'), 5, 5, nativeMouseDownEventMsg(), testDriver);
yield synthesizeNativeMouseEvent(document.getElementById('b'), 100, 100, nativeMouseMoveEventMsg(), driveTest); yield synthesizeNativeMouseEvent(document.getElementById('b'), 100, 100, nativeMouseMoveEventMsg(), testDriver);
yield synthesizeNativeMouseEvent(document.getElementById('b'), 10, 10, nativeMouseMoveEventMsg(), driveTest); yield synthesizeNativeMouseEvent(document.getElementById('b'), 10, 10, nativeMouseMoveEventMsg(), testDriver);
yield synthesizeNativeMouseEvent(document.getElementById('b'), 8, 8, nativeMouseUpEventMsg(), driveTest); yield synthesizeNativeMouseEvent(document.getElementById('b'), 8, 8, nativeMouseUpEventMsg(), testDriver);
dump("Finished synthesizing click with a drag in the middle\n"); dump("Finished synthesizing click with a drag in the middle\n");
} }
@ -30,16 +30,8 @@ function clicked(e) {
subtestDone(); subtestDone();
} }
var gTestContinuation = null; waitUntilApzStable()
.then(runContinuation(test));
function driveTest() {
if (!gTestContinuation) {
gTestContinuation = runTest();
}
gTestContinuation.next();
}
waitUntilApzStable().then(driveTest);
</script> </script>
</head> </head>

Просмотреть файл

@ -7,7 +7,7 @@
<script type="application/javascript"> <script type="application/javascript">
// Scroll the mouse wheel at (dx, dy) relative to |element|. // Scroll the mouse wheel at (dx, dy) relative to |element|.
function scrollWheelOver(element, dx, dy) { function scrollWheelOver(element, dx, dy, testDriver) {
// Move the mouse to the desired wheel location. // Move the mouse to the desired wheel location.
// Not doing so can result in the wheel events from two consecutive // Not doing so can result in the wheel events from two consecutive
// scrollWheelOver() calls on different elements being incorrectly considered // scrollWheelOver() calls on different elements being incorrectly considered
@ -16,63 +16,54 @@ function scrollWheelOver(element, dx, dy) {
// wheel event, otherwise there is a chance they might get reordered, and // wheel event, otherwise there is a chance they might get reordered, and
// we have the transaction problem again. // we have the transaction problem again.
return synthesizeNativeMouseMoveAndWaitForMoveEvent(element, dx, dy, function() { return synthesizeNativeMouseMoveAndWaitForMoveEvent(element, dx, dy, function() {
synthesizeNativeWheelAndWaitForScrollEvent(element, dx, dy, 0, -10, driveTest); synthesizeNativeWheelAndWaitForScrollEvent(element, dx, dy, 0, -10, testDriver);
}); });
} }
function* runTest() { function* test(testDriver) {
var iframeWin = document.getElementById('iframe').contentWindow; var iframeWin = document.getElementById('iframe').contentWindow;
// scroll over the middle of the iframe's position:sticky element, check // scroll over the middle of the iframe's position:sticky element, check
// that it scrolls the iframe // that it scrolls the iframe
var scrollPos = iframeWin.scrollY; var scrollPos = iframeWin.scrollY;
yield scrollWheelOver(iframeWin.document.body, 50, 150); yield scrollWheelOver(iframeWin.document.body, 50, 150, testDriver);
ok(iframeWin.scrollY > scrollPos, "iframe scrolled after wheeling over the position:sticky element"); ok(iframeWin.scrollY > scrollPos, "iframe scrolled after wheeling over the position:sticky element");
// same, but using the iframe's position:fixed element // same, but using the iframe's position:fixed element
scrollPos = iframeWin.scrollY; scrollPos = iframeWin.scrollY;
yield scrollWheelOver(iframeWin.document.body, 250, 150); yield scrollWheelOver(iframeWin.document.body, 250, 150, testDriver);
ok(iframeWin.scrollY > scrollPos, "iframe scrolled after wheeling over the position:fixed element"); ok(iframeWin.scrollY > scrollPos, "iframe scrolled after wheeling over the position:fixed element");
// same, but scrolling the scrollable frame *inside* the position:fixed item // same, but scrolling the scrollable frame *inside* the position:fixed item
var fpos = document.getElementById('fpos_scrollable'); var fpos = document.getElementById('fpos_scrollable');
scrollPos = fpos.scrollTop; scrollPos = fpos.scrollTop;
yield scrollWheelOver(fpos, 50, 150); yield scrollWheelOver(fpos, 50, 150, testDriver);
ok(fpos.scrollTop > scrollPos, "scrollable item inside fixed-pos element scrolled"); ok(fpos.scrollTop > scrollPos, "scrollable item inside fixed-pos element scrolled");
// wait for it to layerize fully and then try again // wait for it to layerize fully and then try again
yield waitForAllPaints(function() { yield waitForAllPaints(function() {
flushApzRepaints(driveTest); flushApzRepaints(testDriver);
}); });
scrollPos = fpos.scrollTop; scrollPos = fpos.scrollTop;
// The mouse is already at the right position. If we call scrollWheelOver it // The mouse is already at the right position. If we call scrollWheelOver it
// hangs on windows waiting for the mouse-move, so instead we just synthesize // hangs on windows waiting for the mouse-move, so instead we just synthesize
// the wheel directly. // the wheel directly.
yield synthesizeNativeWheelAndWaitForScrollEvent(fpos, 50, 150, 0, -10, driveTest); yield synthesizeNativeWheelAndWaitForScrollEvent(fpos, 50, 150, 0, -10, testDriver);
ok(fpos.scrollTop > scrollPos, "scrollable item inside fixed-pos element scrolled after layerization"); ok(fpos.scrollTop > scrollPos, "scrollable item inside fixed-pos element scrolled after layerization");
// same, but using the top-level window's position:sticky element // same, but using the top-level window's position:sticky element
scrollPos = window.scrollY; scrollPos = window.scrollY;
yield scrollWheelOver(document.body, 50, 150); yield scrollWheelOver(document.body, 50, 150, testDriver);
ok(window.scrollY > scrollPos, "top-level document scrolled after wheeling over the position:sticky element"); ok(window.scrollY > scrollPos, "top-level document scrolled after wheeling over the position:sticky element");
// same, but using the top-level window's position:fixed element // same, but using the top-level window's position:fixed element
scrollPos = window.scrollY; scrollPos = window.scrollY;
yield scrollWheelOver(document.body, 250, 150); yield scrollWheelOver(document.body, 250, 150, testDriver);
ok(window.scrollY > scrollPos, "top-level document scrolled after wheeling over the position:fixed element"); ok(window.scrollY > scrollPos, "top-level document scrolled after wheeling over the position:fixed element");
} }
var gTestContinuation = null; waitUntilApzStable()
function driveTest() { .then(runContinuation(test))
if (!gTestContinuation) { .then(subtestDone);
gTestContinuation = runTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
subtestDone();
}
}
waitUntilApzStable().then(driveTest);
</script> </script>
</head> </head>

Просмотреть файл

@ -154,10 +154,10 @@
<pre id="test"> <pre id="test">
<script type="application/javascript;version=1.7"> <script type="application/javascript;version=1.7">
function* runTest() { function* test(testDriver) {
var elm = document.getElementsByClassName('inner')[0]; var elm = document.getElementsByClassName('inner')[0];
elm.scrollTop = 0; elm.scrollTop = 0;
yield flushApzRepaints(driveTest); yield flushApzRepaints(testDriver);
// Take over control of the refresh driver and compositor // Take over control of the refresh driver and compositor
var utils = SpecialPowers.DOMWindowUtils; var utils = SpecialPowers.DOMWindowUtils;
@ -165,12 +165,12 @@ function* runTest() {
// Kick off an APZ smooth-scroll to 0,200 // Kick off an APZ smooth-scroll to 0,200
elm.scrollTo(0, 200); elm.scrollTo(0, 200);
yield waitForAllPaints(function() { setTimeout(driveTest, 0); }); yield waitForAllPaints(function() { setTimeout(testDriver, 0); });
// Let's do a couple of frames of the animation, and make sure it's going // Let's do a couple of frames of the animation, and make sure it's going
utils.advanceTimeAndRefresh(16); utils.advanceTimeAndRefresh(16);
utils.advanceTimeAndRefresh(16); utils.advanceTimeAndRefresh(16);
yield flushApzRepaints(driveTest); yield flushApzRepaints(testDriver);
ok(elm.scrollTop > 0, "APZ animation in progress", "scrollTop is now " + elm.scrollTop); ok(elm.scrollTop > 0, "APZ animation in progress", "scrollTop is now " + elm.scrollTop);
ok(elm.scrollTop < 200, "APZ animation not yet completed", "scrollTop is now " + elm.scrollTop); ok(elm.scrollTop < 200, "APZ animation not yet completed", "scrollTop is now " + elm.scrollTop);
@ -190,7 +190,7 @@ function* runTest() {
// and the frame reconstruction // and the frame reconstruction
utils.advanceTimeAndRefresh(16); utils.advanceTimeAndRefresh(16);
utils.advanceTimeAndRefresh(16); utils.advanceTimeAndRefresh(16);
yield flushApzRepaints(driveTest); yield flushApzRepaints(testDriver);
ok(elm.scrollTop < 200, "APZ animation not yet completed", "scrollTop is now " + elm.scrollTop); ok(elm.scrollTop < 200, "APZ animation not yet completed", "scrollTop is now " + elm.scrollTop);
ok(frameReconstructionTriggered > 0, "Frame reconstruction triggered", "reconstruction triggered " + frameReconstructionTriggered + " times"); ok(frameReconstructionTriggered > 0, "Frame reconstruction triggered", "reconstruction triggered " + frameReconstructionTriggered + " times");
@ -199,27 +199,18 @@ function* runTest() {
utils.advanceTimeAndRefresh(16); utils.advanceTimeAndRefresh(16);
} }
utils.restoreNormalRefresh(); utils.restoreNormalRefresh();
yield waitForAllPaints(function() { setTimeout(driveTest, 0); }); yield waitForAllPaints(function() { setTimeout(testDriver, 0); });
yield flushApzRepaints(driveTest); yield flushApzRepaints(testDriver);
is(elm.scrollTop, 200, "Element should have scrolled by 200px"); is(elm.scrollTop, 200, "Element should have scrolled by 200px");
} }
var gTestContinuation = null;
function driveTest() {
if (!gTestContinuation) {
gTestContinuation = runTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
}
}
if (isApzEnabled()) { if (isApzEnabled()) {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SimpleTest.expectAssertions(0, 1); // this test triggers an assertion, see bug 1247050 SimpleTest.expectAssertions(0, 1); // this test triggers an assertion, see bug 1247050
waitUntilApzStable().then(driveTest); waitUntilApzStable()
.then(runContinuation(test))
.then(SimpleTest.finish);
} }
</script> </script>

Просмотреть файл

@ -54,7 +54,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1173580
<script type="application/javascript;version=1.7"> <script type="application/javascript;version=1.7">
// Scroll the mouse wheel over |element|. // Scroll the mouse wheel over |element|.
function scrollWheelOver(element, waitForScroll = true) { function scrollWheelOver(element, waitForScroll, testDriver) {
var x = 10; var x = 10;
var y = 10; var y = 10;
// Move the mouse to the desired wheel location. // Move the mouse to the desired wheel location.
@ -66,14 +66,13 @@ function scrollWheelOver(element, waitForScroll = true) {
// we have the transaction problem again. // we have the transaction problem again.
synthesizeNativeMouseMoveAndWaitForMoveEvent(element, x, y, function() { synthesizeNativeMouseMoveAndWaitForMoveEvent(element, x, y, function() {
if (waitForScroll) { if (waitForScroll) {
synthesizeNativeWheelAndWaitForScrollEvent(element, x, y, 0, -10, driveTest); synthesizeNativeWheelAndWaitForScrollEvent(element, x, y, 0, -10, testDriver);
} else { } else {
synthesizeNativeWheelAndWaitForWheelEvent(element, x, y, 0, -10, driveTest); synthesizeNativeWheelAndWaitForWheelEvent(element, x, y, 0, -10, testDriver);
} }
}); });
} }
var gTestContinuation = null;
var utils; var utils;
const DISPLAYPORT_EXPIRY = 100; const DISPLAYPORT_EXPIRY = 100;
@ -97,15 +96,19 @@ function isLayerized(elementId) {
return false; return false;
} }
// Helper function to pass to waitForAllPaints rather than passing driveTest // This helper function produces another helper function, which, when invoked,
// directly. If there are no paints pending waitForAllPaints will invoke the // invokes the provided testDriver argument in a setTimeout 0. This is really
// callback synchronously, and if we did waitForAllPaints(driveTest) that might // just useful in cases when there are no paints pending, because then
// cause reentrancy into driveTest which is bad. // waitForAllPaints will invoke its callback synchronously. If we did
function callDriveTestAsync() { // waitForAllPaints(testDriver) that might cause reentrancy into the testDriver
setTimeout(driveTest, 0); // which is bad. This function works around that.
function asyncWrapper(testDriver) {
return function() {
setTimeout(testDriver, 0);
};
} }
function* runTest() { function* test(testDriver) {
utils = SpecialPowers.getDOMWindowUtils(window); utils = SpecialPowers.getDOMWindowUtils(window);
// Initially, nothing should be layerized. // Initially, nothing should be layerized.
@ -119,12 +122,12 @@ function* runTest() {
ok(!isLayerized('inner4'), "initially 'inner4' should not be layerized"); ok(!isLayerized('inner4'), "initially 'inner4' should not be layerized");
// Scrolling over outer1 should layerize outer1, but not inner1. // Scrolling over outer1 should layerize outer1, but not inner1.
yield scrollWheelOver(document.getElementById('outer1')); yield scrollWheelOver(document.getElementById('outer1'), true, testDriver);
ok(isLayerized('outer1'), "scrolling 'outer1' should cause it to be layerized"); ok(isLayerized('outer1'), "scrolling 'outer1' should cause it to be layerized");
ok(!isLayerized('inner1'), "scrolling 'outer1' should not cause 'inner1' to be layerized"); ok(!isLayerized('inner1'), "scrolling 'outer1' should not cause 'inner1' to be layerized");
// Scrolling over inner2 should layerize both outer2 and inner2. // Scrolling over inner2 should layerize both outer2 and inner2.
yield scrollWheelOver(document.getElementById('inner2')); yield scrollWheelOver(document.getElementById('inner2'), true, testDriver);
ok(isLayerized('inner2'), "scrolling 'inner2' should cause it to be layerized"); ok(isLayerized('inner2'), "scrolling 'inner2' should cause it to be layerized");
ok(isLayerized('outer2'), "scrolling 'inner2' should also cause 'outer2' to be layerized"); ok(isLayerized('outer2'), "scrolling 'inner2' should also cause 'outer2' to be layerized");
@ -132,18 +135,18 @@ function* runTest() {
// but with an iframe as the outer scrollable frame. // but with an iframe as the outer scrollable frame.
// Scrolling over outer3 should layerize outer3, but not inner3. // Scrolling over outer3 should layerize outer3, but not inner3.
yield scrollWheelOver(document.getElementById('outer3').contentDocument.documentElement); yield scrollWheelOver(document.getElementById('outer3').contentDocument.documentElement, true, testDriver);
ok(isLayerized('outer3'), "scrolling 'outer3' should cause it to be layerized"); ok(isLayerized('outer3'), "scrolling 'outer3' should cause it to be layerized");
ok(!isLayerized('inner3'), "scrolling 'outer3' should not cause 'inner3' to be layerized"); ok(!isLayerized('inner3'), "scrolling 'outer3' should not cause 'inner3' to be layerized");
// Scrolling over outer4 should layerize both outer4 and inner4. // Scrolling over outer4 should layerize both outer4 and inner4.
yield scrollWheelOver(document.getElementById('outer4').contentDocument.getElementById('inner4')); yield scrollWheelOver(document.getElementById('outer4').contentDocument.getElementById('inner4'), true, testDriver);
ok(isLayerized('inner4'), "scrolling 'inner4' should cause it to be layerized"); ok(isLayerized('inner4'), "scrolling 'inner4' should cause it to be layerized");
ok(isLayerized('outer4'), "scrolling 'inner4' should also cause 'outer4' to be layerized"); ok(isLayerized('outer4'), "scrolling 'inner4' should also cause 'outer4' to be layerized");
// Now we enable displayport expiry, and verify that things are still // Now we enable displayport expiry, and verify that things are still
// layerized as they were before. // layerized as they were before.
yield SpecialPowers.pushPrefEnv({"set": [["apz.displayport_expiry_ms", DISPLAYPORT_EXPIRY]]}, driveTest); yield SpecialPowers.pushPrefEnv({"set": [["apz.displayport_expiry_ms", DISPLAYPORT_EXPIRY]]}, testDriver);
ok(isLayerized('outer1'), "outer1 is still layerized after enabling expiry"); ok(isLayerized('outer1'), "outer1 is still layerized after enabling expiry");
ok(!isLayerized('inner1'), "inner1 is still not layerized after enabling expiry"); ok(!isLayerized('inner1'), "inner1 is still not layerized after enabling expiry");
ok(isLayerized('outer2'), "outer2 is still layerized after enabling expiry"); ok(isLayerized('outer2'), "outer2 is still layerized after enabling expiry");
@ -157,27 +160,27 @@ function* runTest() {
// the displayport expiry gets triggered. // the displayport expiry gets triggered.
// Expire displayport with scrolling on outer1 // Expire displayport with scrolling on outer1
yield scrollWheelOver(document.getElementById('outer1')); yield scrollWheelOver(document.getElementById('outer1'), true, testDriver);
yield waitForAllPaints(function() { yield waitForAllPaints(function() {
flushApzRepaints(driveTest); flushApzRepaints(testDriver);
}); });
yield setTimeout(driveTest, DISPLAYPORT_EXPIRY); yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
yield waitForAllPaints(callDriveTestAsync); yield waitForAllPaints(asyncWrapper(testDriver));
ok(!isLayerized('outer1'), "outer1 is no longer layerized after displayport expiry"); ok(!isLayerized('outer1'), "outer1 is no longer layerized after displayport expiry");
ok(!isLayerized('inner1'), "inner1 is still not layerized after displayport expiry"); ok(!isLayerized('inner1'), "inner1 is still not layerized after displayport expiry");
// Expire displayport with scrolling on inner2 // Expire displayport with scrolling on inner2
yield scrollWheelOver(document.getElementById('inner2')); yield scrollWheelOver(document.getElementById('inner2'), true, testDriver);
yield waitForAllPaints(function() { yield waitForAllPaints(function() {
flushApzRepaints(driveTest); flushApzRepaints(testDriver);
}); });
// Once the expiry elapses, it will trigger expiry on outer2, so we check // Once the expiry elapses, it will trigger expiry on outer2, so we check
// both, one at a time. // both, one at a time.
yield setTimeout(driveTest, DISPLAYPORT_EXPIRY); yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
yield waitForAllPaints(callDriveTestAsync); yield waitForAllPaints(asyncWrapper(testDriver));
ok(!isLayerized('inner2'), "inner2 is no longer layerized after displayport expiry"); ok(!isLayerized('inner2'), "inner2 is no longer layerized after displayport expiry");
yield setTimeout(driveTest, DISPLAYPORT_EXPIRY); yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
yield waitForAllPaints(callDriveTestAsync); yield waitForAllPaints(asyncWrapper(testDriver));
ok(!isLayerized('outer2'), "outer2 got de-layerized with inner2"); ok(!isLayerized('outer2'), "outer2 got de-layerized with inner2");
// Scroll on inner3. inner3 isn't layerized, and this will cause it to // Scroll on inner3. inner3 isn't layerized, and this will cause it to
@ -186,40 +189,30 @@ function* runTest() {
// Note that the displayport expiration might actually happen before the wheel // Note that the displayport expiration might actually happen before the wheel
// input is processed in the compositor (see bug 1246480 comment 3), and so // input is processed in the compositor (see bug 1246480 comment 3), and so
// we make sure not to wait for a scroll event here, since it may never fire. // we make sure not to wait for a scroll event here, since it may never fire.
yield scrollWheelOver(document.getElementById('outer3').contentDocument.getElementById('inner3'), false); yield scrollWheelOver(document.getElementById('outer3').contentDocument.getElementById('inner3'), false, testDriver);
yield waitForAllPaints(function() { yield waitForAllPaints(function() {
flushApzRepaints(driveTest); flushApzRepaints(testDriver);
}); });
yield setTimeout(driveTest, DISPLAYPORT_EXPIRY); yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
yield waitForAllPaints(callDriveTestAsync); yield waitForAllPaints(asyncWrapper(testDriver));
ok(!isLayerized('inner3'), "inner3 becomes unlayerized after expiry"); ok(!isLayerized('inner3'), "inner3 becomes unlayerized after expiry");
yield setTimeout(driveTest, DISPLAYPORT_EXPIRY); yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
yield waitForAllPaints(callDriveTestAsync); yield waitForAllPaints(asyncWrapper(testDriver));
ok(!isLayerized('outer3'), "outer3 is no longer layerized after inner3 triggered expiry"); ok(!isLayerized('outer3'), "outer3 is no longer layerized after inner3 triggered expiry");
// Scroll outer4 and wait for the expiry. It should NOT get expired because // Scroll outer4 and wait for the expiry. It should NOT get expired because
// inner4 is still layerized // inner4 is still layerized
yield scrollWheelOver(document.getElementById('outer4').contentDocument.documentElement); yield scrollWheelOver(document.getElementById('outer4').contentDocument.documentElement, true, testDriver);
yield waitForAllPaints(function() { yield waitForAllPaints(function() {
flushApzRepaints(driveTest); flushApzRepaints(testDriver);
}); });
// Wait for the expiry to elapse // Wait for the expiry to elapse
yield setTimeout(driveTest, DISPLAYPORT_EXPIRY); yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
yield waitForAllPaints(callDriveTestAsync); yield waitForAllPaints(asyncWrapper(testDriver));
ok(isLayerized('inner4'), "inner4 is still layerized because it never expired"); ok(isLayerized('inner4'), "inner4 is still layerized because it never expired");
ok(isLayerized('outer4'), "outer4 is still layerized because inner4 is still layerized"); ok(isLayerized('outer4'), "outer4 is still layerized because inner4 is still layerized");
} }
function driveTest() {
if (!gTestContinuation) {
gTestContinuation = runTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
}
}
if (isApzEnabled()) { if (isApzEnabled()) {
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("we are testing code that measures an actual timeout"); SimpleTest.requestFlakyTimeout("we are testing code that measures an actual timeout");
@ -234,7 +227,8 @@ if (isApzEnabled()) {
["apz.displayport_expiry_ms", 0], ["apz.displayport_expiry_ms", 0],
["apz.test.logging_enabled", true]]) ["apz.test.logging_enabled", true]])
.then(waitUntilApzStable) .then(waitUntilApzStable)
.then(driveTest); .then(runContinuation(test))
.then(SimpleTest.finish);
} }
</script> </script>

Просмотреть файл

@ -77,10 +77,10 @@ document.getElementById("scrollbox").addEventListener("wheel", function (e) {
e.preventDefault(); e.preventDefault();
}); });
function* runTest() { function* test(testDriver) {
var content = document.getElementById('content'); var content = document.getElementById('content');
for (i = 0; i < 300; i++) { // enough iterations that we would scroll to the bottom of 'content' for (i = 0; i < 300; i++) { // enough iterations that we would scroll to the bottom of 'content'
yield synthesizeNativeWheelAndWaitForWheelEvent(content, 100, 150, 0, -5, continueTest); yield synthesizeNativeWheelAndWaitForWheelEvent(content, 100, 150, 0, -5, testDriver);
} }
var scrollbox = document.getElementById('scrollbox'); var scrollbox = document.getElementById('scrollbox');
is(content.scrollTop > 0, true, "We should have scrolled down somewhat"); is(content.scrollTop > 0, true, "We should have scrolled down somewhat");
@ -88,19 +88,6 @@ function* runTest() {
is(rotationAdjusted, true, "The rotation should have been adjusted"); is(rotationAdjusted, true, "The rotation should have been adjusted");
} }
var gTestContinuation = null;
function continueTest() {
if (!gTestContinuation) {
gTestContinuation = runTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
} else {
is(ret.value, true, "Wheel event successfully synthesized");
}
}
SimpleTest.testInChaosMode(); SimpleTest.testInChaosMode();
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
@ -109,7 +96,8 @@ SimpleTest.waitForExplicitFinish();
// we might end up at the bottom of the page. // we might end up at the bottom of the page.
pushPrefs([["general.smoothScroll", false]]) pushPrefs([["general.smoothScroll", false]])
.then(waitUntilApzStable) .then(waitUntilApzStable)
.then(continueTest); .then(runContinuation(test))
.then(SimpleTest.finish);
</script> </script>
</pre> </pre>

Просмотреть файл

@ -41,11 +41,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1175585
<pre id="test"> <pre id="test">
<script type="application/javascript;version=1.7"> <script type="application/javascript;version=1.7">
function scrollWheelOver(element, deltaY) { function scrollWheelOver(element, deltaY, testDriver) {
synthesizeNativeWheelAndWaitForScrollEvent(element, 10, 10, 0, deltaY, driveTest); synthesizeNativeWheelAndWaitForScrollEvent(element, 10, 10, 0, deltaY, testDriver);
} }
function* runTest() { function* test(testDriver) {
var outer = document.getElementById('outer-frame'); var outer = document.getElementById('outer-frame');
var inner = document.getElementById('inner-frame'); var inner = document.getElementById('inner-frame');
var innerContent = document.getElementById('inner-content'); var innerContent = document.getElementById('inner-content');
@ -58,7 +58,7 @@ function* runTest() {
// Scroll |outer| to the bottom. // Scroll |outer| to the bottom.
while (outer.scrollTop < outer.scrollTopMax) { while (outer.scrollTop < outer.scrollTopMax) {
yield scrollWheelOver(outer, -10); yield scrollWheelOver(outer, -10, testDriver);
} }
// Verify that this has brought |inner| under the wheel. // Verify that this has brought |inner| under the wheel.
@ -66,7 +66,7 @@ function* runTest() {
window.removeEventListener("wheel", wheelTargetRecorder); window.removeEventListener("wheel", wheelTargetRecorder);
// Immediately after, scroll it back up a bit. // Immediately after, scroll it back up a bit.
yield scrollWheelOver(outer, 10); yield scrollWheelOver(outer, 10, testDriver);
// Check that it was |outer| that scrolled back, and |inner| didn't // Check that it was |outer| that scrolled back, and |inner| didn't
// scroll at all, as all the above scrolls should be in the same // scroll at all, as all the above scrolls should be in the same
@ -78,21 +78,21 @@ function* runTest() {
// Turn it down a bit so waiting for the timeout to elapse doesn't // Turn it down a bit so waiting for the timeout to elapse doesn't
// slow down the test harness too much. // slow down the test harness too much.
var timeout = 5; var timeout = 5;
yield SpecialPowers.pushPrefEnv({"set": [["mousewheel.transaction.timeout", timeout]]}, driveTest); yield SpecialPowers.pushPrefEnv({"set": [["mousewheel.transaction.timeout", timeout]]}, testDriver);
SimpleTest.requestFlakyTimeout("we are testing code that measures actual elapsed time between two events"); SimpleTest.requestFlakyTimeout("we are testing code that measures actual elapsed time between two events");
// Scroll up a bit more. It's still |outer| scrolling because // Scroll up a bit more. It's still |outer| scrolling because
// |inner| is still scrolled all the way to the top. // |inner| is still scrolled all the way to the top.
yield scrollWheelOver(outer, 10); yield scrollWheelOver(outer, 10, testDriver);
// Wait for the transaction timeout to elapse. // Wait for the transaction timeout to elapse.
// timeout * 5 is used to make it less likely that the timeout is less than // timeout * 5 is used to make it less likely that the timeout is less than
// the system timestamp resolution // the system timestamp resolution
yield window.setTimeout(driveTest, timeout * 5); yield window.setTimeout(testDriver, timeout * 5);
// Now scroll down. The transaction having timed out, the event // Now scroll down. The transaction having timed out, the event
// should pick up a new target, and that should be |inner|. // should pick up a new target, and that should be |inner|.
yield scrollWheelOver(outer, -10); yield scrollWheelOver(outer, -10, testDriver);
ok(inner.scrollTop > 0, "'inner' should have been scrolled"); ok(inner.scrollTop > 0, "'inner' should have been scrolled");
// Finally, test scroll handoff after a timeout. // Finally, test scroll handoff after a timeout.
@ -100,7 +100,7 @@ function* runTest() {
// Continue scrolling |inner| down to the bottom. // Continue scrolling |inner| down to the bottom.
var prevScrollTop = inner.scrollTop; var prevScrollTop = inner.scrollTop;
while (inner.scrollTop < inner.scrollTopMax) { while (inner.scrollTop < inner.scrollTopMax) {
yield scrollWheelOver(outer, -10); yield scrollWheelOver(outer, -10, testDriver);
// Avoid a failure getting us into an infinite loop. // Avoid a failure getting us into an infinite loop.
ok(inner.scrollTop > prevScrollTop, "scrolling down should increase scrollTop"); ok(inner.scrollTop > prevScrollTop, "scrolling down should increase scrollTop");
prevScrollTop = inner.scrollTop; prevScrollTop = inner.scrollTop;
@ -109,36 +109,26 @@ function* runTest() {
// Wait for the transaction timeout to elapse. // Wait for the transaction timeout to elapse.
// timeout * 5 is used to make it less likely that the timeout is less than // timeout * 5 is used to make it less likely that the timeout is less than
// the system timestamp resolution // the system timestamp resolution
yield window.setTimeout(driveTest, timeout * 5); yield window.setTimeout(testDriver, timeout * 5);
// Continued downward scrolling should scroll |outer| to the bottom. // Continued downward scrolling should scroll |outer| to the bottom.
prevScrollTop = outer.scrollTop; prevScrollTop = outer.scrollTop;
while (outer.scrollTop < outer.scrollTopMax) { while (outer.scrollTop < outer.scrollTopMax) {
yield scrollWheelOver(outer, -10); yield scrollWheelOver(outer, -10, testDriver);
// Avoid a failure getting us into an infinite loop. // Avoid a failure getting us into an infinite loop.
ok(outer.scrollTop > prevScrollTop, "scrolling down should increase scrollTop"); ok(outer.scrollTop > prevScrollTop, "scrolling down should increase scrollTop");
prevScrollTop = outer.scrollTop; prevScrollTop = outer.scrollTop;
} }
} }
var gTestContinuation = null;
function driveTest() {
if (!gTestContinuation) {
gTestContinuation = runTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
}
}
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
// Disable smooth scrolling because it makes the test flaky (we don't have a good // Disable smooth scrolling because it makes the test flaky (we don't have a good
// way of detecting when the scrolling is finished). // way of detecting when the scrolling is finished).
pushPrefs([["general.smoothScroll", false]]) pushPrefs([["general.smoothScroll", false]])
.then(waitUntilApzStable) .then(waitUntilApzStable)
.then(driveTest); .then(runContinuation(test))
.then(SimpleTest.finish);
</script> </script>
</pre> </pre>