layout/forms/test/test_bug534785.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/test/test_bug534785.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=534785
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 534785</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/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=534785">Mozilla Bug 534785</a>
    1.17 +<p id="display"></p>
    1.18 +<input type="text" value="test">
    1.19 +<div id="reframe">
    1.20 +<textarea></textarea>
    1.21 +<textarea>test</textarea>
    1.22 +<input type="text">
    1.23 +<input type="text" value="test">
    1.24 +</div>
    1.25 +<pre id="test">
    1.26 +<script type="application/javascript">
    1.27 +
    1.28 +/** Test for Bug 534785 **/
    1.29 +
    1.30 +SimpleTest.waitForExplicitFinish();
    1.31 +
    1.32 +SimpleTest.waitForFocus(function() {
    1.33 +  var i = document.querySelector("input");
    1.34 +  i.addEventListener("focus", function() {
    1.35 +    is(i.value, "test", "Sanity check");
    1.36 +
    1.37 +    is(document.activeElement, i, "Should be focused before frame reconstruction");
    1.38 +    synthesizeKey("1", {});
    1.39 +    is(i.value, "1test", "Can accept keyboard events before frame reconstruction");
    1.40 +
    1.41 +    // force frame reconstruction
    1.42 +    i.style.display = "none";
    1.43 +    document.offsetHeight;
    1.44 +    i.style.display = "";
    1.45 +    document.offsetHeight;
    1.46 +
    1.47 +    is(document.activeElement, i, "Should be focused after frame reconstruction");
    1.48 +    synthesizeKey("2", {});
    1.49 +    is(i.value, "12test", "Can accept keyboard events after frame reconstruction");
    1.50 +
    1.51 +    // Make sure reframing happens gracefully
    1.52 +    var reframeDiv = document.getElementById("reframe");
    1.53 +    var textAreaWithoutValue = reframeDiv.querySelectorAll("textarea")[0];
    1.54 +    var textAreaWithValue = reframeDiv.querySelectorAll("textarea")[1];
    1.55 +    var inputWithoutValue = reframeDiv.querySelectorAll("input")[0];
    1.56 +    var inputWithValue = reframeDiv.querySelectorAll("input")[1];
    1.57 +    reframeDiv.style.display = "none";
    1.58 +    document.body.offsetWidth;
    1.59 +    reframeDiv.style.display = "";
    1.60 +    document.body.offsetWidth;
    1.61 +    [textAreaWithoutValue, inputWithoutValue].forEach(function (elem) {
    1.62 +      is(elem.value, "", "Value should persist correctly");
    1.63 +    });
    1.64 +    [textAreaWithValue, inputWithValue].forEach(function (elem) {
    1.65 +      is(elem.value, "test", "Value should persist correctly");
    1.66 +    });
    1.67 +    [inputWithoutValue, inputWithValue].forEach(function (elem) elem.type = "submit");
    1.68 +    document.body.offsetWidth;
    1.69 +    is(inputWithoutValue.value, "", "Value should persist correctly");
    1.70 +    is(inputWithValue.value, "test", "Value should persist correctly");
    1.71 +    [inputWithoutValue, inputWithValue].forEach(function (elem) elem.type = "text");
    1.72 +    document.body.offsetWidth;
    1.73 +    is(inputWithoutValue.value, "", "Value should persist correctly");
    1.74 +    is(inputWithValue.value, "test", "Value should persist correctly");
    1.75 +    [inputWithoutValue, inputWithValue].forEach(function (elem) elem.focus()); // initialze the editor
    1.76 +    reframeDiv.style.display = "none";
    1.77 +    document.body.offsetWidth;
    1.78 +    reframeDiv.style.display = "";
    1.79 +    document.body.offsetWidth;
    1.80 +    is(inputWithoutValue.value, "", "Value should persist correctly with editor");
    1.81 +    is(inputWithValue.value, "test", "Value should persist correctly with editor");
    1.82 +
    1.83 +    SimpleTest.finish();
    1.84 +  }, false);
    1.85 +  i.focus();
    1.86 +});
    1.87 +
    1.88 +</script>
    1.89 +</pre>
    1.90 +</body>
    1.91 +</html>

mercurial