|
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="Autocomplete Widget Test" |
|
6 onload="setTimeout(keyCaretTest, 0);" |
|
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
8 |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
11 <script type="application/javascript" |
|
12 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
13 |
|
14 <textbox id="autocomplete" type="autocomplete"/> |
|
15 |
|
16 <script class="testbody" type="application/javascript"> |
|
17 <![CDATA[ |
|
18 |
|
19 SimpleTest.waitForExplicitFinish(); |
|
20 |
|
21 function keyCaretTest() |
|
22 { |
|
23 var autocomplete = $("autocomplete"); |
|
24 |
|
25 autocomplete.focus(); |
|
26 checkKeyCaretTest("VK_UP", 0, 0, false, "no value up"); |
|
27 checkKeyCaretTest("VK_DOWN", 0, 0, false, "no value down"); |
|
28 |
|
29 autocomplete.value = "Sample"; |
|
30 |
|
31 autocomplete.selectionStart = 3; |
|
32 autocomplete.selectionEnd = 3; |
|
33 checkKeyCaretTest("VK_UP", 0, 0, true, "value up with caret in middle"); |
|
34 checkKeyCaretTest("VK_UP", 0, 0, false, "value up with caret in middle again"); |
|
35 |
|
36 autocomplete.selectionStart = 2; |
|
37 autocomplete.selectionEnd = 2; |
|
38 checkKeyCaretTest("VK_DOWN", 6, 6, true, "value down with caret in middle"); |
|
39 checkKeyCaretTest("VK_DOWN", 6, 6, false, "value down with caret in middle again"); |
|
40 |
|
41 autocomplete.selectionStart = 1; |
|
42 autocomplete.selectionEnd = 4; |
|
43 checkKeyCaretTest("VK_UP", 0, 0, true, "value up with selection"); |
|
44 |
|
45 autocomplete.selectionStart = 1; |
|
46 autocomplete.selectionEnd = 4; |
|
47 checkKeyCaretTest("VK_DOWN", 6, 6, true, "value down with selection"); |
|
48 |
|
49 SimpleTest.finish(); |
|
50 } |
|
51 |
|
52 function checkKeyCaretTest(key, expectedStart, expectedEnd, result, testid) |
|
53 { |
|
54 var autocomplete = $("autocomplete"); |
|
55 |
|
56 var event = result ? "keypress" : "!keypress"; |
|
57 synthesizeKeyExpectEvent(key, { }, autocomplete.inputField, event, testid); |
|
58 is(autocomplete.selectionStart, expectedStart, testid + " selectionStart"); |
|
59 is(autocomplete.selectionEnd, expectedEnd, testid + " selectionEnd"); |
|
60 } |
|
61 |
|
62 ]]> |
|
63 </script> |
|
64 |
|
65 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
66 <p id="display"> |
|
67 </p> |
|
68 <div id="content" style="display: none"> |
|
69 </div> |
|
70 <pre id="test"> |
|
71 </pre> |
|
72 </body> |
|
73 |
|
74 </window> |