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
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("This test examines the order of the elements attribute of a form element.");
var container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = '<input name=victim id=before1 form=owner />' +
'<input name=victim id=before2 form=owner />' +
'<form id=owner action= method=GET>' +
' <input name=victim id=inner1 form=owner />' +
' <input name=victim id=inner2 form=owner />' +
'</form>' +
'<input name=victim id=after1 form=owner />' +
'<input name=victim id=after2 form=owner />';
var owner = document.getElementById('owner');
var before1 = document.getElementById('before1');
var before2 = document.getElementById('before2');
var inner1 = document.getElementById('inner1');
var inner2 = document.getElementById('inner2');
var after1 = document.getElementById('after1');
var after2 = document.getElementById('after2');
debug('- Test for the case where some elements are outside of the form.');
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
debug('');
debug('- Test for changing the value of the form attribute of a element which is located before the form owner.');
before2.attributes['form'].value = '';
shouldBe('owner.elements.length', '5');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'inner1');
shouldBe('owner.elements[2]', 'inner2');
shouldBe('owner.elements[3]', 'after1');
shouldBe('owner.elements[4]', 'after2');
before2.attributes['form'].value = 'owner';
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
debug('');
debug('- Test for changing the value of the form attribute of a element which is located inside of the form owner.');
inner2.attributes['form'].value = '';
shouldBe('owner.elements.length', '5');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'after1');
shouldBe('owner.elements[4]', 'after2');
inner2.attributes['form'].value = 'owner';
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
debug('');
debug('- Test for changing the value of the form attribute of a element which is located after the form owner.');
after1.attributes['form'].value = '';
shouldBe('owner.elements.length', '5');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after2');
after1.attributes['form'].value = 'owner';
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
debug('');
debug('- Test for setting form attribute of elements in reverse order.');
before1.attributes['form'].value = '';
before2.attributes['form'].value = '';
inner1.attributes['form'].value = '';
inner2.attributes['form'].value = '';
after1.attributes['form'].value = '';
after2.attributes['form'].value = '';
after2.attributes['form'].value = 'owner';
after1.attributes['form'].value = 'owner';
inner2.attributes['form'].value = 'owner';
inner1.attributes['form'].value = 'owner';
before2.attributes['form'].value = 'owner';
before1.attributes['form'].value = 'owner';
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
debug('');
debug('- Test for setting form attribute of elements in random order.');
before1.attributes['form'].value = '';
before2.attributes['form'].value = '';
inner1.attributes['form'].value = '';
inner2.attributes['form'].value = '';
after1.attributes['form'].value = '';
after2.attributes['form'].value = '';
after1.attributes['form'].value = 'owner';
before1.attributes['form'].value = 'owner';
inner2.attributes['form'].value = 'owner';
before2.attributes['form'].value = 'owner';
after2.attributes['form'].value = 'owner';
inner1.attributes['form'].value = 'owner';
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
debug('');
debug('- Test for removing/adding elements');
container.removeChild(before2);
owner.removeChild(inner2);
container.removeChild(after1);
shouldBe('owner.elements.length', '3');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'inner1');
shouldBe('owner.elements[2]', 'after2');
container.insertBefore(before2, owner);
owner.appendChild(inner2);
container.insertBefore(after1, after2);
shouldBe('owner.elements.length', '6');
shouldBe('owner.elements[0]', 'before1');
shouldBe('owner.elements[1]', 'before2');
shouldBe('owner.elements[2]', 'inner1');
shouldBe('owner.elements[3]', 'inner2');
shouldBe('owner.elements[4]', 'after1');
shouldBe('owner.elements[5]', 'after2');
</script>
</body>
</html>
|