зеркало из https://github.com/mozilla/pjs.git
167 строки
6.5 KiB
HTML
167 строки
6.5 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test BackSpace/Delete Keys</title>
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: block">
|
|
<div contentEditable id="editor"></div>
|
|
</div>
|
|
<p id="catch">Catch-all
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript;version=1.7">
|
|
|
|
/** Test for Bug 157546, 417745 **/
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
// This seems to be necessary because the selection is not set up properly otherwise
|
|
setTimeout(test, 0);
|
|
|
|
var eatSpace;
|
|
|
|
function getPrefs() {
|
|
const prefSvcContractID = "@mozilla.org/preferences-service;1";
|
|
const prefSvcIID = Components.interfaces.nsIPrefService;
|
|
return Components.classes[prefSvcContractID].getService(prefSvcIID)
|
|
.getBranch("layout.word_select.");
|
|
}
|
|
|
|
function setEatSpace(newValue) {
|
|
getPrefs().setBoolPref("eat_space_to_next_word", newValue);
|
|
eatSpace = newValue;
|
|
}
|
|
|
|
function restoreEatSpace() {
|
|
try {
|
|
getPrefs().clearUserPref("eat_space_to_next_word");
|
|
} catch(ex) {}
|
|
}
|
|
|
|
function test() {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var wordSelModifiers =
|
|
(navigator.platform.indexOf("Mac") >= 0) ?
|
|
{shiftKey:true, altKey:true} : {shiftKey:true, ctrlKey:true};
|
|
var sel = window.getSelection();
|
|
var editor = document.getElementById("editor");
|
|
|
|
function testRight(node, offset) {
|
|
synthesizeKey("VK_RIGHT", {});
|
|
is(sel.anchorNode, node, "Right movement broken in \"" + editor.innerHTML + "\"");
|
|
is(sel.anchorOffset, offset, "Right movement broken in \"" + editor.innerHTML + "\"");
|
|
}
|
|
|
|
function selErrString(dir) {
|
|
return dir + " selection broken with eatSpace=" + eatSpace + " in \"" + editor.innerHTML + "\"";
|
|
}
|
|
|
|
function testWordSelRight(startNode, startOffset, endNode, endOffset) {
|
|
synthesizeKey("VK_RIGHT", wordSelModifiers);
|
|
var selRange = sel.getRangeAt(0);
|
|
is(selRange.startContainer, startNode, selErrString("Word right"));
|
|
is(selRange.startOffset, startOffset, selErrString("Word right"));
|
|
is(selRange.endContainer, endNode, selErrString("Word right"));
|
|
is(selRange.endOffset, endOffset, selErrString("Word right"));
|
|
}
|
|
|
|
function testDelete(node, offset, text) {
|
|
synthesizeKey("VK_DELETE", {});
|
|
is(sel.anchorNode, node, "Delete broken in \"" + editor.innerHTML + "\"");
|
|
is(sel.anchorOffset, offset, "Delete broken in \"" + editor.innerHTML + "\"");
|
|
is(editor.textContent, text, "Delete broken in \"" + editor.innerHTML + "\"");
|
|
}
|
|
|
|
function testBackspace(node, offset, text) {
|
|
synthesizeKey("VK_BACK_SPACE", {});
|
|
is(sel.anchorNode, node, "Backspace broken in \"" + editor.innerHTML + "\"");
|
|
is(sel.anchorOffset, offset, "Backspace broken in \"" + editor.innerHTML + "\"");
|
|
is(editor.textContent, text, "Backspace broken in \"" + editor.innerHTML + "\"");
|
|
}
|
|
|
|
// Test cell-wise deletion of Delete
|
|
editor.innerHTML = "สวัสดีพ่อแม่พี่น้อง";
|
|
sel.collapse(editor.firstChild, 0);
|
|
testRight(editor.firstChild, 1);
|
|
testDelete(editor.firstChild, 1, "สสดีพ่อแม่พี่น้อง");
|
|
testRight(editor.firstChild, 2);
|
|
testDelete(editor.firstChild, 2, "สสพ่อแม่พี่น้อง");
|
|
testRight(editor.firstChild, 4);
|
|
testDelete(editor.firstChild, 4, "สสพ่แม่พี่น้อง");
|
|
testRight(editor.firstChild, 5);
|
|
testDelete(editor.firstChild, 5, "สสพ่แพี่น้อง");
|
|
testRight(editor.firstChild, 8);
|
|
testDelete(editor.firstChild, 8, "สสพ่แพี่อง");
|
|
testRight(editor.firstChild, 9);
|
|
testDelete(editor.firstChild, 9, "สสพ่แพี่อ");
|
|
|
|
// Test character-wise deletion of Backspace
|
|
editor.innerHTML = "สวัสดีพ่อแม่พี่น้อง";
|
|
sel.collapse(editor.firstChild, 0);
|
|
testRight(editor.firstChild, 1);
|
|
testBackspace(editor.firstChild, 0, "วัสดีพ่อแม่พี่น้อง");
|
|
testRight(editor.firstChild, 2);
|
|
testBackspace(editor.firstChild, 1, "วสดีพ่อแม่พี่น้อง");
|
|
testRight(editor.firstChild, 2);
|
|
testBackspace(editor.firstChild, 1, "วดีพ่อแม่พี่น้อง");
|
|
testRight(editor.firstChild, 3);
|
|
testBackspace(editor.firstChild, 2, "วดพ่อแม่พี่น้อง");
|
|
testRight(editor.firstChild, 4);
|
|
testBackspace(editor.firstChild, 3, "วดพอแม่พี่น้อง");
|
|
testRight(editor.firstChild, 4);
|
|
testBackspace(editor.firstChild, 3, "วดพแม่พี่น้อง");
|
|
testRight(editor.firstChild, 4);
|
|
testBackspace(editor.firstChild, 3, "วดพม่พี่น้อง");
|
|
testRight(editor.firstChild, 5);
|
|
testBackspace(editor.firstChild, 4, "วดพมพี่น้อง");
|
|
testRight(editor.firstChild, 7);
|
|
testBackspace(editor.firstChild, 6, "วดพมพีน้อง");
|
|
testRight(editor.firstChild, 8);
|
|
testBackspace(editor.firstChild, 7, "วดพมพีนอง");
|
|
testRight(editor.firstChild, 8);
|
|
testBackspace(editor.firstChild, 7, "วดพมพีนง");
|
|
testRight(editor.firstChild, 8);
|
|
testBackspace(editor.firstChild, 7, "วดพมพีน");
|
|
|
|
// Tests for Bug 417745
|
|
|
|
setEatSpace(true);
|
|
|
|
editor.innerHTML = "Quick yellow fox";
|
|
sel.collapse(editor.firstChild, 0);
|
|
testWordSelRight(editor.firstChild, 0, editor.firstChild, 6);
|
|
testDelete(editor.firstChild, 0, "yellow fox");
|
|
testWordSelRight(editor.firstChild, 0, editor.firstChild, 7);
|
|
testDelete(editor.firstChild, 0, "fox");
|
|
|
|
setEatSpace(false);
|
|
|
|
editor.innerHTML = "Quick yellow fox";
|
|
sel.collapse(editor.firstChild, 0);
|
|
testWordSelRight(editor.firstChild, 0, editor.firstChild, 5);
|
|
// editor converts the leading space to an , otherwise it
|
|
// wouldn't show up which would confuse users
|
|
testDelete(editor.firstChild, 0, "\u00A0yellow fox");
|
|
testWordSelRight(editor.firstChild, 0, editor.firstChild, 7);
|
|
testDelete(editor.firstChild, 0, "\u00A0fox");
|
|
testWordSelRight(editor.firstChild, 0, editor.firstChild, 4);
|
|
testDelete(editor, 0, "");
|
|
|
|
restoreEatSpace();
|
|
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|