From db546acda7d144e95025f21620a867c0a3750c86 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Wed, 10 Jan 2024 10:12:06 +0000 Subject: [PATCH] Bug 1873662 [wpt PR 43896] - Add more tests for directionality of element., a=testonly Automatic update from web-platform-tests HTML: more tests for directionality of element This adds tests related to https://github.com/whatwg/html/pull/10005. -- wpt-commits: 556b7eb5a3fc5dda915f70435b1a15220617baac wpt-pr: 43896 --- .../global-attributes/dir-assorted.window.js | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/testing/web-platform/tests/html/dom/elements/global-attributes/dir-assorted.window.js b/testing/web-platform/tests/html/dom/elements/global-attributes/dir-assorted.window.js index 038b3f78d4d3..0d4e4b82d9b9 100644 --- a/testing/web-platform/tests/html/dom/elements/global-attributes/dir-assorted.window.js +++ b/testing/web-platform/tests/html/dom/elements/global-attributes/dir-assorted.window.js @@ -80,3 +80,36 @@ test(() => { assert_false(e1.matches(":dir(ltr)"), "parent is RTL after changing text in child"); assert_false(e2.matches(":dir(ltr)"), "child is RTL after changing text in child"); }, "text changes apply to dir=auto on further ancestor after removing dir=auto from closer ancestor"); + +for (const bdi_test of [ + { markup: "A", expected: "ltr", desc: "dir=ltr with LTR contents" }, + { markup: "\u05d0", expected: "ltr", desc: "dir=ltr with RTL contents" }, + { markup: "", expected: "ltr", desc: "dir=ltr empty" }, + { markup: "A", expected: "rtl", desc: "dir=rtl with LTR contents" }, + { markup: "\u05d0", expected: "rtl", desc: "dir=rtl with RTL contents" }, + { markup: "", expected: "rtl", desc: "dir=rtl empty" }, + { markup: "A", expected: "ltr", desc: "dir=auto with LTR contents" }, + { markup: "\u05d0", expected: "rtl", desc: "dir=auto with RTL contents" }, + { markup: "", expected: "parent", desc: "dir=auto empty" }, + { markup: "A", expected: "ltr", desc: "no dir attribute with LTR contents" }, + { markup: "\u05d0", expected: "rtl", desc: "no dir attribute with RTL contents" }, + { markup: "", expected: "parent", desc: "no dir attribute empty" }, +]) { + for (const parent_dir of [ "ltr", "rtl" ]) { + test(() => { + const parent_element = document.createElement("div"); + parent_element.dir = parent_dir; + document.body.appendChild(parent_element); + parent_element.innerHTML = bdi_test.markup; + const bdi_element = parent_element.querySelector("bdi"); + let expected = bdi_test.expected; + if (expected == "parent") { + expected = parent_dir; + } + const not_expected = (expected == "ltr") ? "rtl" : "ltr"; + assert_true(bdi_element.matches(`:dir(${expected})`)); + assert_false(bdi_element.matches(`:dir(${not_expected})`)); + parent_element.remove(); + }, `directionality of bdi elements: ${bdi_test.desc} in ${parent_dir} parent`); + } +} -- 2.11.4.GIT