1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug442186.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=442186 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 442186</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=442186">Mozilla Bug 442186</a> 1.17 +<p id="display"></p> 1.18 +<div id="content"> 1.19 + <h2> two <div> containers </h2> 1.20 + <section contenteditable id="test1"> 1.21 + <div> First paragraph with some text. </div> 1.22 + <div> Second paragraph with some text. </div> 1.23 + </section> 1.24 + 1.25 + <h2> two paragraphs </h2> 1.26 + <section contenteditable id="test2"> 1.27 + <p> First paragraph with some text. </p> 1.28 + <p> Second paragraph with some text. </p> 1.29 + </section> 1.30 + 1.31 + <h2> one text node, one paragraph </h2> 1.32 + <section contenteditable id="test3"> 1.33 + First paragraph with some text. 1.34 + <p> Second paragraph with some text. </p> 1.35 + </section> 1.36 +</div> 1.37 + 1.38 +<pre id="test"> 1.39 +<script type="application/javascript"> 1.40 + 1.41 +/** Test for Bug 442186 **/ 1.42 +SimpleTest.waitForExplicitFinish(); 1.43 +SimpleTest.waitForFocus(runTests); 1.44 + 1.45 +function justify(textNode, pos) { 1.46 + if (!pos) pos = 10; 1.47 + 1.48 + // put the caret on the requested character 1.49 + var range = document.createRange(); 1.50 + var sel = window.getSelection(); 1.51 + range.setStart(textNode, pos); 1.52 + range.setEnd(textNode, pos); 1.53 + sel.addRange(range); 1.54 + 1.55 + // align 1.56 + document.execCommand("justifyright", false, null); 1.57 +} 1.58 + 1.59 +function runTests() { 1.60 + document.execCommand("stylewithcss", false, "true"); 1.61 + 1.62 + const test1 = document.getElementById("test1"); 1.63 + const test2 = document.getElementById("test2"); 1.64 + const test3 = document.getElementById("test3"); 1.65 + 1.66 + // #test1: two <div> containers 1.67 + const line1 = test1.querySelector("div").firstChild; 1.68 + test1.focus(); 1.69 + justify(line1); 1.70 + is(test1.querySelectorAll("*").length, 2, 1.71 + "Aligning the first child should not create nor remove any element."); 1.72 + is(line1.parentNode.nodeName.toLowerCase(), "div", 1.73 + "Aligning the first <div> should not modify its node type."); 1.74 + is(line1.parentNode.style.textAlign, "right", 1.75 + "Aligning the first <div> should set a 'text-align: right' style rule."); 1.76 + 1.77 + // #test2: two paragraphs 1.78 + const line2 = test2.querySelector("p").firstChild; 1.79 + test2.focus(); 1.80 + justify(line2); 1.81 + is(test2.querySelectorAll("*").length, 2, 1.82 + "Aligning the first child should not create nor remove any element."); 1.83 + is(line2.parentNode.nodeName.toLowerCase(), "p", 1.84 + "Aligning the first paragraph should not modify its node type."); 1.85 + is(line2.parentNode.style.textAlign, "right", 1.86 + "Aligning the first paragraph should set a 'text-align: right' style rule."); 1.87 + 1.88 + // #test3: one text node, two paragraphs 1.89 + const line3 = test3.firstChild; 1.90 + test3.focus(); 1.91 + justify(line3); 1.92 + is(test3.querySelectorAll("*").length, 2, 1.93 + "Aligning the first child should create a block element."); 1.94 + is(line3.parentNode.nodeName.toLowerCase(), "div", 1.95 + "Aligning the first child should create a block element."); 1.96 + is(line3.parentNode.style.textAlign, "right", 1.97 + "Aligning the first line should set a 'text-align: right' style rule."); 1.98 + 1.99 + // done 1.100 + SimpleTest.finish(); 1.101 +} 1.102 + 1.103 +</script> 1.104 +</pre> 1.105 +</body> 1.106 +</html>