Bug 1270955 - Add mochitests for scrolling while over position:fixed and sticky elements. r?botond
MozReview-Commit-ID: 2TrPgvKM0nm
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
@@ -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>
--- a/gfx/layers/apz/test/mochitest/mochitest.ini
+++ b/gfx/layers/apz/test/mochitest/mochitest.ini
@@ -8,16 +8,17 @@ support-files =
helper_iframe2.html
helper_subframe_style.css
helper_basic_pan.html
helper_div_pan.html
helper_iframe_pan.html
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]
[test_wheel_scroll.html]
skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel events not supported on mobile; see bug 1164274 for mulet
[test_wheel_transactions.html]
skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel events not supported on mobile; see bug 1164274 for mulet
[test_bug1151667.html]
@@ -34,8 +35,10 @@ skip-if = (os == 'android') || (os == 'b
skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel events not supported on mobile; see bug 1164274 for mulet
[test_scroll_subframe_scrollbar.html]
skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel events not supported on mobile; see bug 1164274 for mulet
[test_frame_reconstruction.html]
[test_tap.html]
# 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
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/test_scroll_window.html
@@ -0,0 +1,71 @@
+<!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': [
+ ['mousewheel.transaction.ignoremovedelay', 0],
+ ['general.smoothScroll', false],
+ ['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>