test_bug277724.html (4122B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=277724 5 --> 6 <head> 7 <title>Test for Bug 277724</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=277724">Mozilla Bug 277724</a> 13 <p id="display"></p> 14 <pre id="test"> 15 <script class="testbody" type="text/javascript"> 16 17 /** Test for Bug 277724 */ 18 19 var childUnloaded = false; 20 21 var nodes = [ 22 [ "select", HTMLSelectElement ], 23 [ "textarea", HTMLTextAreaElement ], 24 [ "text", HTMLInputElement ], 25 [ "password", HTMLInputElement ], 26 [ "checkbox", HTMLInputElement ], 27 [ "radio", HTMLInputElement ], 28 [ "image", HTMLInputElement ], 29 [ "submit", HTMLInputElement ], 30 [ "reset", HTMLInputElement ], 31 [ "button input", HTMLInputElement ], 32 [ "hidden", HTMLInputElement ], 33 [ "file", HTMLInputElement ], 34 [ "submit button", HTMLButtonElement ], 35 [ "reset button", HTMLButtonElement ], 36 [ "button", HTMLButtonElement ] 37 ]; 38 39 function soon(f) { 40 return function() { setTimeout(f, 0); } 41 } 42 43 function startTest(frameid) { 44 is(childUnloaded, false, "Child not unloaded yet"); 45 46 var doc = $(frameid).contentDocument; 47 var win = $(frameid).contentWindow; 48 ok(doc instanceof win.Document, "doc should be a document"); 49 50 for (var i = 0; i < nodes.length; ++i) { 51 var id = nodes[i][0]; 52 var node = doc.getElementById(id); 53 ok(node instanceof win[nodes[i][1].name], id + " should be a " + nodes[i][1]); 54 is(node.disabled, false, "check for " + id + " state"); 55 node.disabled = true; 56 is(node.disabled, true, "check for " + id + " state change"); 57 } 58 59 $(frameid).onload = soon(function() { continueTest(frameid) }); 60 61 // Do this off a timeout so it's not treated like a replace load. 62 function loadBlank() { 63 $(frameid).contentWindow.location = "about:blank"; 64 } 65 setTimeout(loadBlank, 0); 66 } 67 68 function continueTest(frameid) { 69 is(childUnloaded, true, "Unload handler should have fired"); 70 var doc = $(frameid).contentDocument; 71 var win = $(frameid).contentWindow; 72 ok(doc instanceof win.Document, "doc should be a document"); 73 74 for (var i = 0; i < nodes.length; ++i) { 75 var id = nodes[i][0]; 76 var node = doc.getElementById(id); 77 ok(node === null, id + " should be null"); 78 } 79 80 $(frameid).onload = soon(function() { finishTest(frameid); }); 81 82 // Do this off a timeout too. Why, I'm not sure. Something in session 83 // history creates another history state if we don't. :( 84 function goBack() { 85 $(frameid).contentWindow.history.back(); 86 } 87 setTimeout(goBack, 0); 88 } 89 90 // XXXbz this is a nasty hack to work around the XML content sink not being 91 // incremental, so that the _first_ control we test is ok but others are not. 92 var testIs = is; 93 var once = false; 94 function flipper(a, b, c) { 95 if (once) { 96 todo(a == b, c); 97 } else { 98 once = true; 99 is(a, b, c); 100 } 101 } 102 103 function finishTest(frameid) { 104 var doc = $(frameid).contentDocument; 105 var win = $(frameid).contentWindow; 106 ok(doc instanceof win.Document, "doc should be a document"); 107 108 for (var i = 0; i < nodes.length; ++i) { 109 var id = nodes[i][0]; 110 var node = doc.getElementById(id); 111 ok(node instanceof win[nodes[i][1].name], id + " should be a " + nodes[i][1]); 112 //testIs(node.disabled, true, "check for " + id + " state restore"); 113 } 114 115 if (frameid == "frame2") { 116 SimpleTest.finish(); 117 } else { 118 childUnloaded = false; 119 120 // XXXbz this is a nasty hack to deal with the content sink. See above. 121 testIs = flipper; 122 123 $("frame2").onload = soon(function() { startTest("frame2"); }); 124 $("frame2").src = "bug277724_iframe2.xhtml"; 125 } 126 } 127 128 SimpleTest.waitForExplicitFinish(); 129 </script> 130 </pre> 131 132 <!-- Don't use display:none, since we don't support framestate restoration 133 without a frame tree --> 134 <div id="content" style="visibility: hidden"> 135 <iframe src="bug277724_iframe1.html" id="frame1" 136 onload="setTimeout(function() { startTest('frame1') }, 0)"></iframe> 137 <iframe src="" id="frame2"></iframe> 138 </div> 139 </body> 140 </html>