1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/csp/test_bug949549.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for Bug 949549</title> 1.8 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.10 +</head> 1.11 +<body> 1.12 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949549">Mozilla Bug 949549</a> 1.13 +<div id="content" style="display: none"></div> 1.14 +<pre id="test"> 1.15 +<script type="application/javascript;version=1.8"> 1.16 + "use strict"; 1.17 + 1.18 + // Ensure that `setRequestContext` doesn't throw with app:// URLs 1.19 + 1.20 + const csp = SpecialPowers.Cc["@mozilla.org/contentsecuritypolicy;1"] 1.21 + .createInstance(SpecialPowers.Ci.nsIContentSecurityPolicy); 1.22 + 1.23 + const gManifestURL = "http://www.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp"; 1.24 + 1.25 + SimpleTest.waitForExplicitFinish(); 1.26 + var app; 1.27 + 1.28 + function setupTest() { 1.29 + // We have to install an app in order for the app URL to be valid 1.30 + // (otherwise we get a "DummyChannel" that throws NS_NOT_IMPLEMENTED) 1.31 + SpecialPowers.setAllAppsLaunchable(true); 1.32 + SpecialPowers.addPermission("webapps-manage", true, document); 1.33 + SpecialPowers.autoConfirmAppInstall(function () { 1.34 + let req = navigator.mozApps.install(gManifestURL); 1.35 + req.onsuccess = function () { 1.36 + app = this.result; 1.37 + runTest(); 1.38 + } 1.39 + }); 1.40 + } 1.41 + 1.42 + function runTest() { 1.43 + // We have to use a mochitest to test app:// urls, 1.44 + // as app channels can't be instanciated in xpcshell. 1.45 + // Because app protocol depends on webapps.jsm, 1.46 + // which doesn't instanciate properly on xpcshell without many hacks 1.47 + let appchan = SpecialPowers.Services.io.newChannel(gManifestURL, null, null); 1.48 + 1.49 + try { 1.50 + csp.setRequestContext(null, null, null, appchan); 1.51 + ok(true, "setRequestContext hasn't thown"); 1.52 + } catch(e) { 1.53 + ok(false, "setRequestContext throws"); 1.54 + } 1.55 + 1.56 + cleanup() 1.57 + } 1.58 + 1.59 + function cleanup() { 1.60 + let req = navigator.mozApps.mgmt.uninstall(app); 1.61 + req.onsuccess = function () { 1.62 + SimpleTest.finish(); 1.63 + }; 1.64 + } 1.65 + 1.66 + setupTest(); 1.67 +</script> 1.68 +</pre> 1.69 +</body> 1.70 +</html>