Commit 30a02493 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Convert editing/pasteboard/copy-null-characters.html with assert_selection

This patch converts editing/pasteboard/copy-null-characters.html with
assert_selection
to promote the use of w3c testharness and improve code health.


Bug: 679977, 775701
Change-Id: Ib89e9f246b7c7ef559b0d67ac2a4937405524145
Reviewed-on: https://chromium-review.googlesource.com/746341
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513048}
parent 686faa29
If there are NULL characters in text nodes, they should not be copied to the clipboard. This test requires DumpRenderTree.
| "
"
| <div>
| id="outerSource"
| <p>
| <b>
| "bold"
| "
"
| "
"
| <p>
| style="color: green"
| "green"
| "
"
| "
"
| <div>
| contenteditable="true"
| id="destination-rich-text"
| <p>
| <b>
| "bold"
| <div>
| id="source"
| "Copy paste me"
| <span>
| style="color: green;"
| "green"
| "Copy paste me"
| "
"
| <textarea>
| id="destination-plain-text"
| this.value="Copy paste mebold
Copy paste me
green"
| <shadow:root>
| <div>
| "Copy paste mebold
Copy paste me
green"
| "
"
| <div>
| id="results"
| "PASSED"
| "
"
<head> <!doctype html>
<script src="../../resources/dump-as-markup.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script> <script>
Markup.description('If there are NULL characters in text nodes, they should not be copied to the clipboard. This test requires DumpRenderTree.'); selection_test(
Markup.noAutoDump(); '<div contenteditable>|</div>',
selection => {
function runTest() selection.setClipboardData('foo\0bar');
{ selection.document.execCommand("paste");
var sel = window.getSelection(); },
'<div contenteditable>foobar|</div>',
var source = document.getElementById("source"); 'NULL characters should not be copied');
var textWithNull = "Copy\0 paste me";
source.textContent = textWithNull;
var results = document.getElementById("results");
// Make sure innerHTML still has the NULL.
if (source.innerHTML != textWithNull) {
results.innerText = "source.innerHTML has the wrong value (expected " +
JSON.stringify(textWithNull) + " but found " +
JSON.stringify(source.innerHTML) + ").";
Markup.dump(document.body);
Markup.notifyDone();
return;
}
sel.collapse(source, 0);
document.execCommand("SelectAll");
document.execCommand("Copy");
var destinationRichText = document.getElementById("destination-rich-text");
sel.collapse(destinationRichText, 0);
document.execCommand("Paste");
var destinationPlainText = document.getElementById("destination-plain-text");
destinationPlainText.focus();
document.execCommand("Paste");
var expectedPlainTextValue = "Copy paste me";
if (expectedPlainTextValue != destinationPlainText.value) {
results.innerText = "Plain text field has the wrong value (expected " +
JSON.stringify(expectedPlainTextValue) + " but found " +
JSON.stringify(destinationPlainText.value) + ").";
Markup.dump(document.body);
Markup.notifyDone();
return;
}
// Run the same test but include some richly formatted text.
var outerSource = document.getElementById("outerSource");
sel.setBaseAndExtent(outerSource, 0, destinationRichText, 0);
document.execCommand("Copy");
// Remove the source text so we don't end up with a null character in the
// expected output file.
source.parentNode.removeChild(source);
sel.collapse(destinationRichText, 0);
document.execCommand("Paste");
destinationPlainText.focus();
document.execCommand("Paste");
var expectedPlainTextValue2 = "Copy paste mebold\n\nCopy paste me\ngreen";
if (expectedPlainTextValue2 != destinationPlainText.value) {
results.innerText = "Plain text field has the wrong value (expected " +
JSON.stringify(expectedPlainTextValue2) + " but found " +
JSON.stringify(destinationPlainText.value) + ").";
Markup.dump(document.body);
Markup.notifyDone();
return;
}
results.innerText = "PASSED";
Markup.dump(document.body);
Markup.notifyDone();
}
</script> </script>
</head>
<body onload="runTest()">
<div id="outerSource"><p><b>bold</b></p>
<div id="source" contentEditable="true"></div>
<p style="color: green">green</p>
</div>
<div id="destination-rich-text" contentEditable="true"></div>
<textarea id="destination-plain-text"></textarea>
<div id="results">FAILED</div>
</body>
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