diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/css/cssom-view/scroll-behavior-element.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/cssom-view/scroll-behavior-element.html')
-rw-r--r-- | testing/web-platform/tests/css/cssom-view/scroll-behavior-element.html | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/cssom-view/scroll-behavior-element.html b/testing/web-platform/tests/css/cssom-view/scroll-behavior-element.html new file mode 100644 index 0000000000..c598d97b33 --- /dev/null +++ b/testing/web-platform/tests/css/cssom-view/scroll-behavior-element.html @@ -0,0 +1,189 @@ +<!DOCTYPE html> +<title>Testing scrollOptions' behavior for Element.scroll* and scroll-behavior on an element</title> +<meta name="timeout" content="long"/> +<link rel="author" title="Frédéric Wang" href="mailto:fwang@igalia.com"> +<link rel="help" href="https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior"> +<link rel="help" href="https://drafts.csswg.org/cssom-view/#scrolling-box"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="support/scroll-behavior.js"></script> +<style> + .scrollable { + overflow: auto; + width: 400px; + height: 200px; + } + .autoBehavior { + scroll-behavior: auto; + } + .smoothBehavior { + scroll-behavior: smooth; + } +</style> +<div id="log"> +</div> +<div id="overflowNode" class="scrollable"> + <div style="width: 2000px; height: 1000px; background: linear-gradient(135deg, red, green);"> + <span style="display: inline-block; width: 500px; height: 250px;"></span><span id="elementToReveal" style="display: inline-block; vertical-align: -15px; width: 10px; height: 15px; background: black;"></span> + </div> +</div> +<script> + var scrollingElement = overflowNode; + var styledElement = overflowNode; + var elementToRevealLeft = 500; + var elementToRevealTop = 250; + + ["scroll", "scrollTo", "scrollBy", "scrollIntoView"].forEach((scrollFunction) => { + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "autoBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, null, elementToRevealLeft, elementToRevealTop); + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately"); + return new Promise((resolve) => { resolve(); }); + }, `Element with auto scroll-behavior ; ${scrollFunction}() with default behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "autoBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, "auto", elementToRevealLeft, elementToRevealTop); + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately"); + return new Promise((resolve) => { resolve(); }); + }, `Element with auto scroll-behavior ; ${scrollFunction}() with auto behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "autoBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, "instant", elementToRevealLeft, elementToRevealTop); + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately"); + return new Promise((resolve) => { resolve(); }); + }, `Element with auto scroll-behavior ; ${scrollFunction}() with instant behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "autoBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, "smooth", elementToRevealLeft, elementToRevealTop); + assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately"); + assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately"); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop"); + }); + }, `Element with auto scroll-behavior ; ${scrollFunction}() with smooth behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, null, elementToRevealLeft, elementToRevealTop); + assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately"); + assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately"); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop"); + }); + }, `Element with smooth scroll-behavior ; ${scrollFunction}() with default behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, "auto", elementToRevealLeft, elementToRevealTop); + assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately"); + assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately"); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop"); + }); + }, `Element with smooth scroll-behavior ; ${scrollFunction}() with auto behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, "instant", elementToRevealLeft, elementToRevealTop); + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately"); + return new Promise((resolve) => { resolve(); }); + }, `Element with smooth scroll-behavior ; ${scrollFunction}() with instant behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, scrollFunction, "smooth", elementToRevealLeft, elementToRevealTop); + assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately"); + assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately"); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop"); + }); + }, `Element with smooth scroll-behavior ; ${scrollFunction}() with smooth behavior`); + }); + + [{scrollAttribute: "scrollLeft", scrollValue: elementToRevealLeft}, {scrollAttribute: "scrollTop", scrollValue: elementToRevealTop}].forEach((attributeTest) => { + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "autoBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + var expectedValue = Number(attributeTest.scrollValue); + scrollingElement[attributeTest.scrollAttribute] = expectedValue; + assert_equals( scrollingElement[attributeTest.scrollAttribute], expectedValue, "Should set scroll attribute immediately"); + return new Promise((resolve) => { resolve(); }); + }, `Set ${attributeTest.scrollAttribute} to element with auto scroll-behavior`); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + var expectedValue = Number(attributeTest.scrollValue); + scrollingElement[attributeTest.scrollAttribute] = expectedValue; + assert_less_than(scrollingElement[attributeTest.scrollAttribute], expectedValue, "Shouldn't set scroll attribute immediately"); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement[attributeTest.scrollAttribute], expectedValue, "Final value of scroll attribute"); + }); + }, `Set ${attributeTest.scrollAttribute} to element with smooth scroll-behavior`); + }); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, "scroll", "smooth", elementToRevealLeft, elementToRevealTop); + scrollNode(scrollingElement, "scroll", "smooth", elementToRevealLeft / 2, elementToRevealTop / 2); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement.scrollLeft, elementToRevealLeft / 2, "Final value of scrollLeft"); + assert_equals(scrollingElement.scrollTop, elementToRevealTop / 2, "Final value of scrollTop"); + }); + }, "Aborting an ongoing smooth scrolling on an element with another smooth scrolling"); + + promise_test(() => { + resetScroll(scrollingElement); + setScrollBehavior(styledElement, "smoothBehavior"); + assert_equals(scrollingElement.scrollLeft, 0); + assert_equals(scrollingElement.scrollTop, 0); + scrollNode(scrollingElement, "scroll", "smooth", elementToRevealLeft, elementToRevealTop); + scrollNode(scrollingElement, "scroll", "instant", 0, 0); + return waitForScrollEnd(scrollingElement).then(() => { + assert_equals(scrollingElement.scrollLeft, 0, "Final value of scrollLeft"); + assert_equals(scrollingElement.scrollTop, 0, "Final value of scrollTop"); + }); + }, "Aborting an ongoing smooth scrolling on an element with an instant scrolling"); +</script> |