test_splitter.xul 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
  4. <?xml-stylesheet href="data:text/css, hbox { border: 1px solid red; } vbox { border: 1px solid green }" type="text/css"?>
  5. <!--
  6. XUL <splitter> collapsing tests
  7. -->
  8. <window title="XUL splitter collapsing tests"
  9. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  10. orient="horizontal">
  11. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
  12. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"/>
  13. <!-- test results are displayed in the html:body -->
  14. <body xmlns="http://www.w3.org/1999/xhtml">
  15. </body>
  16. <!-- test code goes here -->
  17. <script type="application/javascript"><![CDATA[
  18. SimpleTest.waitForExplicitFinish();
  19. function dragSplitter(offsetX, callback) {
  20. var splitterWidth = splitter.boxObject.width;
  21. synthesizeMouse(splitter, splitterWidth / 2, 2, {type: "mousedown"});
  22. synthesizeMouse(splitter, splitterWidth / 2, 1, {type: "mousemove"});
  23. SimpleTest.executeSoon(function() {
  24. SimpleTest.is(splitter.getAttribute("state"), "dragging", "The splitter should be dragged");
  25. synthesizeMouse(splitter, offsetX, 1, {type: "mousemove"});
  26. synthesizeMouse(splitter, offsetX, 1, {type: "mouseup"});
  27. SimpleTest.executeSoon(callback);
  28. });
  29. }
  30. function shouldBeCollapsed(where) {
  31. SimpleTest.is(splitter.getAttribute("state"), "collapsed", "The splitter should be collapsed");
  32. SimpleTest.is(splitter.getAttribute("substate"), where, "The splitter should be collapsed " + where);
  33. }
  34. function shouldNotBeCollapsed() {
  35. SimpleTest.is(splitter.getAttribute("state"), "", "The splitter should not be collapsed");
  36. }
  37. function runPass(rightCollapsed, leftCollapsed, callback) {
  38. var containerWidth = container.boxObject.width;
  39. var isRTL = getComputedStyle(splitter, null).direction == "rtl";
  40. dragSplitter(containerWidth, function() {
  41. if (rightCollapsed) {
  42. shouldBeCollapsed(isRTL ? "before" : "after");
  43. } else {
  44. shouldNotBeCollapsed();
  45. }
  46. dragSplitter(-containerWidth * 2, function() {
  47. if (leftCollapsed) {
  48. shouldBeCollapsed(isRTL ? "after" : "before");
  49. } else {
  50. shouldNotBeCollapsed();
  51. }
  52. dragSplitter(containerWidth / 2, function() {
  53. // the splitter should never be collapsed in the middle
  54. shouldNotBeCollapsed();
  55. callback();
  56. });
  57. });
  58. });
  59. }
  60. var splitter, container;
  61. function runLTRTests(callback) {
  62. splitter = document.getElementById("ltr-splitter");
  63. container = splitter.parentNode;
  64. splitter.setAttribute("collapse", "before");
  65. runPass(false, true, function() {
  66. splitter.setAttribute("collapse", "after");
  67. runPass(true, false, function() {
  68. splitter.setAttribute("collapse", "both");
  69. runPass(true, true, callback);
  70. });
  71. });
  72. }
  73. function runRTLTests(callback) {
  74. splitter = document.getElementById("rtl-splitter");
  75. container = splitter.parentNode;
  76. splitter.setAttribute("collapse", "before");
  77. runPass(true, false, function() {
  78. splitter.setAttribute("collapse", "after");
  79. runPass(false, true, function() {
  80. splitter.setAttribute("collapse", "both");
  81. runPass(true, true, callback);
  82. });
  83. });
  84. }
  85. function runTests() {
  86. runLTRTests(function() {
  87. runRTLTests(function() {
  88. SimpleTest.finish();
  89. });
  90. });
  91. }
  92. addLoadEvent(function() {SimpleTest.executeSoon(runTests);});
  93. ]]></script>
  94. <hbox style="max-width: 200px; height: 300px; direction: ltr;">
  95. <vbox style="width: 100px; height: 300px;" flex="1"/>
  96. <splitter id="ltr-splitter"/>
  97. <vbox style="width: 100px; height: 300px;" flex="1"/>
  98. </hbox>
  99. <hbox style="max-width: 200px; height: 300px; direction: rtl;">
  100. <vbox style="width: 100px; height: 300px;" flex="1"/>
  101. <splitter id="rtl-splitter"/>
  102. <vbox style="width: 100px; height: 300px;" flex="1"/>
  103. </hbox>
  104. </window>