From 9f43d52917727fdca5b475ca8e57619d5f4faae9 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Mon, 17 Jun 2019 16:32:36 +0200 Subject: [PATCH] Remove alert pop-up in test scenarios to prevent main thread stalls --- .../xcshareddata/xcschemes/MacPass.xcscheme | 5 +++++ MacPass/MPAutotypeDaemon.m | 5 +++++ MacPass/NSApplication+MPAdditions.h | 1 + MacPass/NSApplication+MPAdditions.m | 9 +++++++++ 4 files changed, 20 insertions(+) diff --git a/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme b/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme index 8d47b276..e3598ee7 100644 --- a/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme +++ b/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme @@ -55,6 +55,11 @@ value = "YES" isEnabled = "YES"> + + diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index c33e4b4f..8f84b017 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -143,6 +143,11 @@ static MPAutotypeDaemon *_sharedInstance; if(!self.enabled) { return; } + + if(NSApplication.sharedApplication.isRunningTests) { + return; // Do not display pop-up when running tests + } + BOOL hideAlert = NO; if(nil != [NSUserDefaults.standardUserDefaults objectForKey:kMPSettingsKeyAutotypeHideAccessibiltyWarning]) { hideAlert = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyAutotypeHideAccessibiltyWarning]; diff --git a/MacPass/NSApplication+MPAdditions.h b/MacPass/NSApplication+MPAdditions.h index 2f7a1c9a..f5c86482 100644 --- a/MacPass/NSApplication+MPAdditions.h +++ b/MacPass/NSApplication+MPAdditions.h @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN @property (copy, readonly) NSString *applicationName; @property (copy, readonly, nullable) NSURL *applicationSupportDirectoryURL; @property (nullable, readonly, weak) MPAppDelegate *mp_delegate; +@property (readonly, nonatomic) BOOL isRunningTests; - (NSURL *_Nullable)applicationSupportDirectoryURL:(BOOL)create; - (void)relaunchAfterDelay:(CGFloat)seconds; diff --git a/MacPass/NSApplication+MPAdditions.m b/MacPass/NSApplication+MPAdditions.m index c9cc6915..0970cbdf 100644 --- a/MacPass/NSApplication+MPAdditions.m +++ b/MacPass/NSApplication+MPAdditions.m @@ -66,4 +66,13 @@ return (MPAppDelegate *)self.delegate; } +- (BOOL)isRunningTests { + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + NSString *testEnv = processInfo.environment[@"MPIsRunningTests"]; + if(testEnv) { + return [testEnv isEqualToString:@"YES"]; + } + return NO; +} + @end