blob: 32e59da86da00727ae42c689cc85cbeec4152403 [file] [log] [blame]
rniwa@webkit.orgddbdcc82019-08-21 20:25:10 +00001<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- webkit-test-runner [ enableKeygenElement=true ] -->
tkent@chromium.org995765c2010-12-07 09:40:23 +00002<html>
3<head>
mark.lam@apple.com93720da2013-09-07 23:31:07 +00004<script src="../../resources/js-test-pre.js"></script>
tkent@chromium.org995765c2010-12-07 09:40:23 +00005</head>
6<body>
7<p id="description"></p>
8<div id="console"></div>
tkent@chromium.orga0139532012-02-15 06:56:00 +00009<script>
10description("This test examines the order of form associated elements which are classified as 'listed'.");
11
12var container = document.createElement('div');
13document.body.appendChild(container);
14var owner;
15
16function checkOrder(victims) {
17 if (owner.elements.length != victims.length)
18 return 'length mismatch, elements.length = ' + owner.elements.length +
19 ', expected length = ' + victims.length;
20 for (var i = 0; i < victims.length; ++i)
21 if (owner.elements[i] != victims[i])
22 return 'element mismatch at index ' + i;
23 return 'OK';
24}
25
26debug('- Checks the order of form associated elements.');
27container.innerHTML = '<form id=owner>' +
28 '<button name=victim></button>' +
29 '<fieldset name=victim>Test</fieldset>' +
30 '<input name=victim/>' +
31 '<keygen name=victim></keygen>' +
32 '<label name=victim></label>' +
33 '<meter name=victim></meter>' +
34 '<object name=victim></object>' +
35 '<output name=victim></output>' +
36 '<progress name=victim></progress>' +
37 '<select name=victim></select>' +
38 '<textarea name=victim></textarea>'+
39 '</form>';
40owner = document.getElementById('owner');
41var button = document.getElementsByTagName('button')[0];
42var fieldset = document.getElementsByTagName('fieldset')[0];
43var input = document.getElementsByTagName('input')[0];
44var keygen = document.getElementsByTagName('keygen')[0];
45var label = document.getElementsByTagName('label')[0];
46var meter = document.getElementsByTagName('meter')[0];
47var object = document.getElementsByTagName('object')[0];
48var output = document.getElementsByTagName('output')[0];
49var progress = document.getElementsByTagName('progress')[0];
50var select = document.getElementsByTagName('select')[0];
51var textarea = document.getElementsByTagName('textarea')[0];
52shouldBe('checkOrder([button, fieldset, input, keygen, object, output, select, textarea])', '"OK"');
53
54debug('');
55debug('- Checks the order after some elements removed/inserted.');
56owner.removeChild(object);
57shouldBe('checkOrder([button, fieldset, input, keygen, output, select, textarea])', '"OK"');
58owner.removeChild(button);
59shouldBe('checkOrder([fieldset, input, keygen, output, select, textarea])', '"OK"');
60owner.insertBefore(object, fieldset);
61shouldBe('checkOrder([object, fieldset, input, keygen, output, select, textarea])', '"OK"');
62owner.appendChild(button);
63shouldBe('checkOrder([object, fieldset, input, keygen, output, select, textarea, button])', '"OK"');
64
65debug('');
66debug('- Checks the order of form associated elements with form attribute.');
67container.innerHTML = '<button name=victim form=owner></button>' +
68 '<fieldset name=victim form=owner>Test</fieldset>' +
69 '<input name=victim form=owner />' +
70 '<keygen name=victim form=owner></keygen>' +
71 '<form id=owner>' +
72 '<label name=victim></label>' +
73 '<meter name=victim></meter>' +
74 '<object name=victim></object>' +
75 '</form>' +
76 '<output name=victim form=owner></output>' +
77 '<progress name=victim form=owner></progress>' +
78 '<select name=victim form=owner></select>' +
79 '<textarea name=victim form=owner></textarea>';
80owner = document.getElementById('owner');
81button = document.getElementsByTagName('button')[0];
82fieldset = document.getElementsByTagName('fieldset')[0];
83input = document.getElementsByTagName('input')[0];
84keygen = document.getElementsByTagName('keygen')[0];
85label = document.getElementsByTagName('label')[0];
86meter = document.getElementsByTagName('meter')[0];
87object = document.getElementsByTagName('object')[0];
88output = document.getElementsByTagName('output')[0];
89progress = document.getElementsByTagName('progress')[0];
90select = document.getElementsByTagName('select')[0];
91textarea = document.getElementsByTagName('textarea')[0];
92shouldBe('checkOrder([button, fieldset, input, keygen, object, output, select, textarea])', '"OK"');
93
94debug('');
95debug('- Checks the order after some elements removed/inserted with form attribute.');
96owner.removeChild(object);
97shouldBe('checkOrder([button, fieldset, input, keygen, output, select, textarea])', '"OK"');
98container.removeChild(button);
99shouldBe('checkOrder([fieldset, input, keygen, output, select, textarea])', '"OK"');
100container.removeChild(textarea);
101shouldBe('checkOrder([fieldset, input, keygen, output, select])', '"OK"');
102owner.appendChild(object);
103shouldBe('checkOrder([fieldset, input, keygen, object, output, select])', '"OK"');
104container.insertBefore(textarea, fieldset);
105shouldBe('checkOrder([textarea, fieldset, input, keygen, object, output, select])', '"OK"');
106container.appendChild(button);
107shouldBe('checkOrder([textarea, fieldset, input, keygen, object, output, select, button])', '"OK"');
108</script>
mark.lam@apple.com93720da2013-09-07 23:31:07 +0000109<script src="../../resources/js-test-post.js"></script>
tkent@chromium.org995765c2010-12-07 09:40:23 +0000110</body>
111</html>