forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve coverage for callback this value
Includes CSSPaintCallback, MutationCallback, and IntersectionObserverCallback tests.
- Loading branch information
1 parent
5b22a1f
commit af4259a
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<meta charset="utf-8"> | ||
<title>Paint callback is invoked with `this` value of `paintInstance`</title> | ||
<link rel="help" href="https://drafts.css-houdini.org/css-paint-api-1/#invoke-a-paint-callback"> | ||
<link rel="match" href="parse-input-arguments-ref.html"> | ||
<style> | ||
.container { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
#canvas-geometry { | ||
background-image: paint(geometry); | ||
} | ||
</style> | ||
<script src="/common/reftest-wait.js"></script> | ||
<script src="/common/worklet-reftest.js"></script> | ||
<body> | ||
<div id="canvas-geometry" class="container"></div> | ||
|
||
<script id="code" type="text/worklet"> | ||
let paintInstance; | ||
|
||
registerPaint('geometry', class { | ||
constructor() { | ||
paintInstance = this; | ||
} | ||
paint(ctx, geom) { | ||
if (this === paintInstance) | ||
ctx.fillStyle = 'green'; | ||
else | ||
ctx.fillStyle = 'red'; | ||
ctx.fillRect(0, 0, geom.width, geom.height); | ||
} | ||
}); | ||
</script> | ||
|
||
<script> | ||
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE HTML> | ||
<meta charset=utf-8> | ||
<title>MutationObserver: callback arguments</title> | ||
<link rel="help" href="https://dom.spec.whatwg.org/#notify-mutation-observers"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="mo-target"></div> | ||
<div id="log"></div> | ||
<script> | ||
"use strict"; | ||
|
||
async_test(t => { | ||
const moTarget = document.querySelector("#mo-target"); | ||
const mo = new MutationObserver(function(records, observer) { | ||
t.step(() => { | ||
assert_equals(this, mo); | ||
assert_equals(arguments.length, 2); | ||
assert_true(Array.isArray(records)); | ||
assert_equals(records.length, 1); | ||
assert_true(records[0] instanceof MutationRecord); | ||
assert_equals(observer, mo); | ||
|
||
mo.disconnect(); | ||
t.done(); | ||
}); | ||
}); | ||
|
||
mo.observe(moTarget, {attributes: true}); | ||
moTarget.className = "trigger-mutation"; | ||
}, "Callback is invoked with |this| value of MutationObserver and two arguments"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE HTML> | ||
<meta charset=utf-8> | ||
<title>IntersectionObserver: callback arguments</title> | ||
<link rel="help" href="https://w3c.github.io/IntersectionObserver/#notify-intersection-observers-algo"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="log"></div> | ||
<script> | ||
"use strict"; | ||
|
||
async_test(t => { | ||
const io = new IntersectionObserver(function(entries, observer) { | ||
t.step(() => { | ||
assert_equals(this, io); | ||
assert_equals(arguments.length, 2); | ||
assert_true(Array.isArray(entries)); | ||
assert_equals(entries.length, 1); | ||
assert_true(entries[0] instanceof IntersectionObserverEntry); | ||
assert_equals(observer, io); | ||
|
||
io.disconnect(); | ||
t.done(); | ||
}); | ||
}); | ||
|
||
io.observe(document.body); | ||
}, "Callback is invoked with |this| value of IntersectionObserver and two arguments"); | ||
</script> |