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

Restore on-device testing in iOS 7 #17

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9bf4387
Added KIF as a submodule
MichaelBuckley Dec 19, 2013
0005324
Update the Controls example for iOS 7
MichaelBuckley Dec 20, 2013
886f3bf
Limit Bonjour to IPv4
MichaelBuckley Dec 22, 2013
ab07c40
Rotation now uses private UIApplication method
MichaelBuckley Dec 22, 2013
b9cc4b3
Updated touch and drag events to synthesize UIEvents, making them wor…
MichaelBuckley Jan 16, 2014
c2238e9
Drag UISlider thumbs using the new drag method
MichaelBuckley Jan 17, 2014
74ab637
Fix keyboard in portrait orientation
MichaelBuckley Jan 17, 2014
6428f0b
Updated location override to no longer use PublicAutomation
MichaelBuckley Jan 18, 2014
de5bbe5
Updated Controls example to non-deprecated CLLocationManager delegate…
MichaelBuckley Jan 18, 2014
a1e5d40
Update UISwitch swipe method to work in iOS 7
MichaelBuckley Jan 18, 2014
e6cc21c
Remove PublicAutomation Submodule
MichaelBuckley Jan 18, 2014
c24fff1
Added KIF as a submodule
MichaelBuckley Dec 19, 2013
c1a66be
Update the Controls example for iOS 7
MichaelBuckley Dec 20, 2013
93585e8
Limit Bonjour to IPv4
MichaelBuckley Dec 22, 2013
dcfca58
Rotation now uses private UIApplication method
MichaelBuckley Dec 22, 2013
d74e543
Updated touch and drag events to synthesize UIEvents, making them wor…
MichaelBuckley Jan 16, 2014
b99643b
Drag UISlider thumbs using the new drag method
MichaelBuckley Jan 17, 2014
11d4d56
Fix keyboard in portrait orientation
MichaelBuckley Jan 17, 2014
9996010
Updated location override to no longer use PublicAutomation
MichaelBuckley Jan 18, 2014
5294d00
Updated Controls example to non-deprecated CLLocationManager delegate…
MichaelBuckley Jan 18, 2014
2c9d70e
Update UISwitch swipe method to work in iOS 7
MichaelBuckley Jan 18, 2014
0f41d7b
Remove PublicAutomation Submodule
MichaelBuckley Jan 18, 2014
908b675
Fix UIAlertView tests in controls example
MichaelBuckley Jan 19, 2014
93ac615
Merge branch 'remove-uiautomation-in-ios7' of github.com:MichaelBuckl…
MichaelBuckley Jan 19, 2014
f715354
Merge branch 'master' into remove-uiautomation-in-ios7
qmfrederik Sep 7, 2015
9c76c36
Avoid null reference exception while executing operations - return an…
qmfrederik Sep 7, 2015
70db5ea
Fix duplicate variable name
qmfrederik Sep 7, 2015
071d5e4
Remove FEX_dragWithInitialDelayToX method
qmfrederik Sep 7, 2015
77f4731
Make sure applicationDidBecomeActive is called, even on iOS 9
qmfrederik Oct 13, 2015
b494e83
Merge branch 'pending-moredip-commits' into remove-uiautomation-in-ios7
qmfrederik Jan 20, 2016
261d29e
Merge pull request #46 from quamotion/remove-uiautomation-in-ios7
MichaelBuckley Jan 21, 2016
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
[submodule "lib/cocoahttpserver"]
path = lib/cocoahttpserver
url = https://github.com/robbiehanson/CocoaHTTPServer.git
[submodule "lib/PublicAutomation"]
path = lib/PublicAutomation
url = https://github.com/TestingWithFrank/PublicAutomation.git
[submodule "lib/AnyJSON"]
path = lib/AnyJSON
url = https://github.com/mattt/AnyJSON.git
[submodule "lib/KIF"]
path = lib/KIF
url = https://github.com/kif-framework/KIF.git
107 changes: 59 additions & 48 deletions Frank.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Frank.xcodeproj/xcshareddata/xcschemes/Frank.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Frank.xcodeproj/xcshareddata/xcschemes/FrankMac.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0450"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions lib/KIF
Submodule KIF added at 7ba0c2
1 change: 0 additions & 1 deletion lib/PublicAutomation
Submodule PublicAutomation deleted from 3c76dc
20 changes: 20 additions & 0 deletions src/FrankLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ + (void)load{
selector:@selector(applicationDidBecomeActive:)
name:notificationName
object:nil];

