summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_colorpicker_popup.xul
blob: 3ac84260b2b823fc512086893d42cee371d113f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window title="Colorpicker Tests"
  onload="setTimeout(runTests, 0);"
  onpopupshown="popupShown();"
  onpopuphidden="popupHiding();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      

<colorpicker id="colorpicker-popup" type="button" color="#FF0000" tabindex="1"/>

<script class="testbody" type="application/javascript">
<![CDATA[

var gTestPhase = -1;
var gCp = null;

SimpleTest.waitForExplicitFinish();

function preventDefault(event) {
  event.preventDefault();
}

function runTests()
{
  gCp = document.getElementById("colorpicker-popup");
  is(gCp.color, "#FF0000", "popup color is initialized");
  is(gCp.tabIndex, 1, "button tabindex is initialized");
  is(gCp.disabled, false, "button is not disabled");
  
  document.addEventListener("keypress", preventDefault, false);

  goNext();
}

var phases = [ "mouse click", "showPopup",
               "key left", "key right", "key up", "key down", "key space" ];

function popupShown()
{
  if (gTestPhase >= phases.length)
    return;

  var phase = phases[gTestPhase];

  is(gCp.open, true, phase + " popup shown, open property is true");

  switch (phase) {
    case "mouse click":
      synthesizeMouse(gCp, 2, 2, { });
      break;
    case "showPopup":
      gCp.hidePopup();
      break;
    case "key left":
      synthesizeKey("VK_LEFT", { });
      synthesizeKeyExpectEvent("VK_RETURN", { });
      is(gCp.color, "#C0C0C0", "key left while open");
      break;
    case "key right":
      synthesizeKey("VK_RIGHT", { });
      synthesizeKeyExpectEvent("VK_SPACE", { });
      is(gCp.color, "#FF0000", "key right while open");
      break;
    case "key up":
      synthesizeKey("VK_UP", { });
      synthesizeKeyExpectEvent("VK_RETURN", { });
      is(gCp.color, "#FF6666", "key up while open");
      break;
    case "key down":
      synthesizeKey("VK_DOWN", { });
      synthesizeKeyExpectEvent("VK_SPACE", { });
      is(gCp.color, "#FF0000", "key down while open");
      break;
    default:
      synthesizeMouse(gCp, 2, 2, { });
// this breaks on the Mac, so disable for now
//      synthesizeKey("VK_ESCAPE", { });
      break;
  }
}

function popupHiding()
{
  var phase = phases[gTestPhase];
  if (phase == "showPopup")
    phase = "hidePopup";
  if (phase == "key left")
    phase = "escape";
  is(gCp.open, false, phase + " popup hidden, open property is false");

  goNext();
}

function goNext()
{
  gTestPhase++;
  if (gTestPhase >= phases.length) {
    document.removeEventListener("keypress", preventDefault, false);
    SimpleTest.finish();
    return;
  }

  gCp.focus();

  var phase = phases[gTestPhase];
  switch (phase) {
    case "mouse click":
      synthesizeMouse(gCp, 2, 2, { });
      break;
    case "showPopup":
      gCp.showPopup();
      break;
    case "key left":
      synthesizeKey("VK_LEFT", { });
      break;
    case "key right":
      synthesizeKey("VK_RIGHT", { });
      break;
    case "key down":
      synthesizeKey("VK_UP", { });
      break;
    case "key up":
      synthesizeKey("VK_DOWN", { });
      break;
    case "key space":
      synthesizeKey("VK_SPACE", { });
      break;
  }
}

]]>
</script>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

</window>