1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug677752.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=677752 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 677752</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=677752">Mozilla Bug 677752</a> 1.17 +<p id="display"></p> 1.18 +<div id="content"> 1.19 + <section contenteditable> foo bar </section> 1.20 + <div contenteditable> foo bar </div> 1.21 + <p contenteditable> foo bar </p> 1.22 +</div> 1.23 + 1.24 +<pre id="test"> 1.25 +<script type="application/javascript"> 1.26 + 1.27 +/** Test for Bug 677752 **/ 1.28 +SimpleTest.waitForExplicitFinish(); 1.29 +SimpleTest.waitForFocus(runTests); 1.30 + 1.31 +function selectEditor(aEditor) { 1.32 + aEditor.focus(); 1.33 + var selection = window.getSelection(); 1.34 + selection.selectAllChildren(aEditor); 1.35 + selection.collapseToStart(); 1.36 +} 1.37 + 1.38 +function runTests() { 1.39 + var editor, node, initialHTML; 1.40 + document.execCommand('styleWithCSS', false, true); 1.41 + 1.42 + // editable <section> 1.43 + editor = document.querySelector("section[contenteditable]"); 1.44 + initialHTML = editor.innerHTML; 1.45 + selectEditor(editor); 1.46 + // editable <section>: justify 1.47 + document.execCommand("justifyright", false, null); 1.48 + node = editor.querySelector("*"); 1.49 + is(node.nodeName.toLowerCase(), "div", "'justifyright' should create a <div> in the editable <section>."); 1.50 + is(node.style.textAlign, "right", "'justifyright' should create a 'text-align: right' CSS rule."); 1.51 + document.execCommand("undo", false, null); 1.52 + // editable <section>: indent 1.53 + document.execCommand("indent", false, null); 1.54 + node = editor.querySelector("*"); 1.55 + is(node.nodeName.toLowerCase(), "div", "'indent' should create a <div> in the editable <section>."); 1.56 + is(node.style.marginLeft, "40px", "'indent' should create a 'margin-left: 40px' CSS rule."); 1.57 + // editable <section>: undo with outdent 1.58 + // this should remove the whole <div> but only removing the CSS rule would be acceptable, too 1.59 + document.execCommand("outdent", false, null); 1.60 + is(editor.innerHTML, initialHTML, "'outdent' should undo the 'indent' action."); 1.61 + // editable <section>: outdent again 1.62 + document.execCommand("outdent", false, null); 1.63 + is(editor.innerHTML, initialHTML, "another 'outdent' should not modify the <section> element."); 1.64 + 1.65 + // editable <div> 1.66 + editor = document.querySelector("div[contenteditable]"); 1.67 + initialHTML = editor.innerHTML; 1.68 + selectEditor(editor); 1.69 + // editable <div>: justify 1.70 + document.execCommand("justifyright", false, null); 1.71 + node = editor.querySelector("*"); 1.72 + is(node.nodeName.toLowerCase(), "div", "'justifyright' should create a <div> in the editable <div>."); 1.73 + is(node.style.textAlign, "right", "'justifyright' should create a 'text-align: right' CSS rule."); 1.74 + document.execCommand("undo", false, null); 1.75 + // editable <div>: indent 1.76 + document.execCommand("indent", false, null); 1.77 + node = editor.querySelector("*"); 1.78 + is(node.nodeName.toLowerCase(), "div", "'indent' should create a <div> in the editable <div>."); 1.79 + is(node.style.marginLeft, "40px", "'indent' should create a 'margin-left: 40px' CSS rule."); 1.80 + // editable <div>: undo with outdent 1.81 + // this should remove the whole <div> but only removing the CSS rule would be acceptable, too 1.82 + document.execCommand("outdent", false, null); 1.83 + is(editor.innerHTML, initialHTML, "'outdent' should undo the 'indent' action."); 1.84 + // editable <div>: outdent again 1.85 + document.execCommand("outdent", false, null); 1.86 + is(editor.innerHTML, initialHTML, "another 'outdent' should not modify the <div> element."); 1.87 + 1.88 + // editable <p> 1.89 + // all block-level commands should be ignored (<p><div/></p> is not valid) 1.90 + editor = document.querySelector("p[contenteditable]"); 1.91 + initialHTML = editor.innerHTML; 1.92 + selectEditor(editor); 1.93 + // editable <p>: justify 1.94 + document.execCommand("justifyright", false, null); 1.95 + is(editor.innerHTML, initialHTML, "'justifyright' should have no effect on <p>."); 1.96 + // editable <p>: indent 1.97 + document.execCommand("indent", false, null); 1.98 + is(editor.innerHTML, initialHTML, "'indent' should have no effect on <p>."); 1.99 + // editable <p>: outdent 1.100 + document.execCommand("outdent", false, null); 1.101 + is(editor.innerHTML, initialHTML, "'outdent' should have no effect on <p>."); 1.102 + 1.103 + // done 1.104 + SimpleTest.finish(); 1.105 +} 1.106 + 1.107 +</script> 1.108 +</pre> 1.109 +</body> 1.110 +</html>