toolkit/devtools/apps/tests/test_webapps_actor.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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={821589}
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug {821589} Packaged apps installation and update</title>
michael@0 8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={821589}">Mozilla Bug {821589}</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 <script class="testbody" type="application/javascript;version=1.8">
michael@0 21
michael@0 22 "use strict";
michael@0 23
michael@0 24 var index = -1;
michael@0 25
michael@0 26 function debug(aMsg) {
michael@0 27 //dump("== Tests debug == " + aMsg + "\n");
michael@0 28 }
michael@0 29
michael@0 30 function next() {
michael@0 31 index += 1;
michael@0 32 if (index >= steps.length) {
michael@0 33 ok(false, "Shouldn't get here!");
michael@0 34 return;
michael@0 35 }
michael@0 36 try {
michael@0 37 steps[index]();
michael@0 38 } catch(ex) {
michael@0 39 ok(false, "Caught exception", ex);
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 function start() {
michael@0 44 next();
michael@0 45 }
michael@0 46
michael@0 47 function finish() {
michael@0 48 SpecialPowers.removePermission("webapps-manage", document);
michael@0 49 SimpleTest.finish();
michael@0 50 }
michael@0 51
michael@0 52 function cbError(aError) {
michael@0 53 ok(false, "Error callback invoked " + aError);
michael@0 54 finish();
michael@0 55 }
michael@0 56
michael@0 57
michael@0 58 SimpleTest.waitForExplicitFinish();
michael@0 59
michael@0 60 var installTestApp, mm;
michael@0 61
michael@0 62 const PACKAGED_APP_ID = "test-app-id";
michael@0 63 const PACKAGED_APP_ORIGIN = "app://" + PACKAGED_APP_ID;
michael@0 64 const PACKAGED_APP_MANIFEST = PACKAGED_APP_ORIGIN + "/manifest.webapp";
michael@0 65 const CERTIFIED_APP_ID = "test-certified-id";
michael@0 66 const CERTIFIED_APP_ORIGIN = "app://" + CERTIFIED_APP_ID;
michael@0 67 const CERTIFIED_APP_MANIFEST = CERTIFIED_APP_ORIGIN + "/manifest.webapp";
michael@0 68
michael@0 69 var steps = [
michael@0 70 function() {
michael@0 71 info("== SETUP ==");
michael@0 72 // Set up
michael@0 73 SpecialPowers.setAllAppsLaunchable(true);
michael@0 74 SpecialPowers.addPermission("webapps-manage", true, document);
michael@0 75 SpecialPowers.addPermission("browser", true, document);
michael@0 76 SpecialPowers.addPermission("embed-apps", true, document);
michael@0 77
michael@0 78 // Required on firefox as these prefs are only set on b2g:
michael@0 79 SpecialPowers.pushPrefEnv({
michael@0 80 set: [["dom.mozBrowserFramesEnabled", true],
michael@0 81 ["security.apps.privileged.CSP.default",
michael@0 82 "default-src *; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'"],
michael@0 83 ["devtools.debugger.unix-domain-socket", 6000],
michael@0 84 ["devtools.debugger.prompt-connection", false],
michael@0 85 ["devtools.debugger.forbid-certified-apps", true]
michael@0 86 ]
michael@0 87 }, next);
michael@0 88 },
michael@0 89 function () {
michael@0 90 // Load a chrome script in order to dispatch devtool debugger requests.
michael@0 91 // Because of wrapping issues, we can't use SpecialPowers.Cu.import to load
michael@0 92 // devtools jsm into mochitest scope. We end up not receiving
michael@0 93 // DebuggerClient.addListener callback arguments...
michael@0 94 let scriptUrl = SimpleTest.getTestFileURL("debugger-protocol-helper.js");
michael@0 95 mm = SpecialPowers.loadChromeScript(scriptUrl);
michael@0 96 installTestApp = function (url, appId, callback) {
michael@0 97 let installResponse, appObject;
michael@0 98 let installedEvent = false;
michael@0 99 mm.addMessageListener("installed", function onInstalled(aResponse) {
michael@0 100 mm.removeMessageListener("installed", onInstalled);
michael@0 101 ok(true, "install request replied");
michael@0 102 installResponse = aResponse;
michael@0 103 checkEnd();
michael@0 104 });
michael@0 105 mm.addMessageListener("installed-event", function onInstalledEvent(aResponse) {
michael@0 106 mm.removeMessageListener("installed-event", onInstalledEvent);
michael@0 107 ok(true, "received appInstall actor event");
michael@0 108 installedEvent = true;
michael@0 109 checkEnd();
michael@0 110 });
michael@0 111 navigator.mozApps.mgmt.oninstall = function(evt) {
michael@0 112 appObject = evt.application;
michael@0 113 ok(true, "mozApps.mgmt install event fired");
michael@0 114 checkEnd();
michael@0 115 };
michael@0 116 function checkEnd() {
michael@0 117 if (appObject && installResponse && installedEvent)
michael@0 118 callback(installResponse, appObject);
michael@0 119 }
michael@0 120 mm.sendAsyncMessage("install", {url: url, appId: appId});
michael@0 121 };
michael@0 122 SpecialPowers.autoConfirmAppInstall(next);
michael@0 123 },
michael@0 124 function() {
michael@0 125 info("== TEST == Install packaged app");
michael@0 126 let url = SimpleTest.getTestFileURL("data/app.zip");
michael@0 127 installTestApp(url, PACKAGED_APP_ID,
michael@0 128 function (aResponse, aApp) {
michael@0 129 ok(true, "Installed");
michael@0 130 is(aResponse.appId, PACKAGED_APP_ID, "Got same app id");
michael@0 131 if ("error" in aResponse) {
michael@0 132 ok(false, "Error: " + aResponse.error);
michael@0 133 }
michael@0 134 if ("message" in aResponse) {
michael@0 135 ok(false, "Error message: " + aResponse.message);
michael@0 136 }
michael@0 137 ok(!("error" in aResponse), "app installed without any error");
michael@0 138 is(aApp.manifest.name, "Test app", "app name is correct");
michael@0 139 next();
michael@0 140 }
michael@0 141 );
michael@0 142 },
michael@0 143 function () {
michael@0 144 info("== TEST == Reinstall packaged app");
michael@0 145 let url = SimpleTest.getTestFileURL("data/app-updated.zip");
michael@0 146 installTestApp(url, PACKAGED_APP_ID,
michael@0 147 function (aResponse, aApp) {
michael@0 148 ok(true, "Reinstalled");
michael@0 149 is(aResponse.appId, PACKAGED_APP_ID, "Got same app id");
michael@0 150 if ("error" in aResponse) {
michael@0 151 ok(false, "Error: " + aResponse.error);
michael@0 152 }
michael@0 153 if ("message" in aResponse) {
michael@0 154 ok(false, "Error message: " + aResponse.message);
michael@0 155 }
michael@0 156 ok(!("error" in aResponse), "app installed without any error");
michael@0 157 is(aApp.manifest.name, "updated-name", "app name on update is correct");
michael@0 158 next();
michael@0 159 }
michael@0 160 );
michael@0 161 },
michael@0 162 function() {
michael@0 163 info("== TEST == Install certified app");
michael@0 164 let url = SimpleTest.getTestFileURL("data/app-certified.zip");
michael@0 165 installTestApp(url, CERTIFIED_APP_ID,
michael@0 166 function (aResponse, aApp) {
michael@0 167 ok(true, "Installed");
michael@0 168 is(aResponse.appId, CERTIFIED_APP_ID, "Got same app id");
michael@0 169 if ("error" in aResponse) {
michael@0 170 ok(false, "Error: " + aResponse.error);
michael@0 171 }
michael@0 172 if ("message" in aResponse) {
michael@0 173 ok(false, "Error message: " + aResponse.message);
michael@0 174 }
michael@0 175 ok(!("error" in aResponse), "app installed without any error");
michael@0 176 is(aApp.manifest.name, "Certified app", "app name is correct");
michael@0 177 next();
michael@0 178 }
michael@0 179 );
michael@0 180 },
michael@0 181 function() {
michael@0 182 info("== TEST == Get all apps");
michael@0 183 getAll(false);
michael@0 184 },
michael@0 185 function() {
michael@0 186 info("== TEST == Get packaged app");
michael@0 187 getApp({
michael@0 188 id: PACKAGED_APP_ID,
michael@0 189 manifestURL: PACKAGED_APP_MANIFEST
michael@0 190 }, true);
michael@0 191 },
michael@0 192 function() {
michael@0 193 info("== TEST == Get certified app");
michael@0 194 getApp({
michael@0 195 id: CERTIFIED_APP_ID,
michael@0 196 manifestURL: CERTIFIED_APP_MANIFEST
michael@0 197 }, false);
michael@0 198 },
michael@0 199 function() {
michael@0 200 info("== SETUP == Enable certified app access");
michael@0 201 SpecialPowers.pushPrefEnv({
michael@0 202 "set": [["devtools.debugger.forbid-certified-apps", false]]
michael@0 203 }, next);
michael@0 204 },
michael@0 205 function() {
michael@0 206 info("== TEST == Get all apps (CERTIFIED ENABLED)");
michael@0 207 getAll(true);
michael@0 208 },
michael@0 209 function() {
michael@0 210 info("== TEST == Get packaged app (CERTIFIED ENABLED)");
michael@0 211 getApp({
michael@0 212 id: PACKAGED_APP_ID,
michael@0 213 manifestURL: PACKAGED_APP_MANIFEST
michael@0 214 }, true);
michael@0 215 },
michael@0 216 function() {
michael@0 217 info("== TEST == Get certified app (CERTIFIED ENABLED)");
michael@0 218 getApp({
michael@0 219 id: CERTIFIED_APP_ID,
michael@0 220 manifestURL: CERTIFIED_APP_MANIFEST
michael@0 221 }, true);
michael@0 222 },
michael@0 223 function() {
michael@0 224 info("== SETUP == Disable certified app access");
michael@0 225 SpecialPowers.popPrefEnv(next);
michael@0 226 },
michael@0 227 function() {
michael@0 228 info("== TEST == Uninstall packaged app");
michael@0 229 uninstall(PACKAGED_APP_MANIFEST);
michael@0 230 },
michael@0 231 function() {
michael@0 232 info("== TEST == Uninstall certified app");
michael@0 233 uninstall(CERTIFIED_APP_MANIFEST);
michael@0 234 },
michael@0 235 function() {
michael@0 236 ok(true, "all done!\n");
michael@0 237 mm.sendAsyncMessage("cleanup");
michael@0 238 SpecialPowers.flushPrefEnv(finish);
michael@0 239 }
michael@0 240 ];
michael@0 241
michael@0 242 addLoadEvent(start);
michael@0 243
michael@0 244 function getAll(expectCertified) {
michael@0 245 mm.addMessageListener("appActorResponse", function onResponse(response) {
michael@0 246 mm.removeMessageListener("appActorResponse", onResponse);
michael@0 247
michael@0 248 ok("apps" in response, "Apps found in getAll reply");
michael@0 249 let apps = response.apps;
michael@0 250 let packagedApp, certifiedApp;
michael@0 251 for (let app of apps) {
michael@0 252 switch (app.id) {
michael@0 253 case PACKAGED_APP_ID:
michael@0 254 packagedApp = app;
michael@0 255 break;
michael@0 256 case CERTIFIED_APP_ID:
michael@0 257 certifiedApp = app;
michael@0 258 break;
michael@0 259 }
michael@0 260 }
michael@0 261
michael@0 262 ok(packagedApp, "Packaged app found via getAll");
michael@0 263 is(!!certifiedApp, expectCertified, "Certified app matches expectation");
michael@0 264
michael@0 265 next();
michael@0 266 });
michael@0 267
michael@0 268 mm.sendAsyncMessage("appActorRequest", {
michael@0 269 type: "getAll"
michael@0 270 });
michael@0 271 }
michael@0 272
michael@0 273 function getApp(appInfo, expected) {
michael@0 274 mm.addMessageListener("appActorResponse", function onResponse(response) {
michael@0 275 mm.removeMessageListener("appActorResponse", onResponse);
michael@0 276
michael@0 277 is("app" in response, expected, "App existence matches expectation");
michael@0 278 is("error" in response, !expected, "Error existence matches expectation");
michael@0 279 if (!expected) {
michael@0 280 is(response.error, "forbidden", "Error message is correct");
michael@0 281 next();
michael@0 282 return;
michael@0 283 }
michael@0 284
michael@0 285 let app = response.app;
michael@0 286 for (let key in appInfo) {
michael@0 287 is(app[key], appInfo[key], "Value for " + key + " matches");
michael@0 288 }
michael@0 289
michael@0 290 next();
michael@0 291 });
michael@0 292
michael@0 293 mm.sendAsyncMessage("appActorRequest", {
michael@0 294 type: "getApp",
michael@0 295 manifestURL: appInfo.manifestURL
michael@0 296 });
michael@0 297 }
michael@0 298
michael@0 299 function uninstall(manifestURL) {
michael@0 300 mm.addMessageListener("appActorResponse", function onResponse(response) {
michael@0 301 mm.removeMessageListener("appActorResponse", onResponse);
michael@0 302 ok(!("error" in response), "App uninstalled successfully");
michael@0 303 next();
michael@0 304 });
michael@0 305
michael@0 306 mm.sendAsyncMessage("appActorRequest", {
michael@0 307 type: "uninstall",
michael@0 308 manifestURL: manifestURL
michael@0 309 });
michael@0 310 }
michael@0 311
michael@0 312 </script>
michael@0 313 </pre>
michael@0 314 </body>
michael@0 315 </html>

mercurial