summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/intersection-observer/svg-viewbox.html
blob: 718b97624ae613069497ac467017403ee11fea3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<title>IntersectionObserver observing an SVG &lt;rect> element with changing 'transform'</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/intersection-observer-test-utils.js"></script>
<svg id="container" width="10" height="10" viewBox="0 0 128 128" style="background: lightblue; position: absolute; top: 0; left: 0;">
    <rect id="target" x="0" y="0" width="128" height="128" fill="green"></rect>
</svg>
<script>
const viewportWidth = document.documentElement.clientWidth;
const viewportHeight = document.documentElement.clientHeight;
setup(() => {
  window.entries = [];
  window.target = document.getElementById("target");
  window.targetRect = target.getBoundingClientRect();
});
runTestCycle(function() {
  assert_true(!!target, "target exists");
  const observer = new IntersectionObserver(function(changes) {
    entries = entries.concat(changes);
  }, {root: container, threshold: [0, 0.5, 1]});
  observer.observe(target);
  entries = entries.concat(observer.takeRecords());
  assert_equals(entries.length, 0, "No initial notifications");
  runTestCycle(step0, "First rAF.");
});
function step0() {
  target.setAttribute('y', '-64');
  runTestCycle(step1, "change target's y property to -64)");
  // The numbers in brackets are target client rect; intersection rect;
  // and root bounds.
  checkLastEntry(entries, 0, [
    0, targetRect.width, 0, targetRect.height,
    0, targetRect.width, 0, targetRect.height,
    0, 10, 0, 10,
    true,
  ]);
}
function step1() {
  target.style.transform = "translate(0, 50px)";
  checkLastEntry(entries, 1, [
    0, targetRect.width, -5, -5 + targetRect.height,
    0, targetRect.width, 0, -5 + targetRect.height,
    0, 10, 0, 10,
    true,
  ]);
}
</script>