Skip to content

Commit

Permalink
Bug 1270955 - Add mochitests for scrolling while over position:fixed …
Browse files Browse the repository at this point in the history
…and sticky elements. r=botond

MozReview-Commit-ID: curYWJlnOQ
  • Loading branch information
staktrace committed May 11, 2016
1 parent 4e803a8 commit 6a45683
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
76 changes: 76 additions & 0 deletions gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
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>
3 changes: 3 additions & 0 deletions gfx/layers/apz/test/mochitest/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ support-files =
helper_scrollto_tap.html
helper_tap.html
helper_long_tap.html
helper_scroll_on_position_fixed.html
tags = apz
[test_bug982141.html]
[test_bug1151663.html]
Expand All @@ -39,3 +40,5 @@ skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel ev
# Windows touch injection doesn't work in automation, but this test can be run locally on a windows touch device.
# On OS X we don't support touch events at all.
skip-if = (toolkit == 'windows') || (toolkit == 'cocoa')
[test_scroll_window.html]
skip-if = (toolkit == 'android') # wheel events not supported on mobile
76 changes: 76 additions & 0 deletions gfx/layers/apz/test/mochitest/test_scroll_window.html
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>

0 comments on commit 6a45683

Please sign in to comment.