blob: 6b6031e0c88c24c111e36b8724d9672170c9969b [file] [edit]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test-pre.js"></script>
<script>
description('This tests calling setData with a malformed URL in a null origin document. The malformed value should not be readable in another document');
jsTestIsAsync = true;
if (window.internals)
internals.settings.setCustomPasteboardDataEnabled(true);
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.src = `data:text/html;charset=utf-8,<!DOCTYPE html>
<button onclick="runTest()">1. Copy</button>
<div><br></div>
<div id="source" oncopy="copy(event)" contenteditable>http://webkit.org/b/&%23x1F914;?x=8 + 6<</div>
<div id="destination" onpaste="paste(event)" contenteditable>2. Paste here</div>
<script>
const originalURL = document.getElementById('source').textContent;
function copy(event) {
event.clipboardData.setData('url', originalURL);
event.clipboardData.setData('text/html', 'testing');
event.preventDefault();
}
function paste(event) {
parent.postMessage({
originalURL,
url: event.clipboardData.getData('url'),
html: event.clipboardData.getData('text/html'),
types: event.clipboardData.types,
items: Array.from(event.clipboardData.items).map((item) => ({kind: item.kind, type: item.type})),
}, '*');
}
function runTest() {
document.body.getBoundingClientRect();
document.getElementById('source').focus();
document.execCommand('selectAll');
document.execCommand('copy');
document.getElementById('destination').focus();
if (window.testRunner)
document.execCommand('paste');
}
if (window.testRunner)
runTest();
</scri` + 'pt>';
onmessage = (event) => {
originalURL = event.data.originalURL;
urlReadInSameDocument = event.data.url;
shouldBeEqualToString('urlReadInSameDocument', originalURL);
htmlReadInSameDocument = event.data.html;
shouldBeEqualToString('htmlReadInSameDocument', "testing");
typesInSameDocument = event.data.types;
shouldBeTrue('typesInSameDocument.includes("text/uri-list")');
shouldBeTrue('typesInSameDocument.includes("text/html")');
itemsInSameDocument = event.data.items;
shouldBeEqualToString('JSON.stringify(itemsInSameDocument[0])', '{"kind":"string","type":"text/uri-list"}');
shouldBeEqualToString('JSON.stringify(itemsInSameDocument[1])', '{"kind":"string","type":"text/html"}');
document.getElementById('destination').focus();
if (window.testRunner)
document.execCommand('paste');
}
function doPaste(event) {
shouldBeEqualToString('event.clipboardData.getData("url")', (new URL(originalURL)).href);
shouldBeTrue('event.clipboardData.types.includes("text/uri-list")');
shouldBeTrue('event.clipboardData.types.includes("text/html")');
pastedItems = [...event.clipboardData.items].map(item => ({ kind: item.kind, type: item.type }));
shouldBeEqualToString('JSON.stringify(pastedItems[0])', '{"kind":"string","type":"text/uri-list"}');
shouldBeEqualToString('JSON.stringify(pastedItems[1])', '{"kind":"string","type":"text/html"}');
document.getElementById('destination').remove();
finishJSTest();
}
</script>
<div id="destination" onpaste="doPaste(event)" contenteditable>3. Paste here</div>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>