mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
The update cycle is refactored and simplified. Notably we remove a suite of classes (automatic, probe, UI scheduled, UI initiated, core, basic, more..) and collapse them into a single update driver. If the update driver is started in automatic mode, it can escalate into UI mode without ending the cycle (previously we would end the cycle and flag that the next cycle had to be started in a UI mode carrying the previous update). SPUUpdater doesn't do installer progress queries anymore and thus these have been reduced. Even if a prior update has been downloaded before, the updater uses the regular scheduled check interval and the update driver is responsible for determining whether or not the impatient update interval has elapsed. Every update check checks if a newer superseded update is available and if it should replace any updates that have been previously been downloaded or started installing. The two conditions we do not check for superseded updates is if the installer is ran in the system domain (requiring authorization), and updating other bundles from an external updater (to not conflict with apps self-updating themselves). This change adds a UI test to test a superseded update is downloaded and began to install automatically. Fixes #2469. Previous attempt was in #2908 but I decided that was hacking the current architecture too much and exposing issues making it hard to implement this functionality correctly. Used AI for much of this refactoring, reviewing, and code implementation.
163 lines
6.5 KiB
Swift
163 lines
6.5 KiB
Swift
//
|
|
// SUTestApplicationTest.swift
|
|
// Sparkle
|
|
//
|
|
// Created by Mayur Pawashe on 8/27/15.
|
|
// Copyright © 2015 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
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?
|
|
let TEST_APP_BUNDLE_ID = "org.sparkle-project.SparkleTestApp"
|
|
|
|
func runningTestApplication() -> NSRunningApplication
|
|
{
|
|
let runningApplications = NSRunningApplication.runningApplications(withBundleIdentifier: TEST_APP_BUNDLE_ID)
|
|
XCTAssertEqual(runningApplications.count, 1, "More than one or zero running instances of the Test Application are found")
|
|
return runningApplications[0]
|
|
}
|
|
|
|
func runTestApplication(testMode: String, automatic: Bool, expectedFinalVersion: String, launchSleep: UInt32, extractSleep: UInt32) {
|
|
let app = XCUIApplication()
|
|
app.launchArguments = [
|
|
"-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(launchSleep)
|
|
|
|
let menuBarsQuery = app.menuBars
|
|
menuBarsQuery.menuBarItems["Sparkle Test App"].click()
|
|
|
|
let checkForUpdatesMenuItem = menuBarsQuery.menuItems["Check for Updates…"]
|
|
if checkForUpdatesMenuItem.isEnabled {
|
|
checkForUpdatesMenuItem.click()
|
|
|
|
// Give some time to wait for window to show up
|
|
sleep(5)
|
|
} else {
|
|
// We haven't checked for updates in a while so an automatic check was already done
|
|
// in this case click the main menu again to deactivate it
|
|
menuBarsQuery.menuBarItems["Sparkle Test App"].click()
|
|
}
|
|
|
|
if !automatic {
|
|
app.windows["SUUpdateAlert"].buttons["SPUUserUpdateChoiceInstall"].click()
|
|
|
|
// Give some time for the update to finish downloading / extracting
|
|
sleep(extractSleep)
|
|
|
|
app.windows["SUStatus"].buttons["SUStatusInstallAndRelaunch"].click()
|
|
} else {
|
|
XCTAssertTrue(app.windows["SUUpdateAlert"].buttons["SPUUserUpdateChoiceInstall"].exists)
|
|
|
|
// The app should install automatically on termination
|
|
app.terminate()
|
|
}
|
|
|
|
// Wait for the new updated app to finish launching so we can test if it's the frontmost app
|
|
sleep(10)
|
|
|
|
// From now on, do not rely on XCUIApplication as it only works properly when the XCUITest framework launches the app.
|
|
|
|
// 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)
|
|
|
|
// Verify the new bundle version
|
|
|
|
let infoCFDictionary = CFBundleCopyInfoDictionaryInDirectory(bundleURL as CFURL)
|
|
let infoDictionary = infoCFDictionary! as Dictionary
|
|
|
|
let updatedVersion = infoDictionary[kCFBundleVersionKey] as! String
|
|
XCTAssertEqual(updatedVersion, expectedFinalVersion)
|
|
|
|
// Clean up
|
|
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_AND_MARKDOWN", automatic: false, expectedFinalVersion: "2.1", launchSleep: 75, extractSleep: 45)
|
|
}
|
|
|
|
func test3AutomaticUpdate() {
|
|
runTestApplication(testMode: "AUTOMATIC", automatic: true, expectedFinalVersion: "2.2", launchSleep: 75, extractSleep: 30)
|
|
}
|
|
|
|
// Tests that "3.0" will be downloaded in first automatic update downloading check,
|
|
// then it will be superceded by "3.1" in the next update automatic downloading check
|
|
func test4UpdateSuperseded() {
|
|
let app = XCUIApplication()
|
|
app.launchArguments = [
|
|
"-SUHasLaunchedBefore",
|
|
"YES",
|
|
"-SUEnableAutomaticChecks",
|
|
"YES",
|
|
"-SUAutomaticallyUpdate",
|
|
"YES",
|
|
"-SUScheduledCheckInterval",
|
|
"60"
|
|
]
|
|
app.launchEnvironment = ["TEST_MODE": "SUPERSEDE"]
|
|
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 enough time to set up the web server and install both 3.0 and 3.1 updates
|
|
sleep(150)
|
|
|
|
// Quit without ever checking manually. The superseding "3.1" update should already be prepared
|
|
// and ready to install on quit
|
|
app.terminate()
|
|
|
|
// Wait for the new updated app to be installed
|
|
sleep(5)
|
|
|
|
// Validate update has been installed
|
|
|
|
XCTAssertTrue(initialRunningApplication.isTerminated)
|
|
|
|
let infoCFDictionary = CFBundleCopyInfoDictionaryInDirectory(bundleURL as CFURL)
|
|
let infoDictionary = infoCFDictionary! as Dictionary
|
|
|
|
let updatedVersion = infoDictionary[kCFBundleVersionKey] as! String
|
|
XCTAssertEqual(updatedVersion, "3.1", "Should have installed the superseding update, not the one abandoned mid-install")
|
|
|
|
sleep(10)
|
|
}
|
|
}
|