Commit 14ad48c9 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Rewrite editing/selection/doubleclick-inline-first-last-contenteditable.html...

Rewrite editing/selection/doubleclick-inline-first-last-contenteditable.html to use selection_test()

This patch changes "doubleclick-inline-first-last-contenteditable.html" to
utilize |selection_test()| for ease of maintenance.

Bug: 679977
Change-Id: Id65f597b65a031ff4a6ce2137373b03905e6b839
Reviewed-on: https://chromium-review.googlesource.com/896903Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533929}
parent a85f2acd
Test to check if last and first word can be selected when they double-clicked (Bug 36359)
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS window.getSelection().toString() is 'selectme1'
PASS window.selectedByModify is 'selectme1'
PASS window.getSelection().toString() is 'selectme2'
PASS window.selectedByModify is 'selectme2'
PASS window.getSelection().toString() is 'selectme3'
PASS window.selectedByModify is 'selectme3'
PASS window.getSelection().toString() is 'selectme4'
PASS window.selectedByModify is 'selectme4'
PASS window.getSelection().toString() is 'selectme5'
PASS window.selectedByModify is 'selectme5'
PASS window.getSelection().toString() is 'selectme6'
PASS window.selectedByModify is 'selectme6'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <!doctype html>
<html> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/js-test.js"></script> <script src="../assert_selection.js"></script>
<script src="resources/js-test-selection-shared.js"></script> <script>
</head> // Test to check if last and first word can be selected when they double-clicked
<body> // https://bugs.webkit.org/show_bug.cgi?id=36359
<p id="description"></p>
<div id="console"></div> function computePoint(selection) {
<script src="script-tests/doubleclick-inline-first-last-contenteditable.js"></script> const target = selection.document.getElementById('target');
</body> const width = target.offsetWidth;
</html> const height = target.offsetHeight;
const left = selection.computeLeft(target);
const top = selection.computeTop(target);
return {x: left + width / 2, y: top + height / 2};
}
function doubleClick(selection) {
resetMouse();
const point = computePoint(selection);
eventSender.mouseMoveTo(point.x, point.y);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseDown();
eventSender.mouseUp();
}
function resetMouse() {
if (!window.eventSender)
throw 'This test requires eventSender.';
eventSender.mouseMoveTo(0, 0);
eventSender.mouseDown();
eventSender.mouseUp();
}
function singleClickAndModify(selection) {
resetMouse();
const point = computePoint(selection);
eventSender.mouseMoveTo(point.x, point.y);
eventSender.mouseDown();
eventSender.mouseUp();
selection.modify('extend', 'backward', 'word');
selection.collapseToStart();
selection.modify('extend', 'forward', 'word');
}
// double click
selection_test(
'<span contenteditable id="target">xyz</span> abc',
selection => doubleClick(selection),
'<span contenteditable id="target">^xyz|</span> abc',
'double-click-1 first word');
selection_test(
'abc <span contenteditable id="target">xyz</span>',
selection => doubleClick(selection),
'abc <span contenteditable id="target">^xyz|</span>',
'double-click-2 last word');
selection_test(
'abc <span contenteditable id="target">xyz</span> def',
selection => doubleClick(selection),
'abc <span contenteditable id="target">^xyz|</span> def',
'double-click-3 middle word');
selection_test(
'<div contenteditable><b id="target">xyz</b></div> abc',
selection => doubleClick(selection),
'<div contenteditable><b id="target">^xyz|</b></div> abc',
'double-click-4 first block');
selection_test(
'abc <div contenteditable><b id="target">xyz</b></div>',
selection => doubleClick(selection),
'abc <div contenteditable><b id="target">^xyz|</b></div>',
'double-click-5 last block');
selection_test(
'abc <div contenteditable><b id="target">xyz</b></div> def',
selection => doubleClick(selection),
'abc <div contenteditable><b id="target">^xyz|</b></div> def',
'double-click-6 middle block');
// single click + modify
selection_test(
'<span contenteditable id="target">xyz</span> abc',
selection => singleClickAndModify(selection),
'<span contenteditable id="target">^xyz|</span> abc',
'single-click-modify-1 first word');
selection_test(
'abc <span contenteditable id="target">xyz</span>',
selection => singleClickAndModify(selection),
'abc <span contenteditable id="target">^xyz|</span>',
'single-click-modify-2 last word');
selection_test(
'abc <span contenteditable id="target">xyz</span> def',
selection => singleClickAndModify(selection),
'abc <span contenteditable id="target">^xyz|</span> def',
'single-click-modify-3 middle word');
selection_test(
'<div contenteditable><b id="target">xyz</b></div> abc',
selection => singleClickAndModify(selection),
'<div contenteditable><b id="target">^xyz|</b></div> abc',
'single-click-modify-4 first block');
selection_test(
'abc <div contenteditable><b id="target">xyz</b></div>',
selection => singleClickAndModify(selection),
'abc <div contenteditable><b id="target">^xyz|</b></div>',
'single-click-modify-5 last block');
selection_test(
'abc <div contenteditable><b id="target">xyz</b></div> def',
selection => singleClickAndModify(selection),
'abc <div contenteditable><b id="target">^xyz|</b></div> def',
'single-click-modify-6 middle block');
</script>
description("Test to check if last and first word can be selected when they double-clicked (Bug 36359)");
function toLiteral(textValue)
{
return "'" + textValue + "'";
}
function getPositionOfNode(node)
{
var n = node;
var offsetX = 0, offsetY = 0;
while (n) {
offsetX += n.offsetLeft;
offsetY += n.offsetTop;
n = n.offsetParnet;
}
return {
"x": offsetX,
"y": offsetY
};
}
function doubleClickPosition(pos)
{
eventSender.mouseMoveTo(pos.x, pos.y);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseDown();
eventSender.mouseUp();
}
function singleClickPosition(pos)
{
eventSender.mouseMoveTo(pos.x, pos.y);
eventSender.mouseDown();
eventSender.mouseUp();
}
var targetRoot = document.createElement("div");
document.body.appendChild(targetRoot);
var scratchRoot = document.createElement("div");
document.body.appendChild(scratchRoot);
function computeTextSize(text)
{
scratchRoot.innerHTML = ("<span id='scratch'>" + text + "</span>");
var scratch = document.getElementById("scratch");
return { width: scratch.offsetWidth, height: scratch.offsetHeight };
}
function testWithDoublleClick(targetInnerHTML, expectedText)
{
var textSize = computeTextSize(expectedText);
targetRoot.innerHTML = targetInnerHTML;
var target = document.getElementById("target");
var nodePosition = getPositionOfNode(target);
doubleClickPosition({ x: nodePosition.x + textSize.width / 2, y: nodePosition.y + textSize.height / 2 });
shouldBe("window.getSelection().toString()", toLiteral(expectedText));
}
function testWithClickAndModify(targetInnerHTML, expectedText)
{
var selection = window.getSelection();
targetRoot.innerHTML = targetInnerHTML;
var target = document.getElementById("target");
singleClickPosition(getPositionOfNode(target));
selection.modify("extend", "forward", "word");
var lastHalf = window.getSelection().toString();
selection.modify("extend", "backward", "word");
var firstHalf = window.getSelection().toString();
window.selectedByModify = firstHalf + lastHalf;
shouldBe("window.selectedByModify", toLiteral(expectedText));
}
internals.settings.setSmartInsertDeleteEnabled(true);
internals.settings.setSelectTrailingWhitespaceEnabled(false);
var shouldSelecteFirstWordInline = "<span id='target' contentEditable>selectme1</span> and not select us";
testWithDoublleClick(shouldSelecteFirstWordInline, "selectme1");
testWithClickAndModify(shouldSelecteFirstWordInline, "selectme1");
var shouldSelectLastWordInline = "you should ignore us but <span id='target' contentEditable>selectme2</span>";
testWithDoublleClick(shouldSelectLastWordInline, "selectme2");
testWithClickAndModify(shouldSelectLastWordInline, "selectme2");
var shouldSelectMiddleWordInline = "you should get <span id='target' contentEditable>selectme3</span> selected";
testWithDoublleClick(shouldSelectMiddleWordInline, "selectme3");
testWithClickAndModify(shouldSelectMiddleWordInline, "selectme3");
var shouldSelecteFirstWordBlock = "<div id='target' contentEditable>selectme4</div> and not select us";
testWithDoublleClick(shouldSelecteFirstWordBlock, "selectme4");
testWithClickAndModify(shouldSelecteFirstWordBlock, "selectme4");
var shouldSelectLastWordBlock = "you should ignore us but <div id='target' contentEditable>selectme5</div>";
testWithDoublleClick(shouldSelectLastWordBlock, "selectme5");
testWithClickAndModify(shouldSelectLastWordBlock, "selectme5");
var shouldSelectMiddleWordBlock = "you should get <div id='target' contentEditable>selectme6</div> selected";
testWithDoublleClick(shouldSelectMiddleWordBlock, "selectme6");
testWithClickAndModify(shouldSelectMiddleWordBlock, "selectme6");
targetRoot.style.display = "none";
scratchRoot.style.display = "none";
var successfullyParsed = true;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment