3c19ad24f6e687652296e90464d612dfca9adffe
[WebKit-https.git] / LayoutTests / resources / basic-gestures.js
1 function didShowKeyboard()
2 {
3     return new Promise(resolve => {
4         testRunner.runUIScript(`
5             (function() {
6                 uiController.didShowKeyboardCallback = function() {
7                     uiController.uiScriptComplete();
8                 }
9             })();`, resolve);
10     });
11 }
12
13 function doubleTapToZoomAtPoint(x, y)
14 {
15     return new Promise(resolve => {
16         testRunner.runUIScript(`
17             (function() {
18                 let completionCount = 0;
19                 const checkDone = () => {
20                     if (++completionCount == 3)
21                         uiController.uiScriptComplete();
22                 };
23                 uiController.didEndZoomingCallback = checkDone;
24                 uiController.singleTapAtPoint(${x}, ${y}, checkDone);
25                 uiController.singleTapAtPoint(${x}, ${y}, checkDone);
26             })();`, resolve);
27     });
28 }
29
30 function doubleTapAtPoint(x, y)
31 {
32     return new Promise(resolve => {
33         testRunner.runUIScript(`
34             (function() {
35                 uiController.doubleTapAtPoint(${x}, ${y}, function() {
36                     uiController.uiScriptComplete();
37                 });
38             })();`, resolve);
39     });
40 }
41
42 function longPressAtPoint(x, y)
43 {
44     return new Promise(resolve => {
45         testRunner.runUIScript(`
46             (function() {
47                 uiController.longPressAtPoint(${x}, ${y}, function() {
48                     uiController.uiScriptComplete();
49                 });
50             })();`, resolve);
51     });
52 }
53
54 function liftUpAtPoint(x, y)
55 {
56     return new Promise(resolve => {
57         testRunner.runUIScript(`
58             (function() {
59                 uiController.liftUpAtPoint(${x}, ${y}, 1, function() {
60                     uiController.uiScriptComplete();
61                 });
62             })();`, resolve);
63     });
64 }
65
66 function longPressAndHoldAtPoint(x, y)
67 {
68     return new Promise(resolve => {
69         testRunner.runUIScript(`
70             (function() {
71                 const eventStream = {
72                     events : [
73                         {
74                             interpolate : "linear",
75                             timestep: 0.1,
76                             coordinateSpace : "content",
77                             startEvent : {
78                                 inputType : "hand",
79                                 timeOffset : 0,
80                                 touches : [
81                                     {
82                                         inputType : "finger",
83                                         phase : "began",
84                                         id : 1,
85                                         x : ${x},
86                                         y : ${y},
87                                         pressure : 0
88                                     }
89                                 ]
90                             },
91                             endEvent : {
92                                 inputType : "hand",
93                                 timeOffset : 2.0,
94                                 touches : [
95                                     {
96                                         inputType : "finger",
97                                         phase : "moved",
98                                         id : 1,
99                                         x : ${x},
100                                         y : ${y},
101                                         pressure : 0
102                                     }
103                                 ]
104                             }
105                         }
106                     ]
107                 };
108
109                 uiController.sendEventStream(JSON.stringify(eventStream), () => uiController.uiScriptComplete());
110             })();`, resolve);
111     });
112 }
113
114 function tapAtPoint(x, y)
115 {
116     return new Promise(resolve => {
117         testRunner.runUIScript(`
118             (function() {
119                 uiController.singleTapAtPoint(${x}, ${y}, function() {
120                     uiController.uiScriptComplete();
121                 });
122             })();`, resolve);
123     });
124 }
125
126 function touchAndDragFromPointToPoint(startX, startY, endX, endY)
127 {
128     return new Promise(resolve => {
129         testRunner.runUIScript(`
130             (function() {
131                 const eventStream = {
132                     events : [
133                         {
134                             interpolate : "linear",
135                             timestep: 0.1,
136                             coordinateSpace : "content",
137                             startEvent : {
138                                 inputType : "hand",
139                                 timeOffset : 0,
140                                 touches : [
141                                     {
142                                         inputType : "finger",
143                                         phase : "began",
144                                         id : 1,
145                                         x : ${startX},
146                                         y : ${startY},
147                                         pressure : 0
148                                     }
149                                 ]
150                             },
151                             endEvent : {
152                                 inputType : "hand",
153                                 timeOffset : 0.5,
154                                 touches : [
155                                     {
156                                         inputType : "finger",
157                                         phase : "moved",
158                                         id : 1,
159                                         x : ${endX},
160                                         y : ${endY},
161                                         pressure : 0
162                                     }
163                                 ]
164                             }
165                         }
166                     ]
167                 };
168
169                 uiController.sendEventStream(JSON.stringify(eventStream), () => uiController.uiScriptComplete());
170             })();`, resolve);
171     });
172 }
173
174 function holdAtPoint(x, y)
175 {
176     return new Promise(resolve => {
177         testRunner.runUIScript(`
178             (function() {
179                 const eventStream = {
180                     events : [
181                         {
182                             interpolate : "linear",
183                             timestep: 0.1,
184                             coordinateSpace : "content",
185                             startEvent : {
186                                 inputType : "hand",
187                                 timeOffset : 0,
188                                 touches : [
189                                     {
190                                         inputType : "finger",
191                                         phase : "moved",
192                                         id : 1,
193                                         x : ${x},
194                                         y : ${y},
195                                         pressure : 0
196                                     }
197                                 ]
198                             },
199                             endEvent : {
200                                 inputType : "hand",
201                                 timeOffset : 5.0,
202                                 touches : [
203                                     {
204                                         inputType : "finger",
205                                         phase : "moved",
206                                         id : 1,
207                                         x : ${x},
208                                         y : ${y},
209                                         pressure : 0
210                                     }
211                                 ]
212                             }
213                         }
214                     ]
215                 };
216
217                 uiController.sendEventStream(JSON.stringify(eventStream), () => uiController.uiScriptComplete());
218             })();`, resolve);
219     });
220 }
221
222 function continueTouchAndDragFromPointToPoint(startX, startY, endX, endY)
223 {
224     return new Promise(resolve => {
225         testRunner.runUIScript(`
226             (function() {
227                 const eventStream = {
228                     events : [
229                         {
230                             interpolate : "linear",
231                             timestep: 0.1,
232                             coordinateSpace : "content",
233                             startEvent : {
234                                 inputType : "hand",
235                                 timeOffset : 0,
236                                 touches : [
237                                     {
238                                         inputType : "finger",
239                                         phase : "moved",
240                                         id : 1,
241                                         x : ${startX},
242                                         y : ${startY},
243                                         pressure : 0
244                                     }
245                                 ]
246                             },
247                             endEvent : {
248                                 inputType : "hand",
249                                 timeOffset : 0.5,
250                                 touches : [
251                                     {
252                                         inputType : "finger",
253                                         phase : "moved",
254                                         id : 1,
255                                         x : ${endX},
256                                         y : ${endY},
257                                         pressure : 0
258                                     }
259                                 ]
260                             }
261                         }
262                     ]
263                 };
264
265                 uiController.sendEventStream(JSON.stringify(eventStream), () => uiController.uiScriptComplete());
266             })();`, resolve);
267     });
268 }