toolkit/webapps/tests/test_packaged_update_from_webapp_runtime.xul
author Marco Castelluccio <mar.castelluccio@studenti.unina.it>
Wed, 21 May 2014 18:02:21 +0200
changeset 184220 2f5925bdf249d84ddbe916f29929c323e72d753d
parent 183899 be0dd45203f6d8250652588523141bfb137972cb
child 189971 97b1b4c7f32044a61fdd6f10bdd52f49db60c57d
permissions -rw-r--r--
Bug 1009809 - Use ManifestHelper::biggestIconURL in the desktop app installer. r=myk,jmaher

<?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=981249
-->
<window title="Mozilla Bug 981249"
        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="chrome://mochikit/content/chrome-harness.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=981249"
     target="_blank">Mozilla Bug 981249</a>
  </body>

<script type="application/javascript">
<![CDATA[

/** Test for Bug 981249 **/

"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");
Cu.import("resource://gre/modules/Promise.jsm");

let manifest = {
  name: "test_desktop_packaged_launch",
  version: "0.1a",
  size: 777,
  package_path: "/data/app.zip",
  launch_path: "/doesntexist.html",
};

let updatedManifest = {
  name: "test_desktop_packaged_launch",
  version: "0.2a",
  size: 777,
  package_path: "/data/app.zip",
  launch_path: "/index.html",
};

let app = {
  name: "test_desktop_packaged_launch",
  manifestURL: "http://127.0.0.1:8888/sample.manifest",
  manifest: manifest,
  updateManifest: manifest,
  origin: "app://test_desktop_packaged_launch/",
  categories: [],
  installOrigin: "http://127.0.0.1:8888/",
  receipts: [],
  installTime: Date.now(),
};

let testAppInfo = new TestAppInfo(app);

let runTest = Task.async(function*() {
  // Get to a clean state before the test
  yield testAppInfo.cleanup();

  SimpleTest.registerCleanupFunction(() => testAppInfo.cleanup());

  setDryRunPref();

  let zipPath = buildAppPackage(manifest);

  let nativeApp = new NativeApp(app, manifest, app.categories);
  ok(nativeApp, "NativeApp object created");

  testAppInfo.profileDir = nativeApp.createProfile();
  ok(testAppInfo.profileDir && testAppInfo.profileDir.exists(), "Profile directory created");

  // On Mac build servers, we don't have enough privileges to write to /Applications,
  // so we install apps in a user-owned directory.
  if (MAC) {
    nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications");
    yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true });
  }

  // Install application
  info("Test installation");
  yield nativeApp.install(manifest, zipPath);
  while (!WebappOSUtils.isLaunchable(app)) {
    yield wait(1000);
  }
  ok(true, "App launchable");

  // Prepare update
  info("Test update");

  zipPath = buildAppPackage(updatedManifest);

  yield nativeApp.prepareUpdate(updatedManifest, zipPath);
  while (!WebappOSUtils.isLaunchable(app)) {
    yield wait(1000);
  }
  ok(true, "App launchable");

  // Let the webapp runtime apply the update. The app.sjs?appreq page is
  // accessed only if the app is actually updated (because the old manifest
  // contained a different launch path).

  let exeFile = getFile(testAppInfo.exePath);

  ok(exeFile.isExecutable(), "webapprt executable is executable");

  let appClosed = false;

  testAppInfo.appProcess.init(exeFile)
  testAppInfo.appProcess.runAsync([], 0, () => appClosed = true);

  while (!(yield wasAppSJSAccessed()) && !appClosed) {
    yield wait(1000);
  }
  ok(!appClosed, "App was launched and is still running");

  SimpleTest.finish();
});

// The test doesn't work yet on Mac OS X 10.6 machines.
// See bug 993690.
if (MAC_106) {
  todo(false, "The test doesn't work on Mac OS X 10.6 machines");
  SimpleTest.finish();
} else {
  runTest().then(null, function(e) {
    ok(false, "Error during test: " + e);
    SimpleTest.finish();
  });
}

]]>
</script>
</window>