#if TARGET_OS_IPHONE
NSArray *iOSVersionComponents = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
int majorVersion = [[iOSVersionComponents objectAtIndex:0] intValue];

if (majorVersion >= 9)
{
// iOS9 is installed. The UIApplicationDidBecomeActiveNotification may have been fired *before*
// this code is called.
// See also:
// http://stackoverflow.com/questions/31785878/ios-9-uiapplicationdidbecomeactivenotification-callback-not-called

// Call applicationDidBecomeActive: after 0.5 second.
// Delay execution of my block for 10 seconds.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 500 * USEC_PER_SEC), dispatch_get_main_queue(), ^{
NSLog(@"Forcefully invoking applicationDidBecomeActive");
[FrankLoader applicationDidBecomeActive:nil];
});
}
#endif
}

@end
14 changes: 8 additions & 6 deletions src/IOSKeyboardCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
// To change the template use AppCode | Preferences | File Templates.
//


#import "FranklyProtocolHelper.h"
#import "IOSKeyboardCommand.h"
#import "JSON.h"
#import <PublicAutomation/UIAutomationBridge.h>

#import "FranklyProtocolHelper.h"
#import "KIFTypist.h"
#import "UIApplication-KIFAdditions.h"

@implementation IOSKeyboardCommand {

Expand All @@ -25,11 +24,14 @@ - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
NSDictionary *requestCommand = FROM_JSON(requestBody);
NSString *textToType = [requestCommand objectForKey:@"text_to_type"];

if( ![UIAutomationBridge checkForKeyboard] ){
if( ![[UIApplication sharedApplication] keyboardWindow]){
return [self generateKeyboardNotPresentErrorResponse];
}

[UIAutomationBridge typeIntoKeyboard:textToType];
for (NSUInteger characterIndex = 0; characterIndex < [textToType length]; characterIndex++) {
NSString *characterString = [textToType substringWithRange:NSMakeRange(characterIndex, 1)];
[KIFTypist enterCharacter: characterString];
}

return [FranklyProtocolHelper generateSuccessResponseWithoutResults];
}
Expand Down
170 changes: 168 additions & 2 deletions src/LocationCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,39 @@
//
//

#import <objc/runtime.h>

#import "LocationCommand.h"

#import <PublicAutomation/UIAutomationBridge.h>
#import "FranklyProtocolHelper.h"
#import "JSON.h"

@interface NSObject ()
- (id)initWithLatitude: (double) latitude longitude: (double) longitude;

- (id) location;

- (void) locationManager: (id) locationManager didUpdateLocations: (NSArray*) locations;
- (void) locationManager: (id) locationManager didUpdateToLocation: (id) newLocation fromLocation: (id) oldLocation;
@end

static LocationCommand* FEX_staticLocationCommand = nil;
static id FEX_overridenLocation = nil;
static NSMutableDictionary* FEX_locationDelegates = nil;
static NSMutableDictionary* FEX_updatingManagers = nil;

@implementation LocationCommand

- (id) init
{
if (self = [super init])
{
FEX_staticLocationCommand = self;
}

return self;
}

- (NSString *)handlePost:(NSString *)requestBody{
NSDictionary *requestCommand = FROM_JSON(requestBody);

Expand All @@ -27,7 +51,29 @@ - (NSString *)handlePost:(NSString *)requestBody{

NSLog(@"simulating location of %f,%f",locationAsPoint.x, locationAsPoint.y);

[UIAutomationBridge setLocation:locationAsPoint];
FEX_overridenLocation = [[NSClassFromString(@"CLLocation") alloc] initWithLatitude: locationAsPoint.x
longitude: locationAsPoint.y];

for (id locationManagerDescription in FEX_locationDelegates)
{
id locationManager =[FEX_updatingManagers objectForKey: locationManagerDescription];
if (locationManager != nil)
{
id delegate = [FEX_locationDelegates objectForKey: [locationManager description]];
if ([delegate respondsToSelector: @selector(locationManager:didUpdateLocations:)])
{
[delegate locationManager: locationManager
didUpdateLocations: [NSArray arrayWithObject: [((NSObject*) locationManager) location]]];
}

if ([delegate respondsToSelector: @selector(locationManager:didUpdateToLocation:fromLocation:)])
{
[delegate locationManager: locationManager
didUpdateToLocation: [((NSObject*) locationManager) location]
fromLocation: [((NSObject*) locationManager) location]];
}
}
}

return [FranklyProtocolHelper generateSuccessResponseWithoutResults];
}
Expand All @@ -40,4 +86,124 @@ - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
return [self handlePost:requestBody];
}

- (id) FEX_location
{
id returnValue = nil;

if (FEX_overridenLocation != nil)
{
returnValue = FEX_overridenLocation;
}
else
{
returnValue = [self FEX_location];
}

return returnValue;
}

- (void) FEX_setDelegate: (id) delegate
{
[FEX_locationDelegates setObject: delegate forKey: [self description]];
[self FEX_setDelegate: FEX_staticLocationCommand];
}

- (void) FEX_startUpdatingLocation
{
[FEX_updatingManagers setObject: self forKey: [self description]];
[self FEX_startUpdatingLocation];
}

- (void) FEX_stopUpdatingLocation
{
[FEX_updatingManagers removeObjectForKey: [self description]];
[self FEX_stopUpdatingLocation];
}

- (void) FEX_dealloc
{
[FEX_locationDelegates removeObjectForKey: [self description]];
[FEX_updatingManagers removeObjectForKey: [self description]];

[self FEX_dealloc];
}

+ (void) insertMethod: (SEL) newSelector andSwapWithMethod: (SEL) origSelector
{
Class locationManagerClass = NSClassFromString(@"CLLocationManager");

if (locationManagerClass != nil)
{
Method origMethod = class_getInstanceMethod(locationManagerClass, origSelector);
Method newMethod = class_getInstanceMethod(self, newSelector);
IMP newIMP = method_getImplementation(newMethod);

if (class_addMethod(locationManagerClass, newSelector, newIMP, method_getTypeEncoding(newMethod)))
{
newMethod = class_getInstanceMethod(locationManagerClass, newSelector);

if (origMethod != NULL && newMethod != NULL)
{
method_exchangeImplementations(origMethod, newMethod);
}
}
}
}

+ (void) load
{
FEX_locationDelegates = [NSMutableDictionary new];
FEX_updatingManagers = [NSMutableDictionary new];

[self insertMethod: @selector(FEX_setDelegate:) andSwapWithMethod: @selector(setDelegate:)];
[self insertMethod: @selector(FEX_dealloc) andSwapWithMethod: @selector(dealloc)];
[self insertMethod: @selector(FEX_startUpdatingLocation) andSwapWithMethod: @selector(startUpdatingLocation)];
[self insertMethod: @selector(FEX_stopUpdatingLocation) andSwapWithMethod: @selector(stopUpdatingLocation)];
[self insertMethod: @selector(FEX_location) andSwapWithMethod: @selector(location)];
}

- (void) locationManager: (id) locationManager didUpdateLocations: (NSArray*) locations
{
if (locationManager != nil && [FEX_updatingManagers objectForKey: [locationManager description]] != nil)
{
id delegate = [FEX_locationDelegates objectForKey: [locationManager description]];
if ([delegate respondsToSelector: @selector(locationManager:didUpdateLocations:)])
{
if (FEX_overridenLocation == nil)
{
[delegate locationManager: locationManager
didUpdateLocations: locations];
}
else
{
[delegate locationManager: locationManager
didUpdateLocations: [NSArray arrayWithObject: FEX_overridenLocation]];
}
}
}
}

- (void) locationManager: (id) locationManager didUpdateToLocation: (id) newLocation fromLocation: (id) oldLocation
{
if (locationManager != nil && [FEX_updatingManagers objectForKey: [locationManager description]] != nil)
{
id delegate = [FEX_locationDelegates objectForKey: [locationManager description]];
if ([delegate respondsToSelector: @selector(locationManager:didUpdateToLocation:fromLocation:)])
{
if (FEX_overridenLocation == nil)
{
[delegate locationManager: locationManager
didUpdateToLocation: newLocation
fromLocation: oldLocation];
}
else
{
[delegate locationManager: locationManager
didUpdateToLocation: FEX_overridenLocation
fromLocation: FEX_overridenLocation];
}
}
}
}

@end
10 changes: 9 additions & 1 deletion src/MapOperationCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
for (FrankMapViewType *view in viewsToMap) {
@try {
id result = [self performOperation:operation onView:view];
[results addObject:[ViewJSONSerializer jsonify:result]];
NSString *resultValue = [ViewJSONSerializer jsonify:result];

// Can't add nil objects to an array.
if(resultValue == nil)
{
resultValue = @"";
}

[results addObject:resultValue];
}
@catch (NSException * e) {
NSLog( @"Exception while performing operation %@\n%@", operation, e );
Expand Down
7 changes: 4 additions & 3 deletions src/OrientationCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
//

#import "OrientationCommand.h"

#import <PublicAutomation/UIAutomationBridge.h>
#import "FranklyProtocolHelper.h"
#import "JSON.h"

@interface UIApplication (Private)
- (BOOL)rotateIfNeeded:(UIDeviceOrientation)orientation;
@end

@implementation OrientationCommand

Expand Down Expand Up @@ -106,7 +107,7 @@ - (NSString *)handlePost:(NSString *)requestBody{
andDetails:[NSString stringWithFormat:@"orientation '%@' is invalid. Use 'landscape_right','landscape_left','portrait', or 'portrait_upside_down'", requestBody]];
}

[UIAutomationBridge setOrientation:requestedOrientation];
[[UIApplication sharedApplication] rotateIfNeeded:requestedOrientation];

return [FranklyProtocolHelper generateSuccessResponseWithoutResults];
}
Expand Down
33 changes: 29 additions & 4 deletions src/UISlider+PublicAutomation.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,42 @@
//
// Created by Alvaro Barbeira on 27/3/13
//
#import <PublicAutomation/UIAutomationBridge.h>
#import "LoadableCategory.h"
#import "CGGeometry-KIFAdditions.h"
#import "UIApplication-KIFAdditions.h"

@interface UIView ()

- (BOOL) FEX_dragFromPoint: (CGPoint) startPoint
toPoint: (CGPoint) destPoint
duration: (CGFloat) duration
delay: (BOOL) delay;

@end

MAKE_CATEGORIES_LOADABLE(UISlider_PublicAutomation)

#define UI_SLIDER_TIME_STEP 0.1

@implementation UISlider(PublicAutomation)

- (BOOL) FEX_dragThumbToValue:(double)value withDuration:(NSTimeInterval)interval {
return [UIAutomationBridge dragThumbInSlider:self toValue:value withDuration:interval];
- (BOOL) FEX_dragThumbToValue: (double) value withDuration: (NSTimeInterval) duration
{
CGRect bounds = [self bounds];
CGRect trackRect = [self trackRectForBounds: bounds];
CGRect startRect = [self thumbRectForBounds: bounds trackRect: trackRect value: [self value]];

CGPoint startPoint = CGPointCenteredInRect(startRect);
CGPoint destPoint = CGPointMake(bounds.size.width * value / [self maximumValue], 1.0);

startPoint = [self convertPoint: startPoint toView: nil];
destPoint = [self convertPoint: destPoint toView: nil];

return [self FEX_dragFromPoint: startPoint toPoint: destPoint duration: duration delay: NO];
}

- (BOOL) FEX_dragThumbToValue:(double) value {
return [UIAutomationBridge dragThumbInSlider:self toValue:value];
return [self FEX_dragThumbToValue: value withDuration: UI_SLIDER_TIME_STEP];
}

@end
Loading