Skip to content

Commit

Permalink
Improve coverage for callback this value
Browse files Browse the repository at this point in the history
Includes CSSPaintCallback, MutationCallback, and IntersectionObserverCallback tests.
  • Loading branch information
shvaikalesh authored Aug 5, 2020
1 parent 5b22a1f commit af4259a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
43 changes: 43 additions & 0 deletions css/css-paint-api/paint-function-this-value.https.html
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>
31 changes: 31 additions & 0 deletions dom/nodes/MutationObserver-callback-arguments.html
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>
28 changes: 28 additions & 0 deletions intersection-observer/observer-callback-arguments.html
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>

0 comments on commit af4259a

Please sign in to comment.