1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xbl/test/file_bug946815.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<!-- 1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=946815 1.7 +--> 1.8 +<head> 1.9 + <bindings xmlns="http://www.mozilla.org/xbl"> 1.10 + <binding id="testBinding"> 1.11 + <implementation> 1.12 + <constructor> 1.13 + // Grab some basic infrastructure off the content window. 1.14 + var win = XPCNativeWrapper.unwrap(window); 1.15 + SpecialPowers = win.SpecialPowers; 1.16 + Cu = SpecialPowers.Cu; 1.17 + is = win.is; 1.18 + ok = win.ok; 1.19 + SimpleTest = win.SimpleTest; 1.20 + 1.21 + var bound = document.getElementById('bound'); 1.22 + 1.23 + // This gets invoked by an event handler. 1.24 + window.finish = function() { 1.25 + // XBL scope, with 'wifi-manage' scope 1.26 + testWifiPermissionFromXbl(true, true /* with wifi-manage permission */); 1.27 + SimpleTest.finish(); 1.28 + } 1.29 + 1.30 + eval('var testWifiPermissionFromXbl = ' + win.testWifiPermissionFromContent.toSource()); 1.31 + 1.32 + // XBL scope, with no 'wifi-manage' permission 1.33 + testWifiPermissionFromXbl(true, false /* without wifi-manage permission */); 1.34 + 1.35 + // Hand things off to content. Content will call us back. 1.36 + win.go(); 1.37 + </constructor> 1.38 + </implementation> 1.39 + <handlers> 1.40 + <handler event="testevent" action="ok(true, 'called event handler'); finish();" allowuntrusted="true"/> 1.41 + </handlers> 1.42 + </binding> 1.43 + </bindings> 1.44 + <script type="application/javascript"> 1.45 + <![CDATA[ 1.46 + 1.47 + ok = parent.ok; 1.48 + is = parent.is; 1.49 + SimpleTest = parent.SimpleTest; 1.50 + SpecialPowers = parent.SpecialPowers; 1.51 + 1.52 + function go() { 1.53 + "use strict"; 1.54 + 1.55 + // Content scope, with no 'wifi-manage' permission 1.56 + testWifiPermissionFromContent(false, false /* without wifi-manage permission */); 1.57 + 1.58 + SpecialPowers.pushPermissions([{ "type": "wifi-manage", "allow": 1, "context": window.document }], function() { 1.59 + testWifiPermissionFromContent(false, true /* with wifi-manage permission */); 1.60 + // Hand control back to the XBL scope by dispatching an event on the bound element. 1.61 + bound.dispatchEvent(new CustomEvent('testevent')); 1.62 + }); 1.63 + } 1.64 + 1.65 + function testWifiPermissionFromContent(aIsXblScope, aExpectedWifiPermission) { 1.66 + // Even though the function name has suggested we are either in content or 1.67 + // XBL scope, the argument |aIsXblScope| is still required to print 1.68 + // descriptive enough message for the test. 1.69 + 1.70 + // If this test fails, something must be wrong with the permission manipulation. 1.71 + // Check test_bug946815.html to see if we removed wifi-manage permission in 1.72 + // the beginning and if we forgot to add permission back during testing. 1.73 + is(aExpectedWifiPermission, SpecialPowers.hasPermission("wifi-manage", window.document), 1.74 + "'wifi-manage' permission is not as expected! Expected: " + aExpectedWifiPermission); 1.75 + 1.76 + is(typeof window.MozWifiP2pManager, (aExpectedWifiPermission ? "function" : "undefined"), 1.77 + (aIsXblScope ? "XBL" : "Content") + " should" + (aExpectedWifiPermission ? "" : " NOT") + 1.78 + " see MozWifiP2pManager with" + (aExpectedWifiPermission ? "" : "out") + 1.79 + " 'wifi-manage' permission." ); 1.80 + } 1.81 + 1.82 + function setup() { 1.83 + // When the bindings are applied, the constructor will be invoked and the 1.84 + // test will continue. 1.85 + document.getElementById('bound').style.MozBinding = 'url(#testBinding)'; 1.86 + } 1.87 + 1.88 + ]]> 1.89 +</script> 1.90 +</head> 1.91 +<body onload="setup()"> 1.92 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=946815">Mozilla Bug 946815</a> 1.93 +<p id="display"></p> 1.94 +<div id="content"> 1.95 + <div id="bound">Bound element</div> 1.96 +</div> 1.97 +<pre id="test"> 1.98 +</pre> 1.99 +</body> 1.100 +</html>