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.

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

mercurial