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
|
<!DOCTYPE>
<html>
<head>
<title>Checking zoomToFocusedInput scrolls that focused non-input element is visible position</title>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
</head>
<body>
<div style="height: 8000px;">ABC</div>
<div id="content">
</div>
<!-- Leave additional room below the element so it can be scrolled to the center -->
<div style="height: 1000px;">ABC</div>
<script type="application/javascript">
async function test() {
let utils = SpecialPowers.getDOMWindowUtils(window);
// contenteditable
let div = document.createElement("div");
div.setAttribute("contenteditable", "true");
for (let i = 0; i < 200; i++) {
div.innerHTML += "foo<br>";
}
div.innerHTML += "<span id=last>bar</span>";
document.getElementById("content").appendChild(div);
let selection = window.getSelection();
selection.collapse(div.firstChild, 0);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
let transformEndPromise = promiseTransformEnd();
utils.zoomToFocusedInput();
await transformEndPromise;
await promiseApzFlushedRepaints();
ok(window.scrollY > 0, "scroll position isn't top");
let prevY = window.scrollY;
selection.collapse(document.getElementById("last").firstChild, 0);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
transformEndPromise = promiseTransformEnd();
utils.zoomToFocusedInput();
await promiseApzFlushedRepaints();
ok(prevY < window.scrollY, "scroll position is visibile position of caret");
await transformEndPromise;
document.getElementById("content").removeChild(div);
// <textarea> element
let textarea = document.createElement("textarea");
textarea.rows = 200;
for (let i = 0; i < 200; i++) {
textarea.value += "foo\n";
}
document.getElementById("content").appendChild(textarea);
textarea.focus();
await waitToClearOutAnyPotentialScrolls(window);
textarea.setSelectionRange(0, 0);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
transformEndPromise = promiseTransformEnd();
utils.zoomToFocusedInput();
await promiseApzFlushedRepaints();
ok(window.scrollY > 0, "scroll position isn't top");
prevY = window.scrollY;
await transformEndPromise;
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
transformEndPromise = promiseTransformEnd();
utils.zoomToFocusedInput();
await promiseApzFlushedRepaints();
ok(prevY < window.scrollY, "scroll position is visibile position of caret");
await transformEndPromise;
document.getElementById("content").removeChild(textarea);
}
waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</body>
</html>
|