PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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