test_bug345339.html (3123B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=345339 5 --> 6 <head> 7 <title>Test for Bug 345339</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=345339">Mozilla Bug 345339</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 </div> 16 <iframe id="testframe" 17 src="http://mochi.test:8888/tests/dom/base/test/345339_iframe.html"> 18 </iframe> 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 /** Test for Bug 345339 */ 22 SimpleTest.waitForExplicitFinish(); 23 24 const testData = "Test data\n"; 25 let file = new File([testData], 26 "345339_test.file", 27 { type: "text/plain" }); 28 29 function afterLoad() { 30 var iframeDoc = $("testframe").contentDocument; 31 32 /* change all the form controls */ 33 iframeDoc.getElementById("select").selectedIndex = 1; 34 iframeDoc.getElementById("radio2").checked = true; 35 iframeDoc.getElementById("password").value = "123456"; 36 iframeDoc.getElementById("hidden").value = "gecko"; 37 38 // Toggle the one field to a password type then text type like password 39 // visibility toggles on the web do. 40 iframeDoc.getElementById("passwordToggle").type = "password"; 41 iframeDoc.getElementById("passwordToggle").value = "abcdef"; 42 iframeDoc.getElementById("passwordToggle").type = ""; 43 44 SpecialPowers.wrap(iframeDoc).getElementById("file").mozSetFileArray([file]); 45 46 /* Reload the page */ 47 $("testframe").setAttribute("onload", "afterReload()"); 48 iframeDoc.location.reload(); 49 } 50 51 addLoadEvent(afterLoad); 52 53 function afterReload() { 54 var iframeDoc = $("testframe").contentDocument; 55 56 is(iframeDoc.getElementById("select").selectedIndex, 1, 57 "select element selected index preserved"); 58 is(iframeDoc.getElementById("radio1").checked, false, 59 "radio button #1 value preserved"); 60 is(iframeDoc.getElementById("radio2").checked, true, 61 "radio button #2 value preserved"); 62 isnot(iframeDoc.getElementById("password").value, "123456", 63 "password field value forgotten"); 64 is(iframeDoc.getElementById("hidden").value, "gecko", 65 "hidden field value preserved"); 66 is(iframeDoc.getElementById("passwordToggle").value, "", 67 "former password field value not saved"); 68 69 // The new file object isn't ===, but it's extensionally equal: 70 let newFile = iframeDoc.getElementById("file").files[0]; 71 for (let prop of ["name", "lastModified", "size", "type"]) { 72 is(newFile[prop], file[prop], 73 "file field " + prop + " property preserved"); 74 } 75 let reader = new FileReader(); 76 reader.onloadend = function() { 77 SimpleTest.finish(); 78 }; 79 reader.onload = function() { 80 is(reader.result, testData, 81 "file field contents preserved") 82 }; 83 reader.onerror = function() { 84 is(reader.error, null, 85 "FileReader error"); 86 }; 87 reader.readAsText(newFile); 88 } 89 </script> 90 </pre> 91 </body> 92 </html>