Add a test for form submission by <input type=image>
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Nov 2010 08:25:36 +0000 (08:25 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Nov 2010 08:25:36 +0000 (08:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=49302

Reviewed by Shinichiro Hamaji.

* fast/forms/input-image-submit-expected.txt: Added.
* fast/forms/input-image-submit.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@71799 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/input-image-submit-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/input-image-submit.html [new file with mode: 0644]

index 911d512..ab3a940 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-11  Kent Tamura  <tkent@chromium.org>
+
+        Reviewed by Shinichiro Hamaji.
+
+        Add a test for form submission by <input type=image>
+        https://bugs.webkit.org/show_bug.cgi?id=49302
+
+        * fast/forms/input-image-submit-expected.txt: Added.
+        * fast/forms/input-image-submit.html: Added.
+
 2010-11-10  Ryosuke Niwa  <rniwa@webkit.org>
 
         Reviewed by Adam Barth.
diff --git a/LayoutTests/fast/forms/input-image-submit-expected.txt b/LayoutTests/fast/forms/input-image-submit-expected.txt
new file mode 100644 (file)
index 0000000..17fe7db
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS All tests passed.
+
diff --git a/LayoutTests/fast/forms/input-image-submit.html b/LayoutTests/fast/forms/input-image-submit.html
new file mode 100644 (file)
index 0000000..17b622d
--- /dev/null
@@ -0,0 +1,130 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body onload="startTests()">
+
+<form action="input-image-submit.html" method=GET id=form>
+<input type=hidden name=state id=state value=step1>
+<input type=image name=image id=image src=resources/apple.gif value=value>
+</form>
+
+<div id="console"></div>
+<script>
+function gc() {
+    if (window.GCController)
+        return GCController.collect();
+
+    for (var i = 0; i < 10000; i++)
+        var s = new String("");
+}
+
+function notifyDone() {
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+function failAndDone(message) {
+    testFailed(message);
+    notifyDone();
+}
+
+function handleSubmit() {
+    if (state.value == 'to-text-on-submit') {
+        image.type = 'text';
+    } else if (state.value == 'to-image-on-submit') {
+        image.type = 'image';
+    } else if (state.value == 'remove-input-on-submit') {
+        image.parentNode.removeChild(image);
+        image = null;
+        // Try to clear the reference count of the element.
+        gc();
+    }
+}
+
+function handleClick() {
+    if (state.value == 'to-image-on-click') {
+        image.type = 'image'
+    }
+}
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+var state = document.getElementById('state');
+var image = document.getElementById('image');
+image.addEventListener('click', handleClick, false);
+var form = document.getElementById('form');
+form.addEventListener('submit', handleSubmit, false);
+
+function startTests() {
+    var x = image.offsetLeft + 7;
+    var y = image.offsetTop + 11;
+    var clickEvent = document.createEvent('MouseEvent');
+    clickEvent.initMouseEvent('click', true, false, document.defaultView, 1, x, y, x, y, false, false, false, false, 0, document);
+    var enterEvent = document.createEvent('TextEvent');
+    enterEvent.initTextEvent("textInput", true, true, document.defaultView, "\n");
+    var query = window.location.search;
+
+    if (query.indexOf('state=') == -1) {
+        // Step 1: Normal submission with type=image
+        state.value = 'normal';
+        image.dispatchEvent(clickEvent);
+    } else if (query.indexOf('state=normal') != -1) {
+        // Should have image.x=7&image.y=11&image=value.
+        if (query.indexOf('image.x=7&image.y=11&image=value') == -1) {
+            failAndDone('Normal submission failed: ' + query);
+            return;
+        }
+
+        // Step 2: Change the type to text on 'submit' event
+        state.value = 'to-text-on-submit';
+        image.dispatchEvent(clickEvent);
+    } else if (query.indexOf('state=to-text-on-submit') != -1) {
+        // Should have only image=value.
+        if (query.indexOf('image=value') == -1) {
+            failAndDone('Changing to text on submit failed: ' + query);
+            return;
+        }
+
+        // Step 3: Change the type to image on 'submit' event
+        state.value = 'to-image-on-submit';
+        image.type = 'text';
+        image.focus();
+        image.dispatchEvent(enterEvent);
+    } else if (query.indexOf('state=to-image-on-submit') != -1) {
+        // Should have image.x and image.y, but their values are 0.
+        if (query.indexOf('image.x=0&image.y=0&image=value') == -1) {
+            failAndDone('Changing to image on submit failed: ' + query);
+            return;
+        }
+
+        // Step 4: Change the type to image on 'click' event
+        state.value = 'to-image-on-click';
+        image.type = 'text';
+        image.dispatchEvent(clickEvent);
+    } else if (query.indexOf('state=to-image-on-click') != -1) {
+        // Same as the normal submission.
+        if (query.indexOf('image.x=7&image.y=11&image=value') == -1) {
+            failAndDone('Changing to image on click failed: ' + query);
+            return;
+        }
+
+        // Step 5: Removed the image button on 'submit' event
+        state.value = 'remove-input-on-submit';
+        image.dispatchEvent(clickEvent);
+    } else if (query.indexOf('state=remove-input-on-submit') != -1) {
+        // Should have nothing about image.
+        if (query.indexOf('image.x=') != -1 || query.indexOf('image=value') != -1)
+            testFailed('Removing the input on submit failed: ' + query);
+        else
+            testPassed('All tests passed.');
+        notifyDone();
+    }
+}
+</script>
+</body>
+</html>
+