|
2 | 2 | <html>
|
3 | 3 | <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
4 | 4 | <head>
|
| 5 | + <script src="../../../resources/ui-helper.js"></script> |
5 | 6 | <script src="../../../resources/js-test.js"></script>
|
6 | 7 | <style>
|
7 | 8 | body {
|
|
18 | 19 |
|
19 | 20 | div {
|
20 | 21 | background-image: linear-gradient(0deg, blue, red);
|
21 |
| - height: 4000px; |
| 22 | + height: 10000px; |
22 | 23 | }
|
23 | 24 | </style>
|
24 |
| - <script> |
25 |
| - jsTestIsAsync = true; |
26 |
| - |
27 |
| - function tapInInputScript(tapX, tapY) |
28 |
| - { |
29 |
| - return `(function() { |
30 |
| - uiController.didShowKeyboardCallback = function() { |
31 |
| - uiController.doAfterNextStablePresentationUpdate(function() { |
32 |
| - uiController.uiScriptComplete(JSON.stringify(uiController.textSelectionCaretRect)); |
33 |
| - }); |
34 |
| - }; |
35 |
| - uiController.singleTapAtPoint(${tapX}, ${tapY}, function() { }); |
36 |
| - })()`; |
37 |
| - } |
38 |
| - |
39 |
| - function simulateScrollingScript(distance) |
40 |
| - { |
41 |
| - return `(function() { |
42 |
| - uiController.stableStateOverride = false; |
43 |
| - uiController.immediateScrollToOffset(0, ${distance}); |
44 |
| - uiController.stableStateOverride = true; |
45 |
| - uiController.doAfterNextStablePresentationUpdate(function() { |
46 |
| - uiController.uiScriptComplete(JSON.stringify(uiController.textSelectionCaretRect)); |
47 |
| - }); |
48 |
| - })()`; |
49 |
| - } |
50 |
| - |
51 |
| - function toString(rect) |
52 |
| - { |
53 |
| - return `[${rect.left} ${rect.top} ; ${rect.width} ${rect.height}]`; |
54 |
| - } |
55 |
| - |
56 |
| - function run() |
57 |
| - { |
58 |
| - if (!window.testRunner || !testRunner.runUIScript) { |
59 |
| - description("To manually test, tap this input field and scroll up. The text caret should not end up outside of the input."); |
60 |
| - return; |
61 |
| - } |
62 |
| - |
63 |
| - testRunner.runUIScript(tapInInputScript(window.innerWidth / 2, 30), initialCaretRect => { |
64 |
| - initialCaretRect = JSON.parse(initialCaretRect); |
65 |
| - window.initialCaretRect = initialCaretRect; |
66 |
| - debug(`The initial caret rect is: ${toString(initialCaretRect)}`); |
67 |
| - testRunner.runUIScript(simulateScrollingScript(1000), finalCaretRect => { |
68 |
| - finalCaretRect = JSON.parse(finalCaretRect); |
69 |
| - window.finalCaretRect = finalCaretRect; |
70 |
| - debug(`The caret rect after scrolling 1000px down is: ${toString(finalCaretRect)}`); |
71 |
| - shouldBe("finalCaretRect.top", "initialCaretRect.top"); |
72 |
| - shouldBe("finalCaretRect.left", "initialCaretRect.left"); |
73 |
| - shouldBe("finalCaretRect.width", "initialCaretRect.width"); |
74 |
| - shouldBe("finalCaretRect.height", "initialCaretRect.height"); |
75 |
| - finishJSTest(); |
76 |
| - }); |
77 |
| - }); |
78 |
| - } |
79 |
| - </script> |
80 | 25 | </head>
|
81 |
| -<body onload=run()> |
82 |
| - <input></input> |
| 26 | +<body> |
| 27 | +<div> |
| 28 | +<input id="input"></input> |
| 29 | +</div> |
83 | 30 | </body>
|
| 31 | +<script> |
| 32 | +jsTestIsAsync = true; |
| 33 | + |
| 34 | +(() => { |
| 35 | + if (!window.testRunner || !testRunner.runUIScript) { |
| 36 | + description("To manually test, tap this input field and scroll up. The text caret should not end up outside of the input."); |
| 37 | + return; |
| 38 | + } |
84 | 39 |
|
| 40 | + UIHelper.activateAndWaitForInputSessionAt(innerWidth / 2, 30) |
| 41 | + .then(() => UIHelper.getUICaretRect()) |
| 42 | + .then((rect) => { |
| 43 | + initialCaretRect = rect; |
| 44 | + shouldBe("initialCaretRect.left", "6"); |
| 45 | + shouldBe("initialCaretRect.top", "21"); |
| 46 | + shouldBe("initialCaretRect.width", "3"); |
| 47 | + shouldBe("initialCaretRect.height", "15"); |
| 48 | + document.body.scrollTop += 5000; |
| 49 | + return UIHelper.getUICaretRect(); |
| 50 | + }) |
| 51 | + .then((rect) => { |
| 52 | + finalCaretRect = rect; |
| 53 | + shouldBe("finalCaretRect.left", "6"); |
| 54 | + shouldBe("finalCaretRect.top", "21"); |
| 55 | + shouldBe("finalCaretRect.width", "3"); |
| 56 | + shouldBe("finalCaretRect.height", "15"); |
| 57 | + finishJSTest(); |
| 58 | + }); |
| 59 | +})(); |
| 60 | +</script> |
85 | 61 | </html>
|
0 commit comments