/toolkit/content/tests/chrome/test_menuchecks.xul

http://github.com/zpao/v8monkey · Unknown · 149 lines · 134 code · 15 blank · 0 comment · 0 complexity · 57e0fb42c9f8fa88d2d859d021494c36 MD5 · raw file

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
  4. <window title="Menu Checkbox and Radio Tests"
  5. onload="runTest()"
  6. xmlns:html="http://www.w3.org/1999/xhtml"
  7. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  8. <title>Menu Checkbox and Radio Tests</title>
  9. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  10. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  11. <hbox>
  12. <button id="menu" type="menu" label="View">
  13. <menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()">
  14. <menuitem id="toolbar" label="Show Toolbar" type="checkbox"/>
  15. <menuitem id="statusbar" label="Show Status Bar" type="checkbox" checked="true"/>
  16. <menuitem id="bookmarks" label="Show Bookmarks" type="checkbox" autocheck="false"/>
  17. <menuitem id="history" label="Show History" type="checkbox" autocheck="false" checked="true"/>
  18. <menuseparator/>
  19. <menuitem id="byname" label="By Name" type="radio" name="sort"/>
  20. <menuitem id="bydate" label="By Date" type="radio" name="sort" checked="true"/>
  21. <menuseparator/>
  22. <menuitem id="ascending" label="Ascending" type="radio" name="order" checked="true"/>
  23. <menuitem id="descending" label="Descending" type="radio" name="order" autocheck="false"/>
  24. <menuitem id="bysubject" label="By Subject" type="radio" name="sort"/>
  25. </menupopup>
  26. </button>
  27. </hbox>
  28. <!--
  29. This test checks that checkbox and radio menu items work properly
  30. -->
  31. <script class="testbody" type="application/javascript">
  32. <![CDATA[
  33. SimpleTest.waitForExplicitFinish();
  34. var gTestIndex = 0;
  35. // tests to perform
  36. var tests = [
  37. {
  38. testname: "select unchecked checkbox",
  39. item: "toolbar",
  40. checked: ["toolbar", "statusbar", "history", "bydate", "ascending"]
  41. },
  42. {
  43. testname: "select checked checkbox",
  44. item: "statusbar",
  45. checked: ["toolbar", "history", "bydate", "ascending"]
  46. },
  47. {
  48. testname: "select unchecked autocheck checkbox",
  49. item: "bookmarks",
  50. checked: ["toolbar", "history", "bydate", "ascending"]
  51. },
  52. {
  53. testname: "select checked autocheck checkbox",
  54. item: "history",
  55. checked: ["toolbar", "history", "bydate", "ascending"]
  56. },
  57. {
  58. testname: "select unchecked radio",
  59. item: "byname",
  60. checked: ["toolbar", "history", "byname", "ascending"]
  61. },
  62. {
  63. testname: "select checked radio",
  64. item: "byname",
  65. checked: ["toolbar", "history", "byname", "ascending"]
  66. },
  67. {
  68. testname: "select out of order checked radio",
  69. item: "bysubject",
  70. checked: ["toolbar", "history", "bysubject", "ascending"]
  71. },
  72. {
  73. testname: "select first radio again",
  74. item: "byname",
  75. checked: ["toolbar", "history", "byname", "ascending"]
  76. },
  77. {
  78. testname: "select autocheck radio",
  79. item: "descending",
  80. checked: ["toolbar", "history", "byname", "ascending"]
  81. }
  82. ];
  83. function runTest()
  84. {
  85. checkMenus(["statusbar", "history", "bydate", "ascending"], "initial");
  86. document.getElementById("menu").open = true;
  87. }
  88. function checkMenus(checkedItems, testname)
  89. {
  90. var isok = true;
  91. var children = document.getElementById("popup").childNodes;
  92. for (var c = 0; c < children.length; c++) {
  93. var child = children[c];
  94. if ((checkedItems.indexOf(child.id) != -1 && child.getAttribute("checked") != "true") ||
  95. (checkedItems.indexOf(child.id) == -1 && child.hasAttribute("checked"))) {
  96. isok = false;
  97. break;
  98. }
  99. }
  100. ok(isok, testname);
  101. }
  102. function popupShown()
  103. {
  104. var test = tests[gTestIndex];
  105. synthesizeMouse(document.getElementById(test.item), 4, 4, { });
  106. }
  107. function popupHidden()
  108. {
  109. if (gTestIndex < tests.length) {
  110. var test = tests[gTestIndex];
  111. checkMenus(test.checked, test.testname);
  112. gTestIndex++;
  113. if (gTestIndex < tests.length) {
  114. document.getElementById("menu").open = true;
  115. }
  116. else {
  117. // manually setting the checkbox should also update the radio state
  118. document.getElementById("bydate").setAttribute("checked", "true");
  119. checkMenus(["toolbar", "history", "bydate", "ascending"], "set checked attribute on radio");
  120. SimpleTest.finish();
  121. }
  122. }
  123. }
  124. ]]>
  125. </script>
  126. <body xmlns="http://www.w3.org/1999/xhtml">
  127. <p id="display">
  128. </p>
  129. <div id="content" style="display: none">
  130. </div>
  131. <pre id="test">
  132. </pre>
  133. </body>
  134. </window>