Add UI tests for delta updates and automatic updates (#2054)

This commit is contained in:
Zorg authored and GitHub committed 2022-01-08 18:05:07 -08:00
1 parent f6396aecfb
commit 51ee14c3d3
5 files changed
+269 -75

No files matched your search

+22
View File
@@ -406,6 +406,16 @@
72EF30C42675CFA1008CE987 /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */; };
72EF30C52675CFA1008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; };
72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
72F0EC45278A55CA002A876A /* screenshot.png in Resources */ = {isa = PBXBuildFile; fileRef = 72F0EC44278A55CA002A876A /* screenshot.png */; };
72F0EC46278A5B87002A876A /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5711D3D895B00D1BF90 /* SUBinaryDeltaCommon.m */; };
72F0EC47278A5B87002A876A /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5731D3D895B00D1BF90 /* SUBinaryDeltaCreate.m */; };
72F0EC48278A5B95002A876A /* SPUDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 725EE485277D375F00D820CE /* SPUDeltaArchive.m */; };
72F0EC49278A5B95002A876A /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
72F0EC4A278A5B95002A876A /* SPUXarDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 725EE47F277BF13B00D820CE /* SPUXarDeltaArchive.m */; };
72F0EC4B278A5BB2002A876A /* libxar.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E07681CA616A4001A286B /* libxar.tbd */; };
72F0EC4C278A5BB9002A876A /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E076A1CA616B3001A286B /* libbz2.tbd */; };
72F0EC4D278A5BCA002A876A /* libbsdiff.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EA1E280F22B64522004AA304 /* libbsdiff.a */; };
72F0EC4E278A73C6002A876A /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
72F94F581CC44DE1002DEE68 /* SPUXPCServiceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F94F561CC44DE1002DEE68 /* SPUXPCServiceInfo.h */; };
72F94F591CC44DE1002DEE68 /* SPUXPCServiceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F94F571CC44DE1002DEE68 /* SPUXPCServiceInfo.m */; };
72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */; };
@@ -1331,6 +1341,7 @@
72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemStateResolver.m; sourceTree = "<group>"; };
72EF30BD2675CF38008CE987 /* SPUAppcastItemState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemState.h; sourceTree = "<group>"; };
72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SUAppcastItem+Private.h"; sourceTree = "<group>"; };
72F0EC44278A55CA002A876A /* screenshot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = screenshot.png; sourceTree = "<group>"; };
72F94ED51CC3441A002DEE68 /* ConfigInstallerLauncherDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerLauncherDebug.xcconfig; sourceTree = "<group>"; };
72F94ED61CC344A7002DEE68 /* ConfigDownloaderDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigDownloaderDebug.xcconfig; sourceTree = "<group>"; };
72F94EDA1CC36C37002DEE68 /* ConfigTestAppDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigTestAppDebug.xcconfig; sourceTree = "<group>"; };
@@ -1436,6 +1447,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
72F0EC4D278A5BCA002A876A /* libbsdiff.a in Frameworks */,
72F0EC4C278A5BB9002A876A /* libbz2.tbd in Frameworks */,
72F0EC4B278A5BB2002A876A /* libxar.tbd in Frameworks */,
5A06357423FE33A400478A72 /* libed25519.a in Frameworks */,
14950073195FCE4E00BC5B5B /* AppKit.framework in Frameworks */,
14950072195FCE4B00BC5B5B /* Foundation.framework in Frameworks */,
@@ -1974,6 +1988,7 @@
72E45CF51B640DAE005C701A /* SUUpdateSettingsWindowController.m */,
72E45CF61B640DAE005C701A /* SUUpdateSettingsWindowController.xib */,
61B5F90409C4CEE200B25A18 /* TestApplication-Info.plist */,
72F0EC44278A55CA002A876A /* screenshot.png */,
);
name = "Test Application";
path = TestApplication;
@@ -3052,6 +3067,7 @@
72E45CFC1B641961005C701A /* sparkletestcast.xml in Resources */,
725F97A61C8B304D00265BE4 /* SUInstallUpdateViewController.xib in Resources */,
723ABE02259A9E9E00BDB4FA /* MainMenu.xib in Resources */,
72F0EC45278A55CA002A876A /* screenshot.png in Resources */,
72E45CF81B640DAE005C701A /* SUUpdateSettingsWindowController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -3254,6 +3270,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
72F0EC4E278A73C6002A876A /* SUFileManager.m in Sources */,
72F0EC48278A5B95002A876A /* SPUDeltaArchive.m in Sources */,
72F0EC49278A5B95002A876A /* SPUSparkleDeltaArchive.m in Sources */,
72F0EC4A278A5B95002A876A /* SPUXarDeltaArchive.m in Sources */,
72F0EC46278A5B87002A876A /* SUBinaryDeltaCommon.m in Sources */,
72F0EC47278A5B87002A876A /* SUBinaryDeltaCreate.m in Sources */,
61B5F93009C4CFDC00B25A18 /* main.m in Sources */,
726F2CEB1BC9C733001971A4 /* SUConstants.m in Sources */,
725F97A51C8B304D00265BE4 /* SUInstallUpdateViewController.m in Sources */,
+150 -54
View File
@@ -14,12 +14,14 @@
#import "ed25519.h" // Run `git submodule update --init` if you get an error here
#import <Sparkle/Sparkle.h>
#import "SUPopUpTitlebarUserDriver.h"
#import "SUBinaryDeltaCreate.h"
@interface SUTestApplicationDelegate ()
@interface SUTestApplicationDelegate () <SPUUpdaterDelegate>
@property (nonatomic) SPUUpdater *updater;
@property (nonatomic) SUUpdateSettingsWindowController *updateSettingsWindowController;
@property (nonatomic) SUTestWebServer *webServer;
@property (nonatomic, copy) NSString *testMode;
@end
@@ -28,15 +30,26 @@
@synthesize updater = _updater;
@synthesize updateSettingsWindowController = _updateSettingsWindowController;
@synthesize webServer = _webServer;
static NSString * const UPDATED_VERSION = @"2.0";
@synthesize testMode = _testMode;
- (void)applicationDidFinishLaunching:(NSNotification * __unused)notification
{
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *testModeEnv = [[[NSProcessInfo processInfo] environment] objectForKey:@"TEST_MODE"];
NSString *testMode;
if (testModeEnv == nil) {
testMode = @"REGULAR";
} else {
testMode = testModeEnv;
}
self.testMode = testMode;
// Check if we are already up to date
if ([(NSString *)[mainBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey] isEqualToString:UPDATED_VERSION]) {
NSString *mainBundleVersion = (NSString *)[mainBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
if (([mainBundleVersion hasPrefix:@"2."] && [testMode isEqualToString:@"REGULAR"]) || (([mainBundleVersion isEqualToString:@"2.1"] || [mainBundleVersion isEqualToString:@"2.2"]) && [testMode isEqualToString:@"DELTA"]) || ([mainBundleVersion isEqualToString:@"2.2"] && [testMode isEqualToString:@"AUTOMATIC"])) {
NSAlert *alreadyUpdatedAlert = [[NSAlert alloc] init];
alreadyUpdatedAlert.messageText = @"Update succeeded!";
alreadyUpdatedAlert.informativeText = @"This is the updated version of Sparkle Test App.\n\nDelete and rebuild the app to test updates again.";
@@ -107,57 +120,50 @@ static NSString * const UPDATED_VERSION = @"2.0";
BOOL infoFileExists = [infoURL checkResourceIsReachableAndReturnError:nil];
assert(infoFileExists);
NSString *finalUpdatedVersion;
if ([testMode isEqualToString:@"REGULAR"]) {
finalUpdatedVersion = @"2.0";
} else if ([testMode isEqualToString:@"DELTA"]) {
finalUpdatedVersion = @"2.1";
} else if ([testMode isEqualToString:@"AUTOMATIC"]) {
finalUpdatedVersion = @"2.2";
} else {
assert(false);
}
NSMutableDictionary *infoDictionary = [[NSMutableDictionary alloc] initWithContentsOfURL:infoURL];
[infoDictionary setObject:UPDATED_VERSION forKey:(__bridge NSString *)kCFBundleVersionKey];
[infoDictionary setObject:UPDATED_VERSION forKey:@"CFBundleShortVersionString"];
[infoDictionary setObject:finalUpdatedVersion forKey:(__bridge NSString *)kCFBundleVersionKey];
[infoDictionary setObject:finalUpdatedVersion forKey:@"CFBundleShortVersionString"];
BOOL wroteInfoFile = [infoDictionary writeToURL:infoURL atomically:NO];
assert(wroteInfoFile);
// Overwrite and add new data
{
NSURL *screenshotURL = [[[[destinationBundleURL URLByAppendingPathComponent:@"Contents"] URLByAppendingPathComponent:@"Resources"] URLByAppendingPathComponent:@"screenshot"] URLByAppendingPathExtension:@"png"];
assert([screenshotURL checkResourceIsReachableAndReturnError:NULL]);
NSMutableData *screenshotData = [NSMutableData dataWithContentsOfURL:screenshotURL];
uint32_t garbage = 1337;
[screenshotData appendBytes:&garbage length:sizeof(garbage)];
BOOL wroteData = [screenshotData writeToURL:screenshotURL atomically:NO];
assert(wroteData);
NSURL *newDataURL = [[screenshotURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:@"new_file"];
assert(newDataURL != nil);
BOOL wroteNewData = [[NSData dataWithBytes:&garbage length:sizeof(garbage)] writeToURL:newDataURL atomically:NO];
assert(wroteNewData);
}
[self signApplicationIfRequiredAtPath:destinationBundleURL.path completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
// Change current working directory so web server knows where to list files
NSString *serverDirectoryPath = serverDirectoryURL.path;
assert(serverDirectoryPath != nil);
// Create the archive for our update
NSString *zipName = @"Sparkle_Test_App.zip";
NSTask *dittoTask = [[NSTask alloc] init];
dittoTask.launchPath = @"/usr/bin/ditto";
dittoTask.arguments = @[@"-c", @"-k", @"--sequesterRsrc", @"--keepParent", (NSString *)destinationBundleURL.lastPathComponent, zipName];
dittoTask.currentDirectoryPath = serverDirectoryPath;
[dittoTask launch];
[dittoTask waitUntilExit];
assert(dittoTask.terminationStatus == 0);
[fileManager removeItemAtURL:destinationBundleURL error:NULL];
// Don't ever do this at home, kids (seriously)
// (that is, including the private key inside of your application)
const unsigned char self_sign_demo_only_insecure_hack[64] = {200, 238, 135, 84, 10, 189, 3, 193, 61, 208, 203, 30, 133, 47, 12, 22, 19, 52, 252, 99, 110, 205, 209, 94, 215, 144, 201, 70, 27, 162, 163, 108, 0, 164, 68, 184, 226, 93, 121, 199, 172, 17, 26, 64, 89, 68, 232, 41, 2, 26, 245, 175, 158, 165, 42, 55, 5, 97, 8, 243, 251, 164, 93, 9};
// in normal app this goes to Info.plist
const unsigned char public_key[32] = {121, 17, 79, 45, 155, 141, 51, 169, 188, 110, 91, 102, 182, 147, 215, 225, 252, 202, 110, 231, 200, 215, 62, 171, 40, 145, 237, 128, 130, 44, 150, 89};
unsigned char signature[64];
NSURL *archiveURL = [serverDirectoryURL URLByAppendingPathComponent:zipName];
NSData *archive = [NSData dataWithContentsOfURL:archiveURL];
assert(archive != nil);
ed25519_sign(signature, archive.bytes, archive.length, public_key, self_sign_demo_only_insecure_hack);
NSString *signatureString = [[NSData dataWithBytes:signature length:64] base64EncodedStringWithOptions:0];
// Obtain the file attributes to get the file size of our update later
NSError *fileAttributesError = nil;
NSString *archiveURLPath = archiveURL.path;
assert(archiveURLPath != nil);
NSDictionary *archiveFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:archiveURLPath error:&fileAttributesError];
if (archiveFileAttributes == nil) {
NSLog(@"Failed to retrieve file attributes from archive with error %@", fileAttributesError);
abort();
}
NSString * const appcastName = @"sparkletestcast";
NSString * const appcastExtension = @"xml";
@@ -180,18 +186,97 @@ static NSString * const UPDATED_VERSION = @"2.0";
abort();
}
NSUInteger numberOfLengthReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_ARCHIVE_LENGTH" withString:[NSString stringWithFormat:@"%llu", archiveFileAttributes.fileSize] options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfLengthReplacements == 1);
// Don't ever do this at home, kids (seriously)
// (that is, including the private key inside of your application)
const unsigned char self_sign_demo_only_insecure_hack[64] = {200, 238, 135, 84, 10, 189, 3, 193, 61, 208, 203, 30, 133, 47, 12, 22, 19, 52, 252, 99, 110, 205, 209, 94, 215, 144, 201, 70, 27, 162, 163, 108, 0, 164, 68, 184, 226, 93, 121, 199, 172, 17, 26, 64, 89, 68, 232, 41, 2, 26, 245, 175, 158, 165, 42, 55, 5, 97, 8, 243, 251, 164, 93, 9};
// in normal app this goes to Info.plist
const unsigned char public_key[32] = {121, 17, 79, 45, 155, 141, 51, 169, 188, 110, 91, 102, 182, 147, 215, 225, 252, 202, 110, 231, 200, 215, 62, 171, 40, 145, 237, 128, 130, 44, 150, 89};
unsigned char signature[64];
NSUInteger numberOfSignatureReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_EDDSA_SIGNATURE" withString:signatureString options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfSignatureReplacements == 1);
NSError *writeAppcastError = nil;
if (![appcastContents writeToURL:appcastDestinationURL atomically:NO encoding:NSUTF8StringEncoding error:&writeAppcastError]) {
NSLog(@"Failed to write updated appcast with error %@", writeAppcastError);
abort();
if ([testMode isEqualToString:@"DELTA"]) {
NSError *deltaCreationError = nil;
NSURL *patchURL = [serverDirectoryURL URLByAppendingPathComponent:@"patch.delta"];
if (!createBinaryDelta(bundleURL.path, destinationBundleURL.path, patchURL.path, SUBinaryDeltaMajorVersionDefault, SPUDeltaCompressionModeDefault, 0, NO, &deltaCreationError)) {
NSLog(@"Failed to create binary delta patch: %@", deltaCreationError);
abort();
}
NSData *archive = [NSData dataWithContentsOfURL:patchURL];
assert(archive != nil);
ed25519_sign(signature, archive.bytes, archive.length, public_key, self_sign_demo_only_insecure_hack);
NSString *signatureString = [[NSData dataWithBytes:signature length:64] base64EncodedStringWithOptions:0];
// Obtain the file attributes to get the file size of our update later
NSError *fileAttributesError = nil;
NSString *archiveURLPath = patchURL.path;
assert(archiveURLPath != nil);
NSDictionary *archiveFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:archiveURLPath error:&fileAttributesError];
if (archiveFileAttributes == nil) {
NSLog(@"Failed to retrieve file attributes from delta archive with error %@", fileAttributesError);
abort();
}
NSUInteger numberOfLengthReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_DELTA_ARCHIVE_LENGTH" withString:[NSString stringWithFormat:@"%llu", archiveFileAttributes.fileSize] options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfLengthReplacements == 1);
NSUInteger numberOfSignatureReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_DELTA_EDDSA_SIGNATURE" withString:signatureString options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfSignatureReplacements == 1);
NSUInteger numberOfFromVersionReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_DELTA_FROM_VERSION" withString:mainBundleVersion options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfFromVersionReplacements == 1);
NSError *writeAppcastError = nil;
if (![appcastContents writeToURL:appcastDestinationURL atomically:NO encoding:NSUTF8StringEncoding error:&writeAppcastError]) {
NSLog(@"Failed to write updated appcast with error %@", writeAppcastError);
abort();
}
} else {
// Create the archive for our update
NSString *zipName = @"Sparkle_Test_App.zip";
NSTask *dittoTask = [[NSTask alloc] init];
dittoTask.launchPath = @"/usr/bin/ditto";
dittoTask.arguments = @[@"-c", @"-k", @"--sequesterRsrc", @"--keepParent", (NSString *)destinationBundleURL.lastPathComponent, zipName];
dittoTask.currentDirectoryPath = serverDirectoryPath;
[dittoTask launch];
[dittoTask waitUntilExit];
assert(dittoTask.terminationStatus == 0);
NSURL *archiveURL = [serverDirectoryURL URLByAppendingPathComponent:zipName];
NSData *archive = [NSData dataWithContentsOfURL:archiveURL];
assert(archive != nil);
ed25519_sign(signature, archive.bytes, archive.length, public_key, self_sign_demo_only_insecure_hack);
NSString *signatureString = [[NSData dataWithBytes:signature length:64] base64EncodedStringWithOptions:0];
// Obtain the file attributes to get the file size of our update later
NSError *fileAttributesError = nil;
NSString *archiveURLPath = archiveURL.path;
assert(archiveURLPath != nil);
NSDictionary *archiveFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:archiveURLPath error:&fileAttributesError];
if (archiveFileAttributes == nil) {
NSLog(@"Failed to retrieve file attributes from archive with error %@", fileAttributesError);
abort();
}
NSUInteger numberOfLengthReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_ARCHIVE_LENGTH" withString:[NSString stringWithFormat:@"%llu", archiveFileAttributes.fileSize] options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfLengthReplacements == 2);
NSUInteger numberOfSignatureReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_EDDSA_SIGNATURE" withString:signatureString options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
assert(numberOfSignatureReplacements == 2);
NSError *writeAppcastError = nil;
if (![appcastContents writeToURL:appcastDestinationURL atomically:NO encoding:NSUTF8StringEncoding error:&writeAppcastError]) {
NSLog(@"Failed to write updated appcast with error %@", writeAppcastError);
abort();
}
}
[fileManager removeItemAtURL:destinationBundleURL error:NULL];
// Finally start the server
SUTestWebServer *webServer = [[SUTestWebServer alloc] initWithPort:1337 workingDirectory:serverDirectoryPath];
if (!webServer) {
@@ -220,7 +305,7 @@ static NSString * const UPDATED_VERSION = @"2.0";
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:settingsWindow];
#endif
SPUUpdater *updater = [[SPUUpdater alloc] initWithHostBundle:hostBundle applicationBundle:applicationBundle userDriver:userDriver delegate:nil];
SPUUpdater *updater = [[SPUUpdater alloc] initWithHostBundle:hostBundle applicationBundle:applicationBundle userDriver:userDriver delegate:self];
self.updater = updater;
self.updateSettingsWindowController.updater = updater;
@@ -242,6 +327,17 @@ static NSString * const UPDATED_VERSION = @"2.0";
}];
}
- (NSSet<NSString *> *)allowedChannelsForUpdater:(SPUUpdater *)updater
{
if ([self.testMode isEqualToString:@"DELTA"]) {
return [NSSet setWithObject:@"delta"];
} else if ([self.testMode isEqualToString:@"AUTOMATIC"]) {
return [NSSet setWithObject:@"automatic"];
} else {
return [NSSet set];
}
}
- (void)signApplicationIfRequiredAtPath:(NSString *)applicationPath completion:(void (^)(void))completionBlock
{
// This is unfortunately necessary for testing sandboxing
Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

+46 -2
View File
@@ -4,7 +4,51 @@
<title>Sparkle Test App Changelog</title>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<item>
<title>Version 2.2</title>
<sparkle:version>2.2</sparkle:version>
<link>https://sparkle-project.org</link>
<sparkle:channel>automatic</sparkle:channel>
<sparkle:fullReleaseNotesLink>releasenotes.html</sparkle:fullReleaseNotesLink>
<description>
<![CDATA[
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
</ul>
]]>
</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="$INSERT_ARCHIVE_LENGTH" type="application/octet-stream" sparkle:edSignature="$INSERT_EDDSA_SIGNATURE" />
</item>
<item>
<title>Version 2.1</title>
<sparkle:version>2.1</sparkle:version>
<link>https://sparkle-project.org</link>
<sparkle:channel>delta</sparkle:channel>
<sparkle:fullReleaseNotesLink>releasenotes.html</sparkle:fullReleaseNotesLink>
<description>
<![CDATA[
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Suspendisse sed felis ac ante ultrices rhoncus. Etiam quis elit vel nibh placerat facilisis in id leo.</li>
</ul>
]]>
</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<!-- Note: this file won't actually exist to ensure delta update works -->
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="100000" type="application/octet-stream" sparkle:edSignature="ootgYIwmnS1wa7Q/5SXDXnOVdKnjkjrFhm/D7ukW77k=" />
<sparkle:deltas>
<enclosure url="http://localhost:1337/patch.delta"
sparkle:deltaFrom="$INSERT_DELTA_FROM_VERSION"
length="$INSERT_DELTA_ARCHIVE_LENGTH"
type="application/octet-stream"
sparkle:edSignature="$INSERT_DELTA_EDDSA_SIGNATURE" />
</sparkle:deltas>
</item>
<item>
<title>Version 2.0</title>
<sparkle:version>2.0</sparkle:version>
<link>https://sparkle-project.org</link>
@@ -21,6 +65,6 @@
</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="$INSERT_ARCHIVE_LENGTH" type="application/octet-stream" sparkle:edSignature="$INSERT_EDDSA_SIGNATURE" />
</item>
</item>
</channel>
</rss>
+51 -19
View File
@@ -8,6 +8,9 @@
import XCTest
// The debugger may catch the Test app receiving a SIGTERM signal when Sparkle quits the app before installing the new one
// So you may have better luck running these tests from the command line without the debugger attached:
// xcodebuild -scheme UITests -configuration Debug test
class SUTestApplicationTest: XCTestCase
{
// TODO: don't hardcode bundle ID?
@@ -20,24 +23,30 @@ class SUTestApplicationTest: XCTestCase
return runningApplications[0]
}
// The debugger may catch the Test app receiving a SIGTERM signal when Sparkle quits the app before installing the new one
// So you may have better luck running this test from the command line without the debugger attached:
// xcodebuild -scheme UITests -configuration Debug test
func testRegularUpdate()
{
func runTestApplication(testMode: String, automatic: Bool, expectedFinalVersion: String, launchSleep: UInt32, extractSleep: UInt32) {
let app = XCUIApplication()
app.launchArguments = [
"-AppleLanguages",
"(en)"
"(en)",
"-SUHasLaunchedBefore",
automatic ? "YES" : "NO",
"-SUEnableAutomaticChecks",
automatic ? "YES" : "NO",
"-SUAutomaticallyUpdate",
automatic ? "YES" : "NO",
"-SUScheduledCheckInterval",
"60"
]
app.launchEnvironment = ["TEST_MODE": testMode]
app.launch()
XCTAssertFalse(app.dialogs["alert"].staticTexts["Update succeeded!"].exists, "Update is already installed; please do a clean build")
let initialRunningApplication = runningTestApplication()
let bundleURL = initialRunningApplication.bundleURL!
// Give some time for the Test App to initialize its web server, create an update, and start its updater
sleep(60)
sleep(launchSleep)
let menuBarsQuery = app.menuBars
menuBarsQuery.menuBarItems["Sparkle Test App"].click()
@@ -50,14 +59,21 @@ class SUTestApplicationTest: XCTestCase
// in this case click the main menu again to deactivate it
menuBarsQuery.menuBarItems["Sparkle Test App"].click()
}
app.windows["SUUpdateAlert"].buttons["Install Update"].click()
// Give some time for the update to finish downloading / extracting
sleep(30)
if !automatic {
app.windows["SUUpdateAlert"].buttons["Install Update"].click()
// Give some time for the update to finish downloading / extracting
sleep(extractSleep)
app.windows["SUStatus"].buttons["Install and Relaunch"].click()
} else {
XCTAssertTrue(app.windows["SUUpdateAlert"].buttons["Install and Relaunch"].exists)
// The app should install automatically on termination
app.terminate()
}
app.windows["SUStatus"].buttons["Install and Relaunch"].click()
// Wait for the new updated app to finish launching so we can test if it's the frontmost app
sleep(10)
@@ -66,19 +82,35 @@ class SUTestApplicationTest: XCTestCase
// Our new updated app should be launched now. Test if it's the active app and the old app is terminated.
// We used to run into timing issues where the updated app sometimes may not show up as the frontmost one
XCTAssertTrue(initialRunningApplication.isTerminated)
let newRunningApplication = self.runningTestApplication()
XCTAssertTrue(newRunningApplication.isActive)
// Verify the new bundle version
let infoCFDictionary = CFBundleCopyInfoDictionaryInDirectory(newRunningApplication.bundleURL! as CFURL)
let infoCFDictionary = CFBundleCopyInfoDictionaryInDirectory(bundleURL as CFURL)
let infoDictionary = infoCFDictionary! as Dictionary
let updatedVersion = infoDictionary[kCFBundleVersionKey] as! String
XCTAssertEqual(updatedVersion, "2.0")
XCTAssertEqual(updatedVersion, expectedFinalVersion)
// Clean up
newRunningApplication.forceTerminate()
if !automatic {
let newRunningApplication = self.runningTestApplication()
XCTAssertTrue(newRunningApplication.isActive)
newRunningApplication.forceTerminate()
}
sleep(10)
}
func test1RegularUpdate() {
runTestApplication(testMode: "REGULAR", automatic: false, expectedFinalVersion: "2.0", launchSleep: 60, extractSleep: 30)
}
func test2DeltaUpdate() {
runTestApplication(testMode: "DELTA", automatic: false, expectedFinalVersion: "2.1", launchSleep: 75, extractSleep: 45)
}
func test3AutomaticUpdate() {
runTestApplication(testMode: "AUTOMATIC", automatic: true, expectedFinalVersion: "2.2", launchSleep: 75, extractSleep: 30)
}
}