Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / form-request-autocomplete.html
blob7c3b99a9b245e3a96c71765cf3a804f081602114
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <script>
6 jsTestIsAsync = true;
8 var numErrors = 0;
9 var numErrorsExpected = 4;
10 var eventsBubbleToBody = false;
11 var eventsBubbleToDocument = false;
12 var eventsBubbleToWindow = false;
14 function runTests()
16 checkDynamicAttributes();
17 checkNonUserGesture();
18 checkParsedAttributes();
19 checkEventsBubble();
22 function checkForEnumerableProperties(form)
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');
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');
50 setTimeout(function()
52 form.requestAutocomplete();
53 }, 0);
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();
75 setTimeout(onError);
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');
100 else
101 testFailed('expected an AutocompleteErrorEvent');
103 if (event.reason == reason)
104 testPassed('got expected reason: ' + reason);
105 else
106 testFailed('wrong reason, expected: ' + reason + ', got: ' + event.reason);
108 onError();
112 function onError()
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();
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">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>
138 <p id="console"></p>
139 </body>
140 </html>