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

iOS: Improve notifications dispatch timing #604

Merged
merged 17 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,4 @@ examples/demo-native-ios/ModuleCache
yarn.lock
detox/ios_src
package-lock.json
/detox/src/devices/detox/notifications/notification.json
20 changes: 10 additions & 10 deletions detox/ios/Detox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
3947679C1DBF985400D72256 /* Detox.h in Headers */ = {isa = PBXBuildFile; fileRef = 3947679A1DBF985400D72256 /* Detox.h */; settings = {ATTRIBUTES = (Public, ); }; };
394767AE1DBF987E00D72256 /* DetoxManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 394767A41DBF987E00D72256 /* DetoxManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
394767AF1DBF987E00D72256 /* DetoxManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 394767A51DBF987E00D72256 /* DetoxManager.m */; };
394767B01DBF987E00D72256 /* MethodInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 394767A61DBF987E00D72256 /* MethodInvocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
394767B11DBF987E00D72256 /* MethodInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 394767A71DBF987E00D72256 /* MethodInvocation.m */; };
394767B01DBF987E00D72256 /* DTXMethodInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 394767A61DBF987E00D72256 /* DTXMethodInvocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
394767B11DBF987E00D72256 /* DTXMethodInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 394767A71DBF987E00D72256 /* DTXMethodInvocation.m */; };
394767B21DBF987E00D72256 /* TestFailureHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 394767A81DBF987E00D72256 /* TestFailureHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
394767B31DBF987E00D72256 /* TestFailureHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 394767A91DBF987E00D72256 /* TestFailureHandler.m */; };
394767B41DBF987E00D72256 /* TestRunner.h in Headers */ = {isa = PBXBuildFile; fileRef = 394767AA1DBF987E00D72256 /* TestRunner.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -72,9 +72,9 @@
39C3C3511DBF9A13008177E1 /* EarlGrey.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 394767DC1DBF991E00D72256 /* EarlGrey.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
39C3C3531DBF9A19008177E1 /* SocketRocket.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 394767E91DBF992400D72256 /* SocketRocket.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
39CEFCDB1E34E91B00A09124 /* DetoxUserNotificationDispatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39CEFCDA1E34E91B00A09124 /* DetoxUserNotificationDispatcher.swift */; };
39FFD9471FD730A600C97030 /* DetoxCrashHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 39FFD9451FD730A600C97030 /* DetoxCrashHandler.mm */; };
39F642281FDD5EB100468FED /* DTXLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = 39F642201FDD5EB000468FED /* DTXLogging.h */; };
39F642291FDD5EB100468FED /* DTXLogging.m in Sources */ = {isa = PBXBuildFile; fileRef = 39F642271FDD5EB000468FED /* DTXLogging.m */; };
39FFD9471FD730A600C97030 /* DetoxCrashHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 39FFD9451FD730A600C97030 /* DetoxCrashHandler.mm */; };
468731A51E6C6D0500F151BE /* EarlGrey+Detox.h in Headers */ = {isa = PBXBuildFile; fileRef = 468731A31E6C6D0500F151BE /* EarlGrey+Detox.h */; };
468731A61E6C6D0500F151BE /* EarlGrey+Detox.m in Sources */ = {isa = PBXBuildFile; fileRef = 468731A41E6C6D0500F151BE /* EarlGrey+Detox.m */; };
46A6A63D1EF697BB00E3AA79 /* GREYConfiguration+Detox.m in Sources */ = {isa = PBXBuildFile; fileRef = 46A6A63B1EF697BB00E3AA79 /* GREYConfiguration+Detox.m */; };
Expand Down Expand Up @@ -208,8 +208,8 @@
3947679B1DBF985400D72256 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
394767A41DBF987E00D72256 /* DetoxManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetoxManager.h; sourceTree = "<group>"; };
394767A51DBF987E00D72256 /* DetoxManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetoxManager.m; sourceTree = "<group>"; };
394767A61DBF987E00D72256 /* MethodInvocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MethodInvocation.h; sourceTree = "<group>"; };
394767A71DBF987E00D72256 /* MethodInvocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MethodInvocation.m; sourceTree = "<group>"; };
394767A61DBF987E00D72256 /* DTXMethodInvocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTXMethodInvocation.h; sourceTree = "<group>"; };
394767A71DBF987E00D72256 /* DTXMethodInvocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTXMethodInvocation.m; sourceTree = "<group>"; };
394767A81DBF987E00D72256 /* TestFailureHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestFailureHandler.h; sourceTree = "<group>"; };
394767A91DBF987E00D72256 /* TestFailureHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestFailureHandler.m; sourceTree = "<group>"; };
394767AA1DBF987E00D72256 /* TestRunner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestRunner.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -240,11 +240,11 @@
39A34C6F1E30F10D00BEBB59 /* DetoxAppDelegateProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetoxAppDelegateProxy.h; sourceTree = "<group>"; };
39A34C701E30F10D00BEBB59 /* DetoxAppDelegateProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetoxAppDelegateProxy.m; sourceTree = "<group>"; };
39CEFCDA1E34E91B00A09124 /* DetoxUserNotificationDispatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetoxUserNotificationDispatcher.swift; sourceTree = "<group>"; };
39FFD9451FD730A600C97030 /* DetoxCrashHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DetoxCrashHandler.mm; sourceTree = "<group>"; };
39F642201FDD5EB000468FED /* DTXLogging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DTXLogging.h; path = DTXLoggingInfra/DTXLogging.h; sourceTree = SOURCE_ROOT; };
39F642271FDD5EB000468FED /* DTXLogging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DTXLogging.m; path = DTXLoggingInfra/DTXLogging.m; sourceTree = SOURCE_ROOT; };
39F6422A1FDD5EEC00468FED /* Detox.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Detox.pch; sourceTree = "<group>"; };
39F6422B1FDD5F3300468FED /* DTXLoggingSubsystem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DTXLoggingSubsystem.h; sourceTree = "<group>"; };
39FFD9451FD730A600C97030 /* DetoxCrashHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DetoxCrashHandler.mm; sourceTree = "<group>"; };
468731A31E6C6D0500F151BE /* EarlGrey+Detox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "EarlGrey+Detox.h"; sourceTree = "<group>"; };
468731A41E6C6D0500F151BE /* EarlGrey+Detox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "EarlGrey+Detox.m"; sourceTree = "<group>"; };
46A6A6341EF696B600E3AA79 /* GREYConfiguration+Detox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GREYConfiguration+Detox.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -364,8 +364,8 @@
39A34C6F1E30F10D00BEBB59 /* DetoxAppDelegateProxy.h */,
39A34C701E30F10D00BEBB59 /* DetoxAppDelegateProxy.m */,
39CEFCDA1E34E91B00A09124 /* DetoxUserNotificationDispatcher.swift */,
394767A61DBF987E00D72256 /* MethodInvocation.h */,
394767A71DBF987E00D72256 /* MethodInvocation.m */,
394767A61DBF987E00D72256 /* DTXMethodInvocation.h */,
394767A71DBF987E00D72256 /* DTXMethodInvocation.m */,
394767A81DBF987E00D72256 /* TestFailureHandler.h */,
394767A91DBF987E00D72256 /* TestFailureHandler.m */,
394767AA1DBF987E00D72256 /* TestRunner.h */,
Expand Down Expand Up @@ -477,7 +477,7 @@
394767B41DBF987E00D72256 /* TestRunner.h in Headers */,
390D1CA01E3A4E38007F5F46 /* UNPushNotificationTrigger+PrivateHeaders.h in Headers */,
394767D01DBF98D900D72256 /* WXJSDisplayLinkIdlingResource.h in Headers */,
394767B01DBF987E00D72256 /* MethodInvocation.h in Headers */,
394767B01DBF987E00D72256 /* DTXMethodInvocation.h in Headers */,
394767C11DBF98A700D72256 /* GREYMatchers+Detox.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -711,7 +711,7 @@
A7F76A161ED33DE500FFE77E /* WXAnimatedDisplayLinkIdlingResource.m in Sources */,
394767D11DBF98D900D72256 /* WXJSDisplayLinkIdlingResource.m in Sources */,
39A34C721E30F10D00BEBB59 /* DetoxAppDelegateProxy.m in Sources */,
394767B11DBF987E00D72256 /* MethodInvocation.m in Sources */,
394767B11DBF987E00D72256 /* DTXMethodInvocation.m in Sources */,
39CEFCDB1E34E91B00A09124 /* DetoxUserNotificationDispatcher.swift in Sources */,
394767C21DBF98A700D72256 /* GREYMatchers+Detox.m in Sources */,
394767AF1DBF987E00D72256 /* DetoxManager.m in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions detox/ios/Detox/DTXMethodInvocation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DTXMethodInvocation.h
// Detox
//
// Created by Tal Kol on 6/16/16.
// Copyright © 2016 Wix. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface DTXMethodInvocation : NSObject

+ (id)invoke:(NSDictionary*)params onError:(void (^)(NSString*))onError;
+ (id)serializeValue:(id)value onError:(void (^)(NSString*))onError;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
// Copyright © 2016 Wix. All rights reserved.
//

#import "MethodInvocation.h"
#import "DTXMethodInvocation.h"
@import EarlGrey;

@implementation MethodInvocation
@implementation DTXMethodInvocation

+ (id) getTarget:(id)param onError:(void (^)(NSString*))onError
+ (id)getTarget:(id)param onError:(void (^)(NSString*))onError
{
if (param == nil) return nil;
if ([param isKindOfClass:[NSDictionary class]])
{
NSDictionary *p = (NSDictionary*)param;
NSString *type = [MethodInvocation getString:[p objectForKey:@"type"]];
NSString *type = [DTXMethodInvocation getString:[p objectForKey:@"type"]];
id value = [p objectForKey:@"value"];
return [MethodInvocation getValue:value withType:type onError:onError];
return [DTXMethodInvocation getValue:value withType:type onError:onError];
}
return nil;
}

+ (NSString*) getString:(id)param
+ (NSString*)getString:(id)param
{
if (param == nil) return nil;
if ([param isKindOfClass:[NSString class]]) return param;
return nil;
}

+ (id) getValue:(id)value withType:(id)type onError:(void (^)(NSString*))onError
+ (id)getValue:(id)value withType:(id)type onError:(void (^)(NSString*))onError
{
if (type == nil || value == nil) return nil;
if ([type isEqualToString:@"EarlGrey"])
Expand Down Expand Up @@ -86,33 +86,33 @@ + (id) getValue:(id)value withType:(id)type onError:(void (^)(NSString*))onError
if ([type isEqualToString:@"Invocation"])
{
if (![value isKindOfClass:[NSDictionary class]]) return nil;
return [MethodInvocation invoke:value onError:onError];
return [DTXMethodInvocation invoke:value onError:onError];
}
return nil;
}

+ (id) getArgValue:(id)param onError:(void (^)(NSString*))onError
+ (id)getArgValue:(id)param onError:(void (^)(NSString*))onError
{
if (param == nil) return nil;
if ([param isKindOfClass:[NSDictionary class]])
{
NSDictionary *p = (NSDictionary*)param;
NSString *type = [MethodInvocation getString:[p objectForKey:@"type"]];
NSString *type = [DTXMethodInvocation getString:[p objectForKey:@"type"]];
id value = [p objectForKey:@"value"];
return [MethodInvocation getValue:value withType:type onError:onError];
return [DTXMethodInvocation getValue:value withType:type onError:onError];
}

return param;
}

+ (NSArray*) getArray:(id)param
+ (NSArray*)getArray:(id)param
{
if (param == nil) return nil;
if ([param isKindOfClass:[NSArray class]]) return param;
return nil;
}

+ (id) getReturnValue:(NSInvocation*)invocation
+ (id)getReturnValue:(NSInvocation*)invocation
{
id res = nil;
NSString *type = [NSString stringWithUTF8String:invocation.methodSignature.methodReturnType];
Expand All @@ -139,7 +139,7 @@ + (id) getReturnValue:(NSInvocation*)invocation
return res;
}

+ (id) serializeValue:(id)value onError:(void (^)(NSString*))onError
+ (id)serializeValue:(id)value onError:(void (^)(NSString*))onError
{
if (value == nil) return nil;
if ([value isKindOfClass:[NSValue class]])
Expand All @@ -160,7 +160,7 @@ + (id) serializeValue:(id)value onError:(void (^)(NSString*))onError
return value;
}

+ (void) invocation:(NSInvocation*)invocation setNonPointerArg:(NSValue*)value atIndex:(NSInteger)idx
+ (void)invocation:(NSInvocation*)invocation setNonPointerArg:(NSValue*)value atIndex:(NSInteger)idx
{
NSString *type = [NSString stringWithUTF8String:value.objCType];
if ([type isEqualToString:@"q"])
Expand All @@ -185,21 +185,21 @@ + (void) invocation:(NSInvocation*)invocation setNonPointerArg:(NSValue*)value a
}
}

+ (id) invoke:(NSDictionary*)params onError:(void (^)(NSString*))onError
+ (id)invoke:(NSDictionary*)params onError:(void (^)(NSString*))onError
{
id target = [MethodInvocation getTarget:[params objectForKey:@"target"] onError:onError];
id target = [DTXMethodInvocation getTarget:[params objectForKey:@"target"] onError:onError];
if (target == nil)
{
onError(@"target is invalid");
return nil;
}
NSString *method = [MethodInvocation getString:[params objectForKey:@"method"]];
NSString *method = [DTXMethodInvocation getString:[params objectForKey:@"method"]];
if (method == nil)
{
onError(@"method is not a string");
return nil;
}
NSArray *args = [MethodInvocation getArray:[params objectForKey:@"args"]];
NSArray *args = [DTXMethodInvocation getArray:[params objectForKey:@"args"]];
if (args == nil)
{
onError(@"args is not an array");
Expand All @@ -219,7 +219,7 @@ + (id) invoke:(NSDictionary*)params onError:(void (^)(NSString*))onError
for (int i = 0; i<[args count]; i++)
{
id arg = args[i];
id argValue = [MethodInvocation getArgValue:arg onError:onError];
id argValue = [DTXMethodInvocation getArgValue:arg onError:onError];
if (argValue == nil)
{
onError([NSString stringWithFormat:@"invalid arg value %d", i]);
Expand All @@ -231,11 +231,11 @@ + (id) invoke:(NSDictionary*)params onError:(void (^)(NSString*))onError
}
else
{
[MethodInvocation invocation:invocation setNonPointerArg:argValue atIndex:i + 2];
[DTXMethodInvocation invocation:invocation setNonPointerArg:argValue atIndex:i + 2];
}
}
[invocation invoke];
return [MethodInvocation getReturnValue:invocation];
return [DTXMethodInvocation getReturnValue:invocation];
}

@end
3 changes: 3 additions & 0 deletions detox/ios/Detox/DetoxAppDelegateProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

@property (class, nonatomic, strong, readonly) DetoxAppDelegateProxy* currentAppDelegateProxy;

- (void)dispatchUserNotificationFromDataURL:(NSURL*)userNotificationDataURL delayUntilActive:(BOOL)delay;
- (void)dispatchOpenURL:(NSURL*)URL options:(NSDictionary*)options delayUntilActive:(BOOL)delay;

@end
Loading