[Tests] We should have interactive validation of required value for the "input" element
https://bugs.webkit.org/show_bug.cgi?id=95817

Reviewed by Kent Tamura.

This patch adds tests for required attribute handling on form
submission of input types. The test script is parametrized for
input type and expected type. Each test file simply call one test
script in common-interactive-validation-required.js.

The test script checks:
  - Don't submit form when required value isn't presented.
  - Submit form when required value is presented.

* fast/forms/date/date-interactive-validation-required-expected.txt: Added.
* fast/forms/date/date-interactive-validation-required.html: Added.
* fast/forms/datetime/datetime-interactive-validation-required-expected.txt: Added.
* fast/forms/datetime/datetime-interactive-validation-required.html: Added.
* fast/forms/datetimelocal/datetimelocal-interactive-validation-required-expected.txt: Added.
* fast/forms/datetimelocal/datetimelocal-interactive-validation-required.html: Added.
* fast/forms/month/month-interactive-validation-required-expected.txt: Added.
* fast/forms/month/month-interactive-validation-required.html: Added.
* fast/forms/number/number-interactive-validation-required-expected.txt: Added.
* fast/forms/number/number-interactive-validation-required.html: Added.
* fast/forms/resources/common-interactive-validation-required.js: Added.
* fast/forms/time/time-interactive-validation-required-expected.txt: Added.
* fast/forms/time/time-interactive-validation-required.html: Added.
* fast/forms/week/week-interactive-validation-required-expected.txt: Added.
* fast/forms/week/week-interactive-validation-required.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127564 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 48c2c98..ae61f76 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,35 @@
+2012-09-05  Yoshifumi Inoue  <yosin@chromium.org>
+
+        [Tests] We should have interactive validation of required value for the "input" element
+        https://bugs.webkit.org/show_bug.cgi?id=95817
+
+        Reviewed by Kent Tamura.
+
+        This patch adds tests for required attribute handling on form
+        submission of input types. The test script is parametrized for
+        input type and expected type. Each test file simply call one test
+        script in common-interactive-validation-required.js.
+
+        The test script checks:
+          - Don't submit form when required value isn't presented.
+          - Submit form when required value is presented.
+
+        * fast/forms/date/date-interactive-validation-required-expected.txt: Added.
+        * fast/forms/date/date-interactive-validation-required.html: Added.
+        * fast/forms/datetime/datetime-interactive-validation-required-expected.txt: Added.
+        * fast/forms/datetime/datetime-interactive-validation-required.html: Added.
+        * fast/forms/datetimelocal/datetimelocal-interactive-validation-required-expected.txt: Added.
+        * fast/forms/datetimelocal/datetimelocal-interactive-validation-required.html: Added.
+        * fast/forms/month/month-interactive-validation-required-expected.txt: Added.
+        * fast/forms/month/month-interactive-validation-required.html: Added.
+        * fast/forms/number/number-interactive-validation-required-expected.txt: Added.
+        * fast/forms/number/number-interactive-validation-required.html: Added.
+        * fast/forms/resources/common-interactive-validation-required.js: Added.
+        * fast/forms/time/time-interactive-validation-required-expected.txt: Added.
+        * fast/forms/time/time-interactive-validation-required.html: Added.
+        * fast/forms/week/week-interactive-validation-required-expected.txt: Added.
+        * fast/forms/week/week-interactive-validation-required.html: Added.
+
 2012-09-05  Mike Lawther  <mikelawther@chromium.org>
 
         Moved mac results to be the generic results, and the existing result to be the chromium
