Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=880043 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 880043 Packaged apps installation and update</title> |
michael@0 | 9 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 10 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <script type="text/javascript" src="test_packaged_app_common.js"></script> |
michael@0 | 12 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 13 | </head> |
michael@0 | 14 | <body> |
michael@0 | 15 | |
michael@0 | 16 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=880043">Mozilla Bug 880043</a> |
michael@0 | 17 | <p id="display"></p> |
michael@0 | 18 | <div id="content" style="display: none"> |
michael@0 | 19 | |
michael@0 | 20 | </div> |
michael@0 | 21 | <pre id="test"> |
michael@0 | 22 | <script class="testbody" type="text/javascript"> |
michael@0 | 23 | |
michael@0 | 24 | "use strict"; |
michael@0 | 25 | |
michael@0 | 26 | const Ci = SpecialPowers.Ci; |
michael@0 | 27 | const Cc = SpecialPowers.Cc; |
michael@0 | 28 | const Cu = SpecialPowers.Cu; |
michael@0 | 29 | |
michael@0 | 30 | var index = -1; |
michael@0 | 31 | var gDebug = false; |
michael@0 | 32 | var gApp = null; |
michael@0 | 33 | var gAppName = "Simple App"; |
michael@0 | 34 | var gInstallOrigin = "http://mochi.test:8888/"; |
michael@0 | 35 | var gSJSPath = "tests/dom/apps/tests/signed_app.sjs"; |
michael@0 | 36 | var gSJS = gInstallOrigin + gSJSPath; |
michael@0 | 37 | var gPackagePath = gInstallOrigin + "tests/dom/apps/tests/"; |
michael@0 | 38 | var gSignedAppOriginsStr =""; |
michael@0 | 39 | |
michael@0 | 40 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 41 | |
michael@0 | 42 | function checkAppOnInstallError(aMiniManifestURL, aExpectedError) { |
michael@0 | 43 | navigator.mozApps.mgmt.oninstall = function(evt) { |
michael@0 | 44 | info("Got oninstall event"); |
michael@0 | 45 | gApp = evt.application; |
michael@0 | 46 | gApp.ondownloaderror = function() { |
michael@0 | 47 | is(gApp.downloadError.name, aExpectedError, |
michael@0 | 48 | "Download fails with expected error: " + aExpectedError); |
michael@0 | 49 | if (gApp.downloadError.name != aExpectedError) { |
michael@0 | 50 | PackagedTestHelper.finish(); |
michael@0 | 51 | } else { |
michael@0 | 52 | PackagedTestHelper.next(); |
michael@0 | 53 | } |
michael@0 | 54 | }; |
michael@0 | 55 | gApp.ondownloadsuccess = function() { |
michael@0 | 56 | ok(false, "App download should fail"); |
michael@0 | 57 | PackagedTestHelper.finish(); |
michael@0 | 58 | }; |
michael@0 | 59 | }; |
michael@0 | 60 | var request = navigator.mozApps.installPackage(aMiniManifestURL); |
michael@0 | 61 | request.onerror = function(evt) { |
michael@0 | 62 | ok(false, "Application should throw the error inside oninstall: " + evt.error.name); |
michael@0 | 63 | PackagedTestHelper.finish(); |
michael@0 | 64 | }; |
michael@0 | 65 | request.onsuccess = function() { |
michael@0 | 66 | info("Application install returns successfully"); |
michael@0 | 67 | }; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function checkUninstallApp(aApp) { |
michael@0 | 71 | var req = navigator.mozApps.mgmt.uninstall(aApp); |
michael@0 | 72 | |
michael@0 | 73 | req.onsuccess = function() { |
michael@0 | 74 | info("App uninstalled"); |
michael@0 | 75 | aApp.ondownloadsuccess = null; |
michael@0 | 76 | aApp.ondownloaderror = null; |
michael@0 | 77 | aApp.onprogress = null; |
michael@0 | 78 | PackagedTestHelper.next(); |
michael@0 | 79 | }; |
michael@0 | 80 | req.onerror = function(evt) { |
michael@0 | 81 | ok(false, "App uninstallation should succeed (got unexpected " + |
michael@0 | 82 | evt.target.error.name + ")"); |
michael@0 | 83 | PackagedTestHelper.finish(); |
michael@0 | 84 | }; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | var steps = [ |
michael@0 | 88 | function() { |
michael@0 | 89 | // Set up |
michael@0 | 90 | info("Test Initial Setup"); |
michael@0 | 91 | gSignedAppOriginsStr = SpecialPowers.getCharPref("dom.mozApps.signed_apps_installable_from"); |
michael@0 | 92 | var signedAppOriginsStr = gSignedAppOriginsStr.concat("," + gInstallOrigin.slice(0, -1)); |
michael@0 | 93 | SpecialPowers.pushPrefEnv({'set': [['dom.mozApps.signed_apps_installable_from', signedAppOriginsStr]]}, function() { |
michael@0 | 94 | var url = SimpleTest.getTestFileURL("chromeAddCert.js"); |
michael@0 | 95 | var script = SpecialPowers.loadChromeScript(url); |
michael@0 | 96 | script.addMessageListener("addCertCompleted", function() { |
michael@0 | 97 | SpecialPowers.setAllAppsLaunchable(true); |
michael@0 | 98 | SpecialPowers.addPermission("webapps-manage", true, document); |
michael@0 | 99 | info("Test CA Certificate Selected"); |
michael@0 | 100 | PackagedTestHelper.next(); |
michael@0 | 101 | script.destroy(); |
michael@0 | 102 | }); |
michael@0 | 103 | }); |
michael@0 | 104 | }, |
michael@0 | 105 | function() { |
michael@0 | 106 | info("autoConfirmAppInstall"); |
michael@0 | 107 | SpecialPowers.autoConfirmAppInstall(PackagedTestHelper.next); |
michael@0 | 108 | }, |
michael@0 | 109 | function() { |
michael@0 | 110 | info("== TEST == Install packaged app"); |
michael@0 | 111 | var miniManifestURL = gSJS + "?" + "app=valid&" + "version=1"; |
michael@0 | 112 | |
michael@0 | 113 | navigator.mozApps.mgmt.oninstall = function(evt) { |
michael@0 | 114 | info("Got oninstall event"); |
michael@0 | 115 | gApp = evt.application; |
michael@0 | 116 | gApp.ondownloaderror = function() { |
michael@0 | 117 | ok(false, "Download should succeed (got error: " + |
michael@0 | 118 | gApp.downloadError.name + ")"); |
michael@0 | 119 | PackagedTestHelper.finish(); |
michael@0 | 120 | }; |
michael@0 | 121 | gApp.ondownloadsuccess = function() { |
michael@0 | 122 | info("App downloaded"); |
michael@0 | 123 | var expected = { |
michael@0 | 124 | name: gAppName, |
michael@0 | 125 | manifestURL: miniManifestURL, |
michael@0 | 126 | installOrigin: gInstallOrigin.slice(0, -1), |
michael@0 | 127 | progress: 0, |
michael@0 | 128 | installState: "installed", |
michael@0 | 129 | downloadAvailable: false, |
michael@0 | 130 | downloading: false, |
michael@0 | 131 | readyToApplyDownload: false, |
michael@0 | 132 | }; |
michael@0 | 133 | PackagedTestHelper.checkAppState(gApp, 1, expected, |
michael@0 | 134 | true, false, PackagedTestHelper.next); |
michael@0 | 135 | }; |
michael@0 | 136 | }; |
michael@0 | 137 | info("Installing app: " + miniManifestURL); |
michael@0 | 138 | var request = navigator.mozApps.installPackage(miniManifestURL); |
michael@0 | 139 | request.onerror = function(evt) { |
michael@0 | 140 | ok(false, "Application should have been correctly installed (error: " + |
michael@0 | 141 | JSON.stringify(evt)); |
michael@0 | 142 | }; |
michael@0 | 143 | request.onsuccess = function() { |
michael@0 | 144 | info("Application installed"); |
michael@0 | 145 | }; |
michael@0 | 146 | }, |
michael@0 | 147 | function() { |
michael@0 | 148 | info("== TEST == Uninstall a signed app"); |
michael@0 | 149 | // Uninstall App |
michael@0 | 150 | checkUninstallApp(gApp); |
michael@0 | 151 | }, |
michael@0 | 152 | function() { |
michael@0 | 153 | info("== TEST == Install a corrupted package"); |
michael@0 | 154 | //Scenario: Corrupted package |
michael@0 | 155 | var miniManifestURL = gSJS + "?" + "app=corrupt&" + "version=1"; |
michael@0 | 156 | checkAppOnInstallError(miniManifestURL, "APP_PACKAGE_CORRUPTED"); |
michael@0 | 157 | }, |
michael@0 | 158 | function() { |
michael@0 | 159 | info("== TEST == Install a unsigned app from a trusted store"); |
michael@0 | 160 | //Scenario: Unsigned App from an origin that requires signed apps |
michael@0 | 161 | var miniManifestURL = gSJS + "?" + "app=unknown_issuer&" + "version=1"; |
michael@0 | 162 | checkAppOnInstallError(miniManifestURL, "INVALID_SIGNATURE"); |
michael@0 | 163 | }, |
michael@0 | 164 | function() { |
michael@0 | 165 | info("== TEST == Install packaged app with origin"); |
michael@0 | 166 | var miniManifestURL = gSJS + "?" + |
michael@0 | 167 | "app=origin&" + |
michael@0 | 168 | "version=1"; |
michael@0 | 169 | |
michael@0 | 170 | navigator.mozApps.mgmt.oninstall = function(evt) { |
michael@0 | 171 | info("Got oninstall event"); |
michael@0 | 172 | gApp = evt.application; |
michael@0 | 173 | gApp.ondownloaderror = function() { |
michael@0 | 174 | ok(false, "Download should succeed (got error: " + |
michael@0 | 175 | gApp.downloadError.name + ")"); |
michael@0 | 176 | PackagedTestHelper.finish(); |
michael@0 | 177 | }; |
michael@0 | 178 | gApp.ondownloadsuccess = function() { |
michael@0 | 179 | info("App downloaded"); |
michael@0 | 180 | var expected = { |
michael@0 | 181 | name: gAppName, |
michael@0 | 182 | manifestURL: miniManifestURL, |
michael@0 | 183 | installOrigin: gInstallOrigin.slice(0, -1), |
michael@0 | 184 | progress: 0, |
michael@0 | 185 | installState: "installed", |
michael@0 | 186 | downloadAvailable: false, |
michael@0 | 187 | downloading: false, |
michael@0 | 188 | origin: "app://test.origin.privileged.app", |
michael@0 | 189 | readyToApplyDownload: false, |
michael@0 | 190 | }; |
michael@0 | 191 | PackagedTestHelper.checkAppState(gApp, 1, expected, |
michael@0 | 192 | true, false, PackagedTestHelper.next); |
michael@0 | 193 | }; |
michael@0 | 194 | }; |
michael@0 | 195 | info("Installing app: " + miniManifestURL); |
michael@0 | 196 | var request = navigator.mozApps.installPackage(miniManifestURL); |
michael@0 | 197 | request.onerror = function(evt) { |
michael@0 | 198 | ok(false, "Application should have been correctly installed (error: " + |
michael@0 | 199 | JSON.stringify(evt)); |
michael@0 | 200 | }; |
michael@0 | 201 | request.onsuccess = function() { |
michael@0 | 202 | info("Application installed"); |
michael@0 | 203 | }; |
michael@0 | 204 | }, |
michael@0 | 205 | function() { |
michael@0 | 206 | info("== TEST == Install app from an invalid source"); |
michael@0 | 207 | // Scenario: This is where an unexpected store is signing packages and |
michael@0 | 208 | // attempting to install. Please note that after this test you cannot |
michael@0 | 209 | // add new successful tests without changing the preference again |
michael@0 | 210 | SpecialPowers.pushPrefEnv( |
michael@0 | 211 | {'set': [['dom.mozApps.signed_apps_installable_from', |
michael@0 | 212 | gSignedAppOriginsStr]]}, |
michael@0 | 213 | function() { |
michael@0 | 214 | var miniManifestURL = gSJS + "?" + "app=valid&" + "version=1"; |
michael@0 | 215 | checkAppOnInstallError(miniManifestURL, "INSTALL_FROM_DENIED"); |
michael@0 | 216 | }); |
michael@0 | 217 | }, |
michael@0 | 218 | function() { |
michael@0 | 219 | info("all done!"); |
michael@0 | 220 | PackagedTestHelper.finish(); |
michael@0 | 221 | } |
michael@0 | 222 | ]; |
michael@0 | 223 | |
michael@0 | 224 | PackagedTestHelper.setSteps(steps); |
michael@0 | 225 | PackagedTestHelper.gSJSPath = gSJSPath; |
michael@0 | 226 | |
michael@0 | 227 | addLoadEvent(PackagedTestHelper.start); |
michael@0 | 228 | |
michael@0 | 229 | </script> |
michael@0 | 230 | </pre> |
michael@0 | 231 | </body> |
michael@0 | 232 | </html> |