toolkit/content/tests/chrome/test_bug562554.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_bug562554.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +  XUL Widget Test for bug 562554
     1.9 +  -->
    1.10 +<window title="Bug 562554" width="400" height="400"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.12 +        xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.13 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>  
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    1.15 +
    1.16 +<xbl:bindings xmlns:xbl="http://www.mozilla.org/xbl">
    1.17 +  <xbl:binding id="menu" display="xul:menu"
    1.18 +               extends="chrome://global/content/bindings/button.xml#button-base">
    1.19 +    <xbl:content>
    1.20 +      <xbl:children includes="menupopup"/>
    1.21 +      <xul:stack>
    1.22 +         <xul:button width="100" left="0" top="0" height="30" allowevents="true"
    1.23 +                     onclick="eventReceived('clickbutton1'); return false;"/>
    1.24 +         <xul:button width="100" left="70" top="0" height="30" 
    1.25 +                     onclick="eventReceived('clickbutton2'); return false;"/>
    1.26 +      </xul:stack>
    1.27 +    </xbl:content>
    1.28 +  </xbl:binding>
    1.29 +</xbl:bindings>
    1.30 +
    1.31 +  <toolbarbutton type="menu" id="toolbarmenu" height="200" style="-moz-binding: url(#menu);">
    1.32 +    <menupopup id="menupopup" onpopupshowing="eventReceived('popupshowing'); return false;"/>
    1.33 +  </toolbarbutton>
    1.34 +
    1.35 +  <!-- test results are displayed in the html:body -->
    1.36 +  <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
    1.37 +
    1.38 +<script type="application/javascript">
    1.39 +<![CDATA[
    1.40 +
    1.41 +SimpleTest.waitForExplicitFinish();
    1.42 +SimpleTest.waitForFocus(test);
    1.43 +
    1.44 +// Tests that mouse events are correctly dispatched to <toolbarbutton type="menu"/>
    1.45 +function test() {
    1.46 +  disableNonTestMouseEvents(true);
    1.47 +  nextTest();
    1.48 +}
    1.49 +
    1.50 +let tests = [
    1.51 +  // Click on the toolbarbutton itself - should call popupshowing
    1.52 +  function() synthesizeMouse($("toolbarmenu"), 10, 50, {}, window),
    1.53 +
    1.54 +  // Click on button1 which has allowevents="true" - should call clickbutton1
    1.55 +  function() synthesizeMouse($("toolbarmenu"), 10, 15, {}, window),
    1.56 +
    1.57 +  // Click on button2 where it intersects with button1 - should call popupshowing
    1.58 +  function() synthesizeMouse($("toolbarmenu"), 85, 15, {}, window),
    1.59 +
    1.60 +  // Click on button2 outside of intersection - should call popupshowing
    1.61 +  function() synthesizeMouse($("toolbarmenu"), 150, 15, {}, window)
    1.62 +];
    1.63 +
    1.64 +function nextTest() {
    1.65 +  if (tests.length) {
    1.66 +    let func = tests.shift();
    1.67 +    func();
    1.68 +    SimpleTest.executeSoon(nextTest);
    1.69 +  } else {
    1.70 +    disableNonTestMouseEvents(false);
    1.71 +    SimpleTest.executeSoon(finishTest);
    1.72 +  }
    1.73 +}
    1.74 +
    1.75 +function finishTest() {
    1.76 +  is(eventCount.clickbutton1, 1, "Correct number of clicks on button 1");
    1.77 +  is(eventCount.clickbutton2, 0, "Correct number of clicks on button 2");
    1.78 +  is(eventCount.popupshowing, 3, "Correct number of popupshowing events received");
    1.79 +
    1.80 +  SimpleTest.finish();
    1.81 +}
    1.82 +
    1.83 +let eventCount = {
    1.84 +  popupshowing: 0,
    1.85 +  clickbutton1: 0,
    1.86 +  clickbutton2: 0
    1.87 +};
    1.88 +
    1.89 +function eventReceived(eventName) {
    1.90 +  eventCount[eventName]++;
    1.91 +}
    1.92 +
    1.93 +]]>
    1.94 +</script>
    1.95 +</window>

mercurial