Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / actions / support / keys.py
1 # Licensed to the Software Freedom Conservancy (SFC) under one
2 # or more contributor license agreements.  See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership.  The SFC licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License.  You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied.  See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 """
19 The Keys implementation.
20 """
21
22 from inspect import getmembers
23 import sys
24
25
26 class Keys(object):
27     """
28     Set of special keys codes.
29
30     See also https://w3c.github.io/webdriver/webdriver-spec.html#h-keyboard-actions
31     """
32
33     NULL = u"\ue000"
34     CANCEL = u"\ue001"  # ^break
35     HELP = u"\ue002"
36     BACKSPACE = u"\ue003"
37     TAB = u"\ue004"
38     CLEAR = u"\ue005"
39     RETURN = u"\ue006"
40     ENTER = u"\ue007"
41     SHIFT = u"\ue008"
42     CONTROL = u"\ue009"
43     ALT = u"\ue00a"
44     PAUSE = u"\ue00b"
45     ESCAPE = u"\ue00c"
46     SPACE = u"\ue00d"
47     PAGE_UP = u"\ue00e"
48     PAGE_DOWN = u"\ue00f"
49     END = u"\ue010"
50     HOME = u"\ue011"
51     LEFT = u"\ue012"
52     UP = u"\ue013"
53     RIGHT = u"\ue014"
54     DOWN = u"\ue015"
55     INSERT = u"\ue016"
56     DELETE = u"\ue017"
57     SEMICOLON = u"\ue018"
58     EQUALS = u"\ue019"
59
60     NUMPAD0 = u"\ue01a"  # number pad keys
61     NUMPAD1 = u"\ue01b"
62     NUMPAD2 = u"\ue01c"
63     NUMPAD3 = u"\ue01d"
64     NUMPAD4 = u"\ue01e"
65     NUMPAD5 = u"\ue01f"
66     NUMPAD6 = u"\ue020"
67     NUMPAD7 = u"\ue021"
68     NUMPAD8 = u"\ue022"
69     NUMPAD9 = u"\ue023"
70     MULTIPLY = u"\ue024"
71     ADD = u"\ue025"
72     SEPARATOR = u"\ue026"
73     SUBTRACT = u"\ue027"
74     DECIMAL = u"\ue028"
75     DIVIDE = u"\ue029"
76
77     F1 = u"\ue031"  # function  keys
78     F2 = u"\ue032"
79     F3 = u"\ue033"
80     F4 = u"\ue034"
81     F5 = u"\ue035"
82     F6 = u"\ue036"
83     F7 = u"\ue037"
84     F8 = u"\ue038"
85     F9 = u"\ue039"
86     F10 = u"\ue03a"
87     F11 = u"\ue03b"
88     F12 = u"\ue03c"
89
90     META = u"\ue03d"
91
92     # More keys from webdriver spec
93     ZENKAKUHANKAKU = u"\uE040"
94     R_SHIFT = u"\uE050"
95     R_CONTROL = u"\uE051"
96     R_ALT = u"\uE052"
97     R_META = u"\uE053"
98     R_PAGEUP = u"\uE054"
99     R_PAGEDOWN = u"\uE055"
100     R_END = u"\uE056"
101     R_HOME = u"\uE057"
102     R_ARROWLEFT = u"\uE058"
103     R_ARROWUP = u"\uE059"
104     R_ARROWRIGHT = u"\uE05A"
105     R_ARROWDOWN = u"\uE05B"
106     R_INSERT = u"\uE05C"
107     R_DELETE = u"\uE05D"
108
109
110 ALL_KEYS = getmembers(Keys, lambda x: type(x) == unicode)
111
112 ALL_EVENTS = {
113     "ADD": {
114         "code": "",
115         "ctrl": False,
116         "key": "+",
117         "location": 3,
118         "meta": False,
119         "shift": False,
120         "value": u"\ue025",
121     },
122     "ALT": {
123         "code": "AltLeft",
124         "ctrl": False,
125         "key": "Alt",
126         "location": 1,
127         "meta": False,
128         "shift": False,
129         "value": u"\ue00a",
130     },
131     "BACKSPACE": {
132         "code": "Backspace",
133         "ctrl": False,
134         "key": "Backspace",
135         "location": 0,
136         "meta": False,
137         "shift": False,
138         "value": u"\ue003",
139     },
140     "CANCEL": {
141         "code": "",
142         "ctrl": False,
143         "key": "Cancel",
144         "location": 0,
145         "meta": False,
146         "shift": False,
147         "value": u"\ue001",
148     },
149     "CLEAR": {
150         "code": "",
151         "ctrl": False,
152         "key": "Clear",
153         "location": 0,
154         "meta": False,
155         "shift": False,
156         "value": u"\ue005",
157     },
158     "CONTROL": {
159         "code": "ControlLeft",
160         "ctrl": True,
161         "key": "Control",
162         "location": 1,
163         "meta": False,
164         "shift": False,
165         "value": u"\ue009",
166     },
167     "DECIMAL": {
168         "code": "NumpadDecimal",
169         "ctrl": False,
170         "key": ".",
171         "location": 3,
172         "meta": False,
173         "shift": False,
174         "value": u"\ue028",
175     },
176     "DELETE": {
177         "code": "Delete",
178         "ctrl": False,
179         "key": "Delete",
180         "location": 0,
181         "meta": False,
182         "shift": False,
183         "value": u"\ue017",
184     },
185     "DIVIDE": {
186         "code": "NumpadDivide",
187         "ctrl": False,
188         "key": "/",
189         "location": 3,
190         "meta": False,
191         "shift": False,
192         "value": u"\ue029",
193     },
194     "DOWN": {
195         "code": "ArrowDown",
196         "ctrl": False,
197         "key": "ArrowDown",
198         "location": 0,
199         "meta": False,
200         "shift": False,
201         "value": u"\ue015",
202     },
203     "END": {
204         "code": "End",
205         "ctrl": False,
206         "key": "End",
207         "location": 0,
208         "meta": False,
209         "shift": False,
210         "value": u"\ue010",
211     },
212     "ENTER": {
213         "code": "NumpadEnter",
214         "ctrl": False,
215         "key": "Enter",
216         "location": 1,
217         "meta": False,
218         "shift": False,
219         "value": u"\ue007",
220     },
221     "EQUALS": {
222         "code": "",
223         "ctrl": False,
224         "key": "=",
225         "location": 0,
226         "meta": False,
227         "shift": False,
228         "value": u"\ue019",
229     },
230     "ESCAPE": {
231         "code": "Escape",
232         "ctrl": False,
233         "key": "Escape",
234         "location": 0,
235         "meta": False,
236         "shift": False,
237         "value": u"\ue00c",
238     },
239     "F1": {
240         "code": "F1",
241         "ctrl": False,
242         "key": "F1",
243         "location": 0,
244         "meta": False,
245         "shift": False,
246         "value": u"\ue031",
247     },
248     "F10": {
249         "code": "F10",
250         "ctrl": False,
251         "key": "F10",
252         "location": 0,
253         "meta": False,
254         "shift": False,
255         "value": u"\ue03a",
256     },
257     "F11": {
258         "code": "F11",
259         "ctrl": False,
260         "key": "F11",
261         "location": 0,
262         "meta": False,
263         "shift": False,
264         "value": u"\ue03b",
265     },
266     "F12": {
267         "code": "F12",
268         "ctrl": False,
269         "key": "F12",
270         "location": 0,
271         "meta": False,
272         "shift": False,
273         "value": u"\ue03c",
274     },
275     "F2": {
276         "code": "F2",
277         "ctrl": False,
278         "key": "F2",
279         "location": 0,
280         "meta": False,
281         "shift": False,
282         "value": u"\ue032",
283     },
284     "F3": {
285         "code": "F3",
286         "ctrl": False,
287         "key": "F3",
288         "location": 0,
289         "meta": False,
290         "shift": False,
291         "value": u"\ue033",
292     },
293     "F4": {
294         "code": "F4",
295         "ctrl": False,
296         "key": "F4",
297         "location": 0,
298         "meta": False,
299         "shift": False,
300         "value": u"\ue034",
301     },
302     "F5": {
303         "code": "F5",
304         "ctrl": False,
305         "key": "F5",
306         "location": 0,
307         "meta": False,
308         "shift": False,
309         "value": u"\ue035",
310     },
311     "F6": {
312         "code": "F6",
313         "ctrl": False,
314         "key": "F6",
315         "location": 0,
316         "meta": False,
317         "shift": False,
318         "value": u"\ue036",
319     },
320     "F7": {
321         "code": "F7",
322         "ctrl": False,
323         "key": "F7",
324         "location": 0,
325         "meta": False,
326         "shift": False,
327         "value": u"\ue037",
328     },
329     "F8": {
330         "code": "F8",
331         "ctrl": False,
332         "key": "F8",
333         "location": 0,
334         "meta": False,
335         "shift": False,
336         "value": u"\ue038",
337     },
338     "F9": {
339         "code": "F9",
340         "ctrl": False,
341         "key": "F9",
342         "location": 0,
343         "meta": False,
344         "shift": False,
345         "value": u"\ue039",
346     },
347     "HELP": {
348         "code": "Help",
349         "ctrl": False,
350         "key": "Help",
351         "location": 0,
352         "meta": False,
353         "shift": False,
354         "value": u"\ue002",
355     },
356     "HOME": {
357         "code": "Home",
358         "ctrl": False,
359         "key": "Home",
360         "location": 0,
361         "meta": False,
362         "shift": False,
363         "value": u"\ue011",
364     },
365     "INSERT": {
366         "code": "Insert",
367         "ctrl": False,
368         "key": "Insert",
369         "location": 0,
370         "meta": False,
371         "shift": False,
372         "value": u"\ue016",
373     },
374     "LEFT": {
375         "code": "ArrowLeft",
376         "ctrl": False,
377         "key": "ArrowLeft",
378         "location": 0,
379         "meta": False,
380         "shift": False,
381         "value": u"\ue012",
382     },
383     "META": {
384         "code": "OSLeft",
385         "ctrl": False,
386         "key": "Meta",
387         "location": 1,
388         "meta": True,
389         "shift": False,
390         "value": u"\ue03d",
391     },
392     "MULTIPLY": {
393         "code": "NumpadMultiply",
394         "ctrl": False,
395         "key": "*",
396         "location": 3,
397         "meta": False,
398         "shift": False,
399         "value": u"\ue024",
400     },
401     "NULL": {
402         "code": "",
403         "ctrl": False,
404         "key": "Unidentified",
405         "location": 0,
406         "meta": False,
407         "shift": False,
408         "value": u"\ue000",
409     },
410     "NUMPAD0": {
411         "code": "Numpad0",
412         "ctrl": False,
413         "key": "0",
414         "location": 3,
415         "meta": False,
416         "shift": False,
417         "value": u"\ue01a",
418     },
419     "NUMPAD1": {
420         "code": "Numpad1",
421         "ctrl": False,
422         "key": "1",
423         "location": 3,
424         "meta": False,
425         "shift": False,
426         "value": u"\ue01b",
427     },
428     "NUMPAD2": {
429         "code": "Numpad2",
430         "ctrl": False,
431         "key": "2",
432         "location": 3,
433         "meta": False,
434         "shift": False,
435         "value": u"\ue01c",
436     },
437     "NUMPAD3": {
438         "code": "Numpad3",
439         "ctrl": False,
440         "key": "3",
441         "location": 3,
442         "meta": False,
443         "shift": False,
444         "value": u"\ue01d",
445     },
446     "NUMPAD4": {
447         "code": "PageDown",
448         "ctrl": False,
449         "key": "4",
450         "location": 3,
451         "meta": False,
452         "shift": False,
453         "value": u"\ue01e",
454     },
455     "NUMPAD5": {
456         "code": "PageUp",
457         "ctrl": False,
458         "key": "5",
459         "location": 3,
460         "meta": False,
461         "shift": False,
462         "value": u"\ue01f",
463     },
464     "NUMPAD6": {
465         "code": "Numpad6",
466         "ctrl": False,
467         "key": "6",
468         "location": 3,
469         "meta": False,
470         "shift": False,
471         "value": u"\ue020",
472     },
473     "NUMPAD7": {
474         "code": "Numpad7",
475         "ctrl": False,
476         "key": "7",
477         "location": 3,
478         "meta": False,
479         "shift": False,
480         "value": u"\ue021",
481     },
482     "NUMPAD8": {
483         "code": "Numpad8",
484         "ctrl": False,
485         "key": "8",
486         "location": 3,
487         "meta": False,
488         "shift": False,
489         "value": u"\ue022",
490     },
491     "NUMPAD9": {
492         "code": "Numpad9",
493         "ctrl": False,
494         "key": "9",
495         "location": 3,
496         "meta": False,
497         "shift": False,
498         "value": u"\ue023",
499     },
500     "PAGE_DOWN": {
501         "code": "",
502         "ctrl": False,
503         "key": "PageDown",
504         "location": 0,
505         "meta": False,
506         "shift": False,
507         "value": u"\ue00f",
508     },
509     "PAGE_UP": {
510         "code": "",
511         "ctrl": False,
512         "key": "PageUp",
513         "location": 0,
514         "meta": False,
515         "shift": False,
516         "value": u"\ue00e",
517     },
518     "PAUSE": {
519         "code": "",
520         "ctrl": False,
521         "key": "Pause",
522         "location": 0,
523         "meta": False,
524         "shift": False,
525         "value": u"\ue00b",
526     },
527     "RETURN": {
528         "code": "Enter",
529         "ctrl": False,
530         "key": "Enter",
531         "location": 0,
532         "meta": False,
533         "shift": False,
534         "value": u"\ue006",
535     },
536     "RIGHT": {
537         "code": "ArrowRight",
538         "ctrl": False,
539         "key": "ArrowRight",
540         "location": 0,
541         "meta": False,
542         "shift": False,
543         "value": u"\ue014",
544     },
545     "R_ALT": {
546         "code": "AltRight",
547         "ctrl": False,
548         "key": "Alt",
549         "location": 2,
550         "meta": False,
551         "shift": False,
552         "value": u"\ue052",
553     },
554     "R_ARROWDOWN": {
555         "code": "Numpad2",
556         "ctrl": False,
557         "key": "ArrowDown",
558         "location": 3,
559         "meta": False,
560         "shift": False,
561         "value": u"\ue05b",
562     },
563     "R_ARROWLEFT": {
564         "code": "Numpad4",
565         "ctrl": False,
566         "key": "ArrowLeft",
567         "location": 3,
568         "meta": False,
569         "shift": False,
570         "value": u"\ue058",
571     },
572     "R_ARROWRIGHT": {
573         "code": "Numpad6",
574         "ctrl": False,
575         "key": "ArrowRight",
576         "location": 3,
577         "meta": False,
578         "shift": False,
579         "value": u"\ue05a",
580     },
581     "R_ARROWUP": {
582         "code": "Numpad8",
583         "ctrl": False,
584         "key": "ArrowUp",
585         "location": 3,
586         "meta": False,
587         "shift": False,
588         "value": u"\ue059",
589     },
590     "R_CONTROL": {
591         "code": "ControlRight",
592         "ctrl": True,
593         "key": "Control",
594         "location": 2,
595         "meta": False,
596         "shift": False,
597         "value": u"\ue051",
598     },
599     "R_DELETE": {
600         "code": "NumpadDecimal",
601         "ctrl": False,
602         "key": "Delete",
603         "location": 3,
604         "meta": False,
605         "shift": False,
606         "value": u"\ue05d",
607     },
608     "R_END": {
609         "code": "Numpad1",
610         "ctrl": False,
611         "key": "End",
612         "location": 3,
613         "meta": False,
614         "shift": False,
615         "value": u"\ue056",
616     },
617     "R_HOME": {
618         "code": "Numpad7",
619         "ctrl": False,
620         "key": "Home",
621         "location": 3,
622         "meta": False,
623         "shift": False,
624         "value": u"\ue057",
625     },
626     "R_INSERT": {
627         "code": "Numpad0",
628         "ctrl": False,
629         "key": "Insert",
630         "location": 3,
631         "meta": False,
632         "shift": False,
633         "value": u"\ue05c",
634     },
635     "R_META": {
636         "code": "OSRight",
637         "ctrl": False,
638         "key": "Meta",
639         "location": 2,
640         "meta": True,
641         "shift": False,
642         "value": u"\ue053",
643     },
644     "R_PAGEDOWN": {
645         "code": "Numpad3",
646         "ctrl": False,
647         "key": "PageDown",
648         "location": 3,
649         "meta": False,
650         "shift": False,
651         "value": u"\ue055",
652     },
653     "R_PAGEUP": {
654         "code": "Numpad9",
655         "ctrl": False,
656         "key": "PageUp",
657         "location": 3,
658         "meta": False,
659         "shift": False,
660         "value": u"\ue054",
661     },
662     "R_SHIFT": {
663         "code": "ShiftRight",
664         "ctrl": False,
665         "key": "Shift",
666         "location": 2,
667         "meta": False,
668         "shift": True,
669         "value": u"\ue050",
670     },
671     "SEMICOLON": {
672         "code": "",
673         "ctrl": False,
674         "key": ";",
675         "location": 0,
676         "meta": False,
677         "shift": False,
678         "value": u"\ue018",
679     },
680     "SEPARATOR": {
681         "code": "NumpadSubtract",
682         "ctrl": False,
683         "key": ",",
684         "location": 3,
685         "meta": False,
686         "shift": False,
687         "value": u"\ue026",
688     },
689     "SHIFT": {
690         "code": "ShiftLeft",
691         "ctrl": False,
692         "key": "Shift",
693         "location": 1,
694         "meta": False,
695         "shift": True,
696         "value": u"\ue008",
697     },
698     "SPACE": {
699         "code": "Space",
700         "ctrl": False,
701         "key": " ",
702         "location": 0,
703         "meta": False,
704         "shift": False,
705         "value": u"\ue00d",
706     },
707     "SUBTRACT": {
708         "code": "",
709         "ctrl": False,
710         "key": "-",
711         "location": 3,
712         "meta": False,
713         "shift": False,
714         "value": u"\ue027",
715     },
716     "TAB": {
717         "code": "Tab",
718         "ctrl": False,
719         "key": "Tab",
720         "location": 0,
721         "meta": False,
722         "shift": False,
723         "value": u"\ue004",
724     },
725     "UP": {
726         "code": "ArrowUp",
727         "ctrl": False,
728         "key": "ArrowUp",
729         "location": 0,
730         "meta": False,
731         "shift": False,
732         "value": u"\ue013",
733     },
734     "ZENKAKUHANKAKU": {
735         "code": "",
736         "ctrl": False,
737         "key": "ZenkakuHankaku",
738         "location": 0,
739         "meta": False,
740         "shift": False,
741         "value": u"\ue040",
742     }
743 }
744
745 if sys.platform == 'darwin':
746     MODIFIER_KEY = Keys.META
747 else:
748     MODIFIER_KEY = Keys.CONTROL