AXElements 0.6.0beta1
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 +20 -0
- data/LICENSE.txt +25 -0
- data/README.markdown +150 -0
- data/Rakefile +109 -0
- data/docs/AccessibilityTips.markdown +119 -0
- data/docs/Acting.markdown +340 -0
- data/docs/Debugging.markdown +326 -0
- data/docs/Inspecting.markdown +255 -0
- data/docs/KeyboardEvents.markdown +57 -0
- data/docs/NewBehaviour.markdown +151 -0
- data/docs/Notifications.markdown +271 -0
- data/docs/Searching.markdown +250 -0
- data/docs/TestingExtensions.markdown +52 -0
- data/docs/images/AX.png +0 -0
- data/docs/images/all_the_buttons.jpg +0 -0
- data/docs/images/ui_hierarchy.dot +34 -0
- data/docs/images/ui_hierarchy.png +0 -0
- data/ext/key_coder/extconf.rb +6 -0
- data/ext/key_coder/key_coder.m +77 -0
- data/lib/ax_elements/accessibility/enumerators.rb +104 -0
- data/lib/ax_elements/accessibility/language.rb +347 -0
- data/lib/ax_elements/accessibility/qualifier.rb +73 -0
- data/lib/ax_elements/accessibility.rb +164 -0
- data/lib/ax_elements/core.rb +541 -0
- data/lib/ax_elements/element.rb +593 -0
- data/lib/ax_elements/elements/application.rb +88 -0
- data/lib/ax_elements/elements/button.rb +18 -0
- data/lib/ax_elements/elements/radio_button.rb +18 -0
- data/lib/ax_elements/elements/row.rb +30 -0
- data/lib/ax_elements/elements/static_text.rb +17 -0
- data/lib/ax_elements/elements/systemwide.rb +46 -0
- data/lib/ax_elements/inspector.rb +116 -0
- data/lib/ax_elements/macruby_extensions.rb +255 -0
- data/lib/ax_elements/notification.rb +37 -0
- data/lib/ax_elements/version.rb +9 -0
- data/lib/ax_elements.rb +30 -0
- data/lib/minitest/ax_elements.rb +19 -0
- data/lib/mouse.rb +185 -0
- data/lib/rspec/expectations/ax_elements.rb +15 -0
- data/test/elements/test_application.rb +72 -0
- data/test/elements/test_row.rb +27 -0
- data/test/elements/test_systemwide.rb +38 -0
- data/test/helper.rb +119 -0
- data/test/test_accessibility.rb +127 -0
- data/test/test_blankness.rb +26 -0
- data/test/test_core.rb +448 -0
- data/test/test_element.rb +939 -0
- data/test/test_enumerators.rb +81 -0
- data/test/test_inspector.rb +121 -0
- data/test/test_language.rb +157 -0
- data/test/test_macruby_extensions.rb +303 -0
- data/test/test_mouse.rb +5 -0
- data/test/test_search_semantics.rb +143 -0
- metadata +219 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class TestAccessibilityBFEnumerator < TestAX
|
4
|
+
|
5
|
+
APP = AX::Application.new REF, AX.attrs_of_element(REF)
|
6
|
+
|
7
|
+
def test_each_iterates_in_correct_order
|
8
|
+
tab_group = APP.main_window.children.find { |x| x.class == AX::TabGroup }
|
9
|
+
enum = Accessibility::BFEnumerator.new(tab_group)
|
10
|
+
actual = enum.map &:class
|
11
|
+
expected = [
|
12
|
+
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
13
|
+
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
14
|
+
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
15
|
+
AX::RadioButton, AX::RadioButton, AX::Group,
|
16
|
+
AX::TextField, AX::TextField,
|
17
|
+
AX::StaticText, AX::StaticText
|
18
|
+
]
|
19
|
+
assert_equal expected, actual
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_first_element_is_first_child # not the root
|
23
|
+
enum = Accessibility::BFEnumerator.new(APP)
|
24
|
+
def enum.first
|
25
|
+
each { |x| return x }
|
26
|
+
end
|
27
|
+
assert_instance_of AX::StandardWindow, enum.first
|
28
|
+
end
|
29
|
+
|
30
|
+
# this was a "bug", so we should make sure it doesn't come back
|
31
|
+
def test_find_returns_immediately_after_finding
|
32
|
+
tree = Accessibility::BFEnumerator.new(APP.attribute(:main_window))
|
33
|
+
cache = []
|
34
|
+
tree.find do |element|
|
35
|
+
cache << element.class.to_s
|
36
|
+
element.class == AX::Slider
|
37
|
+
end
|
38
|
+
refute_includes cache, 'AX::ValueIndicator'
|
39
|
+
refute_includes cache, 'AX::IncrementArrow'
|
40
|
+
assert_includes cache, 'AX::Slider'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class TestAccessibilityDFEnumerator < TestAX
|
47
|
+
|
48
|
+
APP = AX::Application.new REF, AX.attrs_of_element(REF)
|
49
|
+
|
50
|
+
def test_each_iterates_in_correct_order
|
51
|
+
tab_group = APP.main_window.children.find { |x| x.class == AX::TabGroup }
|
52
|
+
enum = Accessibility::DFEnumerator.new tab_group
|
53
|
+
actual = enum.map &:class
|
54
|
+
expected = [
|
55
|
+
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
56
|
+
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
57
|
+
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
58
|
+
AX::RadioButton, AX::RadioButton, AX::Group,
|
59
|
+
AX::TextField, AX::StaticText,
|
60
|
+
AX::TextField, AX::StaticText
|
61
|
+
]
|
62
|
+
assert_equal expected, actual
|
63
|
+
end
|
64
|
+
|
65
|
+
# since we have a different implementation, we should also verify order here...
|
66
|
+
def test_each_with_height_has_correct_height
|
67
|
+
enum = Accessibility::DFEnumerator.new APP.attribute(:main_window)
|
68
|
+
enum.each_with_height do |element, height|
|
69
|
+
# msg = element.inspect # for debugging, otherwise makes test too intense for MacRuby
|
70
|
+
case element.class.to_s
|
71
|
+
when 'AX::CloseButton','AX::ZoomButton','AX::Slider','AX::RadioGroup','AX::ScrollArea','AX::CheckBox','AX::Incrementor','AX::SearchField'
|
72
|
+
assert_equal 1, height
|
73
|
+
when 'AX::WebArea','AX::Table','AX::ScrollBar'
|
74
|
+
assert_equal 2, height
|
75
|
+
when 'AX::SortButton'
|
76
|
+
assert_equal 4, height
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class TestPPInspector < MiniTest::Unit::TestCase
|
4
|
+
include Accessibility::PPInspector
|
5
|
+
|
6
|
+
# expected API for PPInspector module
|
7
|
+
def attributes ; @attributes end
|
8
|
+
def attribute attr; @attribute end
|
9
|
+
def size_of attr; @size_of end
|
10
|
+
|
11
|
+
# trivial but important for backwards compat with Snow Leopard
|
12
|
+
def test_identifier_const
|
13
|
+
assert Accessibility::PPInspector.const_defined? :KAXIdentifierAttribute
|
14
|
+
assert_equal 'AXIdentifier', KAXIdentifierAttribute
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_identifier_using_value
|
18
|
+
@attributes = [KAXValueAttribute]
|
19
|
+
|
20
|
+
@attribute = 'cake'
|
21
|
+
assert_match /cake/, pp_identifier
|
22
|
+
|
23
|
+
@attribute = 3.14
|
24
|
+
assert_match /value=3.14/, pp_identifier
|
25
|
+
|
26
|
+
@attribute = ''
|
27
|
+
assert_match NSString.string, pp_identifier
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_identifier_using_title
|
31
|
+
@attributes = [KAXTitleAttribute]
|
32
|
+
@attribute = 'My Title'
|
33
|
+
assert_match /"My Title"/, pp_identifier
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_identifier_using_title_ui_element
|
37
|
+
@attributes = [KAXTitleUIElementAttribute]
|
38
|
+
@attribute = 'hey'
|
39
|
+
assert_match /"hey"/, pp_identifier
|
40
|
+
end
|
41
|
+
|
42
|
+
# hmmm...
|
43
|
+
def test_identifier_using_description
|
44
|
+
@attributes = [KAXDescriptionAttribute]
|
45
|
+
|
46
|
+
@attribute = 'roflcopter'
|
47
|
+
assert_match /roflcopter/, pp_identifier
|
48
|
+
|
49
|
+
@attribute = NSString.string
|
50
|
+
assert_equal NSString.string, pp_identifier
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_identifier_using_identifier
|
54
|
+
@attributes = [KAXIdentifierAttribute]
|
55
|
+
|
56
|
+
@attribute = '_NS:151'
|
57
|
+
assert_match /_NS:151/, pp_identifier
|
58
|
+
|
59
|
+
@attribute = 'contact table'
|
60
|
+
assert_match /contact table/, pp_identifier
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_identifier_empty_string_as_final_fallback
|
64
|
+
@attributes = NSArray.array
|
65
|
+
assert_equal NSString.string, pp_identifier
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_position
|
69
|
+
@attribute = CGPointZero
|
70
|
+
assert_match /\(0\.0, 0\.0\)/, pp_position
|
71
|
+
|
72
|
+
@attribute = CGPoint.new(3.14, -5)
|
73
|
+
assert_match /\(3\.14, -5\.0\)/, pp_position
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_children_pluralizes_properly
|
77
|
+
@size_of = 2
|
78
|
+
assert_match /2 children/, pp_children
|
79
|
+
|
80
|
+
@size_of = 9001
|
81
|
+
assert_match /9001 children/, pp_children
|
82
|
+
|
83
|
+
@size_of = 3.14
|
84
|
+
assert_match /3.14 children/, pp_children
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_children_count
|
88
|
+
@size_of = 1
|
89
|
+
assert_match /1 child/, pp_children
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_children_void_if_none
|
93
|
+
@size_of = 0
|
94
|
+
assert_equal NSString.string, pp_children
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_checkbox_includes_attribute_name_and_box
|
98
|
+
@attribute = true
|
99
|
+
assert_match /thing\[.\]/, pp_checkbox(:thing)
|
100
|
+
assert_match /cake\[.\]/, pp_checkbox(:cake)
|
101
|
+
assert_match /pie\[.\]/, pp_checkbox(:pie)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_checkbox_uses_checks_properly
|
105
|
+
check = /✔/
|
106
|
+
cross = /✘/
|
107
|
+
|
108
|
+
@attribute = true
|
109
|
+
assert_match check, pp_checkbox(:a)
|
110
|
+
|
111
|
+
@attribute = :cake
|
112
|
+
assert_match check, pp_checkbox(:a)
|
113
|
+
|
114
|
+
@attribute = false
|
115
|
+
assert_match cross, pp_checkbox(:a)
|
116
|
+
|
117
|
+
@attribute = nil
|
118
|
+
assert_match cross, pp_checkbox(:a)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
class TestAccessibilityLanguageActions < TestAX
|
2
|
+
|
3
|
+
# LSP FTW
|
4
|
+
class Language
|
5
|
+
include Accessibility::Language
|
6
|
+
end
|
7
|
+
|
8
|
+
# mocking like a pro
|
9
|
+
class LanguageTest < AX::Element
|
10
|
+
attr_reader :called_action
|
11
|
+
def perform_action name
|
12
|
+
@called_action = name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@language = Language.new
|
18
|
+
@element = LanguageTest.new REF, AX.attrs_of_element(REF)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_static_actions_forward
|
22
|
+
@language.cancel @element
|
23
|
+
assert_equal :cancel, @element.called_action
|
24
|
+
|
25
|
+
@language.confirm @element
|
26
|
+
assert_equal :confirm, @element.called_action
|
27
|
+
|
28
|
+
@language.decrement @element
|
29
|
+
assert_equal :decrement, @element.called_action
|
30
|
+
|
31
|
+
@language.delete @element
|
32
|
+
assert_equal :delete, @element.called_action
|
33
|
+
|
34
|
+
@language.increment @element
|
35
|
+
assert_equal :increment, @element.called_action
|
36
|
+
|
37
|
+
@language.pick @element
|
38
|
+
assert_equal :pick, @element.called_action
|
39
|
+
|
40
|
+
@language.press @element
|
41
|
+
assert_equal :press, @element.called_action
|
42
|
+
|
43
|
+
@language.cancel @element
|
44
|
+
assert_equal :cancel, @element.called_action
|
45
|
+
|
46
|
+
@language.raise @element
|
47
|
+
assert_equal :raise, @element.called_action
|
48
|
+
|
49
|
+
@language.show_menu @element
|
50
|
+
assert_equal :show_menu, @element.called_action
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_method_missing_forwards
|
54
|
+
@language.zomg_method @element
|
55
|
+
assert_equal :zomg_method, @element.called_action
|
56
|
+
|
57
|
+
assert_raises NoMethodError do
|
58
|
+
@language.zomg_method 'bacon'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_raise_can_still_raise_exceptions
|
63
|
+
assert_raises ArgumentError do
|
64
|
+
@language.raise ArgumentError
|
65
|
+
end
|
66
|
+
assert_raises NoMethodError do
|
67
|
+
@language.raise NoMethodError
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class TestAccessibilityLanguage < TestAX
|
74
|
+
|
75
|
+
def test_set_focus
|
76
|
+
window = attribute_for(REF, KAXMainWindowAttribute)
|
77
|
+
group = children_for(window).find do |element|
|
78
|
+
attribute_for(element,KAXRoleAttribute) == KAXRadioGroupRole
|
79
|
+
end
|
80
|
+
buttons = children_for group
|
81
|
+
# @todo swich focus between radio buttons in the radio group
|
82
|
+
end
|
83
|
+
|
84
|
+
# def test_set_arbitrary_attribute
|
85
|
+
# end
|
86
|
+
|
87
|
+
# def test_set_value
|
88
|
+
# end
|
89
|
+
|
90
|
+
# def test_type_sends_to_system_by_default
|
91
|
+
# end
|
92
|
+
|
93
|
+
# def test_type_can_send_to_arbitrary_applications
|
94
|
+
# end
|
95
|
+
|
96
|
+
# def test_register_for_notification_forwards_to_element
|
97
|
+
# end
|
98
|
+
|
99
|
+
# def test_wait_for_notification_forwards
|
100
|
+
# end
|
101
|
+
|
102
|
+
# def test_wait_for_notification_has_default
|
103
|
+
# end
|
104
|
+
|
105
|
+
# def test_move_mouse_to_accepts_many_inputs_but_forwards_cgpoint
|
106
|
+
# end
|
107
|
+
|
108
|
+
# def test_drag_mouse_accepts_many_inputs_but_forwards_cgpoint
|
109
|
+
# end
|
110
|
+
|
111
|
+
# def test_scroll_moves_mouse_to_object_first_if_given
|
112
|
+
# end
|
113
|
+
|
114
|
+
# def test_scroll_forwards_properly
|
115
|
+
# end
|
116
|
+
|
117
|
+
# def test_click_moves_mouse_to_object_first
|
118
|
+
# end
|
119
|
+
|
120
|
+
# def test_click_forwards
|
121
|
+
# end
|
122
|
+
|
123
|
+
# def test_right_click_moves_mouse_to_object_first
|
124
|
+
# end
|
125
|
+
|
126
|
+
# def test_right_click_forwards
|
127
|
+
# end
|
128
|
+
|
129
|
+
# def test_right_click_alias
|
130
|
+
# end
|
131
|
+
|
132
|
+
# def test_double_click_moves_mouse_to_object_first
|
133
|
+
# end
|
134
|
+
|
135
|
+
# def test_double_click_forwards
|
136
|
+
# end
|
137
|
+
|
138
|
+
# def test_show_about_window_for
|
139
|
+
# end
|
140
|
+
|
141
|
+
# def test_preferences_window_for
|
142
|
+
# end
|
143
|
+
|
144
|
+
def test_language_is_available_everywhere
|
145
|
+
assert_includes Object.new.class.ancestors, Accessibility::Language
|
146
|
+
assert_includes TopLevel.ancestors, Accessibility::Language
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_callbacks_are_unregistered_when_a_timeout_occurs
|
150
|
+
skip
|
151
|
+
AX.register_for_notif
|
152
|
+
refute_empty AX.notifs.keys
|
153
|
+
AX.wait_for_notification short_timeout
|
154
|
+
assert_empty AX.notifs.keys
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
class TestNSArrayAccessors < MiniTest::Unit::TestCase
|
2
|
+
|
3
|
+
def test_second_returns_second_from_array
|
4
|
+
[[1,2],[:one,:two]].each { |array|
|
5
|
+
assert_equal array.last, NSArray.arrayWithArray(array).second
|
6
|
+
assert_equal array.last, array.second
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_second_returns_nil_from_array_of_one
|
11
|
+
[[1], [:one]].each { |array|
|
12
|
+
assert_nil NSArray.arrayWithArray(array).second
|
13
|
+
assert_nil array.second
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_second_returns_second_from_array
|
18
|
+
[[1,2,3],[:one,:two,:three]].each { |array|
|
19
|
+
assert_equal array.last, NSArray.arrayWithArray(array).third
|
20
|
+
assert_equal array.last, array.third
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_second_returns_nil_from_array_of_two
|
25
|
+
[[1,2], [:one,:two]].each { |array|
|
26
|
+
assert_nil NSArray.arrayWithArray(array).third
|
27
|
+
assert_nil array.third
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
class TestNSArrayToPoint < MiniTest::Unit::TestCase
|
35
|
+
|
36
|
+
def test_makes_a_point
|
37
|
+
assert_instance_of CGPoint, [1, 1].to_point
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_uses_first_two_elements
|
41
|
+
assert_equal CGPoint.new(1,2), NSArray.arrayWithArray([1, 2, 3]).to_point
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
class TestNSArrayToSize < MiniTest::Unit::TestCase
|
48
|
+
|
49
|
+
def test_makes_a_point
|
50
|
+
assert_instance_of CGSize, [1, 1].to_size
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_uses_first_two_elements
|
54
|
+
assert_equal CGSize.new(1,2), NSArray.arrayWithArray([1, 2, 3]).to_size
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class TestNSArrayToRect < MiniTest::Unit::TestCase
|
61
|
+
|
62
|
+
def test_makes_a_rect
|
63
|
+
assert_instance_of CGRect, [1, 1, 1, 1].to_rect
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_uses_first_two_elements
|
67
|
+
expected = CGRect.new(CGPoint.new(4,3),CGSize.new(2,5))
|
68
|
+
actual = NSArray.arrayWithArray([4, 3, 2, 5, 7]).to_rect
|
69
|
+
assert_equal expected, actual
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
class TestNSStringCamelize < MiniTest::Unit::TestCase
|
76
|
+
|
77
|
+
def test_takes_snake_case_string_and_makes_it_camel_case
|
78
|
+
assert_equal 'AMethodName', 'a_method_name'.camelize
|
79
|
+
assert_equal 'MethodName', 'method_name'.camelize
|
80
|
+
assert_equal 'Name', 'name'.camelize
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_takes_camel_case_and_does_nothing
|
84
|
+
assert_equal 'AMethodName', 'AMethodName'.camelize
|
85
|
+
assert_equal 'MethodName', 'MethodName'.camelize
|
86
|
+
assert_equal 'Name', 'Name'.camelize
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
class TestNSStringPredicate < MiniTest::Unit::TestCase
|
93
|
+
|
94
|
+
def test_true_if_string_ends_with_a_question_mark
|
95
|
+
assert 'test?'.predicate?
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_false_if_the_string_does_not_end_with_a_question_mark
|
99
|
+
refute 'tes?t'.predicate?
|
100
|
+
refute 'te?st'.predicate?
|
101
|
+
refute 't?est'.predicate?
|
102
|
+
refute '?test'.predicate?
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_false_if_the_string_has_no_question_mark
|
106
|
+
refute 'test'.predicate?
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
class TestNSStringSingularize < MiniTest::Unit::TestCase
|
113
|
+
|
114
|
+
# a better test might be to take the method and bind it into a
|
115
|
+
# different context where ActiveSupport::Inflector resolved to
|
116
|
+
# a mock class with a mocked version #singularize
|
117
|
+
def test_calls_active_support
|
118
|
+
assert_equal 'octopus', NSString.alloc.initWithString('octopi').singularize
|
119
|
+
assert_equal 'ox', NSString.alloc.initWithString('oxen').singularize
|
120
|
+
assert_equal 'box', NSString.alloc.initWithString('boxes').singularize
|
121
|
+
assert_equal 'box', NSString.alloc.initWithString('box').singularize
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
class TestNSArrayMethodMissing < MiniTest::Unit::TestCase
|
128
|
+
|
129
|
+
ELEMENTS = AX::DOCK.list.application_dock_items
|
130
|
+
|
131
|
+
def test_delegates_up_if_array_is_not_composed_of_elements
|
132
|
+
assert_raises NoMethodError do [1].title_ui_element end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_simple_attribute
|
136
|
+
refute_empty ELEMENTS.url.compact
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_artificially_plural_attribute
|
140
|
+
refute_empty ELEMENTS.urls.compact
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_naturally_plural_attribute
|
144
|
+
refute_empty ELEMENTS.children.compact
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_predicate_method
|
148
|
+
refute_empty ELEMENTS.application_running?.compact
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
class TestCGPointExtensions < MiniTest::Unit::TestCase
|
155
|
+
SCREENS = NSScreen.screens
|
156
|
+
MAIN_SCREEN = NSScreen.mainScreen
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
class TestCGPointCenterOfRect < TestCGPointExtensions
|
161
|
+
|
162
|
+
def test_unaltered_with_cgrectzero
|
163
|
+
assert_equal CGPointZero, CGPoint.center_of_rect(CGRectZero)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_middle_of_screen
|
167
|
+
frame = MAIN_SCREEN.frame
|
168
|
+
point = frame.origin.dup
|
169
|
+
point.x = frame.size.width / 2
|
170
|
+
point.y = frame.size.height / 2
|
171
|
+
assert_equal point, CGPoint.center_of_rect(frame)
|
172
|
+
end
|
173
|
+
|
174
|
+
def center_of_rect origin_x, origin_y, width, height
|
175
|
+
rect = CGRect.new(CGPoint.new(origin_x,origin_y), CGSize.new(width,height))
|
176
|
+
CGPoint.center_of_rect(rect)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_simple_square_with_origin_at_zero
|
180
|
+
point = center_of_rect(0.0, 0.0, 2.0, 2.0)
|
181
|
+
assert_equal 1, point.x
|
182
|
+
assert_equal 1, point.y
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_simple_square_in_positive_positive_quadrant
|
186
|
+
point = center_of_rect(1.0, 1.0, 6.0, 6.0)
|
187
|
+
assert_equal 4, point.x
|
188
|
+
assert_equal 4, point.y
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_rect_in_positive_positive_quadrant
|
192
|
+
point = center_of_rect(1.0, 2.0, 6.0, 10.0)
|
193
|
+
assert_equal 4, point.x
|
194
|
+
assert_equal 7, point.y
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_rect_in_negative_positive_quadrant
|
198
|
+
point = center_of_rect(-123.0, 25.0, 6.0, 10.0)
|
199
|
+
assert_equal -120, point.x
|
200
|
+
assert_equal 30, point.y
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_rect_starts_in_negative_positive_quadrant_but_is_in_positive_positive
|
204
|
+
point = center_of_rect(-10.0, 70.0, 20.0, 42.0)
|
205
|
+
assert_equal 0, point.x
|
206
|
+
assert_equal 91, point.y
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
class TestCGPointCenter < TestCGPointExtensions
|
213
|
+
|
214
|
+
def test_unaltered_with_cgrectzero
|
215
|
+
assert_equal CGPointZero, CGPointZero.center(CGSizeZero)
|
216
|
+
end
|
217
|
+
|
218
|
+
def center origin_x, origin_y, width, height
|
219
|
+
CGPoint.new(origin_x,origin_y).center CGSize.new(width,height)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_simple_square_with_origin_at_zero
|
223
|
+
point = center(0.0, 0.0, 2.0, 2.0)
|
224
|
+
assert_equal 1, point.x
|
225
|
+
assert_equal 1, point.y
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_simple_square_in_positive_positive_quadrant
|
229
|
+
point = center(1.0, 1.0, 6.0, 6.0)
|
230
|
+
assert_equal 4, point.x
|
231
|
+
assert_equal 4, point.y
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_rect_in_positive_positive_quadrant
|
235
|
+
point = center(1.0, 2.0, 6.0, 10.0)
|
236
|
+
assert_equal 4, point.x
|
237
|
+
assert_equal 7, point.y
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_rect_in_negative_positive_quadrant
|
241
|
+
point = center(-123.0, 25.0, 6.0, 10.0)
|
242
|
+
assert_equal -120, point.x
|
243
|
+
assert_equal 30, point.y
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_rect_starts_in_negative_positive_quadrant_but_is_in_positive_positive
|
247
|
+
point = center(-10.0, 70.0, 20.0, 42.0)
|
248
|
+
assert_equal 0, point.x
|
249
|
+
assert_equal 91, point.y
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
|
255
|
+
class TestCGPointToPoint < MiniTest::Unit::TestCase
|
256
|
+
|
257
|
+
def test_returns_self
|
258
|
+
assert_equal CGPointZero, CGPointZero.to_point
|
259
|
+
point = CGPoint.new(1, 1)
|
260
|
+
assert_equal point, point.to_point
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
class TestBoxedToAXValue < MiniTest::Unit::TestCase
|
267
|
+
|
268
|
+
def test_point_makes_a_value
|
269
|
+
value = CGPointZero.to_axvalue
|
270
|
+
ptr = Pointer.new CGPoint.type
|
271
|
+
AXValueGetValue(value, 1, ptr)
|
272
|
+
assert_equal CGPointZero, ptr[0]
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_size_makes_a_value
|
276
|
+
value = CGSizeZero.to_axvalue
|
277
|
+
ptr = Pointer.new CGSize.type
|
278
|
+
AXValueGetValue(value, 2, ptr)
|
279
|
+
assert_equal CGSizeZero, ptr[0]
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_rect_makes_a_value
|
283
|
+
value = CGRectZero.to_axvalue
|
284
|
+
ptr = Pointer.new CGRect.type
|
285
|
+
AXValueGetValue(value, 3, ptr)
|
286
|
+
assert_equal CGRectZero, ptr[0]
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_range_makes_a_value
|
290
|
+
range = CFRange.new(5, 4)
|
291
|
+
value = range.to_axvalue
|
292
|
+
ptr = Pointer.new CFRange.type
|
293
|
+
AXValueGetValue(value, 4, ptr)
|
294
|
+
assert_equal range, ptr[0]
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_values
|
298
|
+
[[CGPoint, 1], [CGSize, 2], [CGRect, 3], [CFRange, 4]].each do |klass, value|
|
299
|
+
assert_equal value, klass.instance_variable_get(:@ax_value)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|