mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
LibWeb: Implement more IntersectionObserver attributes
This commit is contained in:
parent
7444f76b0d
commit
3e536a4cd7
Notes:
github-actions[bot]
2024-11-23 08:53:22 +00:00
Author: https://github.com/Psychpsyo
Commit: 3e536a4cd7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2507
9 changed files with 345 additions and 17 deletions
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<script src="../resources/testharness.js"></script>
|
||||
<script src="../resources/testharnessreport.js"></script>
|
||||
|
||||
<div id="root"></div>
|
||||
|
||||
<script>
|
||||
test(function() {
|
||||
var observer = new IntersectionObserver(function(e) {}, {});
|
||||
test(function() { assert_equals(observer.root, null) },
|
||||
"observer.root");
|
||||
test(function() { assert_array_equals(observer.thresholds, [0]) },
|
||||
"observer.thresholds");
|
||||
test(function() { assert_equals(observer.rootMargin, "0px 0px 0px 0px") },
|
||||
"observer.rootMargin");
|
||||
|
||||
observer = new IntersectionObserver(function(e) {}, {
|
||||
rootMargin: " ",
|
||||
threshold: []
|
||||
});
|
||||
test(function() { assert_array_equals(observer.thresholds, [0]) },
|
||||
"empty observer.thresholds");
|
||||
test(function() { assert_equals(observer.rootMargin, "0px 0px 0px 0px") },
|
||||
"whitespace observer.rootMargin");
|
||||
|
||||
var rootDiv = document.getElementById("root");
|
||||
observer = new IntersectionObserver(function(e) {}, {
|
||||
root: rootDiv,
|
||||
threshold: [0, 0.25, 0.5, 1.0],
|
||||
rootMargin: "10% 20px"
|
||||
});
|
||||
test(function() { assert_equals(observer.root, rootDiv) },
|
||||
"set observer.root");
|
||||
test(function() { assert_array_equals(observer.thresholds, [0, 0.25, 0.5, 1.0]) },
|
||||
"set observer.thresholds");
|
||||
test(function() { assert_equals(observer.rootMargin, "10% 20px 10% 20px") },
|
||||
"set observer.rootMargin");
|
||||
}, "Observer attribute getters.");
|
||||
|
||||
</script>
|
|
@ -0,0 +1,61 @@
|
|||
<!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>
|
||||
test(function () {
|
||||
assert_throws_js(RangeError, function() {
|
||||
new IntersectionObserver(e => {}, {threshold: [1.1]})
|
||||
})
|
||||
}, "IntersectionObserver constructor with { threshold: [1.1] }");
|
||||
|
||||
test(function () {
|
||||
assert_throws_js(TypeError, function() {
|
||||
new IntersectionObserver(e => {}, {threshold: ["foo"]})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { threshold: ["foo"] }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_dom("SYNTAX_ERR", function() {
|
||||
new IntersectionObserver(e => {}, {rootMargin: "1"})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { rootMargin: "1" }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_dom("SYNTAX_ERR", function() {
|
||||
new IntersectionObserver(e => {}, {rootMargin: "2em"})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { rootMargin: "2em" }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_dom("SYNTAX_ERR", function() {
|
||||
new IntersectionObserver(e => {}, {rootMargin: "auto"})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { rootMargin: "auto" }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_dom("SYNTAX_ERR", function() {
|
||||
new IntersectionObserver(e => {}, {rootMargin: "calc(1px + 2px)"})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { rootMargin: "calc(1px + 2px)" }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_dom("SYNTAX_ERR", function() {
|
||||
new IntersectionObserver(e => {}, {rootMargin: "1px !important"})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { rootMargin: "1px !important" }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_dom("SYNTAX_ERR", function() {
|
||||
new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"})
|
||||
})
|
||||
}, 'IntersectionObserver constructor with { rootMargin: "1px 1px 1px 1px 1px" }');
|
||||
|
||||
test(function () {
|
||||
assert_throws_js(TypeError, function() {
|
||||
let observer = new IntersectionObserver(c => {}, {});
|
||||
observer.observe("foo");
|
||||
})
|
||||
}, 'IntersectionObserver.observe("foo")');
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue