Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility parent #171

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2d64139
Initial commit with SLAccessibilityContainer and working tests
jzucker2 Apr 2, 2014
a0413de
Added SLTableViewCell subclass of SLAccessibilityContainer
jzucker2 Apr 2, 2014
8d21da3
Added test for TableViewCell methods
jzucker2 Apr 3, 2014
350b001
Cleaned up comments
jzucker2 Apr 3, 2014
de8f395
Updated SLAccessibilityContainer to be true subclass.
jzucker2 Apr 4, 2014
474772e
Cleaned up method names for table view cells
jzucker2 Apr 4, 2014
58cbd5b
Cleaned up enum for AX container types
jzucker2 Apr 7, 2014
0264c06
Include collection view cell mock views in accessibility paths. (fixe…
Apr 11, 2014
682f721
When confirming the visibility of unknown objects, don't wait to reso…
Apr 12, 2014
2fb5334
Temporarily use UIAutomation to check visibility in non-portrait orie…
Apr 12, 2014
0e11593
Ensure that `-[SLDevice setOrientation:]` waits for the device to rot…
Apr 12, 2014
5829bde
Reset the device orientation after deactivation on iPads running iOS …
Apr 20, 2014
8f4ca7f
Merge pull request #186 from inkling/jeff/update_copyright_year
ahaneyinkling Apr 22, 2014
f42b2d8
Merge pull request #179 from inkling/jeff/collection_view_cells
ahaneyinkling Apr 22, 2014
afbf843
Merge pull request #180 from inkling/jeff/135_landscape_visibility
ahaneyinkling Apr 22, 2014
b836640
Initial commit with SLAccessibilityContainer and working tests
jzucker2 Apr 2, 2014
0a30c47
Added SLTableViewCell subclass of SLAccessibilityContainer
jzucker2 Apr 2, 2014
9e6d1d7
Added test for TableViewCell methods
jzucker2 Apr 3, 2014
786d7b4
Cleaned up comments
jzucker2 Apr 3, 2014
bae103a
Updated SLAccessibilityContainer to be true subclass.
jzucker2 Apr 4, 2014
d2bab85
Cleaned up method names for table view cells
jzucker2 Apr 4, 2014
0e9c612
Cleaned up enum for AX container types
jzucker2 Apr 7, 2014
e277273
Merge branch 'accessibilityParent' of https://github.com/jzucker2/Sub…
jzucker2 Apr 23, 2014
0334e35
Removed focus from tests for official commit
jzucker2 Apr 23, 2014
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
8 changes: 8 additions & 0 deletions Integration Tests/Tests/SLDeviceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ - (void)testCanRotateDevice
}
}

// Exercises a bug in iOS 5.1 and 7.1. See https://github.com/inkling/Subliminal/pull/180#issuecomment-40891098
- (void)testThatDeviceOrientationPersistsThroughDeactivation {
UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;
[[SLDevice currentDevice] deactivateAppForDuration:3.0];
SLAssertTrue([UIDevice currentDevice].orientation == currentOrientation,
@"The device orientation should not have changed.");
}

- (void)rotateToAndCheckOrientation:(UIDeviceOrientation)orientation
{
[[SLDevice currentDevice] setOrientation:orientation];
Expand Down
18 changes: 18 additions & 0 deletions Integration Tests/Tests/SLElementMatchingTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ + (NSString *)testCaseViewControllerClassName {
return @"SLElementMatchingTestViewController";
}

+ (BOOL)testCaseWithSelectorSupportsCurrentPlatform:(SEL)testCaseSelector {
if (![super testCaseWithSelectorSupportsCurrentPlatform:testCaseSelector]) return NO;

if (testCaseSelector == @selector(testMatchingCollectionViewCellChildElement)) {
return kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber_iOS_5_1;
}

return YES;
}

- (void)setUpTestCaseWithSelector:(SEL)testCaseSelector {
[super setUpTestCaseWithSelector:testCaseSelector];

Expand Down Expand Up @@ -263,6 +273,14 @@ - (void)testMatchingTableViewHeaderChildElements {
SLAssertTrue([rightLabel isValid], @"Could not match UITableView header child element.");
}

#pragma mark - Collection views

- (void)testMatchingCollectionViewCellChildElement {
SLButton *fooButton = [SLButton elementWithAccessibilityLabel:@"fooButton"];
SLAssertTrue([[UIAElement(fooButton) label] isEqualToString:@"fooButton"],
@"Could not match `UICollectionViewCell` child element.");
}

#pragma mark - Web views

// This test case is restricted to the iPhone to guarantee the properties of
Expand Down
101 changes: 87 additions & 14 deletions Integration Tests/Tests/SLElementMatchingTestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ @interface SLElementMatchingTestViewController : SLTestCaseViewController
@end


#pragma mark - SLElementMatchingTestCell
#pragma mark - SLElementMatchingTestTableViewCell

@interface SLElementMatchingTestCell : UITableViewCell
@interface SLElementMatchingTestTableViewCell : UITableViewCell

- (void)configureAccessibility;

@end

@implementation SLElementMatchingTestCell {
@implementation SLElementMatchingTestTableViewCell {
SEL _testCase;
UISwitch *_switch;
UILabel *_weatherCity, *_weatherTemp;
Expand Down Expand Up @@ -107,15 +107,15 @@ - (void)layoutSubviews {
@end


#pragma mark - SLElementMatchingTestHeader
#pragma mark - SLElementMatchingTestTableViewHeader

@interface SLElementMatchingTestHeader : UIView
@interface SLElementMatchingTestTableViewHeader : UIView

- (instancetype)initWithTestCaseWithSelector:(SEL)testCase;

@end

@implementation SLElementMatchingTestHeader {
@implementation SLElementMatchingTestTableViewHeader {
UIView *_leftView, *_rightView;
}

Expand Down Expand Up @@ -167,9 +167,50 @@ - (void)removeRightView {
@end


#pragma mark - SLElementMatchingTestCollectionViewCell

@interface SLElementMatchingTestCollectionViewCell : UICollectionViewCell

+ (CGSize)defaultSize;

@end

@implementation SLElementMatchingTestCollectionViewCell {
UIButton *_button;
}

+ (CGSize)defaultSize {
return CGSizeMake(100.0f, 50.0f);
}

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor greenColor];

_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.backgroundColor = [UIColor blueColor];
[_button setTitle:@"fooButton" forState:UIControlStateNormal];
[self.contentView addSubview:_button];
}
return self;
}

- (void)layoutSubviews {
[super layoutSubviews];

[_button sizeToFit];
_button.center = self.center;
}

@end


#pragma mark - SLElementMatchingTestViewController

@interface SLElementMatchingTestViewController () <UITableViewDataSource, UITableViewDelegate, UIWebViewDelegate>
@interface SLElementMatchingTestViewController () < UITableViewDataSource, UITableViewDelegate,
UICollectionViewDataSource, UICollectionViewDelegate,
UIWebViewDelegate >

// fooButton is purposely strong so that we can hold onto it
// while it's removed from the view hierarchy in testElementsWaitToMatchValidObjects
Expand All @@ -185,17 +226,18 @@ @interface SLElementMatchingTestViewController () <UITableViewDataSource, UITabl
@implementation SLElementMatchingTestViewController {
UIView *_parentView, *_childView;

NSString *_testTableViewCellIdentifier;
NSString *_testTableViewCellIdentifier, *_testCollectionViewCellIdentifier;
Class _testTableViewCellClass;

UICollectionView *_collectionView;
UIWebView *_webView;
BOOL _webViewDidFinishLoad;

UIPopoverController *_popoverController;

UIActionSheet *_actionSheet;

SLElementMatchingTestHeader *_headerView;
SLElementMatchingTestTableViewHeader *_headerView;
}

+ (NSString *)nibNameForTestCase:(SEL)testCase {
Expand Down Expand Up @@ -270,6 +312,19 @@ - (void)loadViewForTestCase:(SEL)testCase {

[view addSubview:_parentView];
self.view = view;
} else if (testCase == @selector(testMatchingCollectionViewCellChildElement)) {
// note: `SLElementMatchingTest` marks this test case as not supporting iOS 5.1
// so we don't need to worry about runtime-conditionalizing code here
UICollectionViewFlowLayout *collectionViewLayout = [[UICollectionViewFlowLayout alloc] init];
collectionViewLayout.itemSize = [SLElementMatchingTestCollectionViewCell defaultSize];

_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:collectionViewLayout];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

self.view = _collectionView;
}
}

Expand Down Expand Up @@ -301,11 +356,15 @@ - (void)viewDidLoad {
} else if ((self.testCase == @selector(testMatchingNonLabelTableViewCellChildElement)) ||
(self.testCase == @selector(testMatchingTableViewCellWithCombinedLabel)) ||
(self.testCase == @selector(testCannotMatchIndividualChildLabelsOfTableViewCell))) {
_testTableViewCellClass = [SLElementMatchingTestCell class];
_testTableViewCellClass = [SLElementMatchingTestTableViewCell class];
} else {
NSAssert(NO, @"Table view loaded for unexpected test case: %@.", NSStringFromSelector(self.testCase));
}
_testTableViewCellIdentifier = [NSString stringWithFormat:@"%@_%@", NSStringFromClass(_testTableViewCellClass), NSStringFromSelector(self.testCase)];
} else if (_collectionView) {
Class testCollectionViewCellClass = [SLElementMatchingTestCollectionViewCell class];
_testCollectionViewCellIdentifier = [NSString stringWithFormat:@"%@_%@", NSStringFromClass(testCollectionViewCellClass), NSStringFromSelector(self.testCase)];
[_collectionView registerClass:testCollectionViewCellClass forCellWithReuseIdentifier:_testCollectionViewCellIdentifier];
}

if (_webView) {
Expand All @@ -316,7 +375,7 @@ - (void)viewDidLoad {
}
}

#pragma mark UITableViewDataSource
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
Expand All @@ -338,9 +397,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
(self.testCase == @selector(testSubliminalReloadsTheAccessibilityHierarchyAsNecessaryWhenMatching))) {
cell.textLabel.text = @"fooLabel";
} else {
NSAssert([cell isKindOfClass:[SLElementMatchingTestCell class]],
NSAssert([cell isKindOfClass:[SLElementMatchingTestTableViewCell class]],
@"Unexpected table view cell class for test case: %@.", NSStringFromSelector(self.testCase));
[(SLElementMatchingTestCell *)cell configureAccessibility];
[(SLElementMatchingTestTableViewCell *)cell configureAccessibility];
}

return cell;
Expand All @@ -360,14 +419,28 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
headerView = label;
} else if ((self.testCase == @selector(testMatchingTableViewHeaderChildElements)) ||
(self.testCase == @selector(testSubliminalReloadsTheAccessibilityHierarchyAsNecessaryWhenMatching))) {
_headerView = [[SLElementMatchingTestHeader alloc] initWithTestCaseWithSelector:self.testCase];
_headerView = [[SLElementMatchingTestTableViewHeader alloc] initWithTestCaseWithSelector:self.testCase];
NSAssert([self numberOfSectionsInTableView:tableView] == 1, @"We only expect to track one header.");
headerView = _headerView;
}

return headerView;
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableCellWithReuseIdentifier:_testCollectionViewCellIdentifier forIndexPath:indexPath];
}

#pragma mark - UIWebView delegate

- (void)webViewDidFinishLoad:(UIWebView *)webView {
Expand Down
36 changes: 36 additions & 0 deletions Integration Tests/Tests/SLElementVisibilityTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,25 @@ - (void)setUpTestCaseWithSelector:(SEL)testSelector {

if (testSelector == @selector(testCanDetermineVisibilityOfWebAccessibilityElements)) {
SLAssertTrueWithTimeout(SLAskAppYesNo(webViewDidFinishLoad), 5.0, @"Webview did not load test HTML.");
} else if ((testSelector == @selector(testViewIsVisibleInPortrait)) ||
(testSelector == @selector(testViewIsVisibleInPortraitUpsideDown)) ||
(testSelector == @selector(testViewIsVisibleInLandscapeLeft)) ||
(testSelector == @selector(testViewIsVisibleInLandscapeRight))) {
SLAskApp(showTestView);
}
}

- (void)tearDownTestCaseWithSelector:(SEL)testCaseSelector {
if ((testCaseSelector == @selector(testViewIsVisibleInPortrait)) ||
(testCaseSelector == @selector(testViewIsVisibleInPortraitUpsideDown)) ||
(testCaseSelector == @selector(testViewIsVisibleInLandscapeLeft)) ||
(testCaseSelector == @selector(testViewIsVisibleInLandscapeRight))) {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
}

[super tearDownTestCaseWithSelector:testCaseSelector];
}

#pragma mark - Test isVisible for elements that are views

- (void)testViewIsNotVisibleIfItIsHidden {
Expand Down Expand Up @@ -225,6 +241,26 @@ - (void)testViewIsVisibleIfItsCenterIsCoveredByClearRegion {
SLAssertTrue([_testElement isVisible], @"Subliminal should say that the element is visible.");
}

- (void)testViewIsVisibleInPortrait {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

- (void)testViewIsVisibleInPortraitUpsideDown {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationPortraitUpsideDown];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

- (void)testViewIsVisibleInLandscapeLeft {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

- (void)testViewIsVisibleInLandscapeRight {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

#pragma mark - Test isVisible for elements that are not views

- (void)testAccessibilityElementIsNotVisibleIfContainerIsHidden {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ + (NSString *)nibNameForTestCase:(SEL)testCase {
(testCase == @selector(testIsInvalidOrInvisibleDoesNotThrowIfElementIsInvalid)) ||
(testCase == @selector(testIsInvalidOrInvisibleReturnsYESIfElementIsInvalidOrInvisible))) {
nibName = @"SLElementVisibilityTestHidden";
} else if ((testCase == @selector(testViewIsVisibleInPortrait)) ||
(testCase == @selector(testViewIsVisibleInPortraitUpsideDown)) ||
(testCase == @selector(testViewIsVisibleInLandscapeLeft)) ||
(testCase == @selector(testViewIsVisibleInLandscapeRight))) {
nibName = @"SLElementVisibilityTestHidden";
}
return nibName;
}
Expand Down
58 changes: 58 additions & 0 deletions Integration Tests/Tests/SLNavigationBarTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// SLNavigationBarTests.m
// Subliminal
//
// Created by Jordan Zucker on 4/4/14.
// Copyright (c) 2014 Inkling. All rights reserved.
//

#import "SLIntegrationTest.h"

@interface focus_SLNavigationBarTests : SLIntegrationTest

@end

@implementation focus_SLNavigationBarTests

+ (NSString *)testCaseViewControllerClassName {
return @"SLNavigationBarTestsViewController";
}

// If you override set-up methods,
// you must call super at the beginning of your implementations.

// If you override tear-down methods,
// you must call super at the *end* of your implementations.

- (void)testRightButtonBroadMatching {
SLButton *rightButton = [SLButton elementWithAccessibilityLabel:@"Right"];
SLAssertTrue([UIAElement(rightButton) isValidAndVisible], @"Right button didn't appear");

[UIAElement(rightButton) tap];
}

- (void)testRightButtonWithNewMethod
{
SLAccessibilityContainer *navBar = [SLAccessibilityContainer containerWithIdentifier:@"NavigationBar" andContainerType:SLAccessibilityContainerTypeNavigationBar];
SLLogAsync(@"navBar is %@", navBar);
SLAssertTrue([UIAElement(navBar) isValidAndVisible], @"Couldn't find nav bar matching specifications");
SLButton *rightButton = [navBar childElementMatching:[SLButton elementWithAccessibilityLabel:@"Right"]];
SLAssertTrue([UIAElement(rightButton) isValidAndVisible], @"Couldn't find right button bar");

[UIAElement(rightButton) tap];

}

- (void)testTitleLabel
{
SLAccessibilityContainer *navBar = [SLAccessibilityContainer containerWithIdentifier:@"NavigationBar" andContainerType:SLAccessibilityContainerTypeNavigationBar];
SLLogAsync(@"navBar is %@", navBar);
SLAssertTrue([UIAElement(navBar) isValidAndVisible], @"Couldn't find nav bar matching specifications");
SLElement *title = [navBar childElementMatching:[SLElement elementWithAccessibilityLabel:@"Testing" value:nil traits:UIAccessibilityTraitStaticText]];
SLAssertTrue([UIAElement(title) isValidAndVisible], @"title isn't valid and visible");
SLLogAsync(@"title is %@", title.label);
SLAssertTrue([UIAElement(title.label) isEqualToString:@"Testing"], @"title doesn't match expected string");

}

@end
Loading