Commit 786659de authored by yosin's avatar yosin Committed by Commit bot

Convert execCommand/unlink.html to use w3c test harness

This patch converts "execCommand/unlink.html" to use w3c test
harness with |assert_selection()| to simplify for code and improve code health.

This patch also updates |assert_selection()| to serialize selection correctly
when anchor node and focus node aren't |Text| node, and adds sanity check
for expected text.

This patch is a preparation of committing crrev.com/2001083002, Make
FrameSelection to track associated Document.

BUG=n/a
TEST=n/a; no behavior changes

Review-Url: https://codereview.chromium.org/2016173002
Cr-Commit-Position: refs/heads/master@{#396791}
parent df342034
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
This is a test of execCommand("Unlink"). It tests:
Completely unlinking a link.
Unlinking a single word inside of a link.
Unlinking a selection containing linked and unlinked text.
Unlinking a selection that partially selects a linked table.
The editable regions below describe what their content should be after the test.
This paragraph should should end up unlinked.
The second word in this paragraph should end up being unlinked, everything else should be a link.
This paragraph starts with a link in the middle. Only the 'a' in the previous sentence should be linked after the test.
This editable region contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.
Item 1
Item 2
1 2 3
This line contains an image.
The innerHTML of editable regions after the test:
This paragraph should should end up unlinked.
<a href="http://www.apple.com/">The</a> second<a href="http://www.apple.com/"> word in this paragraph should end up being unlinked, everything else should be a link.</a>
This paragraph starts with <a href="http://www.google.com"><i>a</i></a><span id="test3start"> link</span> in the middle. Only the 'a' in the previous sentence should be linked after the test.
<p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> <table border="1"><tbody><tr><td>1</td><td>2</td><td><span id="test4end"><a href="http://www.google.com/">3</a></span></td></tr></tbody></table> <a href="http://www.google.com/"><br> This <b>line</b> contains <img src="../resources/abe.png"> an image. </a>
<html>
<head>
<script src=../editing.js language="JavaScript" type="text/JavaScript"></script>
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<div id="log"></div>
<script>
function log(message) {
var console = document.getElementById("console");
var li = document.createElement("li");
var text = document.createTextNode(message);
li.appendChild(text);
console.appendChild(li);
}
test(() => {
assert_selection(
'<div contenteditable><a href="abc">^0123456789|</a></div>',
'unlink',
'<div contenteditable>^0123456789|</div>',
'Fully Select A element');
function editingTest() {
var s = window.getSelection();
var d;
if (window.testRunner)
window.testRunner.dumpAsText();
// Fully select the line in the first div.
d = document.getElementById("test1");
s.collapse(d, 0);
extendSelectionForwardByLineCommand();
unlinkCommand();
log(d.innerHTML);
assert_selection(
'<div contenteditable><a href="abc">012^345|6789</a></div>',
'unlink',
'<div contenteditable><a href="abc">012</a>^345|<a href="abc">6789</a></div>',
'Partially Select A element');
// Select the second word in the second div
d = document.getElementById("test2");
s.collapse(d, 0);
moveSelectionForwardByWordCommand();
extendSelectionForwardByWordCommand();
unlinkCommand();
log(d.innerHTML);
// Select part of a link (and a bit of trailing non-linked text)
d = document.getElementById("test3");
var e = document.getElementById("test3start");
s.collapse(e, 0);
extendSelectionForwardByLineCommand();
unlinkCommand();
log(d.innerHTML);
// Link an editable region containing lists, tables, images, etc.
d = document.getElementById("test4");
s.collapse(d, 0);
selectAllCommand();
createLinkCommand("http://www.google.com/");
// Now unlink a portion of it
var end = document.getElementById("test4end");
s.setBaseAndExtent(d, 0, end, 0);
unlinkCommand();
log(d.innerHTML);
}
</script>
</head>
assert_selection(
'<div contenteditable><a href="abc">0123456^789</a>xy|z</div>',
'unlink',
'<div contenteditable><a href=\"abc\">0123456</a>^789xy|z</div>',
'Partially Select A element and following test');
<body style="font-size: 12px;">
<p>This is a test of execCommand("Unlink"). It tests:</p>
<ol>
<li>Completely unlinking a link.</li>
<li>Unlinking a single word inside of a link.</li>
<li>Unlinking a selection containing linked and unlinked text.</li>
<li>Unlinking a selection that partially selects a linked table.</li>
</ol>
<p>The editable regions below describe what their content should be after the test.</p>
<ol>
<li><div id="test1" contenteditable="true"><a href="http://www.apple.com/">This paragraph should should end up unlinked.</a></div></li>
<li><div id="test2" contenteditable="true"><a href="http://www.apple.com/">The second word in this paragraph should end up being unlinked, everything else should be a link.</a></div></li>
<li><div id="test3" contenteditable="true">This paragraph starts with <a href="http://www.google.com"><i>a</i><span id="test3start"> link</span></a> in the middle. Only the 'a' in the previous sentence should be linked after the test.</div></li>
<li><div id="test4" contenteditable="true">
<p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<table border=1><tr><td>1</td><td>2</td><td><span id="test4end">3</span></td></tr></table>
<br>
This <b>line</b> contains <img src="../resources/abe.png"> an image.
</div></li>
</ol>
<p>The innerHTML of editable regions after the test:</p>
<ol id="console"></ol>
<script>
runEditingTest();
</script>
</body>
assert_selection(
'<div contenteditable><a href="abc">^<img src="../resources/abe.png">|</a></div>',
'unlink',
'<div contenteditable>^<img src="../resources/abe.png">|</div>',
'Select image in a link');
</html>
assert_selection(
'<div contenteditable>^<ul><li><a href="1">1</a></li><li><a href="2">2</a></li></ul>|</div>',
'unlink',
'<div contenteditable><ul><li>^1</li><li>2|</li></ul></div>',
'Select a list');
assert_selection(
'<div contenteditable><table><tr><td><a href="1">^1</a></td><td><a href="2">2|</a></td></tr></table></div>',
'unlink',
'<div contenteditable><table><tbody><tr><td>^1</td><td>2|</td></tr></tbody></table></div>',
'Select a table');
});
</script>
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
This is a test of execCommand("Unlink"). It tests:
Completely unlinking a link.
Unlinking a single word inside of a link.
Unlinking a selection containing linked and unlinked text.
Unlinking a selection that partially selects a linked table.
The editable regions below describe what their content should be after the test.
This paragraph should should end up unlinked.
The second word in this paragraph should end up being unlinked, everything else should be a link.
This paragraph starts with a link in the middle. Only the 'a' in the previous sentence should be linked after the test.
This editable region contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.
Item 1
Item 2
1 2 3
This line contains an image.
The innerHTML of editable regions after the test:
This paragraph should should end up unlinked.
<a href="http://www.apple.com/">The </a>second <a href="http://www.apple.com/">word in this paragraph should end up being unlinked, everything else should be a link.</a>
This paragraph starts with <a href="http://www.google.com"><i>a</i></a><span id="test3start"> link</span> in the middle. Only the 'a' in the previous sentence should be linked after the test.
<p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> <table border="1"><tbody><tr><td>1</td><td>2</td><td><span id="test4end"><a href="http://www.google.com/">3</a></span></td></tr></tbody></table> <a href="http://www.google.com/"><br> This <b>line</b> contains <img src="../resources/abe.png"> an image. </a>
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