From efd94e2de0bfda01a14f0cfb1f7fc8342934eaa6 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 6 Feb 2016 11:32:18 -0500 Subject: [PATCH] Add UI Tests for the Test Application This tests the test application checking for updates, downloading & installing, and relaunching --- Configurations/ConfigUITest.xcconfig | 11 ++ Configurations/ConfigUITestCoverage.xcconfig | 4 + Configurations/ConfigUITestDebug.xcconfig | 1 + Configurations/ConfigUITestRelease.xcconfig | 1 + Sparkle.xcodeproj/project.pbxproj | 123 ++++++++++++++++++- UITests/SUTestApplicationTest.swift | 95 ++++++++++++++ UITests/UITests-Info.plist | 24 ++++ 7 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 Configurations/ConfigUITest.xcconfig create mode 100644 Configurations/ConfigUITestCoverage.xcconfig create mode 100644 Configurations/ConfigUITestDebug.xcconfig create mode 100644 Configurations/ConfigUITestRelease.xcconfig create mode 100644 UITests/SUTestApplicationTest.swift create mode 100644 UITests/UITests-Info.plist diff --git a/Configurations/ConfigUITest.xcconfig b/Configurations/ConfigUITest.xcconfig new file mode 100644 index 00000000..7b1706bd --- /dev/null +++ b/Configurations/ConfigUITest.xcconfig @@ -0,0 +1,11 @@ +// UI Test only + +INFOPLIST_FILE = UITests/UITests-Info.plist +WRAPPER_EXTENSION = xctest +MACOSX_DEPLOYMENT_TARGET = 10.11 + +FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR) +LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks + +TEST_TARGET_NAME = Sparkle Test App +USES_XCTRUNNER = YES diff --git a/Configurations/ConfigUITestCoverage.xcconfig b/Configurations/ConfigUITestCoverage.xcconfig new file mode 100644 index 00000000..c4cf79fd --- /dev/null +++ b/Configurations/ConfigUITestCoverage.xcconfig @@ -0,0 +1,4 @@ +#include "ConfigUITest.xcconfig" + +GCC_GENERATE_TEST_COVERAGE_FILES = NO +GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO diff --git a/Configurations/ConfigUITestDebug.xcconfig b/Configurations/ConfigUITestDebug.xcconfig new file mode 100644 index 00000000..464bf485 --- /dev/null +++ b/Configurations/ConfigUITestDebug.xcconfig @@ -0,0 +1 @@ +#include "ConfigUITest.xcconfig" diff --git a/Configurations/ConfigUITestRelease.xcconfig b/Configurations/ConfigUITestRelease.xcconfig new file mode 100644 index 00000000..464bf485 --- /dev/null +++ b/Configurations/ConfigUITestRelease.xcconfig @@ -0,0 +1 @@ +#include "ConfigUITest.xcconfig" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 996c2210..5a196eb9 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -166,6 +166,8 @@ 61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */; }; 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (Required, ); }; }; + 720B16441C66433D006985FB /* UITests-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 720B16421C66433D006985FB /* UITests-Info.plist */; }; + 720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; }; 7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; }; 721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; 721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; }; @@ -299,6 +301,13 @@ remoteGlobalIDString = 8DC2EF4F0486A6940098B216; remoteInfo = Sparkle; }; + 726B2B621C645FC900388755 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 61B5F90109C4CEE200B25A18; + remoteInfo = "Sparkle Test App"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -610,15 +619,22 @@ 61F614540E24A12D009F47E7 /* it */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Sparkle.strings; sourceTree = ""; }; 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBasicUpdateDriver.h; sourceTree = ""; }; 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBasicUpdateDriver.m; sourceTree = ""; }; + 720B16421C66433D006985FB /* UITests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "UITests-Info.plist"; path = "UITests/UITests-Info.plist"; sourceTree = SOURCE_ROOT; }; + 720B16431C66433D006985FB /* SUTestApplicationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SUTestApplicationTest.swift; path = UITests/SUTestApplicationTest.swift; sourceTree = SOURCE_ROOT; }; 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = ""; }; 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaCreate.m; sourceTree = ""; }; 7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaCreate.h; sourceTree = ""; }; + 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 726F2CE31BC9C33D001971A4 /* SUOperatingSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUOperatingSystem.h; sourceTree = ""; }; 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUOperatingSystem.m; sourceTree = ""; }; 7275F9BF1B5F1F2900B1D19E /* SUFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileManager.h; sourceTree = ""; }; 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileManager.m; sourceTree = ""; }; + 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = ""; }; + 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; + 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestDebug.xcconfig; sourceTree = ""; }; + 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestRelease.xcconfig; sourceTree = ""; }; 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUFileManagerTest.swift; sourceTree = ""; }; 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = SparkleTestCodeSignApp.tar.gz; sourceTree = ""; }; 72AC6B271B9AAD6700F62325 /* SparkleTestCodeSignApp.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = SparkleTestCodeSignApp.tar; sourceTree = ""; }; @@ -709,6 +725,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 726B2B5A1C645FC900388755 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DC2EF560486A6940098B216 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -736,6 +759,7 @@ 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */, 612279D90DB5470200AB99EA /* Sparkle Unit Tests.xctest */, 8DC2EF5B0486A6940098B216 /* Sparkle.framework */, + 726B2B5D1C645FC900388755 /* UI Tests.xctest */, ); name = Products; sourceTree = ""; @@ -750,6 +774,7 @@ 14732BB51960ECBA00593899 /* Third Party */, 1420DE391962322200203BB0 /* Documentation */, FA1941C40D94A6EA00DD942E /* Configurations */, + 726B2B5E1C645FC900388755 /* UI Tests */, 0867D69AFE84028FC02AAC07 /* Frameworks */, 034768DFFF38A50411DB9C8B /* Products */, ); @@ -1082,6 +1107,15 @@ name = "Update Control"; sourceTree = ""; }; + 726B2B5E1C645FC900388755 /* UI Tests */ = { + isa = PBXGroup; + children = ( + 720B16421C66433D006985FB /* UITests-Info.plist */, + 720B16431C66433D006985FB /* SUTestApplicationTest.swift */, + ); + path = "UI Tests"; + sourceTree = ""; + }; FA1941C40D94A6EA00DD942E /* Configurations */ = { isa = PBXGroup; children = ( @@ -1106,6 +1140,10 @@ 149B78641B7D3A4800D7D62C /* ConfigUnitTestCoverage.xcconfig */, FA3AAF3A1050B273004B3130 /* ConfigUnitTestDebug.xcconfig */, FA3AAF391050B273004B3130 /* ConfigUnitTestRelease.xcconfig */, + 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */, + 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */, + 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */, + 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */, 14732BC91960F70A00593899 /* make-release-package.sh */, 14652F7919A93E5F00959E44 /* set-git-version-info.sh */, 146EC84E19A68CF8004A50C5 /* Sparkle.podspec */, @@ -1276,6 +1314,24 @@ productReference = 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */; productType = "com.apple.product-type.application"; }; + 726B2B5C1C645FC900388755 /* UI Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 726B2B671C645FC900388755 /* Build configuration list for PBXNativeTarget "UI Tests" */; + buildPhases = ( + 726B2B591C645FC900388755 /* Sources */, + 726B2B5A1C645FC900388755 /* Frameworks */, + 726B2B5B1C645FC900388755 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 726B2B631C645FC900388755 /* PBXTargetDependency */, + ); + name = "UI Tests"; + productName = "UI Tests"; + productReference = 726B2B5D1C645FC900388755 /* UI Tests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; 8DC2EF4F0486A6940098B216 /* Sparkle */ = { isa = PBXNativeTarget; buildConfigurationList = 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "Sparkle" */; @@ -1307,13 +1363,17 @@ isa = PBXProject; attributes = { CLASSPREFIX = SU; - LastSwiftUpdateCheck = 0700; + LastSwiftUpdateCheck = 0720; LastUpgradeCheck = 0710; ORGANIZATIONNAME = "Sparkle Project"; TargetAttributes = { 612279D80DB5470200AB99EA = { TestTargetID = 8DC2EF4F0486A6940098B216; }; + 726B2B5C1C645FC900388755 = { + CreatedOnToolsVersion = 7.2.1; + TestTargetID = 61B5F90109C4CEE200B25A18; + }; }; }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Sparkle" */; @@ -1381,6 +1441,7 @@ 14732BC51960F69300593899 /* Distribution */, 1420DF491962329200203BB0 /* Documentation */, 1495005F195FB89400BC5B5B /* All */, + 726B2B5C1C645FC900388755 /* UI Tests */, ); }; /* End PBXProject section */ @@ -1428,6 +1489,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 726B2B5B1C645FC900388755 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 720B16441C66433D006985FB /* UITests-Info.plist in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DC2EF520486A6940098B216 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1584,6 +1653,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 726B2B591C645FC900388755 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DC2EF540486A6940098B216 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1695,6 +1772,11 @@ target = 8DC2EF4F0486A6940098B216 /* Sparkle */; targetProxy = 61FA528C0E2D9EB200EF58AD /* PBXContainerItemProxy */; }; + 726B2B631C645FC900388755 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 61B5F90109C4CEE200B25A18 /* Sparkle Test App */; + targetProxy = 726B2B621C645FC900388755 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -2070,6 +2152,35 @@ }; name = Release; }; + 726B2B641C645FC900388755 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 726B2B651C645FC900388755 /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Coverage; + }; + 726B2B661C645FC900388755 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -2163,6 +2274,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 726B2B671C645FC900388755 /* Build configuration list for PBXNativeTarget "UI Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 726B2B641C645FC900388755 /* Debug */, + 726B2B651C645FC900388755 /* Coverage */, + 726B2B661C645FC900388755 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 0867D690FE84028FC02AAC07 /* Project object */; diff --git a/UITests/SUTestApplicationTest.swift b/UITests/SUTestApplicationTest.swift new file mode 100644 index 00000000..016d55c1 --- /dev/null +++ b/UITests/SUTestApplicationTest.swift @@ -0,0 +1,95 @@ +// +// SUTestApplicationTest.swift +// Sparkle +// +// Created by Mayur Pawashe on 8/27/15. +// Copyright © 2015 Sparkle Project. All rights reserved. +// + +import XCTest + +class SUTestApplicationTest: XCTestCase +{ + var testApplicationURL: NSURL? = nil + var testApplicationBackupURL: NSURL? = nil + var tempDirectoryURL: NSURL? = nil + + override func setUp() + { + super.setUp() + + let app = XCUIApplication() + app.launch() + + XCTAssertFalse(app.dialogs["alert"].staticTexts["Update succeeded!"].exists, "Update is already installed; please do a clean build") + + // We need to grab the app URL so we can back up the app + // When a successful test is over we'll revert the update + // TODO: don't hardcode bundle ID? + let runningApplications = NSRunningApplication.runningApplicationsWithBundleIdentifier("org.sparkle-project.SparkleTestApp") + XCTAssertEqual(runningApplications.count, 1, "More than one running instance of the Test Application is found") + let testApplicationURL = runningApplications[0].bundleURL! + + let tempDirectoryURL = try! NSFileManager.defaultManager().URLForDirectory(.ItemReplacementDirectory, inDomain: NSSearchPathDomainMask.UserDomainMask, appropriateForURL: testApplicationURL, create: true) + + let testApplicationBackupURL = tempDirectoryURL.URLByAppendingPathComponent(testApplicationURL.lastPathComponent!) + + try! NSFileManager.defaultManager().copyItemAtURL(testApplicationURL, toURL: testApplicationBackupURL) + + self.testApplicationURL = testApplicationURL + self.testApplicationBackupURL = testApplicationBackupURL + self.tempDirectoryURL = tempDirectoryURL + + // when we add more tests we don't want to continue after a failure + // since a test can fail after the new app has been placed in + self.continueAfterFailure = false + } + + override func tearDown() + { + // Terminate just in case the app hasn't already quit + XCUIApplication().terminate() + + // Revert our update with the original test application + + var resultingURL: NSURL? = nil + try! NSFileManager.defaultManager().replaceItemAtURL(self.testApplicationURL!, withItemAtURL: self.testApplicationBackupURL!, backupItemName: nil, options: .UsingNewMetadataOnly, resultingItemURL: &resultingURL) + + do { + try NSFileManager.defaultManager().removeItemAtURL(self.tempDirectoryURL!) + } catch let error as NSError { + NSLog("Failed to remove temporary directory \(self.tempDirectoryURL) with error: \(error)") + } + + // The URL we get back from NSFileManager should be the same.. + XCTAssertEqual(self.testApplicationURL, resultingURL, "Test application was replaced, but at a different location") + + super.tearDown() + } + + func testRegularUpdate() + { + let app = XCUIApplication() + let menuBarsQuery = app.menuBars + + menuBarsQuery.menuBarItems["Sparkle Test App"].click() + + // If the update window already showed up automatically, this option will be disabled. + // Even if it's disabled, attempting to click it will do no harm and continue on + menuBarsQuery.menuItems["Check for Updates…"].click() + + app.dialogs["SUUpdateAlert"].buttons["Install Update"].click() + app.buttons["Install and Relaunch"].click() + + // Our new updated app should be launched now + // Grab another XCUIApplication instance rather than using the old one, just in case + let updatedApp = XCUIApplication() + + // Check if we can click the "Update succeeded!" label rather than using the exists property + // Checking the exists property doesn't reload the "cache" and as such the UI tests still would think we are + // referring to the older app. Clicking does force the UI tests to find the new app however + updatedApp.dialogs["alert"].staticTexts["Update succeeded!"].click() + + updatedApp.dialogs["alert"].buttons["OK"].click() + } +} diff --git a/UITests/UITests-Info.plist b/UITests/UITests-Info.plist new file mode 100644 index 00000000..ba72822e --- /dev/null +++ b/UITests/UITests-Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + +