File: intersection-ratio-ib-split.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (45 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download | duplicates (18)
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
<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="https://mozilla.org" title="Mozilla">
<link rel="help" href="https://w3c.github.io/IntersectionObserver/#dom-intersectionobserverentry-intersectionratio">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1581876">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  block {
    display: block;
    width: 50vw;
    height: 50vh;
    background: green;
  }
</style>
<inline>
  <block></block>
</inline>
<script>

// Account for rounding differences when viewport sizes can't cleanly divide.
const epsilon = 1;

promise_test(async function() {
  for (let element of document.querySelectorAll("inline, block")) {
    let entries = await new Promise(resolve => {
      new IntersectionObserver(resolve).observe(element);
    });
    assert_equals(entries.length, 1, element.nodeName + ": Should get an entry");
    assert_true(entries[0].isIntersecting, element.nodeName + ": Should be intersecting");
    assert_equals(entries[0].intersectionRatio, 1, element.nodeName + ": Should be fully intersecting");

    function assert_rects_equal(r1, r2, label) {
      assert_approx_equals(r1.top, r2.top, epsilon, label + ": top should be equal");
      assert_approx_equals(r1.right, r2.right, epsilon, label + ": right should be equal");
      assert_approx_equals(r1.bottom, r2.bottom, epsilon, label + ": bottom should be equal");
      assert_approx_equals(r1.left, r2.left, epsilon, label + ": left should be equal");
    }

    assert_rects_equal(entries[0].boundingClientRect, element.getBoundingClientRect(), element.nodeName + ": boundingClientRect should match");
    assert_rects_equal(entries[0].intersectionRect, entries[0].boundingClientRect, element.nodeName + ": intersectionRect should match entry.boundingClientRect");
  }
}, "IntersectionObserver on an IB split gets the right intersection ratio");
</script>