Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions commands/FBAccessibilityCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def forceStartAccessibilityServer():
#We try to start accessibility server only if we don't have needed method active
if not fb.evaluateBooleanExpression('[UIView instancesRespondToSelector:@selector(_accessibilityElementsInContainer:)]'):
#Starting accessibility server is different for simulator and device
if fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] model]').GetObjectDescription().lower().find('simulator') >= 0:
if (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] model]').GetObjectDescription().lower().find('simulator') >= 0) | (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] name]').GetObjectDescription().lower().find('simulator') >= 0):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This should use or instead of binary |.
  2. Maybe extract into a helper method, isSimulator?
  3. Is there a reason this isn't using evaluateObjectExpression?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address first 2 comments
3. EvaluateObjectExpression will give us string address, while we need string python representation. expressionValue().GetObjectDescription() seems best way for that

lldb.debugger.HandleCommand('eobjc (void)[[UIApplication sharedApplication] accessibilityActivate]')
else:
lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]')
Expand All @@ -86,6 +86,16 @@ def accessibilityLabel(view):
#using Apple private API to get real value of accessibility string for element.
return fb.evaluateExpressionValue('(id)[%s accessibilityAttributeValue:%i]' % (view, ACCESSIBILITY_LABEL_KEY), False)

def accessibilityElements(view):
if fb.evaluateBooleanExpression('[UIView instancesRespondToSelector:@selector(accessibilityElements)]'):
a11yElements = fb.evaluateExpression('(id)[%s accessibilityElements]' % view, False)
if int(a11yElements, 16) != 0:
return a11yElements
if fb.evaluateBooleanExpression('[%s respondsToSelector:@selector(_accessibleSubviews)]' % view):
return fb.evaluateExpression('(id)[%s _accessibleSubviews]' % (view), False)
else:
return fb.evaluateObjectExpression('[[[UIApplication sharedApplication] keyWindow] _accessibilityElementsInContainer:0 topLevel:%s includeKB:0]' % view)

def printAccessibilityHierarchy(view, indent = 0):
a11yLabel = accessibilityLabel(view)
classDesc = objHelpers.className(view)
Expand All @@ -95,10 +105,10 @@ def printAccessibilityHierarchy(view, indent = 0):
if int(a11yLabel.GetValue(), 16) == 0:
print indentString + ('{} {}'.format(classDesc, view))
#We call private method that gives back all visible accessibility children for view
accessibilityElements = fb.evaluateObjectExpression('[[[UIApplication sharedApplication] keyWindow] _accessibilityElementsInContainer:0 topLevel:%s includeKB:0]' % view)
accessibilityElementsCount = int(fb.evaluateExpression('(int)[%s count]' % accessibilityElements))
a11yElements = accessibilityElements(view)
accessibilityElementsCount = int(fb.evaluateExpression('(int)[%s count]' % a11yElements))
for index in range(0, accessibilityElementsCount):
subview = fb.evaluateObjectExpression('[%s objectAtIndex:%i]' % (accessibilityElements, index))
subview = fb.evaluateObjectExpression('[%s objectAtIndex:%i]' % (a11yElements, index))
printAccessibilityHierarchy(subview, indent + 1)
else:
print indentString + ('({} {}) {}'.format(classDesc, view, a11yLabel.GetObjectDescription()))
Expand Down