dom/tests/mochitest/webapps/test_cross_origin.xul

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <?xml version="1.0"?>
     3 <!-- Any copyright is dedicated to the Public Domain.
     4    - http://creativecommons.org/publicdomain/zero/1.0/ -->
     6 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     7 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     9 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    10         title="Mozilla Bug 741549">
    11   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    12   <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=741549"
    16      target="_blank">Mozilla Bug 741549</a>
    17   </body>
    19   <iframe id="iframe"/>
    21 <script> 
    23 var url1 = "http://test1.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
    24 var url2 = "http://test2.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
    26 // References to the apps we install, so we can uninstall them afterward.
    27 // Note that app2 is set by the helper page, which throws "TypeError: can't
    28 // redefine non-configurable property 'app2'" if we declare it here.
    29 var app1 /* , app2 */;
    31 var steps = [
    32   installAppFromOwnOrigin,
    33   installAppFromOtherOrigin,
    34   getInstalled,
    35   getAll,
    36   uninstall,
    37 ];
    39 runAll(steps);
    41 /**
    42  * Install the first app from our own origin (chrome://mochitests).  Note that
    43  * the app itself is from a different origin (http://test1.example.com).
    44  */
    45 function installAppFromOwnOrigin(next) {
    46   confirmNextInstall();
    47   navigator.mozApps.install(url1, null).onsuccess = function onInstall() {
    48     app1 = this.result;
    49     next();
    50   };
    51 }
    53 /**
    54  * Install the second app from another origin (http://test2.example.com) using
    55  * the helper page.  In this case, the origin of the installing page is the same
    56  * as the origin of the app being installed, so the helper page can test
    57  * getSelf().
    58  */
    59 function installAppFromOtherOrigin(next) {
    60   document.getElementById("iframe").setAttribute("src",
    61     "http://test2.example.com/chrome/dom/tests/mochitest/webapps/cross_origin.html");
    63   window.addEventListener("message", function onMessage(event) {
    64     if (event.data == "next") {
    65       window.removeEventListener("message", onMessage, false);
    66       next();
    67     }
    68   }, false);
    69 }
    71 function getInstalled(next) {
    72   navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() {
    73     var app1 = [a for (a of this.result) if (a.manifestURL == url1)][0];
    74     ok(app1, "getInstalled() includes app installed from own origin");
    76     var app2 = [a for (a of this.result) if (a.manifestURL == url2)][0];
    77     ok(!app2, "getInstalled() excludes app installed from other origin");
    79     next();
    80   };
    81 }
    83 function getAll(next) {
    84   navigator.mozApps.mgmt.getAll().onsuccess = function onMgmtGetAll() {
    85     var app1 = [a for (a of this.result) if (a.manifestURL == url1)][0];
    86     ok(app1, "mgmt.getAll() includes app installed from own origin");
    88     var app2 = [a for (a of this.result) if (a.manifestURL == url2)][0];
    89     ok(app2, "mgmt.getAll() includes app installed from other origin");
    91     next();
    92   };
    93 }
    95 function uninstall(next) {
    96   navigator.mozApps.mgmt.uninstall(app1).onsuccess = function onUninstallApp1() {
    97     navigator.mozApps.mgmt.uninstall(app2).onsuccess = function onUninstallApp2() {
    98       next();
    99     };
   100   };
   101 }
   103 </script> 
   104 </window>

mercurial