gecko/editor/libeditor/html/tests/test_bug677752.html
Fabien Cazenave e48e824329 Bug 677752 - [contentEditable] indent and justify* fail on editable nodes that have only one child; r=ehsan
Issue #1: indent/justify* can create non-valid fragments.
When applying a block-level formatting to a text node, Gecko creates a div or
blockquote block around the text node and sets the corresponding "align" or
"style" attribute. This patch checks that the active editing host can contain
such a block-level element.

Issue #2: indent/justify* can modify the active editing host.
On the first child of the editable element, the selection is extended outside of
the active editing host -- which causes a few issues for our test cases.
In this patch, this issue is "solved" by modifying
`nsHTMLEditRules::GetPromotedPoint' for block-level operations.


** About the tests **

Sorry for the long explanation but I prefer to be as sharp as possible when I
have to modify existing unit tests.

This patch raises 34 unit test "failures" which are improvements.
Two test files are concerned and have been modified accordingly:
  * test_htmleditor_keyevent_handling
  * test_richtext2.html

One test has been clarified (no real modification):
  * test_bug414526.html

Of course, a specific unit test has been added, see `test_bug677752.html'.


** editor/libeditor/html/tests/test_htmleditor_keyevent_handling.html **
Outdenting now works properly, which results in 4 `FAIL'.

  * 7372 ERROR TEST-UNEXPECTED-FAIL
      | non-tabbable HTML editor: Shift+Tab after Tab on UL
      - got "<ul><li id=\"target\">ul list item</li></ul>",
      expected "<ul><ul><li id=\"target\">ul list item</li></ul></ul>"

  * 7379 ERROR TEST-UNEXPECTED-FAIL
      | non-tabbable HTML editor: Shift+Tab on UL
      - got "ul list item",
      expected "<ul><li id=\"target\">ul list item</li></ul>"

  * 7415 ERROR TEST-UNEXPECTED-FAIL
      | non-tabbable HTML editor: Shift+Tab after Tab on OL -
      got "<ol><li id=\"target\">ol list item</li></ol>",
      expected "<ol><ol><li id=\"target\">ol list item</li></ol></ol>"

  * 7422 ERROR TEST-UNEXPECTED-FAIL
      | non-tabbable HTML editor: Shfit+Tab on OL
      - got "ol list item",
      expected "<ol><li id=\"target\">ol list item</li></ol>"


** editor/libeditor/html/tests/browserscope/test_richtext2.html **
The 15 tests that now pass result in 15 `FAIL' and 15 `UNEXPECTED_PASS'.
Here's an overview of what we had before the patch:

  * Section A - Apply Formatting Tests: +10 points
                    before patch: 21/31 (Selection:  9/31)
                     after patch: 28/31 (Selection: 12/31)

      FB:BQ_TEXT-1_SI    EXECUTION EXCEPTION
      FB:BQ_TEXT-1_SI    EXECUTION EXCEPTION
      FB:BQ_BR.BR-1_SM   EXECUTION EXCEPTION
      FB:BQ_BR.BR-1_SM   EXECUTION EXCEPTION
      IND_TEXT-1_SI      EXECUTION EXCEPTION
      IND_TEXT-1_SI      EXECUTION EXCEPTION
      JC_TEXT-1_SC       editing host is modified
      JF_TEXT-1_SC       editing host is modified
      JL_TEXT-1_SC       editing host is modified
      JR_TEXT-1_SC       editing host is modified

  * Section AC - Apply Formatting Tests, using styleWithCSS: +5 points
                    before patch:  7/18 (Selection:  5/18)
                     after patch: 12/18 (Selection:  5/18)

      IND_TEXT-1_SI      editing host is modified
      JC_TEXT-1_SC       editing host is modified
      JF_TEXT-1_SC       editing host is modified
      JL_TEXT-1_SC       editing host is modified
      JR_TEXT-1_SC       editing host is modified


