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
|
<html>
<head>
<title>Implicit Form Submission</title>
<script>
var currentTest = 0;
// match IE and FF unless specified otherwise.
var allTests = [
[ "Single text input", "!text", "y" ],
[ "Single text input with submit disabled", "!text,-submit", "n" ],
[ "Multiple text inputs", "!text,text,text", "n" ],
[ "Multiple text inputs with submit", "!text,text,text,submit", "y" ],
[ "Multiple text inputs with submit disabled", "!text,text,text,-submit", "n" ],
[ "Multiple text inputs and multiple submits, first submit disabled", "!text,text,text,-submit,submit", "n" ], // match Gecko + spec, but not IE.
[ "Text input and text area, text input focused", "!text,textarea", "y" ],
[ "Text input and text area and a submit, text input focused", "!text,textarea,submit", "y" ],
[ "Text input and text area and a disabled submit, text input focused", "!text,textarea,-submit", "n" ], // match Gecko + spec, but not IE.
[ "Text input and checkbox, text input focused", "!text,checkbox", "y" ],
[ "Text input and radio, text input focused", "!text,radio", "y" ],
[ "Text input and text area, textarea focused", "text,!textarea", "n" ],
[ "Text input and checkbox, checkbox focused", "text,!checkbox", "n" ], // match IE, not FF.
[ "Text input and radio, radio focused", "text,!radio", "n" ], // match IE, not FF.
[ "Single radio", "!radio", "n" ], // match IE, not FF.
[ "Single checkbox", "!checkbox", "n" ],
[ "Single checkbox with a submit", "!checkbox,submit", "y" ],
[ "Single checkbox with a submit disabled", "!checkbox,-submit", "n" ],
[ "Single select", "!select", "n" ],
[ "Select with a submit", "!select,submit", "y" ], // match neither FF nor IE, instead follow logic.
[ "Select with a disabled submit", "!select,-submit", "n" ],
[ "Multi-line select with a submit", "!selectBox,submit", "y" ], // match neither FF nor IE, instead follow logic.
[ "Multi-line select with a disabled submit", "!selectBox,-submit", "n" ],
[ "Text field and single select, text focused", "!text,select", "y" ],
[ "Text field and single select, select focused", "text,!select", "n" ],
[ "Multiple text inputs with a button", "!text,text,button", "y"],
[ "Multiple text inputs with a disabled button", "!text,text,-button", "n"],
[ "Multiple text inputs with a hidden submit", "!text,text,?submit", "y"]
];
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var results = {
submissionReported: false,
data: [],
submitted: function()
{
this.submissionReported = true;
if (!window.eventSender)
this.testCompleted();
},
testCompleted: function()
{
this.data.push(this.submissionReported ? 'y' : 'n');
this.submissionReported = false;
runNextTest();
},
publish: function()
{
document.getElementById("log").innerHTML = allTests.map(function(manifest, i)
{
return manifest[0] + " should " + (manifest[2] == 'n' ? "not" : "") + " submit: " + (this.data[i] == manifest[2] ? "PASS" : "FAIL");
}, this).join("<br>");
}
};
function runNextTest()
{
++currentTest;
if (currentTest < allTests.length) {
runTest();
return;
}
document.getElementById('arena').textContent = '';
results.publish();
if (window.testRunner)
testRunner.notifyDone();
}
function buildAndTestForm(arena, inputs, description)
{
arena.textContent = '';
var form = arena.appendChild(document.createElement("form"));
form.addEventListener('submit', function(evt) {
results.submitted();
evt.preventDefault();
})
if (!window.eventSender)
form.appendChild(document.createElement("p")).innerHTML = "Press Enter key";
inputs.forEach(function(type, i)
{
var focused;
if (type[0] == '!') {
type = type.substr(1);
focused = true;
}
var hidden;
if (type[0] == '?') {
type = type.substr(1);
hidden = true;
}
var disabled;
if (type[0] == '-') {
type = type.substr(1);
disabled = true;
}
var control;
if (type == "textarea") {
control = document.createElement(type);
} else if (type == "select") {
control = document.createElement(type);
control.options.add(new Option("a"));
} else if (type == "selectBox") {
control = document.createElement("select");
control.size = 5;
control.options.add(new Option("a"));
} else if (type == "button") {
control = document.createElement(type);
control.type = "submit";
} else {
control = document.createElement("input");
control.type = type;
}
control.id = focused ? "focused" : ("input" + i);
control.disabled = !!disabled;
if (hidden)
control.style.display = 'none';
form.appendChild(control);
});
var input = document.getElementById("focused");
if (input)
input.focus();
if (window.eventSender) {
eventSender.keyDown("\r", []);
results.testCompleted();
} else {
var a = document.createElement("a");
a.href = "javascript:results.testCompleted();";
a.innerText = "Click if didn't submit";
arena.appendChild(a);
}
}
function runTest()
{
var manifest = allTests[currentTest];
buildAndTestForm(document.getElementById('arena'), manifest[1].split(','), manifest[0]);
}
</script>
</head>
<body onload="runTest()">
<p>Tests various combinations of form elements and how implicit submission works with them.
<div id="arena"></div>
<div id="log"></div>
</body>
</html>
|