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/canvas/element/manual/draw-element-image/hit-test/z-index.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<title>elementFromPoint should respect z-index</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/wait-for-canvas-paint.js"></script>
<style>
#canvas {
width: 200px;
height: 200px;
}
div {
width: 100px;
height: 100px;
background: green;
position: absolute;
top: 0;
left: 0;
}
</style>
<canvas id=canvas width="200" height="200" layoutsubtree>
<div id=a></div>
<div id=b></div>
</canvas>
<script>
promise_test(async function() {
a.style.zIndex = 5;
b.style.zIndex = 6;
await waitForCanvasPaint(canvas);
const ctx = canvas.getContext('2d');
ctx.drawElementImage(b, 0, 0);
ctx.drawElementImage(a, 0, 0);
assert_equals(document.elementFromPoint(60, 60), a);
}, 'Draw order trumps z-index in hit testing.');
</script>
</html>