dom/apps/tests/test_packaged_app_asmjs.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=997886
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 997886 - Test installing and updating apps with asm.js pre-compiling</title>
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <script type="application/javascript"
michael@0 12 src="chrome://mochikit/content/chrome-harness.js"></script>
michael@0 13 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
michael@0 14 <script type="application/javascript;version=1.7">
michael@0 15
michael@0 16 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
michael@0 17
michael@0 18 SimpleTest.waitForExplicitFinish();
michael@0 19
michael@0 20 const gBaseURL = 'http://test/chrome/dom/apps/tests/asmjs/';
michael@0 21 const gSJS = gBaseURL + 'asmjs_app.sjs';
michael@0 22 const gManifestURL = gSJS + '?getManifest=true';
michael@0 23 let gGenerator = runTest();
michael@0 24
michael@0 25 // Mock WebappOSUtils
michael@0 26 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
michael@0 27 let oldWebappOSUtils = WebappOSUtils;
michael@0 28 WebappOSUtils.getPackagePath = function(aApp) {
michael@0 29 return aApp.basePath + "/" + aApp.id;
michael@0 30 }
michael@0 31
michael@0 32 // Enable the ScriptPreloader module
michael@0 33 Cu.import("resource://gre/modules/ScriptPreloader.jsm");
michael@0 34 let oldScriptPreloaderEnabled = ScriptPreloader._enabled;
michael@0 35 ScriptPreloader._enabled = true;
michael@0 36
michael@0 37 SimpleTest.registerCleanupFunction(() => {
michael@0 38 WebappOSUtils = oldWebappOSUtils;
michael@0 39 ScriptPreloader._enabled = oldScriptPreloaderEnabled;
michael@0 40 });
michael@0 41
michael@0 42 function go() {
michael@0 43 gGenerator.next();
michael@0 44 }
michael@0 45
michael@0 46 function continueTest() {
michael@0 47 try {
michael@0 48 gGenerator.next();
michael@0 49 } catch (e if e instanceof StopIteration) {
michael@0 50 SimpleTest.finish();
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 function mozAppsError() {
michael@0 55 ok(false, "mozApps error: " + this.error.name);
michael@0 56 SimpleTest.finish();
michael@0 57 }
michael@0 58
michael@0 59 function xhrError(aEvent, aURL) {
michael@0 60 var xhr = aEvent.target;
michael@0 61 ok(false, "XHR error loading " + aURL + ": " + xhr.status + " - " +
michael@0 62 xhr.statusText);
michael@0 63 SimpleTest.finish();
michael@0 64 }
michael@0 65
michael@0 66 function xhrAbort(aURL) {
michael@0 67 ok(false, "XHR abort loading " + aURL);
michael@0 68 SimpleTest.finish();
michael@0 69 }
michael@0 70
michael@0 71 function setState(aQuery, aVersion, aCallback) {
michael@0 72 var xhr = new XMLHttpRequest();
michael@0 73 var url = gSJS + '?' + aQuery + '=' + aVersion;
michael@0 74 xhr.addEventListener("load", function() {
michael@0 75 is(xhr.responseText, "OK", aQuery + " OK");
michael@0 76 aCallback();
michael@0 77 });
michael@0 78 xhr.addEventListener("error", event => xhrError(event, url));
michael@0 79 xhr.addEventListener("abort", event => xhrAbort(url));
michael@0 80 xhr.open('GET', url, true);
michael@0 81 xhr.send();
michael@0 82 }
michael@0 83
michael@0 84 function runApp(aApp, aCallback) {
michael@0 85 let domParent = document.getElementById('container');
michael@0 86
michael@0 87 let ifr = document.createElement('iframe');
michael@0 88 ifr.setAttribute('mozbrowser', 'true');
michael@0 89 ifr.setAttribute('mozapp', gManifestURL);
michael@0 90 ifr.src = aApp.origin + aApp.manifest.launch_path;
michael@0 91
michael@0 92 ifr.addEventListener('mozbrowsershowmodalprompt', function onAlert(e) {
michael@0 93 var message = e.detail.message;
michael@0 94
michael@0 95 if (message.startsWith("OK: ")) {
michael@0 96 ok(true, message.substring(4, message.length));
michael@0 97 } else if (message.startsWith("ERROR: ")) {
michael@0 98 ok(false, message.substring(7, message.length));
michael@0 99 } else if (message == "DONE") {
michael@0 100 ifr.removeEventListener('mozbrowsershowmodalprompt', onAlert, false);
michael@0 101 domParent.removeChild(ifr);
michael@0 102 aCallback();
michael@0 103 }
michael@0 104 }, false);
michael@0 105
michael@0 106 domParent.appendChild(ifr);
michael@0 107 }
michael@0 108
michael@0 109 function testNoPrecompile(aPrecompile, aCallback) {
michael@0 110 setState("setPrecompile", aPrecompile, function() {
michael@0 111 let request = navigator.mozApps.installPackage(gManifestURL);
michael@0 112 request.onerror = mozAppsError;
michael@0 113 request.onsuccess = function() {
michael@0 114 let app = request.result;
michael@0 115 ok(app, "App is non-null");
michael@0 116
michael@0 117 app.ondownloaderror = mozAppsError;
michael@0 118 app.ondownloadapplied = function() {
michael@0 119 runApp(app, function() {
michael@0 120 request = navigator.mozApps.mgmt.uninstall(app);
michael@0 121 request.onerror = mozAppsError;
michael@0 122 request.onsuccess = function() {
michael@0 123 app.ondownloadapplied = null;
michael@0 124 aCallback();
michael@0 125 };
michael@0 126 });
michael@0 127 };
michael@0 128 };
michael@0 129 });
michael@0 130 }
michael@0 131
michael@0 132 function runTest() {
michael@0 133 // Set up.
michael@0 134
michael@0 135 SpecialPowers.setAllAppsLaunchable(true);
michael@0 136 SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true]]},
michael@0 137 continueTest);
michael@0 138 yield undefined;
michael@0 139
michael@0 140 SpecialPowers.autoConfirmAppInstall(continueTest);
michael@0 141 yield undefined;
michael@0 142
michael@0 143 setState("setVersion", 1, continueTest);
michael@0 144 yield undefined;
michael@0 145
michael@0 146 // Test apps with wrong precompile fields
michael@0 147 info("Test with an empty array");
michael@0 148 testNoPrecompile('[]', continueTest);
michael@0 149 yield undefined;
michael@0 150 info("Test with an object");
michael@0 151 testNoPrecompile('{}', continueTest);
michael@0 152 yield undefined;
michael@0 153 info("Test with a string");
michael@0 154 testNoPrecompile('"asmjsmodule"', continueTest);
michael@0 155 yield undefined;
michael@0 156 info("Test with a file that doesn't exist");
michael@0 157 testNoPrecompile('["file.js"]', continueTest);
michael@0 158 yield undefined;
michael@0 159
michael@0 160 setState("setPrecompile", '["asmjsmodule.js"]', continueTest);
michael@0 161 yield undefined;
michael@0 162
michael@0 163 let request = navigator.mozApps.installPackage(gManifestURL);
michael@0 164 request.onerror = mozAppsError;
michael@0 165 request.onsuccess = continueTest;
michael@0 166 yield undefined;
michael@0 167 let app = request.result;
michael@0 168 ok(app, "App is non-null");
michael@0 169 app.ondownloaderror = mozAppsError;
michael@0 170 app.ondownloadsuccess = continueTest;
michael@0 171 app.ondownloadapplied = continueTest;
michael@0 172 yield undefined;
michael@0 173 yield undefined;
michael@0 174
michael@0 175 runApp(app, continueTest);
michael@0 176 yield undefined;
michael@0 177
michael@0 178 // Update app version
michael@0 179 setState("setVersion", 2, continueTest);
michael@0 180 yield undefined;
michael@0 181
michael@0 182 // Check for updates
michael@0 183 lastCheck = app.lastUpdateCheck;
michael@0 184 app.ondownloadavailable = function() {
michael@0 185 ok(true, "downloadavailable fired");
michael@0 186 continueTest();
michael@0 187 }
michael@0 188 request = app.checkForUpdate();
michael@0 189 request.onerror = mozAppsError;
michael@0 190 request.onsuccess = function() {
michael@0 191 ok(true, "checkForUpdate success");
michael@0 192 continueTest();
michael@0 193 }
michael@0 194 yield undefined;
michael@0 195 yield undefined;
michael@0 196
michael@0 197 // Check that there's a download available and download it
michael@0 198 ok(app.downloadAvailable, "Download available");
michael@0 199 app.ondownloaderror = mozAppsError;
michael@0 200 app.ondownloadsuccess = function() {
michael@0 201 ok(true, "downloadsuccess fired");
michael@0 202 continueTest();
michael@0 203 }
michael@0 204 app.download();
michael@0 205 yield undefined;
michael@0 206
michael@0 207 // Apply downloaded update
michael@0 208 ok(app.readyToApplyDownload, "App ready to apply download");
michael@0 209 app.ondownloaderror = mozAppsError;
michael@0 210 app.ondownloadapplied = function() {
michael@0 211 ok(true, "downloadapplied fired");
michael@0 212 continueTest();
michael@0 213 }
michael@0 214 navigator.mozApps.mgmt.applyDownload(app);
michael@0 215 yield undefined;
michael@0 216
michael@0 217 runApp(app, continueTest);
michael@0 218 yield undefined;
michael@0 219
michael@0 220 // Uninstall the app.
michael@0 221 request = navigator.mozApps.mgmt.uninstall(app);
michael@0 222 request.onerror = mozAppsError;
michael@0 223 request.onsuccess = continueTest;
michael@0 224 yield undefined;
michael@0 225 }
michael@0 226
michael@0 227 </script>
michael@0 228 </head>
michael@0 229 <body onload="go()">
michael@0 230 <p id="display"></p>
michael@0 231 <div id="content" style="display: none">
michael@0 232 </div>
michael@0 233 <pre id="test">
michael@0 234 </pre>
michael@0 235 <div id="container"></div>
michael@0 236 </body>
michael@0 237 </html>

mercurial