summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_attributes_reflection.html
blob: 88aeb7f16f26beba39c237b67bc2bdba3b4ecedb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for HTMLInputElement attributes reflection</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="../reflect.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript">

/** Test for HTMLInputElement attributes reflection **/

// TODO: maybe make those reflections be tested against all input types.

function testWidthHeight(attr) {
  var element = document.createElement('input');
  is(element[attr], 0, attr + ' always returns 0 if not type=image');
  element.setAttribute(attr, '42');
  is(element[attr], 0, attr + ' always returns 0 if not type=image');
  is(element.getAttribute(attr), '42');
  element[attr] = 0;
  is(element.getAttribute(attr), '0', 'setting ' + attr + ' changes the content attribute');
  element[attr] = 12;
  is(element.getAttribute(attr), '12', 'setting ' + attr + ' changes the content attribute');

  element.removeAttribute(attr);
  is(element.getAttribute(attr), null);

  element = document.createElement('input');
  element.type = 'image';
  element.style.display = "inline";
  document.getElementById('content').appendChild(element);
  isnot(element[attr], 0, attr + ' represents the dimension of the element if type=image');

  element.setAttribute(attr, '42');
  isnot(element[attr], 0, attr + ' represents the dimension of the element if type=image');
  isnot(element[attr], 42, attr + ' represents the dimension of the element if type=image');
  is(element.getAttribute(attr), '42');
  element[attr] = 0;
  is(element.getAttribute(attr), '0', 'setting ' + attr + ' changes the content attribute');
  element[attr] = 12;
  is(element.getAttribute(attr), '12', 'setting ' + attr + ' changes the content attribute');

  element.removeAttribute(attr);
  is(element.getAttribute(attr), null);
}

// .accept
reflectString({
  element: document.createElement("input"),
  attribute: "accept",
  otherValues: [ "audio/*", "video/*", "image/*", "image/png",
                 "application/msword", "appplication/pdf" ],
});

// .alt
reflectString({
  element: document.createElement("input"),
  attribute: "alt",
});

// .autocomplete
reflectLimitedEnumerated({
  element: document.createElement("input"),
  attribute: "autocomplete",
  validValues: [ "on", "off" ],
  invalidValues: [ "", "default", "foo", "tulip" ],
});

// .autofocus
reflectBoolean({
  element: document.createElement("input"),
  attribute: "autofocus",
});

// .defaultChecked
reflectBoolean({
  element: document.createElement("input"),
  attribute: { idl: "defaultChecked", content: "checked" },
});

// .checked doesn't reflect a content attribute.

// .dirName
todo("dirName" in document.createElement("input"),
     "dirName isn't implemented yet");

// .disabled
reflectBoolean({
  element: document.createElement("input"),
  attribute: "disabled",
});

// TODO: form (HTMLFormElement)
// TODO: files (FileList)

// .formAction
reflectURL({
  element: document.createElement("button"),
  attribute: "formAction",
});

// .formEnctype
reflectLimitedEnumerated({
  element: document.createElement("input"),
  attribute: "formEnctype",
  validValues: [ "application/x-www-form-urlencoded", "multipart/form-data",
                 "text/plain" ],
  invalidValues: [ "", "foo", "tulip", "multipart/foo" ],
  defaultValue: { invalid: "application/x-www-form-urlencoded", missing: "" }
});

// .formMethod
reflectLimitedEnumerated({
  element: document.createElement("input"),
  attribute: "formMethod",
  validValues: [ "get", "post" ],
  invalidValues: [ "", "foo", "tulip" ],
  defaultValue: { invalid: "get", missing: "" }
});

// .formNoValidate
reflectBoolean({
  element: document.createElement("input"),
  attribute: "formNoValidate",
});

// .formTarget
reflectString({
  element: document.createElement("input"),
  attribute: "formTarget",
  otherValues: [ "_blank", "_self", "_parent", "_top" ],
});

// .height
testWidthHeight('height');

// .indeterminate doesn't reflect a content attribute.

// TODO: list (HTMLElement)

// .max
reflectString({
  element: document.createElement('input'),
  attribute: 'max',
});

// .maxLength
reflectInt({
  element: document.createElement("input"),
  attribute: "maxLength",
  nonNegative: true,
});

// .min
reflectString({
  element: document.createElement('input'),
  attribute: 'min',
});

// .multiple
reflectBoolean({
  element: document.createElement("input"),
  attribute: "multiple",
});

// .name
reflectString({
  element: document.createElement("input"),
  attribute: "name",
  otherValues: [ "isindex", "_charset_" ],
});

// .pattern
reflectString({
  element: document.createElement("input"),
  attribute: "pattern",
  otherValues: [ "[0-9][A-Z]{3}" ],
});

// .placeholder
reflectString({
  element: document.createElement("input"),
  attribute: "placeholder",
  otherValues: [ "foo\nbar", "foo\rbar", "foo\r\nbar" ],
});

// .readOnly
reflectBoolean({
  element: document.createElement("input"),
  attribute: "readOnly",
});

// .required
reflectBoolean({
  element: document.createElement("input"),
  attribute: "required",
});

// .size
reflectUnsignedInt({
  element: document.createElement("input"),
  attribute: "size",
  nonZero: true,
  defaultValue: 20,
});

// .src (URL)
reflectURL({
  element: document.createElement('input'),
  attribute: 'src',
});

// .step
reflectString({
  element: document.createElement('input'),
  attribute: 'step',
});

// .type
reflectLimitedEnumerated({
  element: document.createElement("input"),
  attribute: "type",
  validValues: [ "hidden", "text", "search", "tel", "url", "email", "password",
                 "checkbox", "radio", "file", "submit", "image", "reset",
                 "button", "date", "time", "number", "range", "color", "month",
                 "week", "datetime-local" ],
  invalidValues: [ "this-is-probably-a-wrong-type", "", "tulip" ],
  defaultValue: "text"
});

// .defaultValue
reflectString({
  element: document.createElement("input"),
  attribute: { idl: "defaultValue", content: "value" },
  otherValues: [ "foo\nbar", "foo\rbar", "foo\r\nbar" ],
});

// .value doesn't reflect a content attribute.

// .valueAsDate
is("valueAsDate" in document.createElement("input"), true,
   "valueAsDate should be available");

// Deeper check will be done with bug 763305.
is('valueAsNumber' in document.createElement("input"), true,
   "valueAsNumber should be available");

// .selectedOption
todo("selectedOption" in document.createElement("input"),
     "selectedOption isn't implemented yet");

// .width
testWidthHeight('width');

// .willValidate doesn't reflect a content attribute.
// .validity doesn't reflect a content attribute.
// .validationMessage doesn't reflect a content attribute.
// .labels doesn't reflect a content attribute.

</script>
</pre>
</body>
</html>