toolkit/webapps/tests/test_hosted.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
     4 <!--
     5 https://bugzilla.mozilla.org/show_bug.cgi?id=898647
     6 -->
     7 <window title="Mozilla Bug 898647"
     8         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    11   <script type="application/javascript" src="head.js"/>
    13   <!-- test results are displayed in the html:body -->
    14   <body xmlns="http://www.w3.org/1999/xhtml">
    15   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=898647"
    16      target="_blank">Mozilla Bug 898647</a>
    17   </body>
    19 <script type="application/javascript">
    20 <![CDATA[
    22 /** Test for Bug 898647 **/
    24 "use strict";
    26 SimpleTest.waitForExplicitFinish();
    28 Cu.import("resource://gre/modules/Services.jsm");
    29 Cu.import("resource://gre/modules/NativeApp.jsm");
    30 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
    32 let manifest = {
    33   name: "Sample hosted app",
    34 };
    36 let app = {
    37   name: "Sample hosted app",
    38   manifestURL: "http://example.com/sample.manifest",
    39   manifest: manifest,
    40   origin: "http://example.com/",
    41   categories: [],
    42   installOrigin: "http://example.com/",
    43   receipts: [],
    44   installTime: Date.now(),
    45 };
    47 let profileDir;
    48 let profilesIni;
    49 let installPath;
    51 let installedFiles;
    52 let tempUpdatedFiles;
    53 let updatedFiles;
    55 let cleanup;
    57 if (LINUX) {
    58   installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app));
    60   let xdg_data_home = Cc["@mozilla.org/process/environment;1"].
    61                       getService(Ci.nsIEnvironment).
    62                       get("XDG_DATA_HOME");
    63   if (!xdg_data_home) {
    64     xdg_data_home = OS.Path.join(OS.Constants.Path.homeDir, ".local", "share");
    65   }
    67   let desktopINI = OS.Path.join(xdg_data_home, "applications",
    68                                 "owa-" + WebappOSUtils.getUniqueName(app) + ".desktop");
    70   installedFiles = [
    71     OS.Path.join(installPath, "icon.png"),
    72     OS.Path.join(installPath, "webapprt-stub"),
    73     OS.Path.join(installPath, "webapp.json"),
    74     OS.Path.join(installPath, "webapp.ini"),
    75     desktopINI,
    76   ];
    77   tempUpdatedFiles = [
    78     OS.Path.join(installPath, "update", "icon.png"),
    79     OS.Path.join(installPath, "update", "webapp.json"),
    80     OS.Path.join(installPath, "update", "webapp.ini"),
    81   ];
    82   updatedFiles = [
    83     OS.Path.join(installPath, "icon.png"),
    84     OS.Path.join(installPath, "webapp.json"),
    85     OS.Path.join(installPath, "webapp.ini"),
    86     desktopINI,
    87   ];
    89   profilesIni = OS.Path.join(installPath, "profiles.ini");
    91   cleanup = function() {
    92     return Task.spawn(function*() {
    93       if (profileDir) {
    94         yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
    95       }
    97       yield OS.File.removeDir(installPath, { ignoreAbsent: true });
    99       yield OS.File.remove(desktopINI, { ignoreAbsent: true });
   100     });
   101   };
   102 } else if (WIN) {
   103   installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app));
   105   let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "Sample hosted app.lnk");
   106   let startMenuShortcut = OS.Path.join(OS.Constants.Path.winStartMenuProgsDir, "Sample hosted app.lnk");
   108   installedFiles = [
   109     OS.Path.join(installPath, "Sample hosted app.exe"),
   110     OS.Path.join(installPath, "chrome", "icons", "default", "default.ico"),
   111     OS.Path.join(installPath, "webapp.json"),
   112     OS.Path.join(installPath, "webapp.ini"),
   113     OS.Path.join(installPath, "uninstall", "shortcuts_log.ini"),
   114     OS.Path.join(installPath, "uninstall", "uninstall.log"),
   115     OS.Path.join(installPath, "uninstall", "webapp-uninstaller.exe"),
   116     desktopShortcut,
   117     startMenuShortcut,
   118   ];
   119   tempUpdatedFiles = [
   120     OS.Path.join(installPath, "update", "chrome", "icons", "default", "default.ico"),
   121     OS.Path.join(installPath, "update", "webapp.json"),
   122     OS.Path.join(installPath, "update", "webapp.ini"),
   123     OS.Path.join(installPath, "update", "uninstall", "shortcuts_log.ini"),
   124     OS.Path.join(installPath, "update", "uninstall", "uninstall.log"),
   125     OS.Path.join(installPath, "update", "uninstall", "webapp-uninstaller.exe"),
   126   ];
   127   updatedFiles = [
   128     OS.Path.join(installPath, "chrome", "icons", "default", "default.ico"),
   129     OS.Path.join(installPath, "webapp.json"),
   130     OS.Path.join(installPath, "webapp.ini"),
   131     OS.Path.join(installPath, "uninstall", "shortcuts_log.ini"),
   132     OS.Path.join(installPath, "uninstall", "uninstall.log"),
   133     desktopShortcut,
   134     startMenuShortcut,
   135   ];
   137   profilesIni = OS.Path.join(installPath, "profiles.ini");
   139   cleanup = function() {
   140     return Task.spawn(function*() {
   141       let uninstallKey;
   142       try {
   143         uninstallKey = Cc["@mozilla.org/windows-registry-key;1"].
   144                        createInstance(Ci.nsIWindowsRegKey);
   145         uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
   146                           "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
   147                           uninstallKey.ACCESS_WRITE);
   148         if (uninstallKey.hasChild(WebappOSUtils.getUniqueName(app))) {
   149           uninstallKey.removeChild(WebappOSUtils.getUniqueName(app));
   150         }
   151       } catch (e) {
   152       } finally {
   153         if (uninstallKey) {
   154           uninstallKey.close();
   155         }
   156       }
   158       if (profileDir) {
   159         yield OS.File.removeDir(profileDir.parent.parent.path, { ignoreAbsent: true });
   160       }
   162       yield OS.File.removeDir(installPath, { ignoreAbsent: true });
   164       yield OS.File.remove(desktopShortcut, { ignoreAbsent: true });
   165       yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true });
   166     });
   167   };
   168 } else if (MAC) {
   169   installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "Sample hosted app.app");
   170   let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support",
   171                                    WebappOSUtils.getUniqueName(app));
   173   installedFiles = [
   174     OS.Path.join(installPath, "Contents", "Info.plist"),
   175     OS.Path.join(installPath, "Contents", "MacOS", "webapprt"),
   176     OS.Path.join(installPath, "Contents", "MacOS", "webapp.ini"),
   177     OS.Path.join(installPath, "Contents", "Resources", "appicon.icns"),
   178     OS.Path.join(appProfileDir, "webapp.json"),
   179   ];
   180   tempUpdatedFiles = [
   181     OS.Path.join(installPath, "update", "Contents", "Info.plist"),
   182     OS.Path.join(installPath, "update", "Contents", "MacOS", "webapp.ini"),
   183     OS.Path.join(installPath, "update", "Contents", "Resources", "appicon.icns"),
   184     OS.Path.join(installPath, "update", "webapp.json")
   185   ];
   186   updatedFiles = [
   187     OS.Path.join(installPath, "Contents", "Info.plist"),
   188     OS.Path.join(installPath, "Contents", "MacOS", "webapp.ini"),
   189     OS.Path.join(installPath, "Contents", "Resources", "appicon.icns"),
   190     OS.Path.join(appProfileDir, "webapp.json"),
   191   ];
   193   profilesIni = OS.Path.join(appProfileDir, "profiles.ini");
   195   cleanup = function() {
   196     return Task.spawn(function*() {
   197       if (profileDir) {
   198         yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
   199       }
   201       yield OS.File.removeDir(installPath, { ignoreAbsent: true });
   203       yield OS.File.removeDir(appProfileDir, { ignoreAbsent: true });
   204     });
   205   };
   206 }
   208 let runTest = Task.async(function*() {
   209   // Get to a clean state before the test
   210   yield cleanup();
   212   SimpleTest.registerCleanupFunction(cleanup);
   214   setDryRunPref();
   216   let nativeApp = new NativeApp(app, manifest, app.categories);
   217   ok(nativeApp, "NativeApp object created");
   219   info("Test update for an uninstalled application");
   220   try {
   221     yield nativeApp.prepareUpdate(manifest);
   222     ok(false, "Didn't thrown");
   223   } catch (ex) {
   224     is(ex, "The application isn't installed", "Exception thrown");
   225   }
   227   profileDir = nativeApp.createProfile();
   228   ok(profileDir && profileDir.exists(), "Profile directory created");
   229   ok((yield OS.File.exists(profilesIni)), "profiles.ini file created");
   231   // On Mac build servers, we don't have enough privileges to write to /Applications,
   232   // so we install apps in a user-owned directory.
   233   if (MAC) {
   234     nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications");
   235     yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true });
   236   }
   238   // Install application
   239   info("Test installation");
   240   yield nativeApp.install(manifest);
   241   while (!WebappOSUtils.isLaunchable(app)) {
   242     yield wait(1000);
   243   }
   244   ok(true, "App launchable");
   245   ok((yield checkFiles(installedFiles)), "Files correctly written");
   246   is(WebappOSUtils.getInstallPath(app), installPath, "getInstallPath == installPath");
   248   let stat = yield OS.File.stat(installPath);
   249   let installTime = stat.lastModificationDate;
   251   // Wait one second, otherwise the last modification date is the same.
   252   yield wait(1000);
   254   // Reinstall application
   255   info("Test reinstallation");
   256   yield nativeApp.install(manifest);
   257   while (!WebappOSUtils.isLaunchable(app)) {
   258     yield wait(1000);
   259   }
   260   ok(true, "App launchable");
   261   ok((yield checkFiles(installedFiles)), "Installation not corrupted");
   262   ok((yield checkFiles(tempUpdatedFiles)), "Files correctly written in the update subdirectory");
   264   yield nativeApp.applyUpdate();
   265   while (!WebappOSUtils.isLaunchable(app)) {
   266     yield wait(1000);
   267   }
   268   ok(true, "App launchable");
   269   ok((yield checkFiles(installedFiles)), "Installation not corrupted");
   270   ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed");
   271   ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher");
   273   stat = yield OS.File.stat(installPath);
   274   installTime = stat.lastModificationDate;
   276   // Wait one second, otherwise the last modification date is the same.
   277   yield wait(1000);
   279   // Update application
   280   info("Test update");
   281   yield nativeApp.prepareUpdate(manifest);
   282   while (!WebappOSUtils.isLaunchable(app)) {
   283     yield wait(1000);
   284   }
   285   ok(true, "App launchable");
   286   ok((yield checkFiles(installedFiles)), "Installation not corrupted");
   287   ok((yield checkFiles(tempUpdatedFiles)), "Files correctly written in the update subdirectory");
   289   yield nativeApp.applyUpdate();
   290   while (!WebappOSUtils.isLaunchable(app)) {
   291     yield wait(1000);
   292   }
   293   ok(true, "App launchable");
   294   ok((yield checkFiles(installedFiles)), "Installation not corrupted");
   295   ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed");
   296   ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher");
   298   SimpleTest.finish();
   299 });
   301 // The test doesn't work yet on Mac OS X 10.6 machines.
   302 // See bug 993690.
   303 if (MAC_106) {
   304   todo(false, "The test doesn't work on Mac OS X 10.6 machines");
   305   SimpleTest.finish();
   306 } else {
   307   runTest().then(null, function(e) {
   308     ok(false, "Error during test: " + e);
   309     SimpleTest.finish();
   310   });
   311 }
   313 ]]>
   314 </script>
   315 </window>

mercurial