1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/test/test_bug542914.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=542914 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 542914</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=542914">Mozilla Bug 542914</a> 1.17 +<p id="display"> 1.18 + <input type="text" id="a" value="test"> 1.19 + <input type="text" id="b"> 1.20 + <input type="text" id="c"> 1.21 +</p> 1.22 +<div id="content" style="display: none"> 1.23 + 1.24 +</div> 1.25 +<pre id="test"> 1.26 +<script type="application/javascript"> 1.27 + 1.28 +/** Test for Bug 542914 **/ 1.29 +SimpleTest.waitForExplicitFinish(); 1.30 +function runTests(callback, type) { 1.31 + var a = $("a"); 1.32 + 1.33 + // Test that the initial value of the control is available to script 1.34 + // without initilization of the editor 1.35 + is(a.value, "test", "The value is available before initialization"); 1.36 + // Initialize the editor 1.37 + a.focus(); 1.38 + // Test that the value does not change after initialization 1.39 + is(a.value, "test", "The value does not change after initializtion"); 1.40 + 1.41 + var b = $("b"); 1.42 + 1.43 + // Test that the initial value is empty before initialization. 1.44 + is(b.value, "", "The value is empty before initialization"); 1.45 + // Make sure that the value can be changed before initialization 1.46 + b.value ="some value"; 1.47 + is(b.value, "some value", "The value can be changed before initialization"); 1.48 + // Initialize the editor 1.49 + b.focus(); 1.50 + // Make sure that the value does not change after initialization 1.51 + is(b.value, "some value", "The value does not change after initialization"); 1.52 + // Make sure that the value does not change if the element is hidden 1.53 + b.style.display = "none"; 1.54 + document.body.offsetHeight; 1.55 + is(b.value, "some value", "The value does not change while hidden"); 1.56 + b.style.display = ""; 1.57 + document.body.offsetHeight; 1.58 + b.focus(); 1.59 + is(b.value, "some value", "The value does not change after being shown"); 1.60 + 1.61 + var c = $("c"); 1.62 + 1.63 + // Make sure that the control accepts input events without explicit initialization 1.64 + is(c.value, "", "Control is empty initially"); 1.65 + c.focus(); 1.66 + sendChar("a"); 1.67 + is(c.value, "a", "Control accepts input without explicit initialization"); 1.68 + // Make sure that the control retains its caret position 1.69 + c.focus(); 1.70 + c.blur(); 1.71 + c.focus(); 1.72 + sendChar("b"); 1.73 + is(c.value, "ab", "Control retains caret position after being re-focused"); 1.74 + 1.75 + var d = document.createElement("input"); 1.76 + d.setAttribute("type", type); 1.77 + $("display").appendChild(d); 1.78 + document.body.offsetHeight; 1.79 + 1.80 + // Make sure dynamically injected inputs work as expected 1.81 + is(d.value, "", "Dynamic control's initial value should be empty"); 1.82 + d.value = "new"; 1.83 + d.focus(); 1.84 + is(d.value, "new", "Dynamic control's value can be set before initialization"); 1.85 + sendChar("x"); 1.86 + is(d.value, "xnew", "Dynamic control accepts keyboard input without explicit initialization"); 1.87 + $("display").removeChild(d); 1.88 + is(d.value, "xnew", "Dynamic control retains value after being removed from the document"); 1.89 + 1.90 + callback(); 1.91 +} 1.92 + 1.93 +var gPreviousType = "text"; 1.94 +function setTypes(aType) { 1.95 + var content = document.getElementById("display"); 1.96 + content.innerHTML = content.innerHTML.replace(gPreviousType, aType); 1.97 + gPreviousType = aType; 1.98 +} 1.99 + 1.100 +addLoadEvent(function() { 1.101 + ok(true, "Running tests on <input type=text>"); 1.102 + runTests(function() { 1.103 + ok(true, "Running tests on <input type=password>"); 1.104 + setTypes("password"); 1.105 + runTests(function() { 1.106 + ok(true, "Running tests on <input type=tel>"); 1.107 + setTypes("tel"); 1.108 + runTests(function() { 1.109 + SimpleTest.finish(); 1.110 + }, "tel"); 1.111 + }, "password"); 1.112 + }, "text"); 1.113 +}); 1.114 + 1.115 +</script> 1.116 +</pre> 1.117 +</body> 1.118 +</html>