diff --git a/html/dom/elements/global-attributes/dir-assorted.window.js b/html/dom/elements/global-attributes/dir-assorted.window.js
index 038b3f78d4d3732..0d4e4b82d9b9531 100644
--- a/html/dom/elements/global-attributes/dir-assorted.window.js
+++ b/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`);
+ }
+}