dom/events/test/test_bug864040.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug864040.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=864040
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 864040</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
    1.15 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.16 +</head>
    1.17 +<body>
    1.18 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=864040">Mozilla Bug 864040</a>
    1.19 +<div id="display">
    1.20 +  <textarea id="ta" rows="5" cols="20"></textarea>
    1.21 +  <div id="ce" contentEditable="true" style="height: 5em;"></div>
    1.22 +</div>
    1.23 +<div id="content" style="display: none">
    1.24 +</div>
    1.25 +<pre id="test">
    1.26 +  <script type="application/javascript">
    1.27 +    /**
    1.28 +    * Test for Bug 864040
    1.29 +    *
    1.30 +    * We use a selection event to set the selection to the end of an editor
    1.31 +    * containing an ending newline. Then we test to see that the caret is
    1.32 +    * actually drawn on the newline.
    1.33 +    */
    1.34 +
    1.35 +    function testSelectEndOfText(elem) {
    1.36 +      var tn = elem.tagName;
    1.37 +      elem.focus();
    1.38 +
    1.39 +      // Enter test string into editor
    1.40 +      var test_string = 'test\n';
    1.41 +      sendString(test_string);
    1.42 +
    1.43 +      // Get the caret position after what we entered
    1.44 +      var result = synthesizeQuerySelectedText();
    1.45 +      ok(result, tn + ': failed to query selection (1)');
    1.46 +      var refoffset = result.offset;
    1.47 +
    1.48 +      // Take a snapshot of where the caret is (on the new line)
    1.49 +      referenceSnapshot = snapshotWindow(window, true /* withCaret */);
    1.50 +      ok(referenceSnapshot, tn + ': failed to take snapshot (1)');
    1.51 +
    1.52 +      // Set selection to the same spot through a selection event
    1.53 +      ok(synthesizeSelectionSet(refoffset, 0, false), tn + ': failed to set selection');
    1.54 +
    1.55 +      // Make sure new selection is the same
    1.56 +      result = synthesizeQuerySelectedText();
    1.57 +      ok(result, tn + ': failed to query selection (2)');
    1.58 +      is(result.offset, refoffset, tn + ': caret is not at the right position');
    1.59 +
    1.60 +      // Take a snapshot of where the new caret is (shoud still be on the new line)
    1.61 +      testSnapshot = snapshotWindow(window, true /* withCaret */);
    1.62 +      ok(testSnapshot, tn + ': failed to take snapshot (2)');
    1.63 +
    1.64 +      // Compare snapshot (should be the same)
    1.65 +      result = compareSnapshots(referenceSnapshot, testSnapshot, true /* expected */)
    1.66 +      ok(result, tn + ': failed to compare snapshots');
    1.67 +      // result = [correct, s1data, s2data]
    1.68 +      ok(result[0], tn + ': caret is not on new line');
    1.69 +      if (!result[0]) {
    1.70 +        dump('Ref: ' + result[1] + '\n');
    1.71 +        dump('Res: ' + result[2] + '\n');
    1.72 +      }
    1.73 +    }
    1.74 +
    1.75 +    function runTests() {
    1.76 +      // we don't test regular <input> because this test is about multiline support
    1.77 +      // test textarea
    1.78 +      testSelectEndOfText(document.getElementById('ta'));
    1.79 +      // test contentEditable
    1.80 +      testSelectEndOfText(document.getElementById('ce'));
    1.81 +      SimpleTest.finish();
    1.82 +    }
    1.83 +
    1.84 +    SimpleTest.waitForExplicitFinish();
    1.85 +
    1.86 +    SimpleTest.waitForFocus(runTests);
    1.87 +  </script>
    1.88 +</pre>
    1.89 +</body>
    1.90 +</html>

mercurial