blob: e41569c531b0ee0c02ff8dc3ede9abad1291e2cc [file] [log] [blame]
<!DOCTYPE html>
<div id="root"></div>
<div id="target"></div>
<script src="../resources/js-test.js"></script>
<script src="../resources/gc.js"></script>
<script>
description("Test for observer exceptions.");
var exc;
try {
new IntersectionObserver(e => {}, {threshold: [1.1]});
testFailed("IntersectionObserver constructor did not throw due to invalid threshold.");
} catch(e) {
exc = e;
shouldBeType("exc", "RangeError");
}
try {
new IntersectionObserver(e => {}, {threshold: ["foo"]});
testFailed("IntersectionObserver constructor did not throw due to invalid threshold.");
} catch(e) {
exc = e;
shouldBeType("exc", "RangeError");
}
try {
new IntersectionObserver(e => {}, {rootMargin: "1"});
testFailed("IntersectionObserver constructor did not throw due to invalid rootMargin.");
} catch(e) {
exc = e;
shouldBeType("exc", "DOMException");
shouldBe("exc.code", "DOMException.SYNTAX_ERR");
}
try {
new IntersectionObserver(e => {}, {rootMargin: "2em"});
testFailed("IntersectionObserver constructor did not throw due to invalid rootMargin.");
} catch(e) {
exc = e;
shouldBeType("exc", "DOMException");
shouldBe("exc.code", "DOMException.SYNTAX_ERR");
}
try {
new IntersectionObserver(e => {}, {rootMargin: "auto"});
testFailed("IntersectionObserver constructor did not throw due to invalid rootMargin.");
} catch(e) {
exc = e;
shouldBeType("exc", "DOMException");
shouldBe("exc.code", "DOMException.SYNTAX_ERR");
}
try {
new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"});
testFailed("IntersectionObserver constructor did not throw due to too many rootMargin value.");
} catch(e) {
exc = e;
shouldBeType("exc", "DOMException");
shouldBe("exc.code", "DOMException.SYNTAX_ERR");
}
let observer = new IntersectionObserver(c => {}, {});
try {
observer.observe("foo");
testFailed("IntersectionObserver.observe with a bad target argument did not throw.");
} catch(e) {
exc = e;
shouldBeType("exc", "TypeError");
}
// Initialize observer and remove root in an inner function to avoid
// references to rootDiv remaining live on this function's stack frame
// (http://crbug.com/595672/).
function initializeObserverThenRemoveRootDiv() {
let rootDiv = document.getElementById("root");
let observer = new IntersectionObserver(c => {}, {root: rootDiv});
rootDiv.parentNode.removeChild(rootDiv);
return observer;
}
observer = initializeObserverThenRemoveRootDiv();
gc();
observer.observe(target);
observer.unobserve(target);
observer.disconnect();
shouldBeEqualToNumber("0", observer.takeRecords().length);
</script>