diff options
Diffstat (limited to 'testing/web-platform/tests/intersection-observer/isIntersecting-threshold.html')
-rw-r--r-- | testing/web-platform/tests/intersection-observer/isIntersecting-threshold.html | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/testing/web-platform/tests/intersection-observer/isIntersecting-threshold.html b/testing/web-platform/tests/intersection-observer/isIntersecting-threshold.html new file mode 100644 index 0000000000..842c8e2c9f --- /dev/null +++ b/testing/web-platform/tests/intersection-observer/isIntersecting-threshold.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<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> +<style> +#scroller { width: 100px; height: 100px; overflow: scroll; } +#scroller > div { height: 800px; } +#target { margin-top: 25px; height: 50px; background-color: blue; } +</style> +<div id="scroller"> + <div> + <div id="target"></div> + </div> +</div> + +<script> +let entries = []; + +window.onload = function() { + runTestCycle(step2, "At initial scroll position"); + + scroller.scrollTop = 0; + let observer = new IntersectionObserver( + es => entries = entries.concat(es), + { threshold: 1 } + ); + observer.observe(target); +}; + +function step2() { + runTestCycle(step3, "Scrolled to half way through target element"); + + assert_equals(entries.length, 1); + assert_equals(entries[0].intersectionRatio, 1); + assert_equals(entries[0].isIntersecting, true); + scroller.scrollTop = 50; +} + +function step3() { + runTestCycle(step4, "Scrolled to target element completely off screen"); + + assert_equals(entries.length, 2); + assert_true(entries[1].intersectionRatio >= 0.5 && + entries[1].intersectionRatio < 1); + // See https://github.com/w3c/IntersectionObserver/issues/432 + assert_equals(entries[1].isIntersecting, false); + scroller.scrollTop = 100; +} + +function step4() { + assert_equals(entries.length, 2); +} +</script> |