mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
2982bfa483
--HG-- rename : toolkit/webapps/tests/test_hosted.xul => toolkit/webapps/tests/test_hosted_launch.xul rename : toolkit/webapps/tests/test_packaged.xul => toolkit/webapps/tests/test_packaged_launch.xul
339 lines
12 KiB
XML
339 lines
12 KiB
XML
<?xml version="1.0"?>
|
|
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
|
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=898647
|
|
-->
|
|
<window title="Mozilla Bug 898647"
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
<script type="application/javascript"
|
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="application/javascript" src="head.js"/>
|
|
|
|
<!-- test results are displayed in the html:body -->
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=898647"
|
|
target="_blank">Mozilla Bug 898647</a>
|
|
</body>
|
|
|
|
<script type="application/javascript">
|
|
<![CDATA[
|
|
|
|
/** Test for Bug 898647 **/
|
|
|
|
"use strict";
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
Cu.import("resource://gre/modules/NativeApp.jsm");
|
|
Cu.import("resource://gre/modules/WebappOSUtils.jsm");
|
|
|
|
let zipPath = OS.Path.join(OS.Constants.Path.profileDir, "sample.zip");
|
|
|
|
let manifest = {
|
|
name: "Sample packaged app",
|
|
version: "0.1a",
|
|
size: 777,
|
|
package_path: "/sample.zip",
|
|
};
|
|
|
|
let app = {
|
|
name: "Sample packaged app",
|
|
manifestURL: "http://example.com/sample.manifest",
|
|
manifest: manifest,
|
|
updateManifest: manifest,
|
|
origin: "http://example.com/",
|
|
categories: [],
|
|
installOrigin: "http://example.com/",
|
|
receipts: [],
|
|
installTime: Date.now(),
|
|
};
|
|
|
|
let profileDir;
|
|
let profilesIni;
|
|
let installPath;
|
|
|
|
let installedFiles;
|
|
let tempUpdatedFiles;
|
|
let updatedFiles;
|
|
|
|
let cleanup;
|
|
|
|
if (navigator.platform.startsWith("Linux")) {
|
|
installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app));
|
|
|
|
let xdg_data_home = Cc["@mozilla.org/process/environment;1"].
|
|
getService(Ci.nsIEnvironment).
|
|
get("XDG_DATA_HOME");
|
|
if (!xdg_data_home) {
|
|
xdg_data_home = OS.Path.join(OS.Constants.Path.homeDir, ".local", "share");
|
|
}
|
|
|
|
let desktopINI = OS.Path.join(xdg_data_home, "applications",
|
|
"owa-" + WebappOSUtils.getUniqueName(app) + ".desktop");
|
|
|
|
installedFiles = [
|
|
OS.Path.join(installPath, "icon.png"),
|
|
OS.Path.join(installPath, "webapprt-stub"),
|
|
OS.Path.join(installPath, "webapp.json"),
|
|
OS.Path.join(installPath, "webapp.ini"),
|
|
OS.Path.join(installPath, "application.zip"),
|
|
desktopINI,
|
|
];
|
|
tempUpdatedFiles = [
|
|
OS.Path.join(installPath, "update", "icon.png"),
|
|
OS.Path.join(installPath, "update", "webapp.json"),
|
|
OS.Path.join(installPath, "update", "webapp.ini"),
|
|
OS.Path.join(installPath, "update", "application.zip"),
|
|
];
|
|
updatedFiles = [
|
|
OS.Path.join(installPath, "icon.png"),
|
|
OS.Path.join(installPath, "webapp.json"),
|
|
OS.Path.join(installPath, "webapp.ini"),
|
|
OS.Path.join(installPath, "application.zip"),
|
|
desktopINI,
|
|
];
|
|
|
|
profilesIni = OS.Path.join(installPath, "profiles.ini");
|
|
|
|
cleanup = function() {
|
|
return Task.spawn(function*() {
|
|
if (profileDir) {
|
|
yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
|
|
}
|
|
|
|
yield OS.File.removeDir(installPath, { ignoreAbsent: true });
|
|
|
|
yield OS.File.remove(desktopINI, { ignoreAbsent: true });
|
|
});
|
|
};
|
|
} else if (navigator.platform.startsWith("Win")) {
|
|
installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app));
|
|
|
|
let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "Sample packaged app.lnk");
|
|
let startMenuShortcut = OS.Path.join(OS.Constants.Path.winStartMenuProgsDir, "Sample packaged app.lnk");
|
|
|
|
installedFiles = [
|
|
OS.Path.join(installPath, "Sample packaged app.exe"),
|
|
OS.Path.join(installPath, "chrome", "icons", "default", "default.ico"),
|
|
OS.Path.join(installPath, "webapp.json"),
|
|
OS.Path.join(installPath, "webapp.ini"),
|
|
OS.Path.join(installPath, "application.zip"),
|
|
OS.Path.join(installPath, "uninstall", "shortcuts_log.ini"),
|
|
OS.Path.join(installPath, "uninstall", "uninstall.log"),
|
|
OS.Path.join(installPath, "uninstall", "webapp-uninstaller.exe"),
|
|
desktopShortcut,
|
|
startMenuShortcut,
|
|
];
|
|
tempUpdatedFiles = [
|
|
OS.Path.join(installPath, "update", "chrome", "icons", "default", "default.ico"),
|
|
OS.Path.join(installPath, "update", "webapp.json"),
|
|
OS.Path.join(installPath, "update", "webapp.ini"),
|
|
OS.Path.join(installPath, "update", "application.zip"),
|
|
OS.Path.join(installPath, "update", "uninstall", "shortcuts_log.ini"),
|
|
OS.Path.join(installPath, "update", "uninstall", "uninstall.log"),
|
|
OS.Path.join(installPath, "update", "uninstall", "webapp-uninstaller.exe"),
|
|
];
|
|
updatedFiles = [
|
|
OS.Path.join(installPath, "chrome", "icons", "default", "default.ico"),
|
|
OS.Path.join(installPath, "webapp.json"),
|
|
OS.Path.join(installPath, "webapp.ini"),
|
|
OS.Path.join(installPath, "application.zip"),
|
|
OS.Path.join(installPath, "uninstall", "shortcuts_log.ini"),
|
|
OS.Path.join(installPath, "uninstall", "uninstall.log"),
|
|
desktopShortcut,
|
|
startMenuShortcut,
|
|
];
|
|
|
|
profilesIni = OS.Path.join(installPath, "profiles.ini");
|
|
|
|
cleanup = function() {
|
|
return Task.spawn(function*() {
|
|
let uninstallKey;
|
|
try {
|
|
uninstallKey = Cc["@mozilla.org/windows-registry-key;1"].
|
|
createInstance(Ci.nsIWindowsRegKey);
|
|
uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
|
|
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
|
|
uninstallKey.ACCESS_WRITE);
|
|
if (uninstallKey.hasChild(WebappOSUtils.getUniqueName(app))) {
|
|
uninstallKey.removeChild(WebappOSUtils.getUniqueName(app));
|
|
}
|
|
} catch (e) {
|
|
} finally {
|
|
if (uninstallKey) {
|
|
uninstallKey.close();
|
|
}
|
|
}
|
|
|
|
if (profileDir) {
|
|
yield OS.File.removeDir(profileDir.parent.parent.path, { ignoreAbsent: true });
|
|
}
|
|
|
|
yield OS.File.removeDir(installPath, { ignoreAbsent: true });
|
|
|
|
yield OS.File.remove(desktopShortcut, { ignoreAbsent: true });
|
|
yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true });
|
|
});
|
|
};
|
|
} else if (navigator.platform.startsWith("Mac")) {
|
|
installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "Sample packaged app.app");
|
|
let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support",
|
|
WebappOSUtils.getUniqueName(app));
|
|
|
|
installedFiles = [
|
|
OS.Path.join(installPath, "Contents", "Info.plist"),
|
|
OS.Path.join(installPath, "Contents", "MacOS", "webapprt"),
|
|
OS.Path.join(installPath, "Contents", "MacOS", "webapp.ini"),
|
|
OS.Path.join(installPath, "Contents", "Resources", "appicon.icns"),
|
|
OS.Path.join(installPath, "Contents", "Resources", "application.zip"),
|
|
OS.Path.join(appProfileDir, "webapp.json"),
|
|
];
|
|
tempUpdatedFiles = [
|
|
OS.Path.join(installPath, "update", "Contents", "Info.plist"),
|
|
OS.Path.join(installPath, "update", "Contents", "MacOS", "webapp.ini"),
|
|
OS.Path.join(installPath, "update", "Contents", "Resources", "appicon.icns"),
|
|
OS.Path.join(installPath, "update", "Contents", "Resources", "application.zip"),
|
|
OS.Path.join(installPath, "update", "webapp.json"),
|
|
];
|
|
updatedFiles = [
|
|
OS.Path.join(installPath, "Contents", "Info.plist"),
|
|
OS.Path.join(installPath, "Contents", "MacOS", "webapp.ini"),
|
|
OS.Path.join(installPath, "Contents", "Resources", "appicon.icns"),
|
|
OS.Path.join(installPath, "Contents", "Resources", "application.zip"),
|
|
OS.Path.join(appProfileDir, "webapp.json"),
|
|
];
|
|
|
|
profilesIni = OS.Path.join(appProfileDir, "profiles.ini");
|
|
|
|
cleanup = function() {
|
|
return Task.spawn(function*() {
|
|
if (profileDir) {
|
|
yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
|
|
}
|
|
|
|
yield OS.File.removeDir(installPath, { ignoreAbsent: true });
|
|
|
|
yield OS.File.removeDir(appProfileDir, { ignoreAbsent: true });
|
|
});
|
|
};
|
|
}
|
|
|
|
let old_dry_run;
|
|
try {
|
|
old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run");
|
|
} catch (ex) {}
|
|
|
|
Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false);
|
|
|
|
SimpleTest.registerCleanupFunction(function() {
|
|
if (old_dry_run === undefined) {
|
|
Services.prefs.clearUserPref("browser.mozApps.installer.dry_run");
|
|
} else {
|
|
Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run);
|
|
}
|
|
|
|
cleanup();
|
|
});
|
|
|
|
Task.spawn(function() {
|
|
// Get to a clean state before the test
|
|
yield cleanup();
|
|
|
|
let zipFile = yield OS.File.open(zipPath, { create: true });
|
|
yield zipFile.close();
|
|
|
|
let nativeApp = new NativeApp(app, manifest, app.categories);
|
|
ok(nativeApp, "NativeApp object created");
|
|
|
|
info("Test update for an application that isn't installed");
|
|
try {
|
|
yield nativeApp.prepareUpdate(manifest, zipPath);
|
|
ok(false, "Didn't thrown");
|
|
} catch (ex) {
|
|
is(ex, "The application isn't installed", "Exception thrown");
|
|
}
|
|
|
|
profileDir = nativeApp.createProfile();
|
|
ok(profileDir && profileDir.exists(), "Profile directory created");
|
|
ok((yield OS.File.exists(profilesIni)), "profiles.ini file created");
|
|
|
|
// Install application
|
|
info("Test installation");
|
|
yield nativeApp.install(manifest, zipPath);
|
|
while (!WebappOSUtils.isLaunchable(app)) {
|
|
yield wait(1000);
|
|
}
|
|
ok(true, "App launchable");
|
|
ok((yield checkFiles(installedFiles)), "Files correctly written");
|
|
is(WebappOSUtils.getInstallPath(app), installPath, "getInstallPath == installPath");
|
|
|
|
let stat = yield OS.File.stat(installPath);
|
|
let installTime = stat.lastModificationDate;
|
|
|
|
// Wait one second, otherwise the last modification date is the same.
|
|
yield wait(1000);
|
|
|
|
// Reinstall application
|
|
info("Test reinstallation");
|
|
|
|
zipFile = yield OS.File.open(zipPath, { create: true });
|
|
yield zipFile.close();
|
|
|
|
yield nativeApp.install(manifest, zipPath);
|
|
while (!WebappOSUtils.isLaunchable(app)) {
|
|
yield wait(1000);
|
|
}
|
|
ok(true, "App launchable");
|
|
ok((yield checkFiles(installedFiles)), "Installation not corrupted");
|
|
ok((yield checkFiles(tempUpdatedFiles)), "Files correctly written in the update subdirectory");
|
|
|
|
yield nativeApp.applyUpdate();
|
|
while (!WebappOSUtils.isLaunchable(app)) {
|
|
yield wait(1000);
|
|
}
|
|
ok(true, "App launchable");
|
|
ok((yield checkFiles(installedFiles)), "Installation not corrupted");
|
|
ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed");
|
|
ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher");
|
|
|
|
stat = yield OS.File.stat(installPath);
|
|
installTime = stat.lastModificationDate;
|
|
|
|
// Wait one second, otherwise the last modification date is the same.
|
|
yield wait(1000);
|
|
|
|
// Update application
|
|
info("Test update");
|
|
|
|
zipFile = yield OS.File.open(zipPath, { create: true });
|
|
yield zipFile.close();
|
|
|
|
yield nativeApp.prepareUpdate(manifest, zipPath);
|
|
while (!WebappOSUtils.isLaunchable(app)) {
|
|
yield wait(1000);
|
|
}
|
|
ok(true, "App launchable");
|
|
ok((yield checkFiles(installedFiles)), "Installation not corrupted");
|
|
ok((yield checkFiles(tempUpdatedFiles)), "Files correctly written in the update subdirectory");
|
|
|
|
yield nativeApp.applyUpdate();
|
|
while (!WebappOSUtils.isLaunchable(app)) {
|
|
yield wait(1000);
|
|
}
|
|
ok(true, "App launchable");
|
|
ok((yield checkFiles(installedFiles)), "Installation not corrupted");
|
|
ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed");
|
|
ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher");
|
|
|
|
SimpleTest.finish();
|
|
}).then(null, function(e) {
|
|
ok(false, "Error during test: " + e);
|
|
SimpleTest.finish();
|
|
});
|
|
|
|
]]>
|
|
</script>
|
|
</window>
|