Skip media source tests since the feature is not enabled on Windows.
[WebKit-https.git] / LayoutTests / fast / forms / autocomplete-tokens.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="../../resources/js-test-pre.js"></script>
5     </head>
6     <body>
7         <p id="description"></p>
8         <div id="console"></div>
9         <script>
10             description('Tests for valid autocomplete tokens on input, select, and textarea elements.');
11
12             var input = document.createElement('input');
13             var textarea = document.createElement('textarea');
14             var select = document.createElement('select');
15             var button = document.createElement('button');
16             var keygen = document.createElement('keygen');
17             var autocompleteableControls = [ input, textarea, select ];
18
19             var keywords = [ "name", "honorific-prefix", "given-name", "additional-name", "family-name", "honorific-suffix", "nickname", "organization-title", "username", "new-password", "current-password", "organization", "street-address", "address-line1", "address-line2", "address-line3", "address-level4", "address-level3", "address-level2", "address-level1", "country", "country-name", "postal-code", "cc-name", "cc-given-name", "cc-additional-name", "cc-family-name", "cc-number", "cc-exp", "cc-exp-month", "cc-exp-year", "cc-csc", "cc-type", "transaction-currency", "transaction-amount", "language", "bday", "bday-day", "bday-month", "bday-year", "sex", "url", "photo", "tel", "tel-country-code", "tel-national", "tel-area-code", "tel-local", "tel-local-prefix", "tel-local-suffix", "tel-extension", "email", "impp" ];
20
21             var modeTokens = [ "billing", "shipping" ];
22
23             debug('Valid keywords:');
24             keywords.forEach(keyword => {
25                 input.autocomplete = keyword;
26                 shouldBeEqualToString('input.autocomplete', keyword);
27                 if (window.internals)
28                     shouldBeEqualToString('window.internals.autofillFieldName(input)', keyword);
29             });
30
31             debug('');
32             debug('Contact scope:');
33             var contactTokens = [ "tel", "tel-country-code", "tel-national", "tel-area-code", "tel-local", "tel-local-prefix", "tel-local-suffix", "tel-extension", "email", "impp" ];
34             var contactScopeTokens = [ "home", "work", "mobile", "fax", "pager" ];
35             contactScopeTokens.forEach(scopeToken => {
36                 contactTokens.forEach(contactToken => {
37                     input.autocomplete = scopeToken + " " + contactToken;
38                     shouldBeEqualToString('input.autocomplete', scopeToken + " " + contactToken);
39                     if (window.internals)
40                         shouldBeEqualToString('window.internals.autofillFieldName(input)', contactToken);
41                 })
42             });
43
44             debug('');
45             debug('Mode:');
46             var addressTokens = [ "street-address", "address-line1", "address-line2", "address-line3", "address-level4", "address-level3", "address-level2", "address-level1", "country", "country-name", "postal-code" ];
47             var modeTokens = [ "shipping", "billing" ];
48             modeTokens.forEach(modeToken => {
49                 addressTokens.forEach(addressToken => {
50                     input.autocomplete = modeToken + " " + addressToken;
51                     shouldBeEqualToString('input.autocomplete', modeToken + " " + addressToken);
52                     if (window.internals)
53                         shouldBeEqualToString('window.internals.autofillFieldName(input)', addressToken);
54                 })
55             });
56
57             debug('');
58             debug('Section:');
59             keywords.forEach(keyword => {
60                 var value = "section-parent " + keyword;
61                 input.autocomplete = value;
62                 shouldBeEqualToString('input.autocomplete', value);
63                 if (window.internals)
64                     shouldBeEqualToString('window.internals.autofillFieldName(input)', keyword);
65             });
66
67             debug('');
68             debug('Invalid combinations:');
69             autocompleteableControls.forEach(control => {
70                  control.autocomplete = 'invalid';
71                  shouldBeEmptyString('input.autocomplete');
72                  if (window.internals)
73                      shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
74             });
75             // Two normal tokens
76             input.autocomplete = "name name";
77             shouldBeEmptyString('input.autocomplete');
78             if (window.internals)
79                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
80
81             input.autocomplete = "name bday";
82             shouldBeEmptyString('input.autocomplete');
83             if (window.internals)
84                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
85
86             // Contact scope token + non-contact token.
87             input.autocomplete = "pager bday";
88             shouldBeEmptyString('input.autocomplete');
89             if (window.internals)
90                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
91
92             // Two contact scope tokens.
93             input.autocomplete = "home work tel";
94             shouldBeEmptyString('input.autocomplete');
95             if (window.internals)
96                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
97
98             // Two mode tokens.
99             input.autocomplete = "shipping billing tel";
100             shouldBeEmptyString('input.autocomplete');
101             if (window.internals)
102                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
103
104             // Two section tokens.
105             input.autocomplete = "section-a section-b tel";
106             shouldBeEmptyString('input.autocomplete');
107             if (window.internals)
108                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
109
110             // Anything + on/off.
111             input.autocomplete = "tel on";
112             shouldBeEmptyString('input.autocomplete');
113             if (window.internals)
114                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
115
116             input.autocomplete = "tel off";
117             shouldBeEmptyString('input.autocomplete');
118             if (window.internals)
119                 shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
120
121             // Test dynamically changing the form owner's autocomplete attribute
122             // to ensure the field name correctly reflects it.
123             var form = document.createElement("form");
124             var inputInAutocompleteOffForm = document.createElement("input");
125             form.appendChild(inputInAutocompleteOffForm);
126             document.body.appendChild(form);
127             form.autocomplete = "off";
128             inputInAutocompleteOffForm.autocomplete = "";
129             shouldBeEmptyString('inputInAutocompleteOffForm.autocomplete');
130             if (window.internals)
131                 shouldBeEqualToString('window.internals.autofillFieldName(inputInAutocompleteOffForm)', "off");
132
133             form.autocomplete = "on";
134             shouldBeEmptyString('inputInAutocompleteOffForm.autocomplete');
135             if (window.internals)
136                 shouldBeEqualToString('window.internals.autofillFieldName(inputInAutocompleteOffForm)', "on");
137
138             debug('');
139             debug('Non-autocompleteable controls:');
140             // Buttons and keygens are not autocompleteable, so their autocomplete attribute is not sanitized.
141             button.autocomplete = 'invalid';
142             shouldBeEqualToString('button.autocomplete', 'invalid');
143             keygen.autocomplete = 'invalid';
144             shouldBeEqualToString('keygen.autocomplete', 'invalid');
145         </script>
146         <script src="../../resources/js-test-post.js"></script>
147     </body>
148 </html>