editor/libeditor/html/tests/test_bug442186.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=442186
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 442186</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=442186">Mozilla Bug 442186</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16 <h2> two &lt;div&gt; containers </h2>
michael@0 17 <section contenteditable id="test1">
michael@0 18 <div> First paragraph with some text. </div>
michael@0 19 <div> Second paragraph with some text. </div>
michael@0 20 </section>
michael@0 21
michael@0 22 <h2> two paragraphs </h2>
michael@0 23 <section contenteditable id="test2">
michael@0 24 <p> First paragraph with some text. </p>
michael@0 25 <p> Second paragraph with some text. </p>
michael@0 26 </section>
michael@0 27
michael@0 28 <h2> one text node, one paragraph </h2>
michael@0 29 <section contenteditable id="test3">
michael@0 30 First paragraph with some text.
michael@0 31 <p> Second paragraph with some text. </p>
michael@0 32 </section>
michael@0 33 </div>
michael@0 34
michael@0 35 <pre id="test">
michael@0 36 <script type="application/javascript">
michael@0 37
michael@0 38 /** Test for Bug 442186 **/
michael@0 39 SimpleTest.waitForExplicitFinish();
michael@0 40 SimpleTest.waitForFocus(runTests);
michael@0 41
michael@0 42 function justify(textNode, pos) {
michael@0 43 if (!pos) pos = 10;
michael@0 44
michael@0 45 // put the caret on the requested character
michael@0 46 var range = document.createRange();
michael@0 47 var sel = window.getSelection();
michael@0 48 range.setStart(textNode, pos);
michael@0 49 range.setEnd(textNode, pos);
michael@0 50 sel.addRange(range);
michael@0 51
michael@0 52 // align
michael@0 53 document.execCommand("justifyright", false, null);
michael@0 54 }
michael@0 55
michael@0 56 function runTests() {
michael@0 57 document.execCommand("stylewithcss", false, "true");
michael@0 58
michael@0 59 const test1 = document.getElementById("test1");
michael@0 60 const test2 = document.getElementById("test2");
michael@0 61 const test3 = document.getElementById("test3");
michael@0 62
michael@0 63 // #test1: two <div> containers
michael@0 64 const line1 = test1.querySelector("div").firstChild;
michael@0 65 test1.focus();
michael@0 66 justify(line1);
michael@0 67 is(test1.querySelectorAll("*").length, 2,
michael@0 68 "Aligning the first child should not create nor remove any element.");
michael@0 69 is(line1.parentNode.nodeName.toLowerCase(), "div",
michael@0 70 "Aligning the first <div> should not modify its node type.");
michael@0 71 is(line1.parentNode.style.textAlign, "right",
michael@0 72 "Aligning the first <div> should set a 'text-align: right' style rule.");
michael@0 73
michael@0 74 // #test2: two paragraphs
michael@0 75 const line2 = test2.querySelector("p").firstChild;
michael@0 76 test2.focus();
michael@0 77 justify(line2);
michael@0 78 is(test2.querySelectorAll("*").length, 2,
michael@0 79 "Aligning the first child should not create nor remove any element.");
michael@0 80 is(line2.parentNode.nodeName.toLowerCase(), "p",
michael@0 81 "Aligning the first paragraph should not modify its node type.");
michael@0 82 is(line2.parentNode.style.textAlign, "right",
michael@0 83 "Aligning the first paragraph should set a 'text-align: right' style rule.");
michael@0 84
michael@0 85 // #test3: one text node, two paragraphs
michael@0 86 const line3 = test3.firstChild;
michael@0 87 test3.focus();
michael@0 88 justify(line3);
michael@0 89 is(test3.querySelectorAll("*").length, 2,
michael@0 90 "Aligning the first child should create a block element.");
michael@0 91 is(line3.parentNode.nodeName.toLowerCase(), "div",
michael@0 92 "Aligning the first child should create a block element.");
michael@0 93 is(line3.parentNode.style.textAlign, "right",
michael@0 94 "Aligning the first line should set a 'text-align: right' style rule.");
michael@0 95
michael@0 96 // done
michael@0 97 SimpleTest.finish();
michael@0 98 }
michael@0 99
michael@0 100 </script>
michael@0 101 </pre>
michael@0 102 </body>
michael@0 103 </html>

mercurial