dom/tests/mochitest/webapps/test_cross_origin.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/webapps/test_cross_origin.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +<?xml version="1.0"?>
     1.5 +
     1.6 +<!-- Any copyright is dedicated to the Public Domain.
     1.7 +   - http://creativecommons.org/publicdomain/zero/1.0/ -->
     1.8 +
     1.9 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
    1.10 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
    1.11 +
    1.12 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +        title="Mozilla Bug 741549">
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.15 +  <script type="application/javascript" src="head.js"/>
    1.16 +  <!-- test results are displayed in the html:body -->
    1.17 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.18 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
    1.19 +     target="_blank">Mozilla Bug 741549</a>
    1.20 +  </body>
    1.21 +
    1.22 +  <iframe id="iframe"/>
    1.23 +
    1.24 +<script> 
    1.25 +
    1.26 +var url1 = "http://test1.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
    1.27 +var url2 = "http://test2.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
    1.28 +
    1.29 +// References to the apps we install, so we can uninstall them afterward.
    1.30 +// Note that app2 is set by the helper page, which throws "TypeError: can't
    1.31 +// redefine non-configurable property 'app2'" if we declare it here.
    1.32 +var app1 /* , app2 */;
    1.33 +
    1.34 +var steps = [
    1.35 +  installAppFromOwnOrigin,
    1.36 +  installAppFromOtherOrigin,
    1.37 +  getInstalled,
    1.38 +  getAll,
    1.39 +  uninstall,
    1.40 +];
    1.41 +
    1.42 +runAll(steps);
    1.43 +
    1.44 +/**
    1.45 + * Install the first app from our own origin (chrome://mochitests).  Note that
    1.46 + * the app itself is from a different origin (http://test1.example.com).
    1.47 + */
    1.48 +function installAppFromOwnOrigin(next) {
    1.49 +  confirmNextInstall();
    1.50 +  navigator.mozApps.install(url1, null).onsuccess = function onInstall() {
    1.51 +    app1 = this.result;
    1.52 +    next();
    1.53 +  };
    1.54 +}
    1.55 +
    1.56 +/**
    1.57 + * Install the second app from another origin (http://test2.example.com) using
    1.58 + * the helper page.  In this case, the origin of the installing page is the same
    1.59 + * as the origin of the app being installed, so the helper page can test
    1.60 + * getSelf().
    1.61 + */
    1.62 +function installAppFromOtherOrigin(next) {
    1.63 +  document.getElementById("iframe").setAttribute("src",
    1.64 +    "http://test2.example.com/chrome/dom/tests/mochitest/webapps/cross_origin.html");
    1.65 +
    1.66 +  window.addEventListener("message", function onMessage(event) {
    1.67 +    if (event.data == "next") {
    1.68 +      window.removeEventListener("message", onMessage, false);
    1.69 +      next();
    1.70 +    }
    1.71 +  }, false);
    1.72 +}
    1.73 +
    1.74 +function getInstalled(next) {
    1.75 +  navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() {
    1.76 +    var app1 = [a for (a of this.result) if (a.manifestURL == url1)][0];
    1.77 +    ok(app1, "getInstalled() includes app installed from own origin");
    1.78 +
    1.79 +    var app2 = [a for (a of this.result) if (a.manifestURL == url2)][0];
    1.80 +    ok(!app2, "getInstalled() excludes app installed from other origin");
    1.81 +
    1.82 +    next();
    1.83 +  };
    1.84 +}
    1.85 +
    1.86 +function getAll(next) {
    1.87 +  navigator.mozApps.mgmt.getAll().onsuccess = function onMgmtGetAll() {
    1.88 +    var app1 = [a for (a of this.result) if (a.manifestURL == url1)][0];
    1.89 +    ok(app1, "mgmt.getAll() includes app installed from own origin");
    1.90 +
    1.91 +    var app2 = [a for (a of this.result) if (a.manifestURL == url2)][0];
    1.92 +    ok(app2, "mgmt.getAll() includes app installed from other origin");
    1.93 +
    1.94 +    next();
    1.95 +  };
    1.96 +}
    1.97 +
    1.98 +function uninstall(next) {
    1.99 +  navigator.mozApps.mgmt.uninstall(app1).onsuccess = function onUninstallApp1() {
   1.100 +    navigator.mozApps.mgmt.uninstall(app2).onsuccess = function onUninstallApp2() {
   1.101 +      next();
   1.102 +    };
   1.103 +  };
   1.104 +}
   1.105 +
   1.106 +</script> 
   1.107 +</window>

mercurial