gecko-dev/layout/base/tests/bug558663.html
Masayuki Nakano b808917841 Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default.  However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.

Therefore, it doesn't make sense to keep enabling them in default only on
Gecko.  If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.

And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing").  They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE.  However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value.  And also
those commands are related to state of document.  Therefore, they should be
return as bool value of STATE_ALL instead.  Then,
nsHTMLDocument::QueryCommandState() returns the state as expected.  Note that
those commands are supported only by Gecko.  So, we don't need to worry about
the compatibility.

Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.

Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API.  Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.

MozReview-Commit-ID: 1FhYo5vcV60

--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 17:26:46 +09:00

104 lines
3.6 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=558663
-->
<head>
<title>Test for Bug 558663</title>
</head>
<body>
<p><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=558663">Mozilla Bug 558663</a></p>
<!-- 20x20 of red -->
<iframe id="iframe" srcdoc="<img id='image' border='0' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAG0lEQVR42mP8z0A%2BYKJA76jmUc2jmkc1U0EzACKcASfOgGoMAAAAAElFTkSuQmCC'>"></iframe>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 558663 **/
var ok = parent.ok;
var SimpleTest = parent.SimpleTest;
var compareSnapshots = parent.compareSnapshots;
var snapshotWindow = parent.snapshotWindow;
var synthesizeMouse = parent.synthesizeMouse;
window.addEventListener("load", runTest);
function checkSnapshots(s1, s2, shouldBeEqual, testName) {
var res = compareSnapshots(s1, s2, shouldBeEqual);
if (res[0]) {
ok(true, testName + " snapshots compare correctly");
} else {
ok(false, testName + " snapshots compare incorrectly. snapshot 1: " +
res[1] + " snapshot 2: " + res[2]);
}
}
function runTest() {
var contentDocument = document.getElementById("iframe").contentDocument;
contentDocument.designMode = "on";
contentDocument.execCommand("enableObjectResizing", false, true);
// The editor requires the event loop to spin after you turn on design mode
// before it takes effect.
setTimeout(continueTest, 100);
}
function continueTest() {
var win = document.getElementById("iframe").contentWindow;
var doc = win.document;
var image = doc.getElementById("image");
// We want to test that clicking on the image and then clicking on one of the
// draggers doesn't make the draggers disappear.
// clean snapshot
var before = snapshotWindow(win);
// click to get the draggers
synthesizeMouse(image, 1, 1, {type: "mousedown"}, win);
synthesizeMouse(image, 1, 1, {type: "mouseup"}, win);
// mouse over a dragger will change its color, so move the mouse away
synthesizeMouse(doc.documentElement, 50, 50, {type: "mousemove"}, win);
// snapshot with hopefully draggers
var middle = snapshotWindow(win);
// clicking on the top left dragger shouldn't change anything
synthesizeMouse(image, 1, 1, {type: "mousedown"}, win);
synthesizeMouse(image, 1, 1, {type: "mouseup"}, win);
// mouse over a dragger will change its color, so move the mouse away
synthesizeMouse(doc.documentElement, 50, 50, {type: "mousemove"}, win);
// snapshot with hopefully draggers again
var middle2 = snapshotWindow(win);
// click outside the image (but inside the document) to unselect it
synthesizeMouse(doc.documentElement, 50, 50, {type: "mousedown"}, win);
synthesizeMouse(doc.documentElement, 50, 50, {type: "mouseup"}, win);
// and then click outside the document so we don't draw a caret
synthesizeMouse(document.documentElement, 1, 1, {type: "mousedown"}, window);
synthesizeMouse(document.documentElement, 1, 1, {type: "mouseup"}, window);
// hopefully clean snapshot
var end = snapshotWindow(win);
// before == end && middle == middle2 && before/end != middle/middle2
checkSnapshots(before, end, true, "before and after should be the same")
checkSnapshots(middle, middle2, true, "middle two should be the same");
checkSnapshots(before, middle, false, "before and middle should not be the same");
checkSnapshots(before, middle2, false, "before and middle2 should not be the same");
checkSnapshots(middle, end, false, "middle and end should not be the same");
checkSnapshots(middle2, end, false, "middle2 and end should not be the same");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>