Changeset View
Changeset View
Standalone View
Standalone View
drkonqi/tests/integration/test_helper.rb
- This file was added.
1 | # Copyright (C) 2017 Harald Sitter <sitter@kde.org> | ||||
---|---|---|---|---|---|
2 | # | ||||
3 | # This program is free software; you can redistribute it and/or | ||||
4 | # modify it under the terms of the GNU General Public License as | ||||
5 | # published by the Free Software Foundation; either version 2 of | ||||
6 | # the License or (at your option) version 3 or any later version | ||||
7 | # accepted by the membership of KDE e.V. (or its successor approved | ||||
8 | # by the membership of KDE e.V.), which shall act as a proxy | ||||
9 | # defined in Section 14 of version 3 of the license. | ||||
10 | # | ||||
11 | # This program is distributed in the hope that it will be useful, | ||||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | # GNU General Public License for more details. | ||||
15 | # | ||||
16 | # You should have received a copy of the GNU General Public License | ||||
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
18 | | ||||
19 | ENV['DRKONQI_IGNORE_QUALITY'] = '1' | ||||
20 | ENV['KDE_FORK_SLAVES'] = '1' | ||||
21 | | ||||
22 | DRKONQI_PATH = ENV['DRKONQI_PATH'] | ||||
23 | warn "Testing against #{DRKONQI_PATH}" | ||||
24 | | ||||
25 | # Dies together with our dbus. | ||||
26 | # FIXME: hardcoded crap :'< | ||||
27 | spawn '/usr/lib/at-spi2-core/at-spi-bus-launcher --launch-immediately' | ||||
28 | | ||||
29 | require 'atspi' | ||||
30 | require 'minitest/autorun' | ||||
31 | | ||||
32 | # Adds convenience methods for ATSPI on top of minitest. | ||||
33 | class ATSPITest < Minitest::Test | ||||
34 | def find_in(parent, name: nil, recursion: false) | ||||
35 | raise 'no accessible' if parent.nil? | ||||
36 | accessibles = parent.children.collect do |child| | ||||
37 | ret = [] | ||||
38 | if child.children.size != 0 # recurse | ||||
39 | ret += find_in(child, name: name, recursion: true) | ||||
40 | end | ||||
41 | if name && child.states.include?(:showing) | ||||
42 | if (name.is_a?(Regexp) && child.name.match(name)) || | ||||
43 | (name.is_a?(String) && child.name == name) | ||||
44 | ret << child | ||||
45 | end | ||||
46 | end | ||||
47 | ret | ||||
48 | end.compact.uniq.flatten | ||||
49 | return accessibles if recursion | ||||
50 | raise "not exactly one accessible for #{name} => #{accessibles.collect {|x| x.name}.join(', ')}" if accessibles.size > 1 | ||||
51 | raise "cannot find accessible(#{name})" if accessibles.size < 1 | ||||
52 | yield accessibles[0] if block_given? | ||||
53 | accessibles[0] | ||||
54 | end | ||||
55 | | ||||
56 | def press(accessible) | ||||
57 | raise 'no accessible' if accessible.nil? | ||||
58 | action = accessible.actions.find { |x| x.name == 'Press' } | ||||
59 | refute_nil action, 'expected accessible to be pressable' | ||||
60 | action.do_it! | ||||
61 | sleep 0.25 | ||||
62 | end | ||||
63 | | ||||
64 | def focus(accessible) | ||||
65 | raise 'no accessible' if accessible.nil? | ||||
66 | action = accessible.actions.find { |x| x.name == 'SetFocus' } | ||||
67 | refute_nil action, 'expected accessible to be focusable' | ||||
68 | action.do_it! | ||||
69 | sleep 0.1 | ||||
70 | end | ||||
71 | | ||||
72 | def toggle(accessible) | ||||
73 | raise 'no accessible' if accessible.nil? | ||||
74 | action = accessible.actions.find { |x| x.name == 'Toggle' } | ||||
75 | refute_nil action, 'expected accessible to be toggle' | ||||
76 | action.do_it! | ||||
77 | sleep 0.1 | ||||
78 | end | ||||
79 | | ||||
80 | def toggle_on(accessible) | ||||
81 | raise 'no accessible' if accessible.nil? | ||||
82 | return if accessible.states.any? { |x| %i[checked selected].include?(x) } | ||||
83 | toggle(accessible) | ||||
84 | end | ||||
85 | end |