** editor/libeditor/html/tests/test_bug414526.html **
This test has been clarified to get more explicit report messages -- the test
themselves haven't been changed. A `todo_is' test has been added.
This test is the one that shows that `IsNodeInActiveEditor' can't be modified,
and that limiting the range promotion for block-level operations is preferrable.
2011-08-23 15:10:14 -04:00

108 lines
4.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=677752
-->
<head>
<title>Test for Bug 677752</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677752">Mozilla Bug 677752</a>
<p id="display"></p>
<div id="content">
<section contenteditable> foo bar </section>
<div contenteditable> foo bar </div>
<p contenteditable> foo bar </p>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 677752 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTests);
function selectEditor(aEditor) {
aEditor.focus();
var selection = window.getSelection();
selection.selectAllChildren(aEditor);
selection.collapseToStart();
}
function runTests() {
var editor, node, initialHTML;
document.execCommand('styleWithCSS', false, true);
// editable <section>
editor = document.querySelector("section[contenteditable]");
initialHTML = editor.innerHTML;
selectEditor(editor);
// editable <section>: justify
document.execCommand("justifyright", false, null);
node = editor.querySelector("*");
is(node.nodeName.toLowerCase(), "div", "'justifyright' should create a <div> in the editable <section>.");
is(node.style.textAlign, "right", "'justifyright' should create a 'text-align: right' CSS rule.");
document.execCommand("undo", false, null);
// editable <section>: indent
document.execCommand("indent", false, null);
node = editor.querySelector("*");
is(node.nodeName.toLowerCase(), "div", "'indent' should create a <div> in the editable <section>.");
is(node.style.marginLeft, "40px", "'indent' should create a 'margin-left: 40px' CSS rule.");
// editable <section>: undo with outdent
// this should remove the whole <div> but only removing the CSS rule would be acceptable, too
document.execCommand("outdent", false, null);
is(editor.innerHTML, initialHTML, "'outdent' should undo the 'indent' action.");
// editable <section>: outdent again
document.execCommand("outdent", false, null);
is(editor.innerHTML, initialHTML, "another 'outdent' should not modify the <section> element.");
// editable <div>
editor = document.querySelector("div[contenteditable]");
initialHTML = editor.innerHTML;
selectEditor(editor);
// editable <div>: justify
document.execCommand("justifyright", false, null);
node = editor.querySelector("*");
is(node.nodeName.toLowerCase(), "div", "'justifyright' should create a <div> in the editable <div>.");
is(node.style.textAlign, "right", "'justifyright' should create a 'text-align: right' CSS rule.");
document.execCommand("undo", false, null);
// editable <div>: indent
document.execCommand("indent", false, null);
node = editor.querySelector("*");
is(node.nodeName.toLowerCase(), "div", "'indent' should create a <div> in the editable <div>.");
is(node.style.marginLeft, "40px", "'indent' should create a 'margin-left: 40px' CSS rule.");
// editable <div>: undo with outdent
// this should remove the whole <div> but only removing the CSS rule would be acceptable, too
document.execCommand("outdent", false, null);
is(editor.innerHTML, initialHTML, "'outdent' should undo the 'indent' action.");
// editable <div>: outdent again
document.execCommand("outdent", false, null);
is(editor.innerHTML, initialHTML, "another 'outdent' should not modify the <div> element.");
// editable <p>
// all block-level commands should be ignored (<p><div/></p> is not valid)
editor = document.querySelector("p[contenteditable]");
initialHTML = editor.innerHTML;
selectEditor(editor);
// editable <p>: justify
document.execCommand("justifyright", false, null);
is(editor.innerHTML, initialHTML, "'justifyright' should have no effect on <p>.");
// editable <p>: indent
document.execCommand("indent", false, null);
is(editor.innerHTML, initialHTML, "'indent' should have no effect on <p>.");
// editable <p>: outdent
document.execCommand("outdent", false, null);
is(editor.innerHTML, initialHTML, "'outdent' should have no effect on <p>.");
// done
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>