blob: 0a8e101f45095a481a2132badba36c59a3605890 [file] [log] [blame]
mmaxfield@apple.comcb396c72017-01-06 01:04:34 +00001<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
2<html>
3<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
4<head>
5 <script src="../../../resources/js-test-pre.js"></script>
6 <style>
7 body {
8 margin: 0;
9 }
10
11 input {
12 width: 100%;
13 height: 50px;
14 position: absolute;
15 left: 0;
16 top: 0;
17 }
18
19 div {
20 background-image: linear-gradient(0deg, blue, red);
21 height: 4000px;
22 }
23 </style>
24 <script>
25 window.jsTestIsAsync = true;
26
27 function tapInInputScript(tapX, tapY)
28 {
29 return `
30 var caretPositions = [];
31
32 function pressArrow() {
33 uiController.typeCharacterUsingHardwareKeyboard("leftArrow", function() {
34 uiController.doAfterNextStablePresentationUpdate(function() {
35 var selectionRectLeft = uiController.textSelectionCaretRect.left;
36 var caretPositionsLength = caretPositions.length;
37 if (caretPositionsLength == 0 || caretPositions[caretPositionsLength - 1] != selectionRectLeft) {
38 caretPositions.push(selectionRectLeft);
39 pressArrow();
40 } else
41 uiController.uiScriptComplete(JSON.stringify(caretPositions));
42 });
43 });
44 };
45
46 (function() {
47 uiController.didShowKeyboardCallback = function() {
48 uiController.doAfterNextStablePresentationUpdate(function() {
49 pressArrow();
50 });
51 };
52 uiController.singleTapAtPoint(${tapX}, ${tapY}, function() { });
53 })()`;
54 }
55
56 var pixelWidth;
57 var currentWidth;
58 function run()
59 {
60 if (!window.testRunner || !testRunner.runUIScript) {
61 description("To manually test, place the caret in the field above and use the arrow keys to make sure the carets don't appear in the middle of characters.");
62 return;
63 }
64
65 testRunner.runUIScript(tapInInputScript(window.innerWidth * 2 / 3, 30), caretPositions => {
66 caretPositions = JSON.parse(caretPositions);
67 pixelWidth = -1;
68 for (var i = 0; i < caretPositions.length - 1; ++i) {
69 currentWidth = caretPositions[i] - caretPositions[i + 1];
70 if (pixelWidth == -1)
71 pixelWidth = currentWidth;
72 else
73 shouldBeCloseTo("currentWidth", pixelWidth, 1);
74 }
75 finishJSTest();
76 });
77 }
78 </script>
79</head>
80<body onload=run()>
81 <input value="&#x1f46b;&#x1f46b;&#x1f3fb;&#x1f46b;&#x1f3ff;&#x1f46c;&#x1f46c;&#x1f3fb;&#x1f46c;&#x1f3ff;&#x1f46d;&#x1f46d;&#x1f3fb;&#x1f46d;&#x1f3ff;&#x1f46a;&#x1f46a;&#x1f3fb;&#x1f46a;&#x1f3ff;"></input>
82 <script src="../../../resources/js-test-post.js"></script>
83</body>
84
85</html>