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
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <!-- |
michael@0 | 3 | https://bugzilla.mozilla.org/show_bug.cgi?id=946815 |
michael@0 | 4 | --> |
michael@0 | 5 | <head> |
michael@0 | 6 | <bindings xmlns="http://www.mozilla.org/xbl"> |
michael@0 | 7 | <binding id="testBinding"> |
michael@0 | 8 | <implementation> |
michael@0 | 9 | <constructor> |
michael@0 | 10 | // Grab some basic infrastructure off the content window. |
michael@0 | 11 | var win = XPCNativeWrapper.unwrap(window); |
michael@0 | 12 | SpecialPowers = win.SpecialPowers; |
michael@0 | 13 | Cu = SpecialPowers.Cu; |
michael@0 | 14 | is = win.is; |
michael@0 | 15 | ok = win.ok; |
michael@0 | 16 | SimpleTest = win.SimpleTest; |
michael@0 | 17 | |
michael@0 | 18 | var bound = document.getElementById('bound'); |
michael@0 | 19 | |
michael@0 | 20 | // This gets invoked by an event handler. |
michael@0 | 21 | window.finish = function() { |
michael@0 | 22 | // XBL scope, with 'wifi-manage' scope |
michael@0 | 23 | testWifiPermissionFromXbl(true, true /* with wifi-manage permission */); |
michael@0 | 24 | SimpleTest.finish(); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | eval('var testWifiPermissionFromXbl = ' + win.testWifiPermissionFromContent.toSource()); |
michael@0 | 28 | |
michael@0 | 29 | // XBL scope, with no 'wifi-manage' permission |
michael@0 | 30 | testWifiPermissionFromXbl(true, false /* without wifi-manage permission */); |
michael@0 | 31 | |
michael@0 | 32 | // Hand things off to content. Content will call us back. |
michael@0 | 33 | win.go(); |
michael@0 | 34 | </constructor> |
michael@0 | 35 | </implementation> |
michael@0 | 36 | <handlers> |
michael@0 | 37 | <handler event="testevent" action="ok(true, 'called event handler'); finish();" allowuntrusted="true"/> |
michael@0 | 38 | </handlers> |
michael@0 | 39 | </binding> |
michael@0 | 40 | </bindings> |
michael@0 | 41 | <script type="application/javascript"> |
michael@0 | 42 | <![CDATA[ |
michael@0 | 43 | |
michael@0 | 44 | ok = parent.ok; |
michael@0 | 45 | is = parent.is; |
michael@0 | 46 | SimpleTest = parent.SimpleTest; |
michael@0 | 47 | SpecialPowers = parent.SpecialPowers; |
michael@0 | 48 | |
michael@0 | 49 | function go() { |
michael@0 | 50 | "use strict"; |
michael@0 | 51 | |
michael@0 | 52 | // Content scope, with no 'wifi-manage' permission |
michael@0 | 53 | testWifiPermissionFromContent(false, false /* without wifi-manage permission */); |
michael@0 | 54 | |
michael@0 | 55 | SpecialPowers.pushPermissions([{ "type": "wifi-manage", "allow": 1, "context": window.document }], function() { |
michael@0 | 56 | testWifiPermissionFromContent(false, true /* with wifi-manage permission */); |
michael@0 | 57 | // Hand control back to the XBL scope by dispatching an event on the bound element. |
michael@0 | 58 | bound.dispatchEvent(new CustomEvent('testevent')); |
michael@0 | 59 | }); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function testWifiPermissionFromContent(aIsXblScope, aExpectedWifiPermission) { |
michael@0 | 63 | // Even though the function name has suggested we are either in content or |
michael@0 | 64 | // XBL scope, the argument |aIsXblScope| is still required to print |
michael@0 | 65 | // descriptive enough message for the test. |
michael@0 | 66 | |
michael@0 | 67 | // If this test fails, something must be wrong with the permission manipulation. |
michael@0 | 68 | // Check test_bug946815.html to see if we removed wifi-manage permission in |
michael@0 | 69 | // the beginning and if we forgot to add permission back during testing. |
michael@0 | 70 | is(aExpectedWifiPermission, SpecialPowers.hasPermission("wifi-manage", window.document), |
michael@0 | 71 | "'wifi-manage' permission is not as expected! Expected: " + aExpectedWifiPermission); |
michael@0 | 72 | |
michael@0 | 73 | is(typeof window.MozWifiP2pManager, (aExpectedWifiPermission ? "function" : "undefined"), |
michael@0 | 74 | (aIsXblScope ? "XBL" : "Content") + " should" + (aExpectedWifiPermission ? "" : " NOT") + |
michael@0 | 75 | " see MozWifiP2pManager with" + (aExpectedWifiPermission ? "" : "out") + |
michael@0 | 76 | " 'wifi-manage' permission." ); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function setup() { |
michael@0 | 80 | // When the bindings are applied, the constructor will be invoked and the |
michael@0 | 81 | // test will continue. |
michael@0 | 82 | document.getElementById('bound').style.MozBinding = 'url(#testBinding)'; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | ]]> |
michael@0 | 86 | </script> |
michael@0 | 87 | </head> |
michael@0 | 88 | <body onload="setup()"> |
michael@0 | 89 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=946815">Mozilla Bug 946815</a> |
michael@0 | 90 | <p id="display"></p> |
michael@0 | 91 | <div id="content"> |
michael@0 | 92 | <div id="bound">Bound element</div> |
michael@0 | 93 | </div> |
michael@0 | 94 | <pre id="test"> |
michael@0 | 95 | </pre> |
michael@0 | 96 | </body> |
michael@0 | 97 | </html> |