AXElements 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +4 -0
- data/History.markdown +41 -0
- data/README.markdown +59 -62
- data/Rakefile +1 -1
- data/ext/accessibility/key_coder/extconf.rb +1 -1
- data/ext/accessibility/key_coder/key_coder.c +8 -5
- data/lib/accessibility/dsl.rb +261 -87
- data/lib/accessibility/enumerators.rb +14 -11
- data/lib/accessibility/errors.rb +4 -3
- data/lib/accessibility/factory.rb +159 -108
- data/lib/accessibility/graph.rb +13 -9
- data/lib/accessibility/{pp_inspector.rb → pretty_printer.rb} +4 -5
- data/lib/accessibility/qualifier.rb +23 -13
- data/lib/accessibility/string.rb +4 -4
- data/lib/accessibility/system_info.rb +230 -0
- data/lib/accessibility/translator.rb +38 -28
- data/lib/accessibility/version.rb +24 -2
- data/lib/accessibility.rb +25 -8
- data/lib/ax/application.rb +207 -77
- data/lib/ax/element.rb +62 -65
- data/lib/ax/menu.rb +5 -1
- data/lib/ax/row.rb +1 -1
- data/lib/ax/scroll_area.rb +7 -6
- data/lib/ax/systemwide.rb +38 -5
- data/lib/ax_elements/active_support_selections.rb +10 -0
- data/lib/ax_elements/mri.rb +57 -0
- data/lib/ax_elements/nsarray_compat.rb +97 -17
- data/lib/ax_elements.rb +9 -1
- data/rakelib/gem.rake +11 -11
- data/rakelib/test.rake +0 -9
- data/test/helper.rb +10 -18
- data/test/integration/accessibility/test_dsl.rb +52 -42
- data/test/integration/accessibility/test_enumerators.rb +0 -1
- data/test/integration/accessibility/test_graph.rb +1 -0
- data/test/integration/accessibility/test_qualifier.rb +2 -2
- data/test/integration/ax/test_application.rb +9 -2
- data/test/integration/ax/test_element.rb +41 -1
- data/test/sanity/accessibility/test_factory.rb +23 -56
- data/test/sanity/accessibility/{test_pp_inspector.rb → test_pretty_printer.rb} +9 -9
- data/test/sanity/accessibility/test_translator.rb +2 -5
- data/test/sanity/accessibility/test_version.rb +15 -0
- data/test/sanity/ax/test_application.rb +17 -2
- data/test/sanity/ax/test_element.rb +2 -2
- data/test/sanity/ax_elements/test_nsobject_inspect.rb +4 -2
- data/test/sanity/test_ax_elements.rb +1 -0
- metadata +69 -39
- data/lib/accessibility/core.rb +0 -973
- data/lib/accessibility/highlighter.rb +0 -86
- data/lib/ax_elements/vendor/inflection_data.rb +0 -66
- data/lib/ax_elements/vendor/inflections.rb +0 -172
- data/lib/ax_elements/vendor/inflector.rb +0 -306
- data/lib/minitest/ax_elements.rb +0 -175
- data/lib/mouse.rb +0 -223
- data/lib/rspec/expectations/ax_elements.rb +0 -234
- data/test/integration/accessibility/test_core.rb +0 -18
- data/test/integration/minitest/test_ax_elements.rb +0 -89
- data/test/integration/rspec/expectations/test_ax_elements.rb +0 -102
- data/test/sanity/accessibility/test_core.rb +0 -561
- data/test/sanity/accessibility/test_highlighter.rb +0 -56
- data/test/sanity/minitest/test_ax_elements.rb +0 -17
- data/test/sanity/rspec/expectations/test_ax_elements.rb +0 -15
- data/test/sanity/test_mouse.rb +0 -19
@@ -1,561 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'test/helper'
|
4
|
-
require 'accessibility/core'
|
5
|
-
|
6
|
-
|
7
|
-
class TestAccessibilityCore < MiniTest::Unit::TestCase
|
8
|
-
|
9
|
-
def window
|
10
|
-
@@window ||= REF.attribute(KAXMainWindowAttribute)
|
11
|
-
end
|
12
|
-
|
13
|
-
def child name
|
14
|
-
window.children.find { |item|
|
15
|
-
(block_given? ? yield(item) : true) if item.role == name
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def slider; @@slider ||= child KAXSliderRole; end
|
20
|
-
def check_box; @@check_box ||= child KAXCheckBoxRole; end
|
21
|
-
def pop_up; @@pop_up ||= child KAXPopUpButtonRole; end
|
22
|
-
def search_box; @@search_box ||= child KAXTextFieldRole; end
|
23
|
-
def static_text; @@static_text ||= child(KAXStaticTextRole) { |x| x.value.match /My Little Pony/ } end
|
24
|
-
def yes_button; @@yes_button ||= child(KAXButtonRole) { |x| x.attribute(KAXTitleAttribute) == 'Yes' } end
|
25
|
-
def bye_button; @@bye_button ||= child(KAXButtonRole) { |x| x.attribute(KAXTitleAttribute) == 'Bye!' } end
|
26
|
-
def no_button; @@no_button ||= child(KAXButtonRole) { |x| x.attribute(KAXTitleAttribute) == 'No' } end
|
27
|
-
def web_area; @@web_area ||= child("AXScrollArea") { |x| x.attribute("AXDescription" ) == 'Test Web Area' }.children.first end
|
28
|
-
def text_area; @@text_area ||= child("AXScrollArea") { |x| x.attributes.include?("AXIdentifier") && x.attribute("AXIdentifier") == 'Text Area' }.children.first end
|
29
|
-
|
30
|
-
def invalid_ref
|
31
|
-
bye_button # guarantee that it is cached
|
32
|
-
@@dead ||= no_button.perform KAXPressAction
|
33
|
-
bye_button
|
34
|
-
end
|
35
|
-
|
36
|
-
def app
|
37
|
-
@@app ||= Regexp.new(Regexp.escape(REF.inspect))
|
38
|
-
end
|
39
|
-
|
40
|
-
def assert_error args, should_raise: klass, with_fragments: msgs
|
41
|
-
e = assert_raises(klass) { (@derp || REF).handle_error *args }
|
42
|
-
assert_match /test_core.rb:41/, e.backtrace.first unless RUNNING_COMPILED
|
43
|
-
msgs.each { |msg| assert_match msg, e.message }
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
##
|
49
|
-
# AFAICT every accessibility object **MUST** have attributes, so
|
50
|
-
# there are no tests to check what happens when they do not exist;
|
51
|
-
# though I am quite sure that AXElements will raise an exception.
|
52
|
-
|
53
|
-
def test_attributes
|
54
|
-
attrs = REF.attributes
|
55
|
-
assert_includes attrs, KAXRoleAttribute
|
56
|
-
assert_includes attrs, KAXChildrenAttribute
|
57
|
-
assert_includes attrs, KAXTitleAttribute
|
58
|
-
assert_includes attrs, KAXMenuBarAttribute
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_attributes_is_empty_for_dead_elements
|
62
|
-
assert_empty invalid_ref.attributes
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_attribute
|
66
|
-
assert_equal 'AXElementsTester', window.attribute(KAXTitleAttribute )
|
67
|
-
assert_equal false, window.attribute(KAXFocusedAttribute)
|
68
|
-
assert_equal CGSize.new(555,529), window.attribute(KAXSizeAttribute )
|
69
|
-
assert_equal REF, window.attribute(KAXParentAttribute )
|
70
|
-
assert_equal 10..19, window.attribute("AXPie" )
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_attribute_when_no_value
|
74
|
-
assert_nil window.attribute(KAXGrowAreaAttribute)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_attribute_when_dead
|
78
|
-
assert_nil invalid_ref.attribute(KAXRoleAttribute)
|
79
|
-
assert_empty invalid_ref.attribute(KAXChildrenAttribute)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_attribute_when_not_supported_attribute
|
83
|
-
assert_nil REF.attribute('MADEUPATTRIBUTE')
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_role
|
87
|
-
assert_equal KAXApplicationRole, REF.role
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_subrole
|
91
|
-
assert_equal KAXStandardWindowSubrole, window.subrole
|
92
|
-
assert_nil web_area.subrole
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_children
|
96
|
-
assert_equal REF.attribute(KAXChildrenAttribute), REF.children
|
97
|
-
assert_equal slider.attribute(KAXChildrenAttribute), slider.children
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_value
|
101
|
-
assert_equal check_box.attribute(KAXValueAttribute), check_box.value
|
102
|
-
assert_equal slider.attribute(KAXValueAttribute), slider.value
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_pid
|
106
|
-
assert_equal PID, REF.pid
|
107
|
-
assert_equal PID, window.pid
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_pid_is_zero_for_system_wide
|
111
|
-
assert_equal 0, REF.system_wide.pid
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_size_of
|
115
|
-
assert_equal REF.children.size, REF.size_of(KAXChildrenAttribute)
|
116
|
-
assert_equal 0, pop_up.size_of(KAXChildrenAttribute)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_size_of_0_for_dead_element
|
120
|
-
assert_equal 0, invalid_ref.size_of(KAXChildrenAttribute)
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_writable
|
124
|
-
refute REF.writable? KAXTitleAttribute
|
125
|
-
assert window.writable? KAXMainAttribute
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_writable_false_for_dead_cases
|
129
|
-
refute invalid_ref.writable? KAXRoleAttribute
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_writable_false_for_bad_attributes
|
133
|
-
refute REF.writable? 'FAKE'
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_set_number
|
137
|
-
[25, 75, 50].each do |number|
|
138
|
-
assert_equal number, slider.set(KAXValueAttribute, number)
|
139
|
-
assert_equal number, slider.value
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_set_string
|
144
|
-
[Time.now.to_s, ''].each do |string|
|
145
|
-
assert_equal string, search_box.set(KAXValueAttribute, string)
|
146
|
-
assert_equal string, search_box.value
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_set_wrapped
|
151
|
-
text_area.set KAXValueAttribute, 'hey-o'
|
152
|
-
|
153
|
-
text_area.set KAXSelectedTextRangeAttribute, 0..3
|
154
|
-
assert_equal 0..3, text_area.attribute(KAXSelectedTextRangeAttribute)
|
155
|
-
|
156
|
-
text_area.set KAXSelectedTextRangeAttribute, 1...4
|
157
|
-
assert_equal 1..3, text_area.attribute(KAXSelectedTextRangeAttribute)
|
158
|
-
ensure
|
159
|
-
text_area.set KAXValueAttribute, ''
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_set_attr_handles_errors
|
163
|
-
assert_raises(ArgumentError) { REF.set 'FAKE', true }
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_parameterized_attributes
|
167
|
-
assert_empty REF.parameterized_attributes
|
168
|
-
|
169
|
-
attrs = static_text.parameterized_attributes
|
170
|
-
assert_includes attrs, KAXStringForRangeParameterizedAttribute
|
171
|
-
assert_includes attrs, KAXLineForIndexParameterizedAttribute
|
172
|
-
assert_includes attrs, KAXBoundsForRangeParameterizedAttribute
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_parameterized_attributes_empty_for_dead_elements
|
176
|
-
assert_empty invalid_ref.parameterized_attributes
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_parameterized_attribute
|
180
|
-
expected = 'My Li'
|
181
|
-
|
182
|
-
attr = static_text.parameterized_attribute(KAXStringForRangeParameterizedAttribute, 0..4)
|
183
|
-
assert_equal expected, attr
|
184
|
-
|
185
|
-
attr = static_text.parameterized_attribute(KAXAttributedStringForRangeParameterizedAttribute, 0..4)
|
186
|
-
assert_equal expected, attr.string
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_parameterized_attribute_handles_dead_elements_and_no_value
|
190
|
-
assert_nil invalid_ref.parameterized_attribute(KAXStringForRangeParameterizedAttribute, 0..0)
|
191
|
-
|
192
|
-
# Should add a test case to test the no value case, but it will have
|
193
|
-
# to be fabricated in the test app.
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_parameterized_attribute_handles_errors
|
197
|
-
assert_raises(ArgumentError) {
|
198
|
-
REF.parameterized_attribute(KAXStringForRangeParameterizedAttribute, 0..1)
|
199
|
-
}
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_action_names
|
203
|
-
assert_empty REF.actions
|
204
|
-
assert_equal [KAXPressAction], yes_button.actions
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_perform_action
|
208
|
-
2.times do # twice so it should be back where it started
|
209
|
-
val = check_box.value
|
210
|
-
check_box.perform KAXPressAction
|
211
|
-
refute_equal val, check_box.value
|
212
|
-
end
|
213
|
-
|
214
|
-
val = slider.value
|
215
|
-
slider.perform KAXIncrementAction
|
216
|
-
assert slider.value > val
|
217
|
-
|
218
|
-
val = slider.value
|
219
|
-
slider.perform KAXDecrementAction
|
220
|
-
assert slider.value < val
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_action_handles_errors
|
224
|
-
assert_raises(ArgumentError) { REF.perform nil }
|
225
|
-
end
|
226
|
-
|
227
|
-
##
|
228
|
-
# The keyboard simulation stuff is a bit weird...
|
229
|
-
|
230
|
-
def test_post
|
231
|
-
events = [[0x56,true], [0x56,false], [0x54,true], [0x54,false]]
|
232
|
-
string = '42'
|
233
|
-
|
234
|
-
search_box.set KAXFocusedAttribute, true
|
235
|
-
REF.post events
|
236
|
-
|
237
|
-
assert_equal string, search_box.value
|
238
|
-
|
239
|
-
ensure # reset for next test
|
240
|
-
search_box.set KAXValueAttribute, ''
|
241
|
-
end
|
242
|
-
|
243
|
-
##
|
244
|
-
# Kind of a bad test right now because the method itself
|
245
|
-
# lacks certain functionality that needs to be added...
|
246
|
-
|
247
|
-
def test_element_at
|
248
|
-
point = no_button.attribute(KAXPositionAttribute)
|
249
|
-
|
250
|
-
element = REF.element_at point
|
251
|
-
assert_equal no_button, element, "#{no_button.inspect} and #{element.inspect}"
|
252
|
-
|
253
|
-
element = REF.system_wide.element_at point
|
254
|
-
assert_equal no_button, element, "#{no_button.inspect} and #{element.inspect}"
|
255
|
-
|
256
|
-
assert_respond_to element, :role
|
257
|
-
end
|
258
|
-
|
259
|
-
# def test_element_at_returns_nil_on_empty_space
|
260
|
-
# skip 'How do I guarantee an empty space on screen?'
|
261
|
-
# # btw, [0,0] returns something
|
262
|
-
# end
|
263
|
-
|
264
|
-
def test_application_for
|
265
|
-
# @note Should call CFEqual() under the hood, which is what we want
|
266
|
-
assert_equal REF, REF.application_for(PID)
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_application_for_raises_for_bad_pid
|
270
|
-
assert_raises(ArgumentError) { REF.application_for 0 }
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_observer
|
274
|
-
assert_equal AXObserverGetTypeID(), CFGetTypeID(REF.observer { })
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_observer_handles_errors
|
278
|
-
assert_raises(ArgumentError) { REF.observer }
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_run_loop_source_for
|
282
|
-
obsrvr = REF.observer { |_,_,_| }
|
283
|
-
assert_equal CFRunLoopSourceGetTypeID(), CFGetTypeID(REF.run_loop_source_for(obsrvr))
|
284
|
-
end
|
285
|
-
|
286
|
-
# # more than meets the eye
|
287
|
-
def test_notification_registration_and_unregistration
|
288
|
-
obsrvr = REF.observer { |_,_,_| }
|
289
|
-
assert REF.register(obsrvr, KAXWindowCreatedNotification)
|
290
|
-
assert REF.unregister(obsrvr, KAXWindowCreatedNotification)
|
291
|
-
end
|
292
|
-
|
293
|
-
# integration-y
|
294
|
-
def test_notification_registers_everything_correctly
|
295
|
-
obsrvr = REF.observer do |observer, element, notif|
|
296
|
-
@notif_triple = [observer, element, notif]
|
297
|
-
end
|
298
|
-
REF.register observer, 'Cheezburger'
|
299
|
-
source = REF.run_loop_source_for observer
|
300
|
-
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, KCFRunLoopDefaultMode)
|
301
|
-
|
302
|
-
yes_button.perform KAXPressAction
|
303
|
-
yes_button.spin_run_loop
|
304
|
-
|
305
|
-
assert_equal [obsrvr, yes_button, 'Cheezburger'], @notif_triple
|
306
|
-
|
307
|
-
ensure
|
308
|
-
return unless source
|
309
|
-
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, KCFRunLoopDefaultMode)
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_register_handles_errors
|
313
|
-
assert_raises(ArgumentError) {
|
314
|
-
REF.register(nil, KAXWindowCreatedNotification)
|
315
|
-
}
|
316
|
-
assert_raises(ArgumentError) {
|
317
|
-
obsrvr = REF.observer { |_,_,_| }
|
318
|
-
REF.register(obsrvr, nil)
|
319
|
-
}
|
320
|
-
end
|
321
|
-
|
322
|
-
def test_unregister_handles_errors
|
323
|
-
assert_raises(ArgumentError) {
|
324
|
-
REF.unregister(nil, KAXWindowCreatedNotification)
|
325
|
-
}
|
326
|
-
assert_raises(ArgumentError) {
|
327
|
-
obsrvr = REF.observer { |_,_,_| }
|
328
|
-
REF.unregister(obsrvr, nil)
|
329
|
-
}
|
330
|
-
end
|
331
|
-
|
332
|
-
def test_system_wide
|
333
|
-
assert_equal AXUIElementCreateSystemWide(), REF.system_wide
|
334
|
-
end
|
335
|
-
|
336
|
-
def test_application
|
337
|
-
assert_equal REF, REF.application
|
338
|
-
assert_equal REF, window.application
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_set_timeout_for
|
342
|
-
assert_equal 10, REF.set_timeout_to(10)
|
343
|
-
assert_equal 0, REF.set_timeout_to(0)
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_handle_error_failsafe
|
347
|
-
assert_error [99],
|
348
|
-
should_raise: RuntimeError,
|
349
|
-
with_fragments: [/never reach this line/, /99/]
|
350
|
-
end
|
351
|
-
|
352
|
-
def test_handle_failure
|
353
|
-
assert_error [KAXErrorFailure],
|
354
|
-
should_raise: RuntimeError,
|
355
|
-
with_fragments: [/system failure/, app]
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_handle_illegal_argument
|
359
|
-
assert_error [KAXErrorIllegalArgument],
|
360
|
-
should_raise: ArgumentError,
|
361
|
-
with_fragments: [/is not an AXUIElementRef/, app]
|
362
|
-
|
363
|
-
assert_error [KAXErrorIllegalArgument, :cake],
|
364
|
-
should_raise: ArgumentError,
|
365
|
-
with_fragments: [/is not a legal argument/, /the element/, app, /cake/]
|
366
|
-
|
367
|
-
assert_error [KAXErrorIllegalArgument, 'cake', 'chocolate'],
|
368
|
-
should_raise: ArgumentError,
|
369
|
-
with_fragments: [/can't get\/set "cake" with\/to "chocolate"/, app]
|
370
|
-
|
371
|
-
p = CGPoint.new(1,3)
|
372
|
-
assert_error [KAXErrorIllegalArgument, p, nil, nil],
|
373
|
-
should_raise: ArgumentError,
|
374
|
-
with_fragments: [/The point #{p.inspect}/, app]
|
375
|
-
|
376
|
-
assert_error [KAXErrorIllegalArgument, 'cheezburger', 'cake', nil, nil],
|
377
|
-
should_raise: ArgumentError,
|
378
|
-
with_fragments: [/the observer "cake"/,app,/the notification "cheezburger"/]
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_handle_invalid_element
|
382
|
-
assert_error [KAXErrorInvalidUIElement],
|
383
|
-
should_raise: ArgumentError,
|
384
|
-
with_fragments: [/no longer a valid reference/, app]
|
385
|
-
end
|
386
|
-
|
387
|
-
def test_handle_invalid_observer
|
388
|
-
assert_error [KAXErrorInvalidUIElementObserver, :pie, :cake],
|
389
|
-
should_raise: ArgumentError,
|
390
|
-
with_fragments: [/no longer a valid observer/, /or was never valid/, app, /cake/]
|
391
|
-
end
|
392
|
-
|
393
|
-
def test_handle_cannot_complete
|
394
|
-
assert_error [KAXErrorCannotComplete],
|
395
|
-
should_raise: RuntimeError,
|
396
|
-
with_fragments: [/An unspecified error/, app, /:\(/]
|
397
|
-
|
398
|
-
@derp = REF.application_for pid_for 'com.apple.finder'
|
399
|
-
def @derp.pid; false end
|
400
|
-
assert_error [KAXErrorCannotComplete],
|
401
|
-
should_raise: RuntimeError,
|
402
|
-
with_fragments: [/Application for pid/, /Maybe it crashed\?/]
|
403
|
-
end
|
404
|
-
|
405
|
-
def test_attr_unsupported
|
406
|
-
assert_error [KAXErrorAttributeUnsupported, :cake],
|
407
|
-
should_raise: ArgumentError,
|
408
|
-
with_fragments: [/does not have/, /:cake attribute/, app]
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_action_unsupported
|
412
|
-
assert_error [KAXErrorActionUnsupported, :pie],
|
413
|
-
should_raise: ArgumentError,
|
414
|
-
with_fragments: [/does not have/, /:pie action/, app]
|
415
|
-
end
|
416
|
-
|
417
|
-
def test_notif_unsupported
|
418
|
-
assert_error [KAXErrorNotificationUnsupported, :cheese],
|
419
|
-
should_raise: ArgumentError,
|
420
|
-
with_fragments: [/does not support/, /:cheese notification/, app]
|
421
|
-
end
|
422
|
-
|
423
|
-
def test_not_implemented
|
424
|
-
assert_error [KAXErrorNotImplemented],
|
425
|
-
should_raise: NotImplementedError,
|
426
|
-
with_fragments: [/does not work with AXAPI/, app]
|
427
|
-
end
|
428
|
-
|
429
|
-
def test_notif_registered
|
430
|
-
assert_error [KAXErrorNotificationAlreadyRegistered, :lamp],
|
431
|
-
should_raise: ArgumentError,
|
432
|
-
with_fragments: [/already registered/, /:lamp/, app]
|
433
|
-
end
|
434
|
-
|
435
|
-
def test_notif_not_registered
|
436
|
-
assert_error [KAXErrorNotificationNotRegistered, :peas],
|
437
|
-
should_raise: RuntimeError,
|
438
|
-
with_fragments: [/not registered/, /:peas/, app]
|
439
|
-
end
|
440
|
-
|
441
|
-
def test_api_disabled
|
442
|
-
assert_error [KAXErrorAPIDisabled],
|
443
|
-
should_raise: RuntimeError,
|
444
|
-
with_fragments: [/AXAPI has been disabled/]
|
445
|
-
end
|
446
|
-
|
447
|
-
def test_param_attr_unsupported
|
448
|
-
assert_error [KAXErrorParameterizedAttributeUnsupported, :oscar],
|
449
|
-
should_raise: ArgumentError,
|
450
|
-
with_fragments: [/does not have/, /:oscar parameterized attribute/, app]
|
451
|
-
end
|
452
|
-
|
453
|
-
def test_not_enough_precision
|
454
|
-
assert_error [KAXErrorNotEnoughPrecision],
|
455
|
-
should_raise: RuntimeError,
|
456
|
-
with_fragments: [/not enough precision/, '¯\(°_o)/¯']
|
457
|
-
end
|
458
|
-
|
459
|
-
end
|
460
|
-
|
461
|
-
|
462
|
-
class TestToAXToRubyHooks < MiniTest::Unit::TestCase
|
463
|
-
|
464
|
-
def test_to_ax
|
465
|
-
# point_makes_a_value
|
466
|
-
value = CGPointZero.to_ax
|
467
|
-
ptr = Pointer.new CGPoint.type
|
468
|
-
AXValueGetValue(value, 1, ptr)
|
469
|
-
assert_equal CGPointZero, ptr.value
|
470
|
-
|
471
|
-
# size_makes_a_value
|
472
|
-
value = CGSizeZero.to_ax
|
473
|
-
ptr = Pointer.new CGSize.type
|
474
|
-
AXValueGetValue(value, 2, ptr)
|
475
|
-
assert_equal CGSizeZero, ptr.value
|
476
|
-
|
477
|
-
# rect_makes_a_value
|
478
|
-
value = CGRectZero.to_ax
|
479
|
-
ptr = Pointer.new CGRect.type
|
480
|
-
AXValueGetValue(value, 3, ptr)
|
481
|
-
assert_equal CGRectZero, ptr.value
|
482
|
-
|
483
|
-
# range_makes_a_value
|
484
|
-
range = CFRange.new(5, 4)
|
485
|
-
value = range.to_ax
|
486
|
-
ptr = Pointer.new CFRange.type
|
487
|
-
AXValueGetValue(value, 4, ptr)
|
488
|
-
assert_equal range, ptr.value
|
489
|
-
end
|
490
|
-
|
491
|
-
def test_to_axvalue_raises_for_unsupported_boxes
|
492
|
-
assert_raises(NotImplementedError) { NSEdgeInsets.new.to_ax }
|
493
|
-
end
|
494
|
-
|
495
|
-
def test_to_ax_for_ranges
|
496
|
-
assert_equal CFRangeMake(1,10).to_ax, (1..10 ).to_ax
|
497
|
-
assert_equal CFRangeMake(1, 9).to_ax, (1...10 ).to_ax
|
498
|
-
assert_equal CFRangeMake(0, 3).to_ax, (0..2 ).to_ax
|
499
|
-
end
|
500
|
-
|
501
|
-
def test_to_axvalue_for_ranges_raises_for_bad_ranges
|
502
|
-
assert_raises(ArgumentError) { (1..-10).to_ax }
|
503
|
-
assert_raises(ArgumentError) { (-5...10).to_ax }
|
504
|
-
end
|
505
|
-
|
506
|
-
def test_to_ax_on_other_objects
|
507
|
-
obj = Object.new
|
508
|
-
assert_equal obj.self, obj.to_ax
|
509
|
-
end
|
510
|
-
|
511
|
-
|
512
|
-
def test_to_ruby
|
513
|
-
assert_equal CGPointZero, CGPointZero .to_ax.to_ruby
|
514
|
-
assert_equal CGSize.new(10,10), CGSize.new(10,10).to_ax.to_ruby
|
515
|
-
assert_equal Range.new(1,10), CFRange.new(1,10).to_ax.to_ruby
|
516
|
-
end
|
517
|
-
|
518
|
-
def test_to_ruby_on_non_boxes
|
519
|
-
obj = Object.new
|
520
|
-
assert_equal obj.self, obj.to_ruby
|
521
|
-
end
|
522
|
-
|
523
|
-
end
|
524
|
-
|
525
|
-
|
526
|
-
class TestMiscCoreExtensions < MiniTest::Unit::TestCase
|
527
|
-
|
528
|
-
def test_to_point
|
529
|
-
p = CGPoint.new(2,3)
|
530
|
-
assert_equal p, p.to_point
|
531
|
-
|
532
|
-
p = CGPoint.new(1,3)
|
533
|
-
assert_equal p, p.to_a.to_point
|
534
|
-
end
|
535
|
-
|
536
|
-
def test_to_size
|
537
|
-
s = CGSize.new(2,4)
|
538
|
-
assert_equal s, s.to_a.to_size
|
539
|
-
end
|
540
|
-
|
541
|
-
def test_to_rect
|
542
|
-
r = CGRectMake(6, 7, 8, 9)
|
543
|
-
assert_equal r, r.to_a.map(&:to_a).flatten.to_rect
|
544
|
-
end
|
545
|
-
|
546
|
-
def test_to_url
|
547
|
-
site = 'http://marketcircle.com/'
|
548
|
-
url = site.to_url
|
549
|
-
refute_nil url
|
550
|
-
assert_equal NSURL.URLWithString(site), url
|
551
|
-
|
552
|
-
file = 'file://localhost/Applications/Calculator.app/'
|
553
|
-
url = file.to_url
|
554
|
-
refute_nil url
|
555
|
-
assert_equal NSURL.fileURLWithPath('/Applications/Calculator.app/'), url
|
556
|
-
|
557
|
-
void = "not a url at all"
|
558
|
-
assert_nil void.to_url
|
559
|
-
end
|
560
|
-
|
561
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test/runner'
|
2
|
-
require 'accessibility/highlighter'
|
3
|
-
|
4
|
-
class TestHighlighter < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
def bounds
|
7
|
-
CGRectMake(100, 100, 100, 100)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_highlight_returns_created_window
|
11
|
-
w = Accessibility::Highlighter.new bounds
|
12
|
-
assert_kind_of NSWindow, w
|
13
|
-
assert_respond_to w, :stop
|
14
|
-
ensure
|
15
|
-
w.close if w
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_highlight_can_take_a_timeout
|
19
|
-
w = Accessibility::Highlighter.new bounds, timeout: 0.1
|
20
|
-
assert w.visible?
|
21
|
-
sleep 0.15
|
22
|
-
refute w.visible? # Not exactly the assertion I want, but close enough
|
23
|
-
ensure
|
24
|
-
w.close if w
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_highlight_can_have_custom_colour
|
28
|
-
w = Accessibility::Highlighter.new bounds, color: NSColor.cyanColor
|
29
|
-
assert w.backgroundColor == NSColor.cyanColor
|
30
|
-
w.close
|
31
|
-
|
32
|
-
# test both spellings of colour
|
33
|
-
w = Accessibility::Highlighter.new bounds, colour: NSColor.purpleColor
|
34
|
-
assert w.backgroundColor == NSColor.purpleColor
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_highlight_highlights_correct_rect
|
38
|
-
w = Accessibility::Highlighter.new bounds
|
39
|
-
assert_equal w.frame, bounds.flip!
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class TestCGRectExtensions < MiniTest::Unit::TestCase
|
45
|
-
|
46
|
-
def test_flipping
|
47
|
-
size = NSScreen.mainScreen.frame.size
|
48
|
-
assert_equal CGRectMake(0, size.height, 0, 0), CGRectZero.dup.flip!
|
49
|
-
assert_equal CGRectMake(100, size.height-200, 100, 100), CGRectMake(100,100,100,100).flip!
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_flipping_twice_returns_to_original
|
53
|
-
assert_equal CGRectZero.dup, CGRectZero.dup.flip!.flip!
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'test/runner'
|
2
|
-
require 'minitest/ax_elements'
|
3
|
-
|
4
|
-
class TestMiniTestAssertions < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
def test_methods_are_loaded
|
7
|
-
assert_respond_to self, :assert_has_child
|
8
|
-
assert_respond_to self, :assert_has_descendent
|
9
|
-
assert_respond_to self, :assert_has_descendant
|
10
|
-
assert_respond_to self, :assert_shortly_has
|
11
|
-
assert_respond_to self, :refute_has_child
|
12
|
-
assert_respond_to self, :refute_has_descendent
|
13
|
-
assert_respond_to self, :refute_has_descendant
|
14
|
-
assert_respond_to self, :refute_shortly_has
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'test/runner'
|
2
|
-
require 'rspec/expectations/ax_elements'
|
3
|
-
|
4
|
-
class TestRSpecMatchers < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
def test_defined
|
7
|
-
assert TopLevel.method(:have_child)
|
8
|
-
assert TopLevel.method(:have_descendent)
|
9
|
-
assert TopLevel.method(:have_descendant)
|
10
|
-
assert TopLevel.method(:shortly_have_child)
|
11
|
-
assert TopLevel.method(:shortly_have_descendent)
|
12
|
-
assert TopLevel.method(:shortly_have_descendant)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
data/test/sanity/test_mouse.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class TestMouseModule < MiniTest::Unit::TestCase
|
2
|
-
|
3
|
-
def distance point1, point2
|
4
|
-
x = point1.x - point2.x
|
5
|
-
y = point1.y - point2.y
|
6
|
-
Math.sqrt((x**2) + (y**2))
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_move_to
|
10
|
-
point = CGPoint.new(100, 100)
|
11
|
-
Mouse.move_to point
|
12
|
-
assert_in_delta 0, distance(point,Mouse.current_position), 1.0
|
13
|
-
|
14
|
-
point = CGPoint.new(rand(700)+150, rand(500)+100)
|
15
|
-
Mouse.move_to point
|
16
|
-
assert_in_delta 0, distance(point,Mouse.current_position), 1.0
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|