1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1383365
-->
<head>
<meta charset="utf-8">
<title>Async key scrolling test, helper page</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript">
// --------------------------------------------------------------------
// Async key scrolling test
//
// This test checks that a key scroll occurs asynchronously.
//
// The page contains a <div> that is large enough to make the page
// scrollable. We first synthesize a page down to scroll to the bottom
// of the page. Once we have reached the bottom of the page, we synthesize
// a page up to get us back to the top of the page.
//
// Once at the top, we request test data from APZ, rebuild the APZC tree
// structure, and use it to check that async key scrolling happened.
// --------------------------------------------------------------------
function runTests() {
// Sanity check
is(checkHasAsyncKeyScrolled(false), false, "expected no async key scrolling before test");
// Send a key to initiate a page scroll to take us to the bottom of the
// page. This scroll is done synchronously because APZ doesn't have
// current focus state at page load.
window.addEventListener("scroll", waitForScrollBottom);
window.synthesizeKey("KEY_End");
}
function waitForScrollBottom() {
if (window.scrollY < window.scrollMaxY) {
return;
}
SimpleTest.info("Reached final scroll position of sync KEY_End scroll");
window.removeEventListener("scroll", waitForScrollBottom);
// Spin the refresh driver a few times, so that the AsyncScroll instance
// that was running the main-thread scroll animation finishes up and
// triggers any repaints that it needs to.
var utils = SpecialPowers.DOMWindowUtils;
for (var i = 0; i < 10; i++) {
utils.advanceTimeAndRefresh(50);
}
utils.restoreNormalRefresh();
// Wait for the APZ to reach a stable state as well, before dispatching
// the next key input or the default action won't occur.
waitForApzFlushedRepaints(function() {
is(checkHasAsyncKeyScrolled(false), false, "expected no async key scrolling before KEY_Home dispatch");
// This scroll should be asynchronous now that the focus state is up to date.
window.addEventListener("scroll", waitForScrollTop);
window.synthesizeKey("KEY_Home");
});
}
function waitForScrollTop() {
if (window.scrollY > 0) {
return;
}
SimpleTest.info("Reached final scroll position of async KEY_Home scroll");
window.removeEventListener("scroll", waitForScrollTop);
// Wait for APZ to settle and then check that async scrolling happened.
waitForApzFlushedRepaints(function() {
is(checkHasAsyncKeyScrolled(true), true, "expected async key scrolling after test");
subtestDone();
});
}
function checkHasAsyncKeyScrolled(requirePaints) {
// Get the compositor-side test data from nsIDOMWindowUtils.
var utils = SpecialPowers.getDOMWindowUtils(window);
var compositorTestData = utils.getCompositorAPZTestData();
if (requirePaints) {
ok(compositorTestData.paints.length > 0,
"expected at least one paint in compositor test data");
}
// Get the sequence number of the last paint on the compositor side.
// We do this before converting the APZ test data because the conversion
// loses the order of the paints.
var lastPaint = compositorTestData.paints[compositorTestData.paints.length - 1];
var lastPaintSeqNo = lastPaint.sequenceNumber;
// Convert the test data into a representation that's easier to navigate.
compositorTestData = convertTestData(compositorTestData);
// Reconstruct the APZC tree structure in the last paint.
var apzcTree = buildApzcTree(compositorTestData.paints[lastPaintSeqNo]);
var rcd = findRcdNode(apzcTree);
if (rcd) {
return rcd.hasAsyncKeyScrolled === "1";
}
SimpleTest.info("Last paint rcd is null");
return false;
}
waitUntilApzStable().then(forceLayerTreeToCompositor).then(runTests);
</script>
</head>
<body style="height: 500px; overflow: scroll">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1383365">Async key scrolling test</a>
<!-- Put enough content into the page to make it have a nonzero scroll range -->
<div style="height: 5000px"></div>
</body>
</html>
|