summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-pseudo/support
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/css/css-pseudo/support
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-pseudo/support')
-rw-r--r--testing/web-platform/tests/css/css-pseudo/support/100x100-red.pngbin0 -> 510 bytes
-rw-r--r--testing/web-platform/tests/css/css-pseudo/support/60x60-red.pngbin0 -> 217 bytes
-rw-r--r--testing/web-platform/tests/css/css-pseudo/support/highlights.css68
-rw-r--r--testing/web-platform/tests/css/css-pseudo/support/selections.js72
4 files changed, 140 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-pseudo/support/100x100-red.png b/testing/web-platform/tests/css/css-pseudo/support/100x100-red.png
new file mode 100644
index 0000000000..57bf3ddc52
--- /dev/null
+++ b/testing/web-platform/tests/css/css-pseudo/support/100x100-red.png
Binary files differ
diff --git a/testing/web-platform/tests/css/css-pseudo/support/60x60-red.png b/testing/web-platform/tests/css/css-pseudo/support/60x60-red.png
new file mode 100644
index 0000000000..823f125b8e
--- /dev/null
+++ b/testing/web-platform/tests/css/css-pseudo/support/60x60-red.png
Binary files differ
diff --git a/testing/web-platform/tests/css/css-pseudo/support/highlights.css b/testing/web-platform/tests/css/css-pseudo/support/highlights.css
new file mode 100644
index 0000000000..3ec7e0dd31
--- /dev/null
+++ b/testing/web-platform/tests/css/css-pseudo/support/highlights.css
@@ -0,0 +1,68 @@
+/**
+ * Container for the interesting part of a highlight reftest, to be
+ * used on both the test page and any reference pages.
+ */
+.highlight_reftest {
+ /*
+ https://drafts.csswg.org/css-pseudo-4/#highlight-bounds
+ For text, the corresponding overlay must cover at least
+ the entire em box and may extend further above/below the
+ em box to the line box edges.
+ */
+ line-height: 1;
+}
+
+/**
+ * Container for layers. All text is transparent by default, and each direct
+ * child creates a layer that overlaps any text content.
+ */
+.hrt_layers,
+.hrt_layers * {
+ color: transparent;
+}
+.hrt_layers {
+ position: relative;
+}
+.hrt_layers > * {
+ position: absolute;
+}
+
+/**
+ * Cover to clip text from the right. Usage:
+ *
+ * <div class="hrt_layers">
+ * <div><!-- content to clip to “foo” from right --></div>
+ * <div><span class="hrt_cover">bar</span>foobar</div>
+ * foobar
+ * </div>
+ */
+.hrt_cover {
+ background: white;
+ position: absolute;
+ padding: 0.5em 0;
+ top: -0.5em;
+ right: 0;
+}
+
+/**
+ * Hider to clip text from the left. Usage:
+ *
+ * <div class="hrt_layers">
+ * <div>foo<span class="hrt_hider">
+ * <div><!-- content to clip to “bar” from left --></div>
+ * bar
+ * </span></div>
+ * foobar
+ * </div>
+ */
+.hrt_hider {
+ display: inline-block;
+ overflow: hidden;
+ position: relative;
+ padding: 0.5em 0;
+ top: -0.5em;
+}
+.hrt_hider > * {
+ position: absolute;
+ right: 0;
+}
diff --git a/testing/web-platform/tests/css/css-pseudo/support/selections.js b/testing/web-platform/tests/css/css-pseudo/support/selections.js
new file mode 100644
index 0000000000..d0cd3409a7
--- /dev/null
+++ b/testing/web-platform/tests/css/css-pseudo/support/selections.js
@@ -0,0 +1,72 @@
+/**
+ * Replaces the current selection (if any) with a new range, after
+ * it’s configured by the given function.
+ *
+ * See also: selectNodeContents
+ * Example:
+ *
+ * selectRangeWith(range => {
+ * range.selectNodeContents(foo);
+ * range.setStart(foo.childNodes[0], 3);
+ * range.setEnd(foo.childNodes[0], 5);
+ * });
+ */
+function selectRangeWith(fun) {
+ const selection = getSelection();
+
+ // Deselect any ranges that happen to be selected, to prevent the
+ // Selection#addRange call from ignoring our new range (see
+ // <https://www.chromestatus.com/feature/6680566019653632> for
+ // more details).
+ selection.removeAllRanges();
+
+ // Create and configure a range.
+ const range = document.createRange();
+ fun(range);
+
+ // Select our new range.
+ selection.addRange(range);
+}
+
+/**
+ * Replaces the current selection (if any) with a new range, spanning
+ * the contents of the given node.
+ */
+function selectNodeContents(node) {
+ const previousActive = document.activeElement;
+
+ selectRangeWith(range => range.selectNodeContents(node));
+
+ // If the selection update causes the node or an ancestor to be
+ // focused (Chromium 80+), unfocus it, to avoid any focus-related
+ // styling such as outlines.
+ if (document.activeElement != previousActive) {
+ document.activeElement.blur();
+ }
+}
+
+/**
+ * Tries to convince a UA with lazy spellcheck to check and highlight
+ * the contents of the given nodes (form fields or @contenteditables).
+ *
+ * Each node is focused then immediately unfocused. Both focus and
+ * selection can be used for this purpose, but only focus works for
+ * @contenteditables.
+ */
+function trySpellcheck(...nodes) {
+ // This is inherently a flaky test risk, but Chromium (as of 87)
+ // seems to cancel spellcheck on a node if it wasn’t the last one
+ // focused for “long enough” (though immediate unfocus is ok).
+ // Using requestAnimationFrame or setInterval(0) are usually not
+ // long enough (see <https://bucket.daz.cat/work/igalia/0/0.html>
+ // under “trySpellcheck strategy” for an example).
+ const interval = setInterval(() => {
+ if (nodes.length > 0) {
+ const node = nodes.shift();
+ node.focus();
+ node.blur();
+ } else {
+ clearInterval(interval);
+ }
+ }, 250);
+}