forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1270955 - Add mochitests for scrolling while over position:fixed …
…and sticky elements. r=botond MozReview-Commit-ID: curYWJlnOQ
- Loading branch information
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<head> | ||
<meta name="viewport" content="width=device-width; initial-scale=1.0"> | ||
<title>Wheel-scrolling over position:fixed and position:sticky elements, in the top-level document as well as iframes</title> | ||
<script type="application/javascript" src="apz_test_native_event_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"> | ||
|
||
var is = window.opener.is; | ||
var ok = window.opener.ok; | ||
|
||
// Scroll the mouse wheel at (dx, dy) relative to |element|. | ||
function scrollWheelOver(element, dx, dy) { | ||
// Move the mouse to the desired wheel location. | ||
// Not doing so can result in the wheel events from two consecutive | ||
// scrollWheelOver() calls on different elements being incorrectly considered | ||
// as part of the same wheel transaction. | ||
// We also wait for the mouse move event to be processed before sending the | ||
// wheel event, otherwise there is a chance they might get reordered, and | ||
// we have the transaction problem again. | ||
return synthesizeNativeMouseMoveAndWaitForMoveEvent(element, dx, dy, function() { | ||
synthesizeNativeWheelAndWaitForScrollEvent(element, dx, dy, 0, -10, driveTest); | ||
}); | ||
} | ||
|
||
function* runTest() { | ||
var iframeWin = document.getElementById('iframe').contentWindow; | ||
|
||
// scroll over the middle of the iframe's position:sticky element, check | ||
// that it scrolls the iframe | ||
var scrollPos = iframeWin.scrollY; | ||
yield scrollWheelOver(iframeWin.document.body, 50, 150); | ||
ok(iframeWin.scrollY > scrollPos, "iframe scrolled after wheeling over the position:sticky element"); | ||
|
||
// same, but using the iframe's position:fixed element | ||
scrollPos = iframeWin.scrollY; | ||
yield scrollWheelOver(iframeWin.document.body, 250, 150); | ||
ok(iframeWin.scrollY > scrollPos, "iframe scrolled after wheeling over the position:fixed element"); | ||
|
||
// same, but using the top-level window's position:sticky element | ||
scrollPos = window.scrollY; | ||
yield scrollWheelOver(document.body, 50, 150); | ||
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 | ||
scrollPos = window.scrollY; | ||
yield scrollWheelOver(document.body, 250, 150); | ||
ok(window.scrollY > scrollPos, "top-level document scrolled after wheeling over the position:fixed element"); | ||
} | ||
|
||
var gTestContinuation = null; | ||
function driveTest() { | ||
if (!gTestContinuation) { | ||
gTestContinuation = runTest(); | ||
} | ||
var ret = gTestContinuation.next(); | ||
if (ret.done) { | ||
window.opener.testDone(); | ||
} else { | ||
is(ret.value, true, "Test continuation chunk was successful"); | ||
} | ||
} | ||
|
||
window.onload = function() { | ||
waitForAllPaints(function() { | ||
flushApzRepaints(driveTest); | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body style="height:5000px; margin:0"> | ||
<div style="position:sticky; width: 100px; height: 300px; top: 0; background-color:red">sticky</div> | ||
<div style="position:fixed; width: 100px; height: 300px; top: 0; left: 200px; background-color: green">fixed</div> | ||
<iframe id='iframe' width="300" height="400" src="data:text/html,<body style='height:5000px; margin:0'><div style='position:sticky; width:100px; height:300px; top: 0; background-color:red'>sticky</div><div style='position:fixed; right:0; top: 0; width:100px; height:300px; background-color:green'>fixed</div>"></iframe> | ||
</body> | ||
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Various scrolling tests that spawn in a new window</title> | ||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> | ||
<script type="application/javascript"> | ||
|
||
SimpleTest.waitForExplicitFinish(); | ||
|
||
// this page just serially loads each one of the following test helper pages in | ||
// a new window and waits for it to call testDone() | ||
var tests = [ | ||
{'file': 'helper_scroll_on_position_fixed.html', 'prefs': [ | ||
// turn off smooth scrolling so that we don't have to wait for | ||
// APZ animations to finish before sampling the scroll offset | ||
['general.smoothScroll', false], | ||
// ensure that any mouse movement will trigger a new wheel transaction, | ||
// because in this test we move the mouse a bunch and want to recalculate | ||
// the target APZC after each such movement. | ||
['mousewheel.transaction.ignoremovedelay', 0], | ||
['mousewheel.transaction.timeout', 0]]} | ||
]; | ||
|
||
var testIndex = -1; | ||
var w = null; | ||
|
||
function testDone() { | ||
var test = tests[testIndex]; | ||
if (w) { | ||
if (!!test.prefs) { | ||
// We pushed some prefs for this test, pop them, and re-invoke | ||
// testDone() after that's been processed | ||
SpecialPowers.popPrefEnv(function() { | ||
w.close(); | ||
w = null; | ||
testDone(); | ||
}); | ||
return; | ||
} | ||
|
||
w.close(); | ||
} | ||
|
||
testIndex++; | ||
if (testIndex >= tests.length) { | ||
SimpleTest.finish(); | ||
return; | ||
} | ||
|
||
test = tests[testIndex]; | ||
if (!!test.prefs) { | ||
// Got some prefs for this subtest, push them | ||
SpecialPowers.pushPrefEnv({"set": test.prefs}, function() { | ||
w = window.open(test.file, "_blank"); | ||
}); | ||
} else { | ||
w = window.open(test.file, "_blank"); | ||
} | ||
} | ||
|
||
window.onload = function() { | ||
if (!SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled) { | ||
ok(true, "APZ is not enabled, this test is not relevant, sorry!\n"); | ||
SimpleTest.finish(); | ||
return; | ||
} | ||
testDone(); | ||
}; | ||
|
||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |