/toolkit/content/tests/chrome/test_colorpicker_popup.xul

http://github.com/zpao/v8monkey · Unknown · 150 lines · 127 code · 23 blank · 0 comment · 0 complexity · 5832fd94ae8e51c7a8a80bd59974ff56 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="Colorpicker Tests"
  5. onload="setTimeout(runTests, 0);"
  6. onpopupshown="popupShown();"
  7. onpopuphidden="popupHiding();"
  8. xmlns:html="http://www.w3.org/1999/xhtml"
  9. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  10. <title>Colorpicker Tests</title>
  11. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  12. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  13. <colorpicker id="colorpicker-popup" type="button" color="#FF0000" tabindex="1"/>
  14. <script class="testbody" type="application/javascript">
  15. <![CDATA[
  16. var gTestPhase = -1;
  17. var gCp = null;
  18. SimpleTest.waitForExplicitFinish();
  19. function preventDefault(event) {
  20. event.preventDefault();
  21. }
  22. function runTests()
  23. {
  24. gCp = document.getElementById("colorpicker-popup");
  25. is(gCp.color, "#FF0000", "popup color is initialized");
  26. is(gCp.tabIndex, 1, "button tabindex is initialized");
  27. is(gCp.disabled, false, "button is not disabled");
  28. document.addEventListener("keypress", preventDefault, false);
  29. goNext();
  30. }
  31. var phases = [ "mouse click", "showPopup",
  32. "key left", "key right", "key up", "key down", "key space" ];
  33. function popupShown()
  34. {
  35. if (gTestPhase >= phases.length)
  36. return;
  37. var phase = phases[gTestPhase];
  38. is(gCp.open, true, phase + " popup shown, open property is true");
  39. switch (phase) {
  40. case "mouse click":
  41. synthesizeMouse(gCp, 2, 2, { });
  42. break;
  43. case "showPopup":
  44. gCp.hidePopup();
  45. break;
  46. case "key left":
  47. synthesizeKey("VK_LEFT", { });
  48. synthesizeKeyExpectEvent("VK_RETURN", { });
  49. is(gCp.color, "#C0C0C0", "key left while open");
  50. break;
  51. case "key right":
  52. synthesizeKey("VK_RIGHT", { });
  53. synthesizeKeyExpectEvent("VK_SPACE", { });
  54. is(gCp.color, "#FF0000", "key right while open");
  55. break;
  56. case "key up":
  57. synthesizeKey("VK_UP", { });
  58. synthesizeKeyExpectEvent("VK_RETURN", { });
  59. is(gCp.color, "#FF6666", "key up while open");
  60. break;
  61. case "key down":
  62. synthesizeKey("VK_DOWN", { });
  63. synthesizeKeyExpectEvent("VK_SPACE", { });
  64. is(gCp.color, "#FF0000", "key down while open");
  65. break;
  66. default:
  67. synthesizeMouse(gCp, 2, 2, { });
  68. // this breaks on the Mac, so disable for now
  69. // synthesizeKey("VK_ESCAPE", { });
  70. break;
  71. }
  72. }
  73. function popupHiding()
  74. {
  75. var phase = phases[gTestPhase];
  76. if (phase == "showPopup")
  77. phase = "hidePopup";
  78. if (phase == "key left")
  79. phase = "escape";
  80. is(gCp.open, false, phase + " popup hidden, open property is false");
  81. goNext();
  82. }
  83. function goNext()
  84. {
  85. gTestPhase++;
  86. if (gTestPhase >= phases.length) {
  87. document.removeEventListener("keypress", preventDefault, false);
  88. SimpleTest.finish();
  89. return;
  90. }
  91. gCp.focus();
  92. var phase = phases[gTestPhase];
  93. switch (phase) {
  94. case "mouse click":
  95. synthesizeMouse(gCp, 2, 2, { });
  96. break;
  97. case "showPopup":
  98. gCp.showPopup();
  99. break;
  100. case "key left":
  101. synthesizeKey("VK_LEFT", { });
  102. break;
  103. case "key right":
  104. synthesizeKey("VK_RIGHT", { });
  105. break;
  106. case "key down":
  107. synthesizeKey("VK_UP", { });
  108. break;
  109. case "key up":
  110. synthesizeKey("VK_DOWN", { });
  111. break;
  112. case "key space":
  113. synthesizeKey("VK_SPACE", { });
  114. break;
  115. }
  116. }
  117. ]]>
  118. </script>
  119. <body xmlns="http://www.w3.org/1999/xhtml">
  120. <p id="display">
  121. </p>
  122. <div id="content" style="display: none">
  123. </div>
  124. <pre id="test">
  125. </pre>
  126. </body>
  127. </window>