class Accessibility::Test

Constants

Data
Options
Path
Tests

Public Class Methods

application(app) click to toggle source
# File lib/project/test.rb, line 347
def self.application(app)
        self.run_tests(app.keyWindow)
end
bar(obj) click to toggle source
# File lib/project/test.rb, line 351
        def self.bar(obj)
                result=true
                obj.items {|item| result=result&&self.run_tests(item)}
        result
end
container(container) click to toggle source
# File lib/project/test.rb, line 357
def self.container(container)
        container.accessibility_element_count.times {|n| return false unless container.accessibility_element_at_index(n).accessible?}
        true
end
debug() click to toggle source
# File lib/project/test.rb, line 324
def self.debug
        Data[:debug]
end
debug=(d) click to toggle source
# File lib/project/test.rb, line 327
def self.debug=(d)
        Data[:debug]=d
end
find_tests(obj) click to toggle source
# File lib/project/test.rb, line 444
                def self.find_tests(obj)
                        return Tests[obj] if obj.kind_of?(Symbol)
                        return Tests[obj.to_s.to_sym] if obj.is_a?(Class)
                        obj_tests=A11y::Test::Tests[:NSObject].clone
cl=obj.class
class_name=cl.to_s.to_sym
if obj.accessibility_test
        tests=Tests[obj.accessibility_test]
else
        tests=Tests[class_name]
until tests do
        cl=cl.superclass
class_name=cl.to_s.to_sym
        tests=Tests[class_name]
end
end
return self.find_tests(tests) if tests.kind_of?(Symbol)
                        tests.each do |attribute, test|
                                obj_tests[attribute]=test
                        end
obj_tests
                end
navigationViewController(controller) click to toggle source
nonstandard(value, options={}) click to toggle source
# File lib/project/test.rb, line 331
                        def self.nonstandard(value, options={})
                                if options[:apple]
                                        return true if value.class==options[:apple]
                                else
                                        return true if [Bignum,Fixnum].include?(value.class)
                                end
                                options[:custom]||=:none.accessibility_trait
                                return true if value==options[:custom]
                                options[:attribute]||=:accessibility_traits
                                message="Apple has this set to a non-standard value."
options[:message]||="Hopefully you can get away with using :none."
                                options[:message]="#{options[:attribute]}: #{message} #{options[:message]}"
A11y::Test::Log.add(Path, options[:message])
false
                        end
pickerView(picker) click to toggle source
# File lib/project/test.rb, line 369
                def self.pickerView(picker)
                        result=true
picker.numberOfComponents.times do |component|
picker.numberOfRowsInComponent(component).times do |row|
title=picker.delegate.pickerView(picker, titleForRow: row, forComponent: component)
view=picker.    viewForRow(row, forComponent: component)
if !title&&!self.run_tests(view)
        A11y::Test::Log(Path, picker.inspect+": component #{component} row #{row} not accessible. You can use the pickerView:titleForRow:forComponent or pickerView:accessibility_label_for_component methods to do this.")
        result=false
end
end
end
                              result
                end
quiet() click to toggle source
# File lib/project/test.rb, line 11
def self.quiet
        Data[:quiet]
end
quiet=(q) click to toggle source
# File lib/project/test.rb, line 14
def self.quiet=(q)
        Data[:quiet]=q
end
rmq_app(app) click to toggle source
# File lib/project/test.rb, line 435
def self.rmq_app(app)
        self.run_tests(app.window)
end
rmq_rmq(rmq_obj) click to toggle source
# File lib/project/test.rb, line 439
def self.rmq_rmq(rmq_obj)
        rmq_obj.each {|obj| return false unless obj.accessible?}
        true
end
run_test(obj, attribute, expected, message=nil) click to toggle source
# File lib/project/test.rb, line 467
                def self.run_test(obj, attribute, expected, message=nil)
                        return true if expected==:ignore
        value=obj.send(attribute) if obj.respond_to?(attribute)
        return value if expected==:something
        return nonstandard(value) if expected==:nonstandard
        result=true
        if expected.class==Class
