Commit d177fe1e authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Convert editing/selection/extend-by-word-002.html with assert_selection

This patch converts the layout test with assert_selection to improve code
health and also increase the usage of w3c testharness. It also moves the
test file to editing/selection/modify_extend for better organization.

Note: Chrome's current behavior is incorrect. It will be fixed by
https://codereview.chromium.org/2541163003

BUG=n/a

Review-Url: https://codereview.chromium.org/2535173009
Cr-Commit-Position: refs/heads/master@{#436223}
parent 4ed88b28
PASS selection.type is "Range"
PASS selection.anchorNode is $("test").querySelectorAll("li")[0].childNodes[0]
PASS selection.anchorOffset is 0
PASS selection.focusNode is $("test").querySelectorAll("li a")[3].firstChild
PASS selection.focusOffset is 4
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<style>
.editing {
border: 2px solid red;
padding: 12px;
font-size: 24px;
}
.cell {
padding: 12px;
font-size: 24px;
height: 48px;
}
li {
font-size: 12px;
font-family: Verdana, Arial, sans-serif;
}
div.nav {
width:120px;
}
ul.menu, ul.menu li {
margin: 0;padding:0;
font-size:10px
}
ul.menu li { padding: 3px; padding-left: 1.6em; padding-right:5px; text-indent: -1.1em !important; text-indent: -.5em; }
ul.menu li:first-letter { font-size:20px;line-height:10px; }
</style>
<title>Editing Test</title>
</head>
<body>
<div id="container">
<div contenteditable id="root" class="editing" style="width:120px;">
<ul class="menu" id="test">
<li>&middot; <a href="detail.asp?cat=7">Appetizers</a></li>
<li>&middot; <a href="detail.asp?cat=13">Soups & Salads</a></li>
<li>&middot; <a href="detail.asp?cat=5">Sandwiches & Burgers</a></li>
<li>&middot; <a href="detail.asp?cat=14">Steak & Ribs</a></li>
<li>&middot; <a href="detail.asp?cat=11">Seafood</a></li>
<li>&middot; <a href="detail.asp?cat=17">Combos</a></li>
</ul>
</div>
</div>
<!--
Specifically checks test case in bug:
<rdar://problem/4244976> reproducible hang at ocharleys.com in VisiblePosition::initDownstream
-->
<script src="../../resources/js-test.js"></script>
<script>
function $(id) { return document.getElementById(id); }
if (window.internals)
internals.settings.setEditingBehavior('mac');
var range = document.createRange();
range.setStart($("test").querySelectorAll("li")[0], 0);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
for (var i = 0; i < 6; ++i)
selection.modify('extend', 'forward', 'word');
shouldBeEqualToString('selection.type', 'Range');
shouldBe('selection.anchorNode', '$("test").querySelectorAll("li")[0].childNodes[0]');
shouldBe('selection.anchorOffset', '0');
shouldBe('selection.focusNode', '$("test").querySelectorAll("li a")[3].firstChild');
shouldBe('selection.focusOffset', '4');
if (window.testRunner)
$('container').outerHTML = '';
</script>
</body>
</html>
<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const middot = String.fromCharCode(183); // &middot;
const isMac = navigator.platform.indexOf('Mac') !== -1;
// The current behavior is wrong. The correct focus should be at 'Steak |& ...'
// on Windows, and 'Steak| & ....' on other platforms.
test(() => assert_selection(
[
'<style>ul li:first-letter {color: red;}</style>',
'<ul>',
`<li>${middot} <a href="foo.html">|Appetizers</a></li>`,
`<li>${middot} <a href="foo.html">Soups & Salads</a></li>`,
`<li>${middot} <a href="foo.html">Sandwiches & Burgers</a></li>`,
`<li>${middot} <a href="foo.html">Steak & Ribs</a></li>`,
`<li>${middot} <a href="foo.html">Seafood</a></li>`,
`<li>${middot} <a href="foo.html">Combos</a></li>`,
'</ul>'
].join(''),
selection => {
for (let i = 0; i < 6; ++i)
selection.modify('extend', 'forward', 'word');
},
[
'<style>ul li:first-letter {color: red;}</style>',
'<ul>',
`<li>${middot} <a href="foo.html">^Appetizers</a></li>`,
`<li>${middot} <a href="foo.html">Soups & Salads</a></li>`,
`<li>${middot} <a href="foo.html">Sandwiches & Burgers</a></li>`,
isMac ? `<li>${middot} <a href="foo.html">Stea|k & Ribs</a></li>`
: `<li>${middot} <a href="foo.html">Steak &| Ribs</a></li>`,
`<li>${middot} <a href="foo.html">Seafood</a></li>`,
`<li>${middot} <a href="foo.html">Combos</a></li>`,
'</ul>'
].join('')), 'Extend by word in lines with :first-letter');
</script>
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