editor/libeditor/html/tests/test_bug677752.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=677752
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 677752</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=677752">Mozilla Bug 677752</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16 <section contenteditable> foo bar </section>
michael@0 17 <div contenteditable> foo bar </div>
michael@0 18 <p contenteditable> foo bar </p>
michael@0 19 </div>
michael@0 20
michael@0 21 <pre id="test">
michael@0 22 <script type="application/javascript">
michael@0 23
michael@0 24 /** Test for Bug 677752 **/
michael@0 25 SimpleTest.waitForExplicitFinish();
michael@0 26 SimpleTest.waitForFocus(runTests);
michael@0 27
michael@0 28 function selectEditor(aEditor) {
michael@0 29 aEditor.focus();
michael@0 30 var selection = window.getSelection();
michael@0 31 selection.selectAllChildren(aEditor);
michael@0 32 selection.collapseToStart();
michael@0 33 }
michael@0 34
michael@0 35 function runTests() {
michael@0 36 var editor, node, initialHTML;
michael@0 37 document.execCommand('styleWithCSS', false, true);
michael@0 38
michael@0 39 // editable <section>
michael@0 40 editor = document.querySelector("section[contenteditable]");
michael@0 41 initialHTML = editor.innerHTML;
michael@0 42 selectEditor(editor);
michael@0 43 // editable <section>: justify
michael@0 44 document.execCommand("justifyright", false, null);
michael@0 45 node = editor.querySelector("*");
michael@0 46 is(node.nodeName.toLowerCase(), "div", "'justifyright' should create a <div> in the editable <section>.");
michael@0 47 is(node.style.textAlign, "right", "'justifyright' should create a 'text-align: right' CSS rule.");
michael@0 48 document.execCommand("undo", false, null);
michael@0 49 // editable <section>: indent
michael@0 50 document.execCommand("indent", false, null);
michael@0 51 node = editor.querySelector("*");
michael@0 52 is(node.nodeName.toLowerCase(), "div", "'indent' should create a <div> in the editable <section>.");
michael@0 53 is(node.style.marginLeft, "40px", "'indent' should create a 'margin-left: 40px' CSS rule.");
michael@0 54 // editable <section>: undo with outdent
michael@0 55 // this should remove the whole <div> but only removing the CSS rule would be acceptable, too
michael@0 56 document.execCommand("outdent", false, null);
michael@0 57 is(editor.innerHTML, initialHTML, "'outdent' should undo the 'indent' action.");
michael@0 58 // editable <section>: outdent again
michael@0 59 document.execCommand("outdent", false, null);
michael@0 60 is(editor.innerHTML, initialHTML, "another 'outdent' should not modify the <section> element.");
michael@0 61
michael@0 62 // editable <div>
michael@0 63 editor = document.querySelector("div[contenteditable]");
michael@0 64 initialHTML = editor.innerHTML;
michael@0 65 selectEditor(editor);
michael@0 66 // editable <div>: justify
michael@0 67 document.execCommand("justifyright", false, null);
michael@0 68 node = editor.querySelector("*");
michael@0 69 is(node.nodeName.toLowerCase(), "div", "'justifyright' should create a <div> in the editable <div>.");
michael@0 70 is(node.style.textAlign, "right", "'justifyright' should create a 'text-align: right' CSS rule.");
michael@0 71 document.execCommand("undo", false, null);
michael@0 72 // editable <div>: indent
michael@0 73 document.execCommand("indent", false, null);
michael@0 74 node = editor.querySelector("*");
michael@0 75 is(node.nodeName.toLowerCase(), "div", "'indent' should create a <div> in the editable <div>.");
michael@0 76 is(node.style.marginLeft, "40px", "'indent' should create a 'margin-left: 40px' CSS rule.");
michael@0 77 // editable <div>: undo with outdent
michael@0 78 // this should remove the whole <div> but only removing the CSS rule would be acceptable, too
michael@0 79 document.execCommand("outdent", false, null);
michael@0 80 is(editor.innerHTML, initialHTML, "'outdent' should undo the 'indent' action.");
michael@0 81 // editable <div>: outdent again
michael@0 82 document.execCommand("outdent", false, null);
michael@0 83 is(editor.innerHTML, initialHTML, "another 'outdent' should not modify the <div> element.");
michael@0 84
michael@0 85 // editable <p>
michael@0 86 // all block-level commands should be ignored (<p><div/></p> is not valid)
michael@0 87 editor = document.querySelector("p[contenteditable]");
michael@0 88 initialHTML = editor.innerHTML;
michael@0 89 selectEditor(editor);
michael@0 90 // editable <p>: justify
michael@0 91 document.execCommand("justifyright", false, null);
michael@0 92 is(editor.innerHTML, initialHTML, "'justifyright' should have no effect on <p>.");
michael@0 93 // editable <p>: indent
michael@0 94 document.execCommand("indent", false, null);
michael@0 95 is(editor.innerHTML, initialHTML, "'indent' should have no effect on <p>.");
michael@0 96 // editable <p>: outdent
michael@0 97 document.execCommand("outdent", false, null);
michael@0 98 is(editor.innerHTML, initialHTML, "'outdent' should have no effect on <p>.");
michael@0 99
michael@0 100 // done
michael@0 101 SimpleTest.finish();
michael@0 102 }
michael@0 103
michael@0 104 </script>
michael@0 105 </pre>
michael@0 106 </body>
michael@0 107 </html>

mercurial