toolkit/webapps/tests/test_packaged_launch.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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=981249
     6 -->
     7 <window title="Mozilla Bug 981249"
     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"
    12           src="chrome://mochikit/content/chrome-harness.js"></script>
    13   <script type="application/javascript" src="head.js"/>
    15   <!-- test results are displayed in the html:body -->
    16   <body xmlns="http://www.w3.org/1999/xhtml">
    17   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=981249"
    18      target="_blank">Mozilla Bug 981249</a>
    19   </body>
    21 <script type="application/javascript">
    22 <![CDATA[
    24 /** Test for Bug 981249 **/
    26 "use strict";
    28 SimpleTest.waitForExplicitFinish();
    30 Cu.import("resource://gre/modules/Services.jsm");
    31 Cu.import("resource://gre/modules/NativeApp.jsm");
    32 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
    33 Cu.import("resource://gre/modules/Promise.jsm");
    35 const PR_RDWR        = 0x04;
    36 const PR_CREATE_FILE = 0x08;
    37 const PR_TRUNCATE    = 0x20;
    39 let manifest = {
    40   name: "test_desktop_packaged_launch",
    41   version: "0.1a",
    42   size: 777,
    43   package_path: "/data/app.zip",
    44   launch_path: "/index.html",
    45 };
    47 let app = {
    48   name: "test_desktop_packaged_launch",
    49   manifestURL: "http://127.0.0.1:8888/sample.manifest",
    50   manifest: manifest,
    51   updateManifest: manifest,
    52   origin: "app://test_desktop_packaged_launch/",
    53   categories: [],
    54   installOrigin: "http://127.0.0.1:8888/",
    55   receipts: [],
    56   installTime: Date.now(),
    57 };
    59 let profileDir;
    60 let installPath;
    61 let exePath;
    62 let appProcess = Cc["@mozilla.org/process/util;1"].
    63                  createInstance(Ci.nsIProcess);
    65 let cleanup;
    67 if (LINUX) {
    68   installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app));
    69   exePath = OS.Path.join(installPath, "webapprt-stub");
    71   let xdg_data_home = Cc["@mozilla.org/process/environment;1"].
    72                       getService(Ci.nsIEnvironment).
    73                       get("XDG_DATA_HOME");
    74   if (!xdg_data_home) {
    75     xdg_data_home = OS.Path.join(OS.Constants.Path.homeDir, ".local", "share");
    76   }
    78   let desktopINI = OS.Path.join(xdg_data_home, "applications",
    79                                 "owa-" + WebappOSUtils.getUniqueName(app) + ".desktop");
    81   cleanup = function() {
    82     return Task.spawn(function*() {
    83       if (appProcess.isRunning) {
    84         appProcess.kill();
    85       }
    87       if (profileDir) {
    88         yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
    89       }
    91       yield OS.File.removeDir(installPath, { ignoreAbsent: true });
    93       yield OS.File.remove(desktopINI, { ignoreAbsent: true });
    94     });
    95   };
    96 } else if (WIN) {
    97   installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app));
    98   exePath = OS.Path.join(installPath, "test_desktop_packaged_launch.exe");
   100   let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "test_desktop_packaged_launch.lnk");
   101   let startMenuShortcut = OS.Path.join(OS.Constants.Path.winStartMenuProgsDir, "test_desktop_packaged_launch.lnk");
   103   cleanup = function() {
   104     return Task.spawn(function*() {
   105       if (appProcess.isRunning) {
   106         appProcess.kill();
   107       }
   109       let uninstallKey;
   110       try {
   111         uninstallKey = Cc["@mozilla.org/windows-registry-key;1"].
   112                        createInstance(Ci.nsIWindowsRegKey);
   113         uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
   114                           "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
   115                           uninstallKey.ACCESS_WRITE);
   116         if (uninstallKey.hasChild(WebappOSUtils.getUniqueName(app))) {
   117           uninstallKey.removeChild(WebappOSUtils.getUniqueName(app));
   118         }
   119       } catch (e) {
   120       } finally {
   121         if (uninstallKey) {
   122           uninstallKey.close();
   123         }
   124       }
   126       if (profileDir) {
   127         yield OS.File.removeDir(profileDir.parent.parent.path, { ignoreAbsent: true });
   128       }
   130       yield OS.File.removeDir(installPath, { ignoreAbsent: true });
   132       yield OS.File.remove(desktopShortcut, { ignoreAbsent: true });
   133       yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true });
   134     });
   135   };
   136 } else if (MAC) {
   137   installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "test_desktop_packaged_launch.app");
   138   exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt");
   140   let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support",
   141                                    WebappOSUtils.getUniqueName(app));
   143   cleanup = function() {
   144     return Task.spawn(function*() {
   145       if (appProcess.isRunning) {
   146         appProcess.kill();
   147       }
   149       if (profileDir) {
   150         yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
   151       }
   153       yield OS.File.removeDir(installPath, { ignoreAbsent: true });
   155       yield OS.File.removeDir(appProfileDir, { ignoreAbsent: true });
   156     });
   157   };
   158 }
   160 function buildAppPackage() {
   161   let zipFile = getFile(OS.Constants.Path.profileDir, "sample.zip");
   163   let zipWriter = Cc["@mozilla.org/zipwriter;1"].createInstance(Ci.nsIZipWriter);
   164   zipWriter.open(zipFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
   165   zipWriter.addEntryFile("index.html",
   166                          Ci.nsIZipWriter.COMPRESSION_NONE,
   167                          getFile(getTestFilePath("data/app/index.html")),
   168                          false);
   169   zipWriter.addEntryFile("manifest.webapp",
   170                          Ci.nsIZipWriter.COMPRESSION_NONE,
   171                          getFile(getTestFilePath("data/app/manifest.webapp")),
   172                          false);
   173   zipWriter.close();
   175   return zipFile.path;
   176 }
   178 function wasAppSJSAccessed() {
   179   let deferred = Promise.defer();
   181   var xhr = new XMLHttpRequest();
   183   xhr.addEventListener("load", function() {
   184     let ret = (xhr.responseText == "done") ? true : false;
   185     deferred.resolve(ret);
   186   });
   188   xhr.addEventListener("error", aError => deferred.reject(aError));
   189   xhr.addEventListener("abort", aError => deferred.reject(aError));
   191   xhr.open('GET', 'http://test/chrome/toolkit/webapps/tests/app.sjs?testreq', true);
   192   xhr.send();
   194   return deferred.promise;
   195 }
   197 let runTest = Task.async(function*() {
   198   // Get to a clean state before the test
   199   yield cleanup();
   201   SimpleTest.registerCleanupFunction(cleanup);
   203   setDryRunPref();
   205   let zipPath = buildAppPackage();
   207   let nativeApp = new NativeApp(app, manifest, app.categories);
   208   ok(nativeApp, "NativeApp object created");
   210   profileDir = nativeApp.createProfile();
   211   ok(profileDir && profileDir.exists(), "Profile directory created");
   213   // On Mac build servers, we don't have enough privileges to write to /Applications,
   214   // so we install apps in a user-owned directory.
   215   if (MAC) {
   216     nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications");
   217     yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true });
   218   }
   220   // Install application
   221   info("Test installation");
   222   yield nativeApp.install(manifest, zipPath);
   223   while (!WebappOSUtils.isLaunchable(app)) {
   224     yield wait(1000);
   225   }
   226   ok(true, "App launchable");
   228   let exeFile = getFile(exePath);
   230   ok(exeFile.isExecutable(), "webapprt executable is executable");
   232   let appClosed = false;
   234   appProcess.init(exeFile)
   235   appProcess.runAsync([], 0, () => appClosed = true);
   237   while (!(yield wasAppSJSAccessed()) && !appClosed) {
   238     yield wait(1000);
   239   }
   240   ok(!appClosed, "App was launched and is still running");
   242   SimpleTest.finish();
   243 });
   245 // The test doesn't work yet on Mac OS X 10.6 machines.
   246 // See bug 993690.
   247 if (MAC_106) {
   248   todo(false, "The test doesn't work on Mac OS X 10.6 machines");
   249   SimpleTest.finish();
   250 } else {
   251   runTest().then(null, function(e) {
   252     ok(false, "Error during test: " + e);
   253     SimpleTest.finish();
   254   });
   255 }
   257 ]]>
   258 </script>
   259 </window>

mercurial