Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test for Bug 949549</title>
5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7 </head>
8 <body>
9 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949549">Mozilla Bug 949549</a>
10 <div id="content" style="display: none"></div>
11 <pre id="test">
12 <script type="application/javascript;version=1.8">
13 "use strict";
15 // Ensure that `setRequestContext` doesn't throw with app:// URLs
17 const csp = SpecialPowers.Cc["@mozilla.org/contentsecuritypolicy;1"]
18 .createInstance(SpecialPowers.Ci.nsIContentSecurityPolicy);
20 const gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
22 SimpleTest.waitForExplicitFinish();
23 var app;
25 function setupTest() {
26 // We have to install an app in order for the app URL to be valid
27 // (otherwise we get a "DummyChannel" that throws NS_NOT_IMPLEMENTED)
28 SpecialPowers.setAllAppsLaunchable(true);
29 SpecialPowers.addPermission("webapps-manage", true, document);
30 SpecialPowers.autoConfirmAppInstall(function () {
31 let req = navigator.mozApps.install(gManifestURL);
32 req.onsuccess = function () {
33 app = this.result;
34 runTest();
35 }
36 });
37 }
39 function runTest() {
40 // We have to use a mochitest to test app:// urls,
41 // as app channels can't be instanciated in xpcshell.
42 // Because app protocol depends on webapps.jsm,
43 // which doesn't instanciate properly on xpcshell without many hacks
44 let appchan = SpecialPowers.Services.io.newChannel(gManifestURL, null, null);
46 try {
47 csp.setRequestContext(null, null, null, appchan);
48 ok(true, "setRequestContext hasn't thown");
49 } catch(e) {
50 ok(false, "setRequestContext throws");
51 }
53 cleanup()
54 }
56 function cleanup() {
57 let req = navigator.mozApps.mgmt.uninstall(app);
58 req.onsuccess = function () {
59 SimpleTest.finish();
60 };
61 }
63 setupTest();
64 </script>
65 </pre>
66 </body>
67 </html>