2007-10-09 19:21:33 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test Word Movement (including nsTextFrame::PeekOffsetWord)</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2007-10-09 19:21:33 -07:00
|
|
|
<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>
|
2007-11-09 00:54:47 -08:00
|
|
|
<p id="catch">Catch-all
|
|
|
|
<pre id="test"><script class="testbody" type="text/javascript;version=1.7">
|
2007-10-09 19:21:33 -07:00
|
|
|
|
|
|
|
/** Test for Bug 384147 **/
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
// This seems to be necessary because the selection is not set up properly otherwise
|
2009-04-23 12:36:55 -07:00
|
|
|
setTimeout(test, 0);
|
2007-10-09 19:21:33 -07:00
|
|
|
|
2007-11-09 00:54:47 -08:00
|
|
|
var eatSpace;
|
|
|
|
|
2007-10-10 15:32:51 -07:00
|
|
|
function getPrefs() {
|
|
|
|
const prefSvcContractID = "@mozilla.org/preferences-service;1";
|
|
|
|
const prefSvcIID = Components.interfaces.nsIPrefService;
|
|
|
|
return Components.classes[prefSvcContractID].getService(prefSvcIID)
|
|
|
|
.getBranch("layout.word_select.");
|
|
|
|
}
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
function setPrefs(eat_space, stop_at_punctuation) {
|
|
|
|
getPrefs().setBoolPref("eat_space_to_next_word", eat_space);
|
|
|
|
getPrefs().setBoolPref("stop_at_punctuation", stop_at_punctuation);
|
|
|
|
eatSpace = eat_space;
|
2007-10-10 15:32:51 -07:00
|
|
|
}
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
function restorePrefs() {
|
2009-10-29 06:44:10 -07:00
|
|
|
try {
|
|
|
|
getPrefs().clearUserPref("eat_space_to_next_word");
|
|
|
|
} catch(ex) {}
|
|
|
|
try {
|
|
|
|
getPrefs().clearUserPref("stop_at_punctuation");
|
|
|
|
} catch(ex) {}
|
2007-10-10 15:32:51 -07:00
|
|
|
}
|
|
|
|
|
2007-10-09 19:21:33 -07:00
|
|
|
function test() {
|
2007-10-10 15:32:51 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
2007-10-09 19:21:33 -07:00
|
|
|
var wordModifiers =
|
|
|
|
(navigator.platform.indexOf("Mac") >= 0) ? {altKey:true} : {ctrlKey:true};
|
|
|
|
var sel = window.getSelection();
|
|
|
|
var editor = document.getElementById("editor");
|
|
|
|
|
2007-11-09 00:54:47 -08:00
|
|
|
function errString(dir) {
|
|
|
|
return dir + " movement broken with eatSpace=" + eatSpace + " in \"" + editor.innerHTML +
|
|
|
|
"\"; sel.anchorNode.parentNode=" + sel.anchorNode.parentNode;
|
|
|
|
}
|
|
|
|
|
2007-10-09 19:21:33 -07:00
|
|
|
function testRight(node, offset) {
|
|
|
|
synthesizeKey("VK_RIGHT", wordModifiers);
|
2007-11-09 00:54:47 -08:00
|
|
|
is(sel.anchorNode, node, errString("Right"));
|
|
|
|
is(sel.anchorOffset, offset, errString("Right"));
|
2007-10-09 19:21:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testLeft(node, offset) {
|
|
|
|
synthesizeKey("VK_LEFT", wordModifiers);
|
2007-11-09 00:54:47 -08:00
|
|
|
is(sel.anchorNode, node, errString("Left"));
|
|
|
|
is(sel.anchorOffset, offset, errString("Left"));
|
2007-10-09 19:21:33 -07:00
|
|
|
}
|
|
|
|
|
2007-11-09 00:54:47 -08:00
|
|
|
var afterEditorNode = document.getElementById("catch").firstChild;
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
setPrefs(false, true);
|
2007-10-10 15:32:51 -07:00
|
|
|
|
2007-10-09 19:21:33 -07:00
|
|
|
editor.innerHTML = "Hello Kitty";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 5);
|
|
|
|
testRight(editor.firstChild, 11);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>Hello</b> Kitty";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.nextSibling, 0);
|
|
|
|
testRight(editor.firstChild.nextSibling, 6);
|
|
|
|
testLeft(editor.firstChild.nextSibling, 1);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>Hello </b>Kitty";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.firstChild, 5);
|
|
|
|
testRight(editor.firstChild.nextSibling, 5);
|
|
|
|
testLeft(editor.firstChild.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>Log out</b> roc";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.firstChild, 3);
|
|
|
|
testRight(editor.firstChild.nextSibling, 0);
|
|
|
|
testRight(editor.firstChild.nextSibling, 5);
|
|
|
|
// In the next test, we expect to be at the end of the
|
|
|
|
// space that is not collapsed away
|
|
|
|
testLeft(editor.firstChild.nextSibling, 1);
|
|
|
|
testLeft(editor.firstChild.firstChild, 4);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
editor.innerHTML = "http://www.mozilla.org";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 7);
|
|
|
|
testRight(editor.firstChild, 11);
|
|
|
|
testRight(editor.firstChild, 19);
|
|
|
|
testLeft(editor.firstChild, 11);
|
|
|
|
testLeft(editor.firstChild, 7);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "Set .rc to <b>'</b>quiz'";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 3);
|
|
|
|
testRight(editor.firstChild, 7);
|
|
|
|
testRight(editor.firstChild, 10);
|
|
|
|
testRight(editor.firstChild.nextSibling.nextSibling, 5);
|
|
|
|
testLeft(editor.firstChild.nextSibling.firstChild, 1);
|
|
|
|
testLeft(editor.firstChild, 10);
|
|
|
|
testLeft(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 5);
|
|
|
|
testLeft(editor.firstChild, 3);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
2008-07-09 01:32:24 -07:00
|
|
|
var ChineseChars = "漢字";
|
|
|
|
var HiraganaChars = "ひらがな";
|
|
|
|
var KatakanaChars = "カタカナ";
|
|
|
|
var JapaneseFullStop = "。";
|
|
|
|
var JapaneseComma = "、";
|
|
|
|
|
|
|
|
editor.innerHTML = ChineseChars + HiraganaChars + ChineseChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 2);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 2);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = ChineseChars + KatakanaChars + ChineseChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 2);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 2);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = KatakanaChars + HiraganaChars + KatakanaChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 4);
|
|
|
|
testRight(editor.firstChild, 8);
|
|
|
|
testRight(editor.firstChild, 12);
|
|
|
|
testLeft(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 4);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = HiraganaChars + JapaneseComma + HiraganaChars + JapaneseFullStop + HiraganaChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 5);
|
|
|
|
testRight(editor.firstChild, 10);
|
|
|
|
testRight(editor.firstChild, 14);
|
|
|
|
testLeft(editor.firstChild, 10);
|
|
|
|
testLeft(editor.firstChild, 5);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = KatakanaChars + JapaneseComma + KatakanaChars + JapaneseFullStop + KatakanaChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 5);
|
|
|
|
testRight(editor.firstChild, 10);
|
|
|
|
testRight(editor.firstChild, 14);
|
|
|
|
testLeft(editor.firstChild, 10);
|
|
|
|
testLeft(editor.firstChild, 5);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = ChineseChars + JapaneseComma + ChineseChars + JapaneseFullStop + ChineseChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 3);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 3);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
setPrefs(true, true);
|
2007-11-09 00:54:47 -08:00
|
|
|
|
|
|
|
// test basic word movement with eat_space_next_to_word true.
|
|
|
|
|
|
|
|
editor.innerHTML = "Hello Kitty";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>Hello</b> Kitty";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.nextSibling, 1);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild.nextSibling, 1);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>Hello </b>Kitty";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.nextSibling, 0);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>Log out</b> roc";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.firstChild, 4);
|
|
|
|
testRight(editor.firstChild.nextSibling, 2);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild.nextSibling, 1);
|
|
|
|
testLeft(editor.firstChild.firstChild, 4);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
editor.innerHTML = "http://www.mozilla.org";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 7);
|
|
|
|
testRight(editor.firstChild, 11);
|
|
|
|
testRight(editor.firstChild, 19);
|
|
|
|
testLeft(editor.firstChild, 11);
|
|
|
|
testLeft(editor.firstChild, 7);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "Set .rc to <b>'</b>quiz'";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 4);
|
|
|
|
testRight(editor.firstChild, 8);
|
|
|
|
testRight(editor.firstChild.nextSibling.firstChild, 0);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild.nextSibling.firstChild, 1);
|
|
|
|
testLeft(editor.firstChild, 10);
|
|
|
|
testLeft(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 5);
|
|
|
|
testLeft(editor.firstChild, 3);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
2008-07-09 01:32:24 -07:00
|
|
|
editor.innerHTML = ChineseChars + HiraganaChars + ChineseChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 2);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 2);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = ChineseChars + KatakanaChars + ChineseChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 2);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 2);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = KatakanaChars + HiraganaChars + KatakanaChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 4);
|
|
|
|
testRight(editor.firstChild, 8);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 8);
|
|
|
|
testLeft(editor.firstChild, 4);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = HiraganaChars + JapaneseComma + HiraganaChars + JapaneseFullStop + HiraganaChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 5);
|
|
|
|
testRight(editor.firstChild, 10);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 10);
|
|
|
|
testLeft(editor.firstChild, 5);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = KatakanaChars + JapaneseComma + KatakanaChars + JapaneseFullStop + KatakanaChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 5);
|
|
|
|
testRight(editor.firstChild, 10);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 10);
|
|
|
|
testLeft(editor.firstChild, 5);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = ChineseChars + JapaneseComma + ChineseChars + JapaneseFullStop + ChineseChars;
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 3);
|
|
|
|
testRight(editor.firstChild, 6);
|
|
|
|
testRight(afterEditorNode, 0);
|
|
|
|
testLeft(editor.firstChild, 6);
|
|
|
|
testLeft(editor.firstChild, 3);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
2008-03-03 00:37:34 -08:00
|
|
|
restorePrefs();
|
2007-10-10 15:32:51 -07:00
|
|
|
|
2007-10-09 19:21:33 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-09 00:54:47 -08:00
|
|
|
</script></pre>
|
2007-10-09 19:21:33 -07:00
|
|
|
</body>
|
|
|
|
</html>
|