Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / implicit-submission.html
blob10d1e1f878dc9faf10689e0b78c1d6848d313897
1 <html>
2 <head>
3 <title>Implicit Form Submission</title>
4 <script>
6 var currentTest = 0;
8 // match IE and FF unless specified otherwise.
9 var allTests = [
10 [ "Single text input", "!text", "y" ],
11 [ "Single text input with submit disabled", "!text,-submit", "n" ],
12 [ "Multiple text inputs", "!text,text,text", "n" ],
13 [ "Multiple text inputs with submit", "!text,text,text,submit", "y" ],
14 [ "Multiple text inputs with submit disabled", "!text,text,text,-submit", "n" ],
15 [ "Multiple text inputs and multiple submits, first submit disabled", "!text,text,text,-submit,submit", "n" ], // match Gecko + spec, but not IE.
16 [ "Text input and text area, text input focused", "!text,textarea", "y" ],
17 [ "Text input and text area and a submit, text input focused", "!text,textarea,submit", "y" ],
18 [ "Text input and text area and a disabled submit, text input focused", "!text,textarea,-submit", "n" ], // match Gecko + spec, but not IE.
19 [ "Text input and checkbox, text input focused", "!text,checkbox", "y" ],
20 [ "Text input and radio, text input focused", "!text,radio", "y" ],
21 [ "Text input and text area, textarea focused", "text,!textarea", "n" ],
22 [ "Text input and checkbox, checkbox focused", "text,!checkbox", "n" ], // match IE, not FF.
23 [ "Text input and radio, radio focused", "text,!radio", "n" ], // match IE, not FF.
24 [ "Single radio", "!radio", "n" ], // match IE, not FF.
25 [ "Single checkbox", "!checkbox", "n" ],
26 [ "Single checkbox with a submit", "!checkbox,submit", "y" ],
27 [ "Single checkbox with a submit disabled", "!checkbox,-submit", "n" ],
28 [ "Single select", "!select", "n" ],
29 [ "Select with a submit", "!select,submit", "y" ], // match neither FF nor IE, instead follow logic.
30 [ "Select with a disabled submit", "!select,-submit", "n" ],
31 [ "Multi-line select with a submit", "!selectBox,submit", "y" ], // match neither FF nor IE, instead follow logic.
32 [ "Multi-line select with a disabled submit", "!selectBox,-submit", "n" ],
33 [ "Text field and single select, text focused", "!text,select", "y" ],
34 [ "Text field and single select, select focused", "text,!select", "n" ],
35 [ "Multiple text inputs with a button", "!text,text,button", "y"],
36 [ "Multiple text inputs with a disabled button", "!text,text,-button", "n"],
37 [ "Multiple text inputs with a hidden submit", "!text,text,?submit", "y"]
40 if (window.testRunner) {
41 testRunner.dumpAsText();
42 testRunner.waitUntilDone();
45 var results = {
46 submissionReported: false,
47 data: [],
48 submitted: function()
50 this.submissionReported = true;
51 if (!window.eventSender)
52 this.testCompleted();
54 testCompleted: function()
56 this.data.push(this.submissionReported ? 'y' : 'n');
57 this.submissionReported = false;
58 runNextTest();
60 publish: function()
62 document.getElementById("log").innerHTML = allTests.map(function(manifest, i)
64 return manifest[0] + " should " + (manifest[2] == 'n' ? "not" : "") + " submit: " + (this.data[i] == manifest[2] ? "PASS" : "FAIL");
65 }, this).join("<br>");
69 function runNextTest()
71 ++currentTest;
72 if (currentTest < allTests.length) {
73 runTest();
74 return;
76 document.getElementById('arena').textContent = '';
77 results.publish();
78 if (window.testRunner)
79 testRunner.notifyDone();
82 function buildAndTestForm(arena, inputs, description)
84 arena.textContent = '';
85 var form = arena.appendChild(document.createElement("form"));
86 form.addEventListener('submit', function(evt) {
87 results.submitted();
88 evt.preventDefault();
90 if (!window.eventSender)
91 form.appendChild(document.createElement("p")).innerHTML = "Press Enter key";
92 inputs.forEach(function(type, i)
94 var focused;
95 if (type[0] == '!') {
96 type = type.substr(1);
97 focused = true;
99 var hidden;
100 if (type[0] == '?') {
101 type = type.substr(1);
102 hidden = true;
104 var disabled;
105 if (type[0] == '-') {
106 type = type.substr(1);
107 disabled = true;
109 var control;
110 if (type == "textarea") {
111 control = document.createElement(type);
112 } else if (type == "select") {
113 control = document.createElement(type);
114 control.options.add(new Option("a"));
115 } else if (type == "selectBox") {
116 control = document.createElement("select");
117 control.size = 5;
118 control.options.add(new Option("a"));
119 } else if (type == "button") {
120 control = document.createElement(type);
121 control.type = "submit";
122 } else {
123 control = document.createElement("input");
124 control.type = type;
126 control.id = focused ? "focused" : ("input" + i);
127 control.disabled = !!disabled;
128 if (hidden)
129 control.style.display = 'none';
130 form.appendChild(control);
132 var input = document.getElementById("focused");
133 if (input)
134 input.focus();
135 if (window.eventSender) {
136 eventSender.keyDown("\r", []);
137 results.testCompleted();
138 } else {
139 var a = document.createElement("a");
140 a.href = "javascript:results.testCompleted();";
141 a.innerText = "Click if didn't submit";
142 arena.appendChild(a);
146 function runTest()
148 var manifest = allTests[currentTest];
149 buildAndTestForm(document.getElementById('arena'), manifest[1].split(','), manifest[0]);
152 </script>
153 </head>
154 <body onload="runTest()">
155 <p>Tests various combinations of form elements and how implicit submission works with them.
156 <div id="arena"></div>
157 <div id="log"></div>
158 </body>
159 </html>