2016-08-30 18:01:33 +03:00
|
|
|
<!doctype html>
|
|
|
|
<title>Test for nsSelectionMoveCommands</title>
|
|
|
|
<link rel=stylesheet href="/tests/SimpleTest/test.css">
|
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script src="/tests/SimpleTest/SpawnTask.js"></script>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=454004">Mozilla Bug 454004</a>
|
2008-10-11 07:24:12 +04:00
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
<iframe id="edit" width="200" height="100" src="about:blank"></iframe>
|
2008-10-11 07:24:12 +04:00
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
<script>
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SimpleTest.requestFlakyTimeout("Legacy test, possibly no good reason");
|
2012-01-14 04:26:34 +04:00
|
|
|
|
2012-10-02 22:41:04 +04:00
|
|
|
var winUtils = SpecialPowers.getDOMWindowUtils(window);
|
2016-08-30 18:01:33 +03:00
|
|
|
|
|
|
|
function* setup() {
|
|
|
|
yield SpecialPowers.pushPrefEnv({set: [["general.smoothScroll", false]]});
|
|
|
|
winUtils.advanceTimeAndRefresh(100);
|
2009-01-26 10:46:56 +03:00
|
|
|
}
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
function* runTests() {
|
2008-09-18 03:28:17 +04:00
|
|
|
var e = document.getElementById("edit");
|
|
|
|
var doc = e.contentDocument;
|
|
|
|
var win = e.contentWindow;
|
|
|
|
var root = doc.documentElement;
|
2008-10-11 07:24:12 +04:00
|
|
|
var body = doc.body;
|
|
|
|
|
|
|
|
body.style.fontSize='16px';
|
|
|
|
body.style.lineHeight='16px';
|
|
|
|
body.style.height='400px';
|
|
|
|
body.style.padding='0px';
|
|
|
|
body.style.margin='0px';
|
2012-01-15 07:54:48 +04:00
|
|
|
body.style.borderWidth='0px';
|
2008-10-11 07:24:12 +04:00
|
|
|
|
2008-09-18 03:28:17 +04:00
|
|
|
var sel = win.getSelection();
|
|
|
|
doc.designMode='on';
|
2008-10-11 07:24:12 +04:00
|
|
|
body.innerHTML = "1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>";
|
2008-09-18 03:28:17 +04:00
|
|
|
win.focus();
|
2012-01-15 07:54:48 +04:00
|
|
|
// Flush out layout to make sure that the subdocument will be the size we
|
|
|
|
// expect by the time we try to scroll it.
|
|
|
|
is(body.getBoundingClientRect().height, 400,
|
|
|
|
"Body height should be what we set it to");
|
2011-12-24 04:11:30 +04:00
|
|
|
yield;
|
2008-09-18 03:28:17 +04:00
|
|
|
|
|
|
|
function testScrollCommand(cmd, expectTop) {
|
2015-07-03 07:19:10 +03:00
|
|
|
// http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect
|
|
|
|
// doesn't explicitly rule out -0 here, but for now assume that only
|
|
|
|
// positive zeroes are permitted.
|
2017-05-10 23:34:35 +03:00
|
|
|
is(root.getBoundingClientRect().top, -expectTop + 0, cmd);
|
2008-09-18 03:28:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function testMoveCommand(cmd, expectNode, expectOffset) {
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, cmd);
|
2008-09-18 03:28:17 +04:00
|
|
|
is(sel.isCollapsed, true, "collapsed after " + cmd);
|
|
|
|
is(sel.anchorNode, expectNode, "node after " + cmd);
|
|
|
|
is(sel.anchorOffset, expectOffset, "offset after " + cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
function findChildNum(e, child) {
|
|
|
|
var i = 0;
|
|
|
|
var n = e.firstChild;
|
|
|
|
while (n && n != child) {
|
|
|
|
n = n.nextSibling;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (!n)
|
|
|
|
return -1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPageMoveCommand(cmd, expectOffset) {
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, cmd);
|
2008-09-18 03:28:17 +04:00
|
|
|
is(sel.isCollapsed, true, "collapsed after " + cmd);
|
|
|
|
is(sel.anchorOffset, expectOffset, "offset after " + cmd);
|
2008-10-11 07:24:12 +04:00
|
|
|
return findChildNum(body, sel.anchorNode);
|
2008-09-18 03:28:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSelectCommand(cmd, expectNode, expectOffset) {
|
|
|
|
var anchorNode = sel.anchorNode;
|
|
|
|
var anchorOffset = sel.anchorOffset;
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, cmd);
|
2008-09-18 03:28:17 +04:00
|
|
|
is(sel.isCollapsed, false, "not collapsed after " + cmd);
|
|
|
|
is(sel.anchorNode, anchorNode, "anchor not moved after " + cmd);
|
|
|
|
is(sel.anchorOffset, anchorOffset, "anchor not moved after " + cmd);
|
|
|
|
is(sel.focusNode, expectNode, "node after " + cmd);
|
|
|
|
is(sel.focusOffset, expectOffset, "offset after " + cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPageSelectCommand(cmd, expectOffset) {
|
|
|
|
var anchorNode = sel.anchorNode;
|
|
|
|
var anchorOffset = sel.anchorOffset;
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, cmd);
|
2008-09-18 03:28:17 +04:00
|
|
|
is(sel.isCollapsed, false, "not collapsed after " + cmd);
|
|
|
|
is(sel.anchorNode, anchorNode, "anchor not moved after " + cmd);
|
|
|
|
is(sel.anchorOffset, anchorOffset, "anchor not moved after " + cmd);
|
|
|
|
is(sel.focusOffset, expectOffset, "offset after " + cmd);
|
2008-10-11 07:24:12 +04:00
|
|
|
return findChildNum(body, sel.focusNode);
|
2008-09-18 03:28:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function node(i) {
|
2008-10-11 07:24:12 +04:00
|
|
|
var n = body.firstChild;
|
2008-09-18 03:28:17 +04:00
|
|
|
while (i > 0) {
|
|
|
|
n = n.nextSibling;
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollBottom");
|
2013-05-09 06:25:09 +04:00
|
|
|
yield;
|
2008-09-18 03:28:17 +04:00
|
|
|
testScrollCommand("cmd_scrollBottom", root.scrollHeight - 100);
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollTop");
|
2013-05-09 06:25:09 +04:00
|
|
|
yield;
|
2008-09-18 03:28:17 +04:00
|
|
|
testScrollCommand("cmd_scrollTop", 0);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollPageDown");
|
2008-12-02 16:18:08 +03:00
|
|
|
yield;
|
2008-09-18 03:28:17 +04:00
|
|
|
var pageHeight = -root.getBoundingClientRect().top;
|
|
|
|
ok(pageHeight > 0, "cmd_scrollPageDown works");
|
|
|
|
ok(pageHeight <= 100, "cmd_scrollPageDown doesn't scroll too much");
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollBottom");
|
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollPageUp");
|
2008-12-02 16:18:08 +03:00
|
|
|
yield;
|
2008-09-18 03:28:17 +04:00
|
|
|
testScrollCommand("cmd_scrollPageUp", root.scrollHeight - 100 - pageHeight);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollTop");
|
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollLineDown");
|
2012-01-06 01:33:41 +04:00
|
|
|
yield;
|
|
|
|
var lineHeight = -root.getBoundingClientRect().top;
|
|
|
|
ok(lineHeight > 0, "Can scroll by lines");
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollBottom");
|
|
|
|
SpecialPowers.doCommand(window, "cmd_scrollLineUp");
|
2012-01-06 01:33:41 +04:00
|
|
|
yield;
|
|
|
|
testScrollCommand("cmd_scrollLineUp", root.scrollHeight - 100 - lineHeight);
|
|
|
|
|
2008-10-11 07:24:12 +04:00
|
|
|
var runSelectionTests = function(selectWordNextNode, selectWordNextOffset) {
|
|
|
|
testMoveCommand("cmd_moveBottom", body, 23);
|
|
|
|
testMoveCommand("cmd_moveTop", node(0), 0);
|
|
|
|
testSelectCommand("cmd_selectBottom", body, 23);
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
2008-10-11 07:24:12 +04:00
|
|
|
testSelectCommand("cmd_selectTop", node(0), 0);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveTop");
|
2008-10-11 07:24:12 +04:00
|
|
|
testMoveCommand("cmd_lineNext", node(2), 0);
|
|
|
|
testMoveCommand("cmd_linePrevious", node(0), 0);
|
|
|
|
testSelectCommand("cmd_selectLineNext", node(2), 0);
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
2008-10-11 07:24:12 +04:00
|
|
|
testSelectCommand("cmd_selectLinePrevious", node(20), 2);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
2008-10-11 07:24:12 +04:00
|
|
|
testMoveCommand("cmd_charPrevious", node(22), 1);
|
|
|
|
testMoveCommand("cmd_charNext", node(22), 2);
|
|
|
|
testSelectCommand("cmd_selectCharPrevious", node(22), 1);
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveTop");
|
2008-10-11 07:24:12 +04:00
|
|
|
testSelectCommand("cmd_selectCharNext", node(0), 1);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveTop");
|
2015-03-27 23:16:05 +03:00
|
|
|
testMoveCommand("cmd_endLine", node(0), 1);
|
2008-10-11 07:24:12 +04:00
|
|
|
testMoveCommand("cmd_beginLine", node(0), 0);
|
2015-03-27 23:16:05 +03:00
|
|
|
testSelectCommand("cmd_selectEndLine", node(0), 1);
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
2008-10-11 07:24:12 +04:00
|
|
|
testSelectCommand("cmd_selectBeginLine", node(22), 0);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
2008-10-11 07:24:12 +04:00
|
|
|
testMoveCommand("cmd_wordPrevious", node(22), 0);
|
|
|
|
testMoveCommand("cmd_wordNext", body, 23);
|
|
|
|
testSelectCommand("cmd_selectWordPrevious", node(22), 0);
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveTop");
|
2008-10-11 07:24:12 +04:00
|
|
|
testSelectCommand("cmd_selectWordNext", selectWordNextNode, selectWordNextOffset);
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveTop");
|
2008-10-11 07:24:12 +04:00
|
|
|
var lineNum = testPageMoveCommand("cmd_movePageDown", 0);
|
|
|
|
ok(lineNum > 0, "cmd_movePageDown works");
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
|
|
|
SpecialPowers.doCommand(window, "cmd_beginLine");
|
2008-10-11 07:24:12 +04:00
|
|
|
is(testPageMoveCommand("cmd_movePageUp", 0), 22 - lineNum, "cmd_movePageUp");
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveTop");
|
2008-10-11 07:24:12 +04:00
|
|
|
is(testPageSelectCommand("cmd_selectPageDown", 0), lineNum, "cmd_selectPageDown");
|
2016-08-30 18:01:33 +03:00
|
|
|
SpecialPowers.doCommand(window, "cmd_moveBottom");
|
|
|
|
SpecialPowers.doCommand(window, "cmd_beginLine");
|
2008-10-11 07:24:12 +04:00
|
|
|
is(testPageSelectCommand("cmd_selectPageUp", 0), 22 - lineNum, "cmd_selectPageUp");
|
|
|
|
}
|
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
yield SpecialPowers.pushPrefEnv({set: [["layout.word_select.eat_space_to_next_word", false]]});
|
|
|
|
runSelectionTests(body, 1);
|
|
|
|
yield SpecialPowers.pushPrefEnv({set: [["layout.word_select.eat_space_to_next_word", true]]});
|
|
|
|
runSelectionTests(node(2), 0);
|
|
|
|
}
|
2008-09-18 03:28:17 +04:00
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
function cleanup() {
|
2012-10-02 22:41:04 +04:00
|
|
|
winUtils.restoreNormalRefresh();
|
2008-09-18 03:28:17 +04:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
async function testRunner() {
|
2016-08-30 18:01:33 +03:00
|
|
|
let curTest = runTests();
|
|
|
|
while (true) {
|
|
|
|
winUtils.advanceTimeAndRefresh(100);
|
|
|
|
if (curTest.next().done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
winUtils.advanceTimeAndRefresh(100);
|
2017-06-22 13:51:42 +03:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 20));
|
2016-08-30 18:01:33 +03:00
|
|
|
}
|
|
|
|
}
|
2008-10-11 07:24:12 +04:00
|
|
|
|
2016-08-30 18:01:33 +03:00
|
|
|
spawn_task(setup)
|
|
|
|
.then(() => spawn_task(testRunner))
|
|
|
|
.then(() => spawn_task(cleanup))
|
|
|
|
.catch(err => ok(false, err));
|
|
|
|
</script>
|