forked from pharo-project/pharo
/
SpPresenterFocusOrderTest.class.st
207 lines (175 loc) · 5.46 KB
/
SpPresenterFocusOrderTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Class {
#name : #SpPresenterFocusOrderTest,
#superclass : #TestCase,
#traits : 'SpTMorphicUIRedrawer',
#classTraits : 'SpTMorphicUIRedrawer classTrait',
#instVars : [
'mock'
],
#category : #'Spec2-Morphic-Backend-Tests'
}
{ #category : #private }
SpPresenterFocusOrderTest >> focusedPresenter [
^ mock allPresentersInFocusOrder
detect: [ :each | each adapter widget hasKeyboardFocus ]
ifNone: [ nil ]
]
{ #category : #emulating }
SpPresenterFocusOrderTest >> keyDown: keyCode shift: shiftBoolean meta: metaBoolean control: controlBoolean option: optionBoolean [
^ self
keyEvent: #keyDown
code: keyCode
shift: shiftBoolean
meta: metaBoolean
control: controlBoolean
option: optionBoolean
]
{ #category : #emulating }
SpPresenterFocusOrderTest >> keyEvent: type code: keyCode shift: shiftBoolean meta: metaBoolean control: controlBoolean option: optionBoolean [
| evt modifiers widget |
widget := self focusedPresenter adapter widget.
modifiers := 0.
shiftBoolean ifTrue: [ modifiers := modifiers | 8 ].
metaBoolean ifTrue: [ modifiers := modifiers |
(Smalltalk os isWin32 | Smalltalk os isUnix
ifTrue: [ 2r00010000 ]
ifFalse: [ 2r01000000 ]) ].
controlBoolean ifTrue: [ modifiers := modifiers | 2r00010000 ].
optionBoolean ifTrue: [ modifiers := modifiers |
(Smalltalk os isWin32 | Smalltalk os isUnix
ifTrue: [ 2r01000000 ]
ifFalse: [ 2r00100000 ]) ].
evt := KeyboardEvent new
setType: type
buttons: modifiers
position: widget position + (1 @ 1)
keyValue: keyCode
charCode: keyCode
hand: self currentWorld activeHand
stamp: Time millisecondClockValue.
evt key: (KeyboardKey fromCharacter: keyCode asCharacter).
evt sentTo: widget.
"Some time to allow things to happen?"
10 milliSeconds wait
]
{ #category : #emulating }
SpPresenterFocusOrderTest >> keyPressed: keyCode shift: shiftBoolean meta: metaBoolean control: controlBoolean option: optionBoolean [
^ self
keyEvent: #keystroke
code: keyCode asciiValue
shift: shiftBoolean
meta: metaBoolean
control: controlBoolean
option: optionBoolean
]
{ #category : #emulating }
SpPresenterFocusOrderTest >> pressShiftTab [
self
keyDown: Character tab
shift: true
meta: false
control: false
option: false.
self waitUntilUIRedrawed
]
{ #category : #emulating }
SpPresenterFocusOrderTest >> pressTab [
self
keyDown: Character tab
shift: false
meta: false
control: false
option: false.
self waitUntilUIRedrawed
]
{ #category : #running }
SpPresenterFocusOrderTest >> setUp [
super setUp.
self initializeSemaphore
]
{ #category : #emulating }
SpPresenterFocusOrderTest >> takeKeyboardFocus: aPresenter [
aPresenter takeKeyboardFocus.
self waitUntilUIRedrawed
]
{ #category : #running }
SpPresenterFocusOrderTest >> tearDown [
mock ifNotNil: [
mock hasWindow ifTrue: [
mock window close ] ].
super tearDown
]
{ #category : #tests }
SpPresenterFocusOrderTest >> testCustomFocusOrder [
mock := SpMockFocusOrderPresenter new.
mock focusOrder
add: (mock thirdPresenter);
add: (mock firstPresenter);
add: (mock secondPresenter).
mock openWithSpec.
"Focus third"
self takeKeyboardFocus: mock.
self assert: (mock thirdPresenter) equals: self focusedPresenter.
"Focus first"
self pressTab.
self assert: (mock firstPresenter) equals: self focusedPresenter.
"Focus second"
self pressTab.
self assert: (mock secondPresenter) equals: self focusedPresenter.
"Focus third again"
self pressTab.
self assert: (mock thirdPresenter) equals: self focusedPresenter
]
{ #category : #tests }
SpPresenterFocusOrderTest >> testFocusRotationBackwards [
mock := SpMockFocusOrderPresenter new
openWithSpec;
yourself.
"Focus first"
self takeKeyboardFocus: mock.
self assert: (mock presenterAt: #firstPresenter) equals: self focusedPresenter.
"Focus third"
self pressShiftTab.
self assert: (mock presenterAt: #thirdPresenter) equals: self focusedPresenter.
"Focus second"
self pressShiftTab.
self assert: (mock presenterAt: #secondPresenter) equals: self focusedPresenter.
"Focus first again"
self pressShiftTab.
self assert: (mock presenterAt: #firstPresenter) equals: self focusedPresenter
]
{ #category : #tests }
SpPresenterFocusOrderTest >> testFocusRotationForward [
mock := SpMockFocusOrderPresenter new
openWithSpec;
yourself.
"Focus first"
self takeKeyboardFocus: mock.
self assert: (mock presenterAt: #firstPresenter) equals: self focusedPresenter.
"Focus second"
self pressTab.
self assert: (mock presenterAt: #secondPresenter) equals: self focusedPresenter.
"Focus third"
self pressTab.
self assert: (mock presenterAt: #thirdPresenter) equals: self focusedPresenter.
"Focus first again"
self pressTab.
self assert: (mock presenterAt: #firstPresenter) equals: self focusedPresenter
]
{ #category : #tests }
SpPresenterFocusOrderTest >> testTakeKeyboardFocus [
mock := SpMockFocusOrderPresenter new
openWithSpec;
yourself.
"Focus first"
self takeKeyboardFocus: mock.
self assert: (mock presenterAt: #firstPresenter) equals: self focusedPresenter.
"Focus second"
self takeKeyboardFocus: (mock presenterAt: #secondPresenter).
self deny: (mock presenterAt: #firstPresenter) equals: self focusedPresenter.
self assert: (mock presenterAt: #secondPresenter) equals: self focusedPresenter.
"Focus first again"
self takeKeyboardFocus: (mock presenterAt: #firstPresenter).
self assert: (mock presenterAt: #firstPresenter) equals: self focusedPresenter.
self deny: (mock presenterAt: #secondPresenter) equals: self focusedPresenter
]