if value.class!=expected
        result=false
message||="#{attribute} must have an object of type #{expected} instead of #{value}"
end
        elsif expected.kind_of?(Proc)
                r=expected.call(obj)
                unless r
                        result=false
                end
        else
                unless expected==value
result=false
message||="#{attribute} must have the value \"#{expected}\" instead of \"#{value}\""
                end
        end
        A11y::Test::Log.add(Path, message) if message&&!result
        puts "Testing #{attribute}... #{result}" if Data[:debug]
        result
                end
run_tests(obj) click to toggle source
# File lib/project/test.rb, line 494
                def self.run_tests(obj)
                        puts "Entering run_tests: #{obj.inspect}" if Data[:debug]
                        return self.run_tests(obj.get) if defined?(RubyMotionQuery::RMQ)&&obj.is_a?(RubyMotionQuery::RMQ)
                        if Data[:depth]==0
                        A11y::Test::Log::Events.clear
                        Path.clear
                        end
                        Path<<obj
                        tests=self.find_tests(obj)
        tests[:options]||={}
        tests[:options]=self::Options.merge(tests[:options])
result=true
tests.each do |attribute, test|
        next if attribute==:options
        if test.kind_of?(Array)
        (expected, message)=test
        this_result=self.run_test(obj, attribute, expected, message)
        else
        this_result=self.run_test(obj, attribute, test)
        end
        result=result&&this_result
end
after=tests[:options][:test]
 if after&&self.respond_to?(after)
         puts "Running the after test: #{after}" if Data[:debug]
                        Data[:depth]=Data[:depth]+1
         this_result=self.send(after, obj)
         result=result&&this_result
                        Data[:depth]=Data[:depth]-1
 end
 if result&&obj.accessibility_element_container?
         result=result&&self.container(obj)
 end
if result&&tests[:options][:recurse]&&obj.respond_to?(:subviews)&&obj.subviews
        puts "Recursing..." if Data[:debug]
        Data[:depth]=Data[:depth]+1
obj.subviews.each {|view| result=result&&A11y::Test.run_tests(view)}    
Data[:depth]=Data[:depth]-1
end
Path.pop
puts "Returning #{result}" if Data[:debug]
        result
                end
tabBarViewController(controller) click to toggle source
# File lib/project/test.rb, line 384
                def self.tabBarViewController(controller)
                        result=true
                        result&&self.run_tests(controller.tabBar)
controller.viewControllers.each {|c| result=result&&self.run_tests(c)}
result
                end
tableViewCell(cell) click to toggle source
# File lib/project/test.rb, line 421
def self.tableViewCell(cell)
        return true if cell.accessibility_label||cell.textLabel.text
        A11y::Test::Log.add(Path, "Please set the accessibility_label of the UITableViewCell. You can do this by setting the textLabel.text property.")
        false
end
table_is_element(table) click to toggle source
# File lib/project/test.rb, line 391
def self.table_is_element(table)
                        if table.empty?
                                unless table.accessibility_element?
                                        A11y::Test::Log.add(Path, "You must set is_accessibility_element to true for an empty table.")
                                        return false
                                end
                        else
                                if table.accessibility_element?
                                        A11y::Test::Log.add(Path, "You must set is_accessibility_element to false for a table with data.")
                                        return false
                                end
                        end
                        true
end
table_label(table) click to toggle source
# File lib/project/test.rb, line 406
                def self.table_label(table)
if table.empty?
        unless table.accessibility_label.is_a?(String)
                A11y::Test::Log.add(Path, "You must set the accessibility label to what you want VoiceOver to say instead of an empty table.")
                return false
        end
else
        unless table.accessibility_label.nil?
                A11y::Test::Log.add(Path, "You must set the accessibility label to nil.")
                return false
        end
end
true
                end
viewController(controller) click to toggle source
# File lib/project/test.rb, line 427
def self.viewController(controller)
        self.run_tests(controller.view)
end
window(window) click to toggle source
# File lib/project/test.rb, line 431
def self.window(window)
        self.run_tests(window.rootViewController)
end