Add test to ensure that text-overflow: ellipsis text is scrollable
[WebKit-https.git] / LayoutTests / resources / ui-helper.js
1
2 window.UIHelper = class UIHelper {
3     static isIOS()
4     {
5         return navigator.userAgent.includes('iPhone') || navigator.userAgent.includes('iPad');
6     }
7
8     static isWebKit2()
9     {
10         return window.testRunner.isWebKit2;
11     }
12
13     static tapAt(x, y)
14     {
15         console.assert(this.isIOS());
16
17         if (!this.isWebKit2()) {
18             eventSender.addTouchPoint(x, y);
19             eventSender.touchStart();
20             eventSender.releaseTouchPoint(0);
21             eventSender.touchEnd();
22             return Promise.resolve();
23         }
24
25         return new Promise((resolve) => {
26             testRunner.runUIScript(`
27                 uiController.singleTapAtPoint(${x}, ${y}, function() {
28                     uiController.uiScriptComplete('Done');
29                 });`, resolve);
30         });
31     }
32
33     static activateAt(x, y)
34     {
35         if (!this.isWebKit2() || !this.isIOS()) {
36             eventSender.mouseMoveTo(x, y);
37             eventSender.mouseDown();
38             eventSender.mouseUp();
39             return Promise.resolve();
40         }
41
42         return new Promise((resolve) => {
43             testRunner.runUIScript(`
44                 uiController.singleTapAtPoint(${x}, ${y}, function() {
45                     uiController.uiScriptComplete('Done');
46                 });`, resolve);
47         });
48     }
49
50     static keyDown(key)
51     {
52         if (!this.isWebKit2() || !this.isIOS()) {
53             eventSender.keyDown(key);
54             return Promise.resolve();
55         }
56
57         return new Promise((resolve) => {
58             testRunner.runUIScript(`
59                 uiController.keyDownUsingHardwareKeyboard("downArrow", function() {
60                     uiController.uiScriptComplete("Done");
61                 });`, resolve);
62         });
63     }
64
65     static ensurePresentationUpdate()
66     {
67         if (!this.isWebKit2()) {
68             testRunner.display();
69             return Promise.resolve();
70         }
71
72         return new Promise(resolve => {
73             testRunner.runUIScript(`
74                 uiController.doAfterPresentationUpdate(function() {
75                     uiController.uiScriptComplete('Done');
76                 });`, resolve);
77         });
78     }
79
80     static activateAndWaitForInputSessionAt(x, y)
81     {
82         if (!this.isWebKit2() || !this.isIOS())
83             return this.activateAt(x, y);
84
85         return new Promise(resolve => {
86             testRunner.runUIScript(`
87                 (function() {
88                     uiController.didShowKeyboardCallback = function() {
89                         uiController.uiScriptComplete("Done");
90                     };
91                     uiController.singleTapAtPoint(${x}, ${y}, function() { });
92                 })()`, resolve);
93         });
94     }
95
96     static getUICaretRect()
97     {
98         if (!this.isWebKit2() || !this.isIOS())
99             return Promise.resolve();
100
101         return new Promise(resolve => {
102             testRunner.runUIScript(`(function() {
103                 uiController.doAfterNextStablePresentationUpdate(function() {
104                     uiController.uiScriptComplete(JSON.stringify(uiController.textSelectionCaretRect));
105                 });
106             })()`, jsonString => {
107                 resolve(JSON.parse(jsonString));
108             });
109         });
110     }
111
112     static getUISelectionRects()
113     {
114         if (!this.isWebKit2() || !this.isIOS())
115             return Promise.resolve();
116
117         return new Promise(resolve => {
118             testRunner.runUIScript(`(function() {
119                 uiController.doAfterNextStablePresentationUpdate(function() {
120                     uiController.uiScriptComplete(JSON.stringify(uiController.selectionRangeViewRects));
121                 });
122             })()`, jsonString => {
123                 resolve(JSON.parse(jsonString));
124             });
125         });
126     }
127
128     static replaceTextAtRange(text, location, length) {
129         return new Promise(resolve => {
130             testRunner.runUIScript(`(() => {
131                 uiController.replaceTextAtRange("${text}", ${location}, ${length});
132                 uiController.uiScriptComplete('Done');
133             })()`, resolve);
134         });
135     }
136
137     static wait(promise)
138     {
139         testRunner.waitUntilDone();
140         if (window.finishJSTest)
141             window.jsTestIsAsync = true;
142
143         let finish = () => {
144             if (window.finishJSTest)
145                 finishJSTest();
146             else
147                 testRunner.notifyDone();
148         }
149
150         return promise.then(finish, finish);
151     }
152 }