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 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | let scope = {}; |
michael@0 | 7 | Cu.import("resource://gre/modules/PermissionSettings.jsm", scope); |
michael@0 | 8 | |
michael@0 | 9 | const TEST_URL = |
michael@0 | 10 | "http://mochi.test:8888/browser/dom/tests/browser/test-webapps-permissions.html"; |
michael@0 | 11 | const TEST_MANIFEST_URL = |
michael@0 | 12 | "http://mochi.test:8888/browser/dom/tests/browser/test-webapp.webapp"; |
michael@0 | 13 | const TEST_ORIGIN_URL = "http://mochi.test:8888"; |
michael@0 | 14 | |
michael@0 | 15 | const installedPermsToTest = { |
michael@0 | 16 | "geolocation": "prompt", |
michael@0 | 17 | "alarms": "allow", |
michael@0 | 18 | "contacts": "deny", |
michael@0 | 19 | "device-storage:apps": "deny", |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | const reinstalledPermsToTest = { |
michael@0 | 23 | "geolocation": "prompt", |
michael@0 | 24 | "alarms": "unknown", |
michael@0 | 25 | "contacts": "deny", |
michael@0 | 26 | "device-storage:apps": "deny", |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | var gWindow, gNavigator; |
michael@0 | 30 | |
michael@0 | 31 | function test() { |
michael@0 | 32 | waitForExplicitFinish(); |
michael@0 | 33 | |
michael@0 | 34 | var tab = gBrowser.addTab(TEST_URL); |
michael@0 | 35 | gBrowser.selectedTab = tab; |
michael@0 | 36 | var browser = gBrowser.selectedBrowser; |
michael@0 | 37 | PopupNotifications.panel.addEventListener("popupshown", handlePopup, false); |
michael@0 | 38 | |
michael@0 | 39 | registerCleanupFunction(function () { |
michael@0 | 40 | gWindow = null; |
michael@0 | 41 | gBrowser.removeTab(tab); |
michael@0 | 42 | }); |
michael@0 | 43 | |
michael@0 | 44 | browser.addEventListener("DOMContentLoaded", function onLoad(event) { |
michael@0 | 45 | browser.removeEventListener("DOMContentLoaded", onLoad, false); |
michael@0 | 46 | gWindow = browser.contentWindow; |
michael@0 | 47 | SpecialPowers.setBoolPref("dom.mozPermissionSettings.enabled", true); |
michael@0 | 48 | SpecialPowers.addPermission("permissions", true, browser.contentWindow.document); |
michael@0 | 49 | SpecialPowers.addPermission("permissions", true, browser.contentDocument); |
michael@0 | 50 | |
michael@0 | 51 | let pendingInstall; |
michael@0 | 52 | |
michael@0 | 53 | function testInstall() { |
michael@0 | 54 | var nav = XPCNativeWrapper.unwrap(browser.contentWindow.navigator); |
michael@0 | 55 | ok(nav.mozApps, "we have a mozApps property"); |
michael@0 | 56 | var navMozPerms = nav.mozPermissionSettings; |
michael@0 | 57 | ok(navMozPerms, "mozPermissions is available"); |
michael@0 | 58 | |
michael@0 | 59 | // INSTALL app |
michael@0 | 60 | pendingInstall = nav.mozApps.install(TEST_MANIFEST_URL, null); |
michael@0 | 61 | pendingInstall.onsuccess = function onsuccess() |
michael@0 | 62 | { |
michael@0 | 63 | ok(this.result, "we have a result: " + this.result); |
michael@0 | 64 | function testPerm(aPerm, aAccess) |
michael@0 | 65 | { |
michael@0 | 66 | var res = |
michael@0 | 67 | navMozPerms.get(aPerm, TEST_MANIFEST_URL, TEST_ORIGIN_URL, false); |
michael@0 | 68 | is(res, aAccess, "install: " + aPerm + " is " + res); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | for (let permName in installedPermsToTest) { |
michael@0 | 72 | testPerm(permName, installedPermsToTest[permName]); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | writeUpdatesToWebappManifest(); |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | pendingInstall.onerror = function onerror(e) |
michael@0 | 79 | { |
michael@0 | 80 | ok(false, "install()'s onerror was called: " + e); |
michael@0 | 81 | ok(false, "All permission checks failed, reinstall tests were not run"); |
michael@0 | 82 | }; |
michael@0 | 83 | } |
michael@0 | 84 | testInstall(); |
michael@0 | 85 | }, false); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | function reinstallApp() |
michael@0 | 89 | { |
michael@0 | 90 | var browser = gBrowser.selectedBrowser; |
michael@0 | 91 | var nav = XPCNativeWrapper.unwrap(browser.contentWindow.navigator); |
michael@0 | 92 | var navMozPerms = nav.mozPermissionSettings; |
michael@0 | 93 | |
michael@0 | 94 | var pendingReinstall = nav.mozApps.install(TEST_MANIFEST_URL); |
michael@0 | 95 | pendingReinstall.onsuccess = function onsuccess() |
michael@0 | 96 | { |
michael@0 | 97 | ok(this.result, "we have a result: " + this.result); |
michael@0 | 98 | |
michael@0 | 99 | function testPerm(aPerm, aAccess) |
michael@0 | 100 | { |
michael@0 | 101 | var res = |
michael@0 | 102 | navMozPerms.get(aPerm, TEST_MANIFEST_URL, TEST_ORIGIN_URL, false); |
michael@0 | 103 | is(res, aAccess, "reinstall: " + aPerm + " is " + res); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | for (let permName in reinstalledPermsToTest) { |
michael@0 | 107 | testPerm(permName, reinstalledPermsToTest[permName]); |
michael@0 | 108 | } |
michael@0 | 109 | writeUpdatesToWebappManifest(); |
michael@0 | 110 | finish(); |
michael@0 | 111 | }; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | var qtyPopups = 0; |
michael@0 | 115 | |
michael@0 | 116 | function handlePopup(aEvent) |
michael@0 | 117 | { |
michael@0 | 118 | qtyPopups++; |
michael@0 | 119 | if (qtyPopups == 2) { |
michael@0 | 120 | aEvent.target.removeEventListener("popupshown", handlePopup, false); |
michael@0 | 121 | } |
michael@0 | 122 | SpecialPowers.wrap(this).childNodes[0].button.doCommand(); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function writeUpdatesToWebappManifest(aRestore) |
michael@0 | 126 | { |
michael@0 | 127 | let newfile = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 128 | getService(Ci.nsIProperties). |
michael@0 | 129 | get("XCurProcD", Ci.nsIFile); |
michael@0 | 130 | |
michael@0 | 131 | let devPath = ["_tests", "testing", "mochitest", |
michael@0 | 132 | "browser", "dom" , "tests", "browser"]; |
michael@0 | 133 | // make package-tests moves tests to: |
michael@0 | 134 | // dist/test-package-stage/mochitest/browser/dom/tests/browser |
michael@0 | 135 | let slavePath = ["dist", "test-package-stage", "mochitest", |
michael@0 | 136 | "browser", "dom", "tests", "browser"]; |
michael@0 | 137 | |
michael@0 | 138 | newfile = newfile.parent; // up to dist/ |
michael@0 | 139 | newfile = newfile.parent;// up to obj-dir/ |
michael@0 | 140 | |
michael@0 | 141 | info(newfile.path); |
michael@0 | 142 | try { |
michael@0 | 143 | for (let idx in devPath) { |
michael@0 | 144 | newfile.append(devPath[idx]); |
michael@0 | 145 | if (!newfile.isDirectory()) { |
michael@0 | 146 | info("*** NOT RUNNING ON DEV MACHINE\n\n"); |
michael@0 | 147 | throw new Error("Test is not running on dev machine, try dev path"); |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | catch (ex) { |
michael@0 | 152 | info(ex + "\n\n"); |
michael@0 | 153 | for (let idx in slavePath) { |
michael@0 | 154 | newfile.append(slavePath[idx]); |
michael@0 | 155 | if (!newfile.isDirectory()) { |
michael@0 | 156 | info("*** NOT RUNNING ON BUILD SLAVE\n\n"); |
michael@0 | 157 | throw new Error("Test is not running on slave machine, abort test"); |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | info("Final path: " + newfile.path); |
michael@0 | 163 | |
michael@0 | 164 | if (aRestore) { |
michael@0 | 165 | newfile.append("test-webapp-original.webapp"); |
michael@0 | 166 | } else { |
michael@0 | 167 | newfile.append("test-webapp-reinstall.webapp"); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | let oldfile = newfile.parent; |
michael@0 | 171 | oldfile.append("test-webapp.webapp"); |
michael@0 | 172 | |
michael@0 | 173 | newfile.copyTo(null, "test-webapp.webapp"); |
michael@0 | 174 | |
michael@0 | 175 | if (!aRestore) { |
michael@0 | 176 | executeSoon(function (){ reinstallApp(); }); |
michael@0 | 177 | } |
michael@0 | 178 | } |