summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/intersection-observer/svg-container-element.html
blob: 1c27acee514a3e197c21d2cea1a022fe3e294769 (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
50
51
52
53
54
<!DOCTYPE html>
<title>IntersectionObserver observing an SVG container element changing position</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 width="400" height="10000">
  <!-- Ensure the svg bounds are unchanged with a white fill -->
  <rect x="-5000" y="-5000" width="100000" height="100000" fill="white"/>
  <svg id="target" x="0" y="100vh" width="100px" height="100px">
    <rect x="0" y="0" width="100" height="100" fill="green"/>
  </svg>
</svg>
<script>
const viewportWidth = document.documentElement.clientWidth;
const viewportHeight = document.documentElement.clientHeight;
const kEpsilon = 1; // clientHeight and clientWidth are rounded if the viewport is fractional.
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);
  });
  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', '0');
  runTestCycle(step1, "Change inner svg element")
  // The numbers in brackets are target client rect; intersection rect;
  // and root bounds.
  checkLastEntry(entries, 0, [
    // the 8 pixels comes from the html body padding.
    8, 8 + targetRect.width, viewportHeight+8, viewportHeight+8 + targetRect.height,
    0, 0, 0, 0,
    0, viewportWidth, 0, viewportHeight,
    false,
  ], kEpsilon);
}
function step1() {
  checkLastEntry(entries, 1, [
    8, 8 + targetRect.width, 8, 8 + targetRect.height,
    8, 8 + targetRect.width, 8, 8 + targetRect.height,
    0, viewportWidth, 0, viewportHeight,
    true,
  ], kEpsilon);
}
</script>