Tue, 06 Jan 2015 21:39:09 +0100
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 781379"> |
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 781379</a> |
michael@0 | 17 | </body> |
michael@0 | 18 | |
michael@0 | 19 | <script type="application/javascript;version=1.8"> |
michael@0 | 20 | |
michael@0 | 21 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 22 | Cu.import("resource://gre/modules/Webapps.jsm"); |
michael@0 | 23 | |
michael@0 | 24 | // We use a different origin than other webapps test files because we compare |
michael@0 | 25 | // the number of apps before and after installing this one; and if a test file |
michael@0 | 26 | // installs our app and then doesn't uninstall it (f.e. because it isn't written |
michael@0 | 27 | // to clean up after itself, or because it throws an exception or times out), |
michael@0 | 28 | // then this test will *reinstall* the app, and the number of apps won't change, |
michael@0 | 29 | // which will look like a failure in this test although it's actually a failure |
michael@0 | 30 | // in the other one. |
michael@0 | 31 | // |
michael@0 | 32 | // Using a different origin here isn't a foolproof solution, as another test |
michael@0 | 33 | // could start using it. Reviewer vigilance is required! And to anyone reading |
michael@0 | 34 | // this: don't use this origin without good reason and due consideration for |
michael@0 | 35 | // the potential consequences! |
michael@0 | 36 | // |
michael@0 | 37 | // Alternately, we could define a test-specific domain, getNotInstalled.com, |
michael@0 | 38 | // in source/build/pgo/server-locations.txt. But that seems like overkill, |
michael@0 | 39 | // and this problem will go away once we support multiple apps per origin, |
michael@0 | 40 | // since then we can make this test install its own personal webapp from any |
michael@0 | 41 | // origin. |
michael@0 | 42 | // |
michael@0 | 43 | let url = "http://example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp"; |
michael@0 | 44 | |
michael@0 | 45 | let app, notInstalled, _isLaunchable; |
michael@0 | 46 | |
michael@0 | 47 | let steps = [ |
michael@0 | 48 | monkeyPatchDOMApplicationRegistry, |
michael@0 | 49 | getNotInstalled, |
michael@0 | 50 | installApp, |
michael@0 | 51 | compareNotInstalled, |
michael@0 | 52 | unmonkeyPatchDOMApplicationRegistry, |
michael@0 | 53 | uninstallApp, |
michael@0 | 54 | ]; |
michael@0 | 55 | |
michael@0 | 56 | runAll(steps); |
michael@0 | 57 | |
michael@0 | 58 | // Monkey patch DOMApplicationRegistry._isLaunchable for testing. |
michael@0 | 59 | // This way, we don't have to create a platform specific application with a |
michael@0 | 60 | // status other than "installed". |
michael@0 | 61 | function monkeyPatchDOMApplicationRegistry(next) { |
michael@0 | 62 | _isLaunchable = DOMApplicationRegistry._isLaunchable; |
michael@0 | 63 | DOMApplicationRegistry._isLaunchable = function mockIsLaunchable(aOrigin) { |
michael@0 | 64 | return false; |
michael@0 | 65 | } |
michael@0 | 66 | next(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | // Call navigator.mozApps.mgmt.getNotInstalled and save the result. |
michael@0 | 70 | function getNotInstalled(next) { |
michael@0 | 71 | window.navigator.mozApps.mgmt.getNotInstalled().onsuccess = |
michael@0 | 72 | function onGetNotInstalled() { |
michael@0 | 73 | notInstalled = this.result.length; |
michael@0 | 74 | next(); |
michael@0 | 75 | }; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | // Add an app to the appregistry |
michael@0 | 79 | function installApp(next) { |
michael@0 | 80 | confirmNextInstall(); |
michael@0 | 81 | navigator.mozApps.install(url, null).onsuccess = function onInstall() { |
michael@0 | 82 | app = this.result; |
michael@0 | 83 | next(); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | // Call navigator.mozApps.mgmt.getNotInstalled and make sure there is one more. |
michael@0 | 88 | function compareNotInstalled(next) { |
michael@0 | 89 | let results; |
michael@0 | 90 | function getNotInstalledError() { |
michael@0 | 91 | ok(false, "window.mozApps.mgmt.getNotInstalled onerror called"); |
michael@0 | 92 | next(); |
michael@0 | 93 | } |
michael@0 | 94 | function getNotInstalledSuccess() { |
michael@0 | 95 | ok(true, "window.mozApps.mgmt.getNotInstalled onsuccess called"); |
michael@0 | 96 | is(this.result.length, notInstalled + 1, |
michael@0 | 97 | "should get one more notInstalled app"); |
michael@0 | 98 | |
michael@0 | 99 | if (this.result.length > 0) { |
michael@0 | 100 | is(this.result[this.result.length-1].origin, "http://example.com", |
michael@0 | 101 | "getNotInstalled returned the expected app"); |
michael@0 | 102 | } |
michael@0 | 103 | next(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | let type = typeof window.navigator.mozApps.getNotInstalled; |
michael@0 | 107 | is(type, "undefined", "getNotInstalled moved from window.navigator"); |
michael@0 | 108 | type = typeof window.navigator.mozApps.mgmt.getNotInstalled; |
michael@0 | 109 | if (type === "function") { |
michael@0 | 110 | is(type, "function", "getNotInstalled moved to window.navigator.mgmt"); |
michael@0 | 111 | results = window.navigator.mozApps.mgmt.getNotInstalled(); |
michael@0 | 112 | results.onerror = getNotInstalledError; |
michael@0 | 113 | results.onsuccess = getNotInstalledSuccess; |
michael@0 | 114 | } else { |
michael@0 | 115 | ok(false, "getNotInstalled not a function"); |
michael@0 | 116 | next(); |
michael@0 | 117 | } |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function unmonkeyPatchDOMApplicationRegistry(next) { |
michael@0 | 121 | if (typeof _isLaunchable === "function") { |
michael@0 | 122 | DOMApplicationRegistry._isLaunchable = _isLaunchable; |
michael@0 | 123 | ok(true, "restored DOMApplicationRegistry._isLaunchable"); |
michael@0 | 124 | } else { |
michael@0 | 125 | ok(false, "can't restore DOMApplicationRegistry._isLaunchable"); |
michael@0 | 126 | } |
michael@0 | 127 | next(); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | // Remove the app from the appregistry |
michael@0 | 131 | function uninstallApp(next) { |
michael@0 | 132 | window.navigator.mozApps.mgmt.uninstall(app).onsuccess = function onUninstall() { |
michael@0 | 133 | app = null; |
michael@0 | 134 | next(); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | </script> |
michael@0 | 139 | </window> |