submit-entity-body.html (5791B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <meta name="timeout" content="long"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script> 7 var simple_tests = [ 8 { 9 name: "form submission from form should navigate to url with x-www-form-urlencoded", 10 input: "<input name=foo value=bara>", 11 enctype: "application/x-www-form-urlencoded", 12 submitelement: "", 13 submitaction: function(doc) { doc.getElementById("testform").submit(); } 14 }, 15 { 16 name: "form submission from form should navigate to url with multipart/form-data", 17 input: "<textarea name=foo>bar</textarea>", 18 enctype: "multipart/form-data", 19 submitelement: "", 20 submitaction: function(doc) { doc.getElementById("testform").submit(); } 21 }, 22 { 23 name: "form submission from form should navigate to url with text/plain", 24 input: "<textarea name=qux>baz</textarea>", 25 enctype: "text/plain", 26 submitelement: "", 27 submitaction: function(doc) { doc.getElementById("testform").submit(); } 28 }, 29 { 30 name: "form submission from button should navigate to url with x-www-form-urlencoded", 31 input: "<input name=foo value=bara>", 32 enctype: "application/x-www-form-urlencoded", 33 submitelement: "<button id=buttonsubmit type=\"submit\">Submit</button>", 34 submitaction: function(doc) { doc.getElementById("buttonsubmit").click(); } 35 }, 36 { 37 name: "form submission from button should navigate to url with multipart/form-data", 38 input: "<textarea name=foo>bar</textarea>", 39 enctype: "multipart/form-data", 40 submitelement: "<button id=buttonsubmit type=\"submit\">Submit</button>", 41 submitaction: function(doc) { doc.getElementById("buttonsubmit").click(); } 42 }, 43 { 44 name: "form submission from button should navigate to url with text/plain", 45 input: "<textarea name=qux>baz</textarea>", 46 enctype: "text/plain", 47 submitelement: "<button id=buttonsubmit type=\"submit\">Submit</button>", 48 submitaction: function(doc) { doc.getElementById("buttonsubmit").click(); } 49 }, 50 { 51 name: "form submission from input should navigate to url with x-www-form-urlencoded", 52 input: "<input name=foo value=bara>", 53 enctype: "application/x-www-form-urlencoded", 54 submitelement: "<input id=inputsubmit type=\"submit\">Submit</input>", 55 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); } 56 }, 57 { 58 name: "form submission from input should navigate to url with multipart/form-data", 59 input: "<textarea name=foo>bar</textarea>", 60 enctype: "multipart/form-data", 61 submitelement: "<input id=inputsubmit type=\"submit\">Submit</input>", 62 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); } 63 }, 64 { 65 name: "form submission from input should navigate to url with text/plain", 66 input: "<input name=qux value=baz>", 67 enctype: "text/plain", 68 submitelement: "<input id=inputsubmit type=\"submit\">Submit</input>", 69 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); } 70 }, 71 { 72 name: "form submission from submit input should contain submit button value", 73 input: "<button type=submit name=notclicked value=nope>not clicked</button>", 74 enctype: "application/x-www-form-urlencoded", 75 submitelement: "<button id=inputsubmit type=\"submit\" name=foo value=bara>Submit</button>", 76 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); } 77 }, 78 { 79 name: "form submission from submit button should contain submit button value", 80 input: "<input type=submit name=notclicked value=nope/>", 81 enctype: "application/x-www-form-urlencoded", 82 submitelement: "<input id=inputsubmit type=\"submit\" name=foo value=bara >", 83 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); } 84 }, 85 { 86 name: "form submission from image input should contain entries for its clicked coordinate", 87 input: "<input type=submit name=notclicked value=nope/>", 88 enctype: "application/x-www-form-urlencoded", 89 submitelement: "<input id=inputsubmit type=image name=foo>", 90 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); }, 91 expected_body: "foo.x=0&foo.y=0" 92 }, 93 { 94 name: "form submission from image input should only contain entries for the submitter's clicked coordinate when multiple image inputs are present", 95 input: "<input type=image name=bar>", 96 enctype: "application/x-www-form-urlencoded", 97 submitelement: "<input id=inputsubmit type=image name=foo>", 98 submitaction: function(doc) { doc.getElementById("inputsubmit").click(); }, 99 expected_body: "foo.x=0&foo.y=0" 100 }, 101 ]; 102 simple_tests.forEach(function(test_obj) { 103 test_obj.test = async_test(test_obj.name); 104 }); 105 function run_simple_test() { 106 if (simple_tests.length == 0) { 107 return; 108 } 109 var test_obj = simple_tests.pop(); 110 var enctype = test_obj.enctype || "application/x-www-form-urlencoded"; 111 var query = test_obj.expected_body ? "expected_body=" + encodeURIComponent(test_obj.expected_body) : "query=1"; 112 var t = test_obj.test; 113 var testframe = document.getElementById("testframe"); 114 var testdocument = testframe.contentWindow.document; 115 testdocument.body.innerHTML = 116 "<form id=testform method=post action=\"/html/semantics/forms/form-submission-0/resources/form-submission.py?" + query + "\" enctype=\"" + enctype + "\">" + 117 test_obj.input + 118 test_obj.submitelement + 119 "</form>"; 120 testframe.onload = function() { 121 t.step(function (){ 122 var response = testframe.contentDocument.documentElement.textContent; 123 assert_equals(response, "OK"); 124 }); 125 t.done(); 126 run_simple_test(); 127 }; 128 test_obj.submitaction(testdocument); 129 } 130 </script> 131 <iframe id=testframe src="/common/blank.html" onload="run_simple_test();"></iframe>