OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 <script> | |
6 jsTestIsAsync = true; | |
7 | |
8 var numErrors = 0; | |
9 var numErrorsExpected = 4; | |
10 var eventsBubbleToBody = false; | |
11 var eventsBubbleToDocument = false; | |
12 var eventsBubbleToWindow = false; | |
13 | |
14 function runTests() | |
15 { | |
16 checkDynamicAttributes(); | |
17 checkNonUserGesture(); | |
18 checkParsedAttributes(); | |
19 checkEventsBubble(); | |
20 } | |
21 | |
22 function checkForEnumerableProperties(form) | |
23 { | |
24 var enumerable = {}; | |
25 for (var field in form) | |
26 enumerable[field] = true; | |
27 if (!enumerable.onautocomplete) | |
28 testFailed('failed to enumerate HTMLFormElement.onautocomplete'); | |
29 if (!enumerable.onautocompleteerror) | |
30 testFailed('failed to enumerate HTMLFormElement.onautocompleteerror'); | |
31 testPassed('found enumerable properties on HTMLFormElement'); | |
32 } | |
33 | |
34 function checkDynamicAttributes() | |
35 { | |
36 var form = document.createElement('form'); | |
37 checkForEnumerableProperties(form); | |
38 | |
39 form.autocomplete = 'off'; | |
40 form.addEventListener('autocompleteerror', errorWithReason('disabled')); | |
41 form.requestAutocomplete(); | |
42 } | |
43 | |
44 function checkNonUserGesture() | |
45 { | |
46 var form = document.createElement('form'); | |
47 checkForEnumerableProperties(form); | |
48 form.onautocompleteerror = errorWithReason('disabled'); | |
49 | |
50 setTimeout(function() | |
51 { | |
52 form.requestAutocomplete(); | |
53 }, 0); | |
54 } | |
55 | |
56 function checkParsedAttributes() | |
57 { | |
58 var form = document.forms[0]; | |
59 if (!form || !form.onautocompleteerror || form.autocomplete != 'off') | |
60 testFailed('failed to pick up parsed DOM attributes correctly'); | |
61 checkForEnumerableProperties(form); | |
62 | |
63 form.requestAutocomplete(); | |
64 } | |
65 | |
66 function checkEventsBubble() | |
67 { | |
68 var form = document.createElement('form'); | |
69 form.autocomplete = 'off'; | |
70 | |
71 document.body.onautocompleteerror = function(event) { | |
72 eventsBubbleToBody = true; | |
73 if (event.target == form) { | |
74 event.stopPropagation(); | |
75 setTimeout(onError); | |
76 } | |
77 }; | |
78 | |
79 document.onautocompleteerror = function(event) { | |
80 eventsBubbleToDocument = true; | |
81 if (event.target == form) | |
82 testFailed("event should've been cancelled"); | |
83 }; | |
84 | |
85 window.onautocompleteerror = function(event) { | |
86 eventsBubbleToWindow = true; | |
87 if (event.target == form) | |
88 testFailed("event should've been cancelled"); | |
89 }; | |
90 | |
91 document.body.appendChild(form); | |
92 form.requestAutocomplete(); | |
93 } | |
94 | |
95 function errorWithReason(reason) | |
96 { | |
97 return function(event) { | |
98 if (event instanceof AutocompleteErrorEvent) | |
99 testPassed('event is an AutocompleteErrorEvent'); | |
100 else | |
101 testFailed('expected an AutocompleteErrorEvent'); | |
102 | |
103 if (event.reason == reason) | |
104 testPassed('got expected reason: ' + reason); | |
105 else | |
106 testFailed('wrong reason, expected: ' + reason + ', got: ' + event.r
eason); | |
107 | |
108 onError(); | |
109 }; | |
110 } | |
111 | |
112 function onError() | |
113 { | |
114 numErrors += 1; | |
115 if (numErrors > numErrorsExpected) { | |
116 testFailed('too many error events'); | |
117 } else if (numErrors == numErrorsExpected) { | |
118 if (!eventsBubbleToBody) | |
119 testFailed('no events bubbled to body'); | |
120 if (!eventsBubbleToDocument) | |
121 testFailed('no events bubbled to document'); | |
122 if (!eventsBubbleToWindow) | |
123 testFailed('no events bubbled to window'); | |
124 if (eventsBubbleToBody && eventsBubbleToDocument && eventsBubbleToWindow
) | |
125 testPassed('events bubbled as expected'); | |
126 testPassed('got expected number of error events (' + numErrorsExpected +
')'); | |
127 finishJSTest(); | |
128 } | |
129 } | |
130 | |
131 window.addEventListener('load', runTests, true); | |
132 </script> | |
133 </head> | |
134 <body> | |
135 <p> <a href="https://code.google.com/p/chromium/issues/detail?id=159537">HTMLFor
mElement#requestAutocomplete and associated events</a> </p> | |
136 <p> For this test to pass, you should see all PASSED below. </p> | |
137 <form autocomplete="off" onautocompleteerror="onError();"></form> | |
138 <p id="console"></p> | |
139 </body> | |
140 </html> | |
OLD | NEW |