editor/libeditor/html/tests/test_bug668599.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=668599
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 668599</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=668599">Mozilla Bug 668599</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16 <div id="test1">
michael@0 17 block <span contenteditable>type here</span> block
michael@0 18 </div>
michael@0 19 <div id="test2">
michael@0 20 <p contenteditable>
michael@0 21 block <span>type here</span> block
michael@0 22 </p>
michael@0 23 </div>
michael@0 24 </div>
michael@0 25
michael@0 26 <pre id="test">
michael@0 27 <script type="application/javascript">
michael@0 28
michael@0 29 /** Test for Bug 668599 **/
michael@0 30 SimpleTest.waitForExplicitFinish();
michael@0 31 SimpleTest.waitForFocus(runTests);
michael@0 32
michael@0 33 function select(element) {
michael@0 34 // select the element text content
michael@0 35 var userSelection = window.getSelection();
michael@0 36 window.getSelection().removeAllRanges();
michael@0 37 var range = document.createRange();
michael@0 38 range.setStart(element.firstChild, 0);
michael@0 39 range.setEnd(element.firstChild, element.textContent.length);
michael@0 40 userSelection.addRange(range);
michael@0 41 };
michael@0 42
michael@0 43 function runTests() {
michael@0 44 var span = document.querySelector("#test1 span");
michael@0 45
michael@0 46 // editable <span> => the <span> *content* should be deleted
michael@0 47 select(span);
michael@0 48 span.focus();
michael@0 49 synthesizeKey("x", {});
michael@0 50 is(span.textContent, "x", "The <span> content should have been replaced by 'x'.");
michael@0 51
michael@0 52 // same thing, but using [Del] instead of typing some text
michael@0 53 document.execCommand("Undo", false, null);
michael@0 54 select(span);
michael@0 55 span.focus();
michael@0 56 synthesizeKey("VK_DELETE", {});
michael@0 57 is(span.textContent, "", "The <span> content should have been deleted.");
michael@0 58
michael@0 59 // <span> in editable block => the <span> *element* should be deleted
michael@0 60 select(document.querySelector("#test2 span"));
michael@0 61 document.querySelector("#test2 [contenteditable]").focus();
michael@0 62 synthesizeKey("VK_DELETE", {});
michael@0 63 is(document.querySelector("#test2 span"), null,
michael@0 64 "The <span> element should have been deleted.");
michael@0 65
michael@0 66 // done
michael@0 67 SimpleTest.finish();
michael@0 68 }
michael@0 69
michael@0 70 </script>
michael@0 71 </pre>
michael@0 72 </body>
michael@0 73 </html>

mercurial