File indexing completed on 2024-04-28 16:44:13
0001 # SPDX-FileCopyrightText: 2017 Harald Sitter <sitter@kde.org> 0002 # 0003 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 STDOUT.sync = true # force immediate flushing without internal caching 0006 0007 DRKONQI_PATH = ENV['DRKONQI_PATH'] 0008 AT_SPI_BUS_LAUNCHER_PATH = ENV['AT_SPI_BUS_LAUNCHER_PATH'] 0009 AT_SPI_REGISTRY_PATH = ENV['AT_SPI_REGISTRY_PATH'] 0010 warn "Testing against #{DRKONQI_PATH} with #{AT_SPI_BUS_LAUNCHER_PATH} " \ 0011 " and #{AT_SPI_REGISTRY_PATH}" 0012 0013 # Only set inside the test to prevent dbus activation of supporting services. 0014 # We'll force a11y here as depending on the distribution a11y may not be enabled 0015 # by default. 0016 ENV['QT_ACCESSIBILITY'] = '1' 0017 ENV['QT_LINUX_ACCESSIBILITY_ALWAYS_ON'] = '1' 0018 0019 # We kill these after our test run. When isolated they would die with our 0020 # bus, on CI systems we employ no isolation and instead need to manage them 0021 # manually. 0022 # NB: do not give additional options to the launcher. Ubuntu broke theirs 0023 # causing crashes... 0024 launcher_pid = spawn(AT_SPI_BUS_LAUNCHER_PATH, '--launch-immediately') 0025 registry_pid = spawn(AT_SPI_REGISTRY_PATH) 0026 0027 require 'atspi' 0028 require 'minitest/autorun' 0029 0030 # Adds convenience methods for ATSPI on top of minitest. 0031 class ATSPITest < Minitest::Test 0032 def find_in(parent, name: nil, recursion: false) 0033 raise 'no accessible' if parent.nil? 0034 accessibles = parent.children.collect do |child| 0035 ret = [] 0036 if child.children.size != 0 # recurse 0037 ret += find_in(child, name: name, recursion: true) 0038 end 0039 if name && child.states.include?(:showing) 0040 if (name.is_a?(Regexp) && child.name.match(name)) || 0041 (name.is_a?(String) && child.name == name) 0042 ret << child 0043 end 0044 end 0045 ret 0046 end.compact.uniq.flatten 0047 return accessibles if recursion 0048 raise "not exactly one accessible for #{name} => #{accessibles.collect {|x| x.name}.join(', ')}" if accessibles.size > 1 0049 raise "cannot find accessible(#{name})" if accessibles.size < 1 0050 yield accessibles[0] if block_given? 0051 accessibles[0] 0052 end 0053 0054 def press(accessible) 0055 raise 'no accessible' if accessible.nil? 0056 action = accessible.actions.find { |x| x.name == 'Press' } 0057 refute_nil action, 'expected accessible to be pressable' 0058 action.do_it! 0059 sleep 0.25 0060 end 0061 0062 def focus(accessible) 0063 raise 'no accessible' if accessible.nil? 0064 action = accessible.actions.find { |x| x.name == 'SetFocus' } 0065 refute_nil action, 'expected accessible to be focusable' 0066 action.do_it! 0067 sleep 0.1 0068 end 0069 0070 def toggle(accessible) 0071 raise 'no accessible' if accessible.nil? 0072 action = accessible.actions.find { |x| x.name == 'Toggle' } 0073 refute_nil action, 'expected accessible to be toggle' 0074 action.do_it! 0075 sleep 0.1 0076 end 0077 0078 def toggle_on(accessible) 0079 raise 'no accessible' if accessible.nil? 0080 return if accessible.states.any? { |x| %i[checked selected].include?(x) } 0081 toggle(accessible) 0082 end 0083 end 0084 0085 Minitest.after_run do 0086 Process.kill('KILL', launcher_pid) 0087 Process.kill('KILL', registry_pid) 0088 end