1<!DOCTYPE html>
2<meta charset="utf-8" />
3<title>CSS Selectors Invalidation: :modal pseudo class in :has()</title>
4<link rel="author" title="Tim Nguyen" href="https://github.com/nt1m">
5<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
6<script src="/resources/testharness.js"></script>
7<script src="/resources/testharnessreport.js"></script>
8<style>
9 #subject:has(#dialog:modal) { color: green }
10</style>
11<div id="subject">
12 This is some text.
13 <dialog id="dialog">This is a dialog</dialog>
14</div>
15<script>
16 test(function() {
17 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
18 "ancestor should be black since dialog is not modal");
19 dialog.show();
20 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
21 "ancestor should be black since dialog is not modal");
22 dialog.close();
23 }, ":modal pseudo-class is not active with dialog.show()");
24 test(function() {
25 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
26 "ancestor should be black");
27 dialog.showModal();
28 assert_equals(getComputedStyle(subject).color, "rgb(0, 128, 0)",
29 "ancestor should be green since dialog is shown modally");
30 dialog.close();
31 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
32 "ancestor should be black since dialog is closed");
33 }, ":modal pseudo-class invalidation with showModal+close");
34 test(function() {
35 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
36 "ancestor should be black");
37 dialog.showModal();
38 assert_equals(getComputedStyle(subject).color, "rgb(0, 128, 0)",
39 "ancestor should be green since dialog is shown modally");
40 dialog.remove();
41 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
42 "ancestor should be black since dialog is closed");
43 }, ":modal pseudo-class invalidation with showModal+remove");
44</script>