dom/xbl/test/file_bug944407.xml

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:203162de8dc3
1 <?xml version="1.0"?>
2 <bindings id="testBindings" xmlns="http://www.mozilla.org/xbl"
3 xmlns:html="http://www.w3.org/1999/xhtml">
4 <binding id="testAllowScript">
5 <implementation>
6 <property name="someProp" onget="return 2;" readonly="true"></property>
7 <method name="someMethod"><body> return 3; </body></method>
8 <method name="startTest">
9 <body>
10 <![CDATA[
11 // Make sure we only get constructed when we're loaded from a domain
12 // with script enabled.
13 is(this.id, 'allow', "XBL should only be bound when the origin of the binding allows scripts");
14
15 var t = this;
16 doFinish = function() {
17 // Take a moment to make sure that other constructors don't run when they shouldn't.
18 if (t.id == 'allow')
19 setTimeout(SpecialPowers.wrap(window.parent).finish, 100);
20 }
21
22 onTestEvent = function(target) {
23 ok(true, 'called event handler');
24
25 // Try calling event handlers on anonymous content.
26 var e = new MouseEvent('click');
27 document.getAnonymousNodes(target)[1].dispatchEvent(e);
28 ok(window.calledEventHandlerOnAC, "Should invoke event handler on AC");
29
30 // Now, dispatch a key event to test key handlers and move the test along.
31 var k = document.createEvent('KeyboardEvent');
32 k.initEvent('keyup', true, true);
33 target.dispatchEvent(k);
34 }
35
36 // Check the implementation.
37 is(this.someProp, 2, "Properties work");
38 is(this.someMethod(), 3, "Methods work");
39
40 // Kick over to the event handlers. This tests XBL event handlers,
41 // XBL key handlers, and event handlers on anonymous content.
42 this.dispatchEvent(new CustomEvent('testEvent'));
43 ]]>
44 </body>
45 </method>
46
47 <constructor>
48 <![CDATA[
49 win = XPCNativeWrapper.unwrap(window);
50 SpecialPowers = win.SpecialPowers;
51 ok = win.ok = SpecialPowers.wrap(window.parent).ok;
52 is = win.is = SpecialPowers.wrap(window.parent).is;
53 info = win.info = SpecialPowers.wrap(window.parent).info;
54
55 info("Invoked constructor for " + this.id);
56
57 var t = this;
58 window.addEventListener('load', function loadListener() {
59 window.removeEventListener('load', loadListener);
60 // Wait two refresh-driver ticks to make sure that the constructor runs
61 // for both |allow| and |deny| if it's ever going to.
62 //
63 // See bug 944407 comment 37.
64 info("Invoked load listener for " + t.id);
65 window.requestAnimationFrame(function() { window.requestAnimationFrame(t.startTest.bind(t)); });
66 });
67 ]]>
68 </constructor>
69 </implementation>
70 <handlers>
71 <handler event="testEvent" action="onTestEvent(this)" allowuntrusted="true"/>
72 <handler event="keyup" action="ok(true, 'called key handler'); doFinish();" allowuntrusted="true"/>
73 </handlers>
74 <content>Anonymous Content<html:div onclick="window.calledEventHandlerOnAC = true;"></html:div><html:b style="display:none"><children/></html:b></content>
75 </binding>
76 </bindings>

mercurial