diff --git a/LayoutTests/fast/forms/date/date-interactive-validation-required-expected.txt b/LayoutTests/fast/forms/date/date-interactive-validation-required-expected.txt
new file mode 100644
index 0000000..af050ec
--- /dev/null
+++ b/LayoutTests/fast/forms/date/date-interactive-validation-required-expected.txt
@@ -0,0 +1,10 @@
+Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS queryValues["test"] is "2012-08-25"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/date/date-interactive-validation-required.html b/LayoutTests/fast/forms/date/date-interactive-validation-required.html
new file mode 100644
index 0000000..ebba9c4
--- /dev/null
+++ b/LayoutTests/fast/forms/date/date-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '2012-08-25',
+    'inputType' : 'date',
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/datetime/datetime-interactive-validation-required.html b/LayoutTests/fast/forms/datetime/datetime-interactive-validation-required.html
new file mode 100644
index 0000000..2a73441
--- /dev/null
+++ b/LayoutTests/fast/forms/datetime/datetime-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '1982-11-02T12:34Z',
+    'inputType' : 'datetime',
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/datetimelocal/datetimelocal-interactive-validation-required-expected.txt b/LayoutTests/fast/forms/datetimelocal/datetimelocal-interactive-validation-required-expected.txt
new file mode 100644
index 0000000..ff144c2
--- /dev/null
+++ b/LayoutTests/fast/forms/datetimelocal/datetimelocal-interactive-validation-required-expected.txt
@@ -0,0 +1,10 @@
+Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS queryValues["test"] is "1982-11-02T12:34"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/datetimelocal/datetimelocal-interactive-validation-required.html b/LayoutTests/fast/forms/datetimelocal/datetimelocal-interactive-validation-required.html
new file mode 100644
index 0000000..078b014
--- /dev/null
+++ b/LayoutTests/fast/forms/datetimelocal/datetimelocal-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '1982-11-02T12:34',
+    'inputType' : 'datetime-local',
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/month/month-interactive-validation-required-expected.txt b/LayoutTests/fast/forms/month/month-interactive-validation-required-expected.txt
new file mode 100644
index 0000000..974ba80
--- /dev/null
+++ b/LayoutTests/fast/forms/month/month-interactive-validation-required-expected.txt
@@ -0,0 +1,10 @@
+Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS queryValues["test"] is "2012-09"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/month/month-interactive-validation-required.html b/LayoutTests/fast/forms/month/month-interactive-validation-required.html
new file mode 100644
index 0000000..8b17013
--- /dev/null
+++ b/LayoutTests/fast/forms/month/month-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '2012-09',
+    'inputType' : 'month',
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/number/number-interactive-validation-required-expected.txt b/LayoutTests/fast/forms/number/number-interactive-validation-required-expected.txt
new file mode 100644
index 0000000..82d9bee
--- /dev/null
+++ b/LayoutTests/fast/forms/number/number-interactive-validation-required-expected.txt
@@ -0,0 +1,10 @@
+Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS queryValues["test"] is "123456789"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/number/number-interactive-validation-required.html b/LayoutTests/fast/forms/number/number-interactive-validation-required.html
new file mode 100644
index 0000000..5a0ea89
--- /dev/null
+++ b/LayoutTests/fast/forms/number/number-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '123456789',
+    'inputType' : 'number',
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/resources/common-interactive-validation-required.js b/LayoutTests/fast/forms/resources/common-interactive-validation-required.js
new file mode 100644
index 0000000..0c79e4b
--- /dev/null
+++ b/LayoutTests/fast/forms/resources/common-interactive-validation-required.js
@@ -0,0 +1,45 @@
+var queryValues = {};
+
+function testInteractiveValidationRequired(config) {
+    description("Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.");
+
+    var expectedValue = config['expectedValue'];
+
+    var keyValuePairs = window.location.search.replace('?', '').split('&');
+    for (var index = 0; index < keyValuePairs.length; ++index) {
+        var keyValue = keyValuePairs[index].split('=');
+        queryValues[keyValue[0]] = unescape(keyValue[1]);
+    }
+
+    if (queryValues['submitted']) {
+        shouldBeEqualToString('queryValues["test"]', expectedValue);
+        window.jsTestIsAsync = true;
+        finishJSTest();
+        return;
+    }
+
+    var form = document.createElement("form");
+    form.setAttribute("action", window.location);
+    form.innerHTML = '<input type=hidden name=submitted value=1><input  id=submit type=submit><input id=test name=test type=' + config['inputType'] + ' required>';
+    document.body.appendChild(form);
+
+    debug('Submit without required value');
+    document.getElementById('submit').click();
+
+    if (document.activeElement.id != 'test') {
+        testFailed('Focus should be on test element.');
+        finishJSTest();
+        return;
+    }
+
+    debug('Submit with required value');
+    document.getElementById('test').value = expectedValue;
+    document.getElementById('submit').click();
+    testFailed('The form was not submitted.');
+    finishJSTest();
+}
+
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+wasPostTestScriptParsed = true;
diff --git a/LayoutTests/fast/forms/time/time-interactive-validation-required-expected.txt b/LayoutTests/fast/forms/time/time-interactive-validation-required-expected.txt
new file mode 100644
index 0000000..6fe0e4c
--- /dev/null
+++ b/LayoutTests/fast/forms/time/time-interactive-validation-required-expected.txt
@@ -0,0 +1,10 @@
+Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS queryValues["test"] is "12:34"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/time/time-interactive-validation-required.html b/LayoutTests/fast/forms/time/time-interactive-validation-required.html
new file mode 100644
index 0000000..8be9358
--- /dev/null
+++ b/LayoutTests/fast/forms/time/time-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '12:34',
+    'inputType' : 'time',
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/week/week-interactive-validation-required-expected.txt b/LayoutTests/fast/forms/week/week-interactive-validation-required-expected.txt
new file mode 100644
index 0000000..f226ee1
--- /dev/null
+++ b/LayoutTests/fast/forms/week/week-interactive-validation-required-expected.txt
@@ -0,0 +1,10 @@
+Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS queryValues["test"] is "2012-W15"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/week/week-interactive-validation-required.html b/LayoutTests/fast/forms/week/week-interactive-validation-required.html
new file mode 100644
index 0000000..12a5922
--- /dev/null
+++ b/LayoutTests/fast/forms/week/week-interactive-validation-required.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="../resources/common-interactive-validation-required.js"></script>
+</head>
+<body>
+<script>
+testInteractiveValidationRequired({
+    'expectedValue' : '2012-W15',
+    'inputType' : 'week',
+});
+</script>
+</body>
+</html>