Bug 944407 - Tests. r=bz, a=lsblakk
authorBobby Holley <bobbyholley@gmail.com>
Fri, 13 Dec 2013 08:54:04 -0800
changeset 174519 e73905e8ca8b13ace366bed4a63ebcb865b37ff1
parent 174518 c80a5475fb2583aedb31ad0bbed9c6bd8d3ba008
child 174520 4efc91df009d3ea53b3829aa0d81bc3ad7dfb1a2
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, lsblakk
bugs944407
milestone28.0a2
Bug 944407 - Tests. r=bz, a=lsblakk
content/xbl/test/chrome.ini
content/xbl/test/file_bug944407.html
content/xbl/test/file_bug944407.xml
content/xbl/test/mochitest.ini
content/xbl/test/test_bug944407.xul
--- a/content/xbl/test/chrome.ini
+++ b/content/xbl/test/chrome.ini
@@ -1,8 +1,11 @@
 [DEFAULT]
+support-files =
+  file_bug944407.xml
 
 [test_bug378518.xul]
 [test_bug398135.xul]
 [test_bug398492.xul]
 [test_bug721452.xul]
 [test_bug723676.xul]
 [test_bug772966.xul]
+[test_bug944407.xul]
new file mode 100644
--- /dev/null
+++ b/content/xbl/test/file_bug944407.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="deny" style="-moz-binding: url(file_bug944407.xml#testAllowScript)"></div>
+<div id="allow" style="-moz-binding: url(chrome://mochitests/content/chrome/content/xbl/test/file_bug944407.xml#testAllowScript)"</div>
+<script>/* Flush layout with a script tab - see bug 944407 comment 37. */</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/xbl/test/file_bug944407.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<bindings id="testBindings" xmlns="http://www.mozilla.org/xbl"
+          xmlns:html="http://www.w3.org/1999/xhtml">
+  <binding id="testAllowScript">
+    <implementation>
+       <property name="someProp" onget="return 2;" readonly="true"></property>
+       <method name="someMethod"><body> return 3; </body></method>
+       <method name="startTest">
+         <body>
+         <![CDATA[
+           // Make sure we only get constructed when we're loaded from a domain
+           // with script enabled.
+           is(this.id, 'allow', "XBL should only be bound when the origin of the binding allows scripts");
+
+           var t = this;
+           doFinish = function() {
+             // Take a moment to make sure that other constructors don't run when they shouldn't.
+             if (t.id == 'allow')
+               setTimeout(SpecialPowers.wrap(window.parent).finish, 100);
+           }
+
+           onTestEvent = function(target) {
+             ok(true, 'called event handler');
+
+             // First, dispatch an event to the anonymous content. The event
+             // handlers on the AC should run, but they won't until bug 948000
+             // is fixed. So the check here is a todo().
+             var e = new MouseEvent('click');
+             document.getAnonymousNodes(target)[1].dispatchEvent(e);
+
+             // Now, dispatch a key event to test key handlers and move the test along.
+             var k = document.createEvent('KeyboardEvent');
+             k.initEvent('keyup', true, true);
+             target.dispatchEvent(k);
+           }
+
+           // Check the implementation.
+           is(this.someProp, 2, "Properties work");
+           is(this.someMethod(), 3, "Methods work");
+
+           // Kick over to the event handlers. This tests XBL event handlers,
+           // XBL key handlers, and event handlers on anonymous content.
+           this.dispatchEvent(new CustomEvent('testEvent'));
+         ]]>
+         </body>
+       </method>
+
+      <constructor>
+      <![CDATA[
+        win = XPCNativeWrapper.unwrap(window);
+        SpecialPowers = win.SpecialPowers;
+        ok = win.ok = SpecialPowers.wrap(window.parent).ok;
+        todo = win.todo = SpecialPowers.wrap(window.parent).todo;
+        is = win.is = SpecialPowers.wrap(window.parent).is;
+        info = win.info = SpecialPowers.wrap(window.parent).info;
+
+        info("Invoked constructor for " + this.id);
+
+        var t = this;
+        window.addEventListener('load', function loadListener() {
+          window.removeEventListener('load', loadListener);
+          // Wait two refresh-driver ticks to make sure that the constructor runs
+          // for both |allow| and |deny| if it's ever going to.
+          //
+          // See bug 944407 comment 37.
+          info("Invoked load listener for " + t.id);
+          window.requestAnimationFrame(function() { window.requestAnimationFrame(t.startTest.bind(t)); });
+        });
+      ]]>
+      </constructor>
+    </implementation>
+    <handlers>
+      <handler event="testEvent" action="onTestEvent(this)" allowuntrusted="true"/>
+      <handler event="keyup" action="ok(true, 'called key handler'); doFinish();" allowuntrusted="true"/>
+    </handlers>
+    <content>Anonymous Content<html:div onclick="todo(true, 'called event handler on ac, this needs bug 948000');"></html:div><html:b style="display:none"><children/></html:b></content>
+  </binding>
+</bindings>
--- a/content/xbl/test/mochitest.ini
+++ b/content/xbl/test/mochitest.ini
@@ -7,16 +7,18 @@ support-files =
   file_bug379959_xbl.xml
   file_bug397934.xhtml
   file_bug481558.xbl
   file_bug481558css.sjs
   file_bug591198_inner.html
   file_bug591198_xbl.xml
   file_bug821850.xhtml
   file_bug844783.xhtml
+  file_bug944407.html
+  file_bug944407.xml
 
 [test_bug310107.html]
 [test_bug366770.html]
 [test_bug371724.xhtml]
 [test_bug372769.html]
 [test_bug378866.xhtml]
 [test_bug379959.html]
 [test_bug389322.xhtml]
new file mode 100644
--- /dev/null
+++ b/content/xbl/test/test_bug944407.xul
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=944407
+-->
+<window title="Mozilla Bug 944407"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=944407"
+     target="_blank">Mozilla Bug 944407</a>
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+
+  /** Test for XBL bindings with script disabled. **/
+  SimpleTest.waitForExplicitFinish();
+  const Cu = Components.utils;
+  Cu.import('resource://gre/modules/Services.jsm');
+
+  function go() {
+
+    // Disable javascript, and load the frame.
+    function loadFrame() {
+      ok(!Services.prefs.getBoolPref('javascript.enabled'), "Javascript should be disabled");
+      $('ifr').setAttribute('src', 'http://mochi.test:8888/tests/content/xbl/test/file_bug944407.html');
+    }
+    SpecialPowers.pushPrefEnv({ set: [['javascript.enabled', false]] }, loadFrame);
+  }
+
+  function finish() {
+    SimpleTest.finish();
+  }
+
+  addLoadEvent(go);
+  ]]>
+  </script>
+  <iframe id='ifr' />
+</window>