-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,138 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "GTXBlacklisting.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
A matcher block that determines if the given element must be ignored for the given check. | ||
@param element Element to be looked up if it needs to be ignored. | ||
@param checkName Name of the check for which element must be looked up. | ||
@return @c YES if element needs to be ignored for the given check @c NO other wise. | ||
*/ | ||
typedef BOOL(^GTXIgnoreElementMatcher)(id element, NSString *checkName); | ||
|
||
@interface GTXBlacklistBlock: NSObject<GTXBlacklisting> | ||
|
||
/** | ||
* GTXBlacklistBlock::init is disabled, instead use GTXBlacklistBlock::blacklistWithBlock: | ||
* method to create GTXBlacklists. | ||
*/ | ||
- (instancetype)init __attribute__((unavailable("Use blacklistWithBlock: instead."))); | ||
|
||
/** | ||
* Creates an GTXBlacklist with the given @c block that determines if an element should be ignored. | ||
* | ||
* @param block A block that determines if an element should be ignored. | ||
* | ||
* @return A GTXBlacklist object. | ||
*/ | ||
+ (id<GTXBlacklisting>)blacklistWithBlock:(GTXIgnoreElementMatcher)block; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import "GTXBlacklistBlock.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@implementation GTXBlacklistBlock { | ||
GTXIgnoreElementMatcher _block; | ||
} | ||
|
||
+ (id<GTXBlacklisting>)blacklistWithBlock:(GTXIgnoreElementMatcher)block { | ||
return [[GTXBlacklistBlock alloc] initWithBlock:block]; | ||
} | ||
|
||
- (instancetype)initWithBlock:(GTXIgnoreElementMatcher)block { | ||
NSParameterAssert(block); | ||
|
||
self = [super init]; | ||
if (self) { | ||
_block = block; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - GTXBlacklisting | ||
|
||
- (BOOL)shouldIgnoreElement:(id)element forCheckNamed:(NSString *)check { | ||
return _block(element, check); | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "GTXBlacklisting.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Factory for GTXBlacklisting objects for blacklisting elements. | ||
*/ | ||
@interface GTXBlacklistFactory : NSObject | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
/** | ||
* Returns a GTXBlacklisting object that ignores all elements that are instances of | ||
* a given @c elementClassName. | ||
* | ||
* @param elementClassName The name of the class that should be blacklisted. | ||
* @return A GTXBlacklisting object that ignores all elements of the given class. | ||
*/ | ||
+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName; | ||
/** | ||
* Returns a GTXBlacklisting object that ignores all elements that are instances of | ||
* a given @c elementClassName, but only for GTXChecking objects with a given @c checkName. | ||
* | ||
* @param elementClassName The name of the class that should be blacklisted. | ||
* @param skipCheckName The name of the check that should ignore elements of the given class. | ||
* @return A GTXBlacklisting object that ignores all elements of the given class when running the | ||
* given check. | ||
*/ | ||
+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName | ||
checkName:(NSString *)skipCheckName; | ||
/** | ||
* Returns a GTXBlacklisting object that ignores all elements with a given accessibility | ||
* identifier, but only for GTXChecking objects with a given @c checkName. | ||
* | ||
* @param accessibilityId The accessibility identifier of the element that should be blacklisted. | ||
* @param skipCheckName The name of the check that should ignore elements with the given | ||
* accessibility identifier. | ||
*/ | ||
+ (id<GTXBlacklisting>)blacklistWithAccessibilityIdentifier:(NSString *)accessibilityId | ||
checkName:(NSString *)skipCheckName; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import "GTXBlacklistFactory.h" | ||
|
||
#import "GTXBlacklistBlock.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@implementation GTXBlacklistFactory | ||
|
||
+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName { | ||
Class classObject = NSClassFromString(elementClassName); | ||
NSAssert(classObject, @"Class named %@ does not exist!", elementClassName); | ||
GTXIgnoreElementMatcher matcher = ^BOOL(id element, NSString *checkName) { | ||
return [element isKindOfClass:classObject]; | ||
}; | ||
return [GTXBlacklistBlock blacklistWithBlock:matcher]; | ||
} | ||
|
||
+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName | ||
checkName:(NSString *)skipCheckName { | ||
NSParameterAssert(elementClassName); | ||
Class classObject = NSClassFromString(elementClassName); | ||
NSAssert(classObject, @"Class named %@ does not exist!", elementClassName); | ||
GTXIgnoreElementMatcher matcher = ^BOOL(id element, NSString *checkName) { | ||
return [element isKindOfClass:classObject] && [checkName isEqualToString:skipCheckName]; | ||
}; | ||
return [GTXBlacklistBlock blacklistWithBlock:matcher]; | ||
} | ||
|
||
+ (id<GTXBlacklisting>)blacklistWithAccessibilityIdentifier:(NSString *)accessibilityId | ||
checkName:(NSString *)skipCheckName { | ||
NSParameterAssert(accessibilityId); | ||
NSParameterAssert(skipCheckName); | ||
GTXIgnoreElementMatcher matcher = ^BOOL(id element, NSString *checkName) { | ||
return [[element accessibilityIdentifier] isEqualToString:accessibilityId] && | ||
[checkName isEqualToString:skipCheckName]; | ||
}; | ||
return [GTXBlacklistBlock blacklistWithBlock:matcher]; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Protocol for blacklisting certain types of UI elements in accessibility checks. | ||
*/ | ||
@protocol GTXBlacklisting<NSObject> | ||
|
||
/** | ||
* Determines if the given @c check should not be run on the given @c element. | ||
* | ||
* @param element The target element on which the GTX check is to be performed. | ||
* @param[out] checkName The name of the check being run. | ||
* | ||
* @return @c YES if the check should NOT be performed on the given element, NO otherwise. | ||
*/ | ||
- (BOOL)shouldIgnoreElement:(id)element forCheckNamed:(NSString *)checkName; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.