Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/editing/dnd/reload/001.html - WPT Dashboard Interop Dashboard
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Reload during canvas drag and drop roundtrip</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="support/drag-reload-test.js"></script>
<style>
body { margin: 20px; }
</style>
<script>
function sourceDragStart(event) {
event.dataTransfer.effectAllowed = 'copy';
event.dataTransfer.setData(
'text/uri-list', event.currentTarget.toDataURL('image/png'));
location.reload();
}
function targetDrop(event) {
event.preventDefault();
const data = event.dataTransfer.getData('text/uri-list').replace(/\r\n$/, '');
const image = document.createElement('img');
image.id = 'dropped-image';
image.src = data;
event.currentTarget.after(image);
}
</script>
</head>
<body>
<canvas id="source" width="100" height="100" draggable="true"
ondragstart="sourceDragStart(event)" ondragenter="event.preventDefault()"
ondragover="event.preventDefault()" ondrop="targetDrop(event)"></canvas>
<script>
const canvas = document.getElementById('source');
const context = canvas.getContext('2d');
for (let x = 0; x < 50; ++x) {
context.fillStyle = x % 2 === 0 ? 'navy' : 'white';
context.fillRect(x, x, 100 - 2 * x, 100 - 2 * x);
}
testDragAcrossReload({
dataType: 'text/uri-list',
getExpectedData: source => source.toDataURL('image/png'),
verifyDrop: async (target, expectedData) => {
const image = target.ownerDocument.getElementById('dropped-image');
assert_not_equals(image, null, 'The drop handler duplicates the image');
assert_equals(image.src, expectedData, 'The duplicate has the original URL');
await image.decode();
},
});
</script>
</body>
</html>