|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for Layout of Form History Autocomplete: Bug 787624</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
7 <script type="text/javascript" src="satchel_common.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
9 <style> |
|
10 .container { |
|
11 border: 1px solid #333; |
|
12 width: 80px; |
|
13 height: 26px; |
|
14 position: absolute; |
|
15 z-index: 2; |
|
16 } |
|
17 |
|
18 .subcontainer { |
|
19 width: 100%; |
|
20 overflow: hidden; |
|
21 } |
|
22 |
|
23 .subcontainer input { |
|
24 width: 120px; |
|
25 margin: 2px 6px; |
|
26 padding-right: 4px; |
|
27 border: none; |
|
28 height: 22px; |
|
29 z-index: 1; |
|
30 outline: 1px dashed #555 |
|
31 } |
|
32 </style> |
|
33 </head> |
|
34 <body> |
|
35 Form History Layout test: form field autocomplete: Bug 787624 |
|
36 <p id="display"></p> |
|
37 |
|
38 <!-- we presumably can't hide the content for this test. --> |
|
39 <div id="content" style="direction: rtl;"> |
|
40 <!-- unused --> |
|
41 <form id="unused" onsubmit="return false;"> |
|
42 <input type="text" name="field1" value="unused"> |
|
43 </form> |
|
44 |
|
45 <!-- normal, basic form --> |
|
46 <div class="container"> |
|
47 <div class="subcontainer"> |
|
48 <form id="form1" onsubmit="return false;"> |
|
49 <input type="text" name="field1"> |
|
50 <button type="submit">Submit</button> |
|
51 </form> |
|
52 </div> |
|
53 </div> |
|
54 </div> |
|
55 |
|
56 <pre id="test"> |
|
57 <script class="testbody" type="text/javascript"> |
|
58 |
|
59 /** Test for Form History autocomplete Layout: Bug 787624 **/ |
|
60 |
|
61 var autocompletePopup = getAutocompletePopup(); |
|
62 autocompletePopup.style.direction = "ltr"; |
|
63 |
|
64 var input = $_(1, "field1"); |
|
65 var rect = input.getBoundingClientRect(); |
|
66 |
|
67 // Get the form history service |
|
68 function setupFormHistory() { |
|
69 updateFormHistory([ |
|
70 { op : "remove" }, |
|
71 { op : "add", fieldname : "field1", value : "value1" }, |
|
72 { op : "add", fieldname : "field1", value : "value2" }, |
|
73 ], function() runTest(1)); |
|
74 } |
|
75 |
|
76 function checkForm(expectedValue) { |
|
77 var formID = input.parentNode.id; |
|
78 if (input.value != expectedValue) |
|
79 return false; |
|
80 |
|
81 is(input.value, expectedValue, "Checking " + formID + " input"); |
|
82 return true; |
|
83 } |
|
84 |
|
85 function checkPopupOpen(isOpen, expectedIndex) { |
|
86 var actuallyOpen = autocompletePopup.popupOpen; |
|
87 var actualIndex = autocompletePopup.selectedIndex; |
|
88 if (actuallyOpen != isOpen) |
|
89 return false; |
|
90 |
|
91 is(actuallyOpen, isOpen, "popup should be " + (isOpen ? "open" : "closed")); |
|
92 if (isOpen) { |
|
93 if (actualIndex != expectedIndex) |
|
94 return false; |
|
95 is(actualIndex, expectedIndex, "checking selected index"); |
|
96 } |
|
97 return true; |
|
98 } |
|
99 |
|
100 function runTest(testNum) { |
|
101 ok(true, "Starting test #" + testNum); |
|
102 var retry = false; |
|
103 var formOK, popupOK; |
|
104 |
|
105 switch(testNum) { |
|
106 // |
|
107 // Check initial state |
|
108 // |
|
109 case 1: |
|
110 input.value = ""; |
|
111 formOK = checkForm(""); |
|
112 if (!formOK) { |
|
113 retry = true; |
|
114 break; |
|
115 } |
|
116 is(autocompletePopup.popupOpen, false, "popup should be initially closed"); |
|
117 break; |
|
118 |
|
119 // try a focus() |
|
120 case 2: |
|
121 input.focus(); |
|
122 break; |
|
123 case 3: |
|
124 popupOK = checkPopupOpen(false); |
|
125 formOK = checkForm(""); |
|
126 if (!formOK || !popupOK) |
|
127 retry = true; |
|
128 break; |
|
129 // try a click() |
|
130 case 4: |
|
131 input.click(); |
|
132 break; |
|
133 case 5: |
|
134 popupOK = checkPopupOpen(false); |
|
135 formOK = checkForm(""); |
|
136 if (!formOK || !popupOK) |
|
137 retry = true; |
|
138 break; |
|
139 case 6: |
|
140 // We're privileged for this test, so open the popup. |
|
141 popupOK = checkPopupOpen(false); |
|
142 formOK = checkForm(""); |
|
143 if (!formOK || !popupOK) |
|
144 retry = true; |
|
145 doKey("down"); |
|
146 break; |
|
147 case 7: |
|
148 popupOK = checkPopupOpen(true, -1); |
|
149 formOK = checkForm(""); |
|
150 if (!formOK || !popupOK) |
|
151 retry = true; |
|
152 break; |
|
153 case 8: |
|
154 var newRect = input.getBoundingClientRect(); |
|
155 is(newRect.left, rect.left, |
|
156 "autocomplete popup does not disturb the input position"); |
|
157 is(newRect.top, rect.top, |
|
158 "autocomplete popup does not disturb the input position"); |
|
159 SimpleTest.finish(); |
|
160 return; |
|
161 |
|
162 default: |
|
163 ok(false, "Unexpected invocation of test #" + testNum); |
|
164 SimpleTest.finish(); |
|
165 return; |
|
166 } |
|
167 |
|
168 if (!retry) |
|
169 testNum++; |
|
170 |
|
171 setTimeout(runTest, 0, testNum); |
|
172 } |
|
173 |
|
174 function startTest() { |
|
175 setupFormHistory(); |
|
176 } |
|
177 |
|
178 window.onload = startTest; |
|
179 |
|
180 SimpleTest.waitForExplicitFinish(); |
|
181 </script> |
|
182 </pre> |
|
183 </body> |
|
184 </html> |