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