4 <script src=
"../../resources/js-test.js"></script>
9 var numErrorsExpected
= 4;
10 var eventsBubbleToBody
= false;
11 var eventsBubbleToDocument
= false;
12 var eventsBubbleToWindow
= false;
16 checkDynamicAttributes();
17 checkNonUserGesture();
18 checkParsedAttributes();
22 function checkForEnumerableProperties(form
)
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');
34 function checkDynamicAttributes()
36 var form
= document
.createElement('form');
37 checkForEnumerableProperties(form
);
39 form
.autocomplete
= 'off';
40 form
.addEventListener('autocompleteerror', errorWithReason('disabled'));
41 form
.requestAutocomplete();
44 function checkNonUserGesture()
46 var form
= document
.createElement('form');
47 checkForEnumerableProperties(form
);
48 form
.onautocompleteerror
= errorWithReason('disabled');
52 form
.requestAutocomplete();
56 function checkParsedAttributes()
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
);
63 form
.requestAutocomplete();
66 function checkEventsBubble()
68 var form
= document
.createElement('form');
69 form
.autocomplete
= 'off';
71 document
.body
.onautocompleteerror = function(event
) {
72 eventsBubbleToBody
= true;
73 if (event
.target
== form
) {
74 event
.stopPropagation();
79 document
.onautocompleteerror = function(event
) {
80 eventsBubbleToDocument
= true;
81 if (event
.target
== form
)
82 testFailed("event should've been cancelled");
85 window
.onautocompleteerror = function(event
) {
86 eventsBubbleToWindow
= true;
87 if (event
.target
== form
)
88 testFailed("event should've been cancelled");
91 document
.body
.appendChild(form
);
92 form
.requestAutocomplete();
95 function errorWithReason(reason
)
97 return function(event
) {
98 if (event
instanceof AutocompleteErrorEvent
)
99 testPassed('event is an AutocompleteErrorEvent');
101 testFailed('expected an AutocompleteErrorEvent');
103 if (event
.reason
== reason
)
104 testPassed('got expected reason: ' + reason
);
106 testFailed('wrong reason, expected: ' + reason
+ ', got: ' + event
.reason
);
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
+ ')');
131 window
.addEventListener('load', runTests
, true);
135 <p> <a href=
"https://code.google.com/p/chromium/issues/detail?id=159537">HTMLFormElement#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>