1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xbl/test/file_bug944407.xml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +<?xml version="1.0"?> 1.5 +<bindings id="testBindings" xmlns="http://www.mozilla.org/xbl" 1.6 + xmlns:html="http://www.w3.org/1999/xhtml"> 1.7 + <binding id="testAllowScript"> 1.8 + <implementation> 1.9 + <property name="someProp" onget="return 2;" readonly="true"></property> 1.10 + <method name="someMethod"><body> return 3; </body></method> 1.11 + <method name="startTest"> 1.12 + <body> 1.13 + <![CDATA[ 1.14 + // Make sure we only get constructed when we're loaded from a domain 1.15 + // with script enabled. 1.16 + is(this.id, 'allow', "XBL should only be bound when the origin of the binding allows scripts"); 1.17 + 1.18 + var t = this; 1.19 + doFinish = function() { 1.20 + // Take a moment to make sure that other constructors don't run when they shouldn't. 1.21 + if (t.id == 'allow') 1.22 + setTimeout(SpecialPowers.wrap(window.parent).finish, 100); 1.23 + } 1.24 + 1.25 + onTestEvent = function(target) { 1.26 + ok(true, 'called event handler'); 1.27 + 1.28 + // Try calling event handlers on anonymous content. 1.29 + var e = new MouseEvent('click'); 1.30 + document.getAnonymousNodes(target)[1].dispatchEvent(e); 1.31 + ok(window.calledEventHandlerOnAC, "Should invoke event handler on AC"); 1.32 + 1.33 + // Now, dispatch a key event to test key handlers and move the test along. 1.34 + var k = document.createEvent('KeyboardEvent'); 1.35 + k.initEvent('keyup', true, true); 1.36 + target.dispatchEvent(k); 1.37 + } 1.38 + 1.39 + // Check the implementation. 1.40 + is(this.someProp, 2, "Properties work"); 1.41 + is(this.someMethod(), 3, "Methods work"); 1.42 + 1.43 + // Kick over to the event handlers. This tests XBL event handlers, 1.44 + // XBL key handlers, and event handlers on anonymous content. 1.45 + this.dispatchEvent(new CustomEvent('testEvent')); 1.46 + ]]> 1.47 + </body> 1.48 + </method> 1.49 + 1.50 + <constructor> 1.51 + <![CDATA[ 1.52 + win = XPCNativeWrapper.unwrap(window); 1.53 + SpecialPowers = win.SpecialPowers; 1.54 + ok = win.ok = SpecialPowers.wrap(window.parent).ok; 1.55 + is = win.is = SpecialPowers.wrap(window.parent).is; 1.56 + info = win.info = SpecialPowers.wrap(window.parent).info; 1.57 + 1.58 + info("Invoked constructor for " + this.id); 1.59 + 1.60 + var t = this; 1.61 + window.addEventListener('load', function loadListener() { 1.62 + window.removeEventListener('load', loadListener); 1.63 + // Wait two refresh-driver ticks to make sure that the constructor runs 1.64 + // for both |allow| and |deny| if it's ever going to. 1.65 + // 1.66 + // See bug 944407 comment 37. 1.67 + info("Invoked load listener for " + t.id); 1.68 + window.requestAnimationFrame(function() { window.requestAnimationFrame(t.startTest.bind(t)); }); 1.69 + }); 1.70 + ]]> 1.71 + </constructor> 1.72 + </implementation> 1.73 + <handlers> 1.74 + <handler event="testEvent" action="onTestEvent(this)" allowuntrusted="true"/> 1.75 + <handler event="keyup" action="ok(true, 'called key handler'); doFinish();" allowuntrusted="true"/> 1.76 + </handlers> 1.77 + <content>Anonymous Content<html:div onclick="window.calledEventHandlerOnAC = true;"></html:div><html:b style="display:none"><children/></html:b></content> 1.78 + </binding> 1.79 +</bindings>