1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=737851
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 737851</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=737851">Mozilla Bug 737851</a>
<p id="display"></p>
<div id="content">
<iframe id="frame" width="800px" height="600px" srcdoc='
<html>
<body style="display:none;">
<h3>Checking persistence of inputs through js inserts and moves</h3>
<div id="test">
<input id="a"/>
<input id="b"/>
<form id="form1">
<input id="c"/>
<input id="d"/>
</form>
<form id="form2">
<input id="radio1" type="radio" name="radio"/>
<input type="radio" name="radio"/>
<input type="radio" name="radio"/>
<input type="radio" name="radio"/>
</form>
<input id="e"/>
</div>
<h3>Bug 728798: checking persistence of inputs when forward-using @form</h3>
<div>
<input id="728798-a" form="728798-form" name="a"/>
<form id="728798-form">
<input id="728798-b" form="728798-form" name="b"/>
<input id="728798-c" name="c"/>
</form>
<input id="728798-d" form="728798-form" name="d"/>
</div>
</body>
</html>
'></iframe>
</div>
<pre id="test">
<script type="text/javascript">
var frameElem = document.getElementById("frame");
var frame = frameElem.contentWindow;
/* -- Main test run -- */
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
shuffle();
fill();
frameElem.addEventListener("load", function() {
shuffle();
checkAllFields();
SimpleTest.finish();
});
frame.location.reload();
})
/* -- Input fields js changes and moves -- */
function shuffle() {
var framedoc = frame.document;
// Insert a button (toplevel)
var btn = framedoc.createElement("button");
var testdiv = framedoc.getElementById("test");
testdiv.insertBefore(btn, framedoc.getElementById("b"));
// Insert a dynamically generated input (in a form)
var newInput = framedoc.createElement("input");
newInput.setAttribute("id","c0");
var form1 = framedoc.getElementById("form1");
form1.insertBefore(newInput, form1.firstChild);
// Move an input around
var inputD = framedoc.getElementById("d");
var form2 = framedoc.getElementById("form2");
form2.insertBefore(inputD, form2.firstChild)
// Clone an existing input
var inputE2 = framedoc.getElementById("e").cloneNode(true);
inputE2.setAttribute("id","e2");
testdiv.appendChild(inputE2);
}
/* -- Input fields fill & check -- */
/* Values entered in the input fields (by id) */
var fieldValues = {
'a':'simple input',
'b':'moved by inserting a button before (no form)',
'c0':'dynamically generated input',
'c':'moved by inserting an input before (in a form)',
'd':'moved from a form to another',
'e':'the original',
'e2':'the clone',
'728798-a':'before the form',
'728798-b':'from within the form',
'728798-c':'no form attribute in the form',
'728798-d':'after the form'
}
/* Fields for which the input is changed, and corresponding value
(clone and creation, same behaviour as webkit) */
var changedFields = {
// dynamically generated input field not preserved
'c0':'',
// cloned input field is restored with the value of the original
'e2':fieldValues.e
}
/* Simulate user input by entering the values */
function fill() {
for (id in fieldValues) {
frame.document.getElementById(id).value = fieldValues[id];
}
// an input is inserted before the radios (that may move the selected one by 1)
frame.document.getElementById('radio1').checked = true;
}
/* Check that all the fields are as they have been entered */
function checkAllFields() {
for (id in fieldValues) {
var fieldValue = frame.document.getElementById(id).value;
if (changedFields[id] === undefined) {
is(fieldValue, fieldValues[id],
"Field "+id+" should be restored after reload");
} else {
is(fieldValue, changedFields[id],
"Field "+id+" normally gets a different value after reload");
}
}
ok(frame.document.getElementById('radio1').checked,
"Radio button radio1 should be restored after reload")
}
</script>
</pre>
</body>
</html>
|