summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/media/sound-state.html
blob: d9eb86a5ebe3935359040b6478046a2dd4ffee0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<title>Sound State: the :muted and :volume-locked pseudo-classes</title>
<link
  rel="help"
  href="https://w3c.github.io/csswg-drafts/selectors/#sound-state"
/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
  <video width="300" height="300" loop></video>
  <script type="module">
    // Unfortunately, we can't test the volume-locked state because it's not
    // possible to lock the volume of a video element with JS.

    test((t) => {
      for (const pseudo of [":muted", ":volume-locked"]) {
        try {
          document.querySelector(`.not-a-thing${pseudo}`);
        } catch (e) {
          assert_unreached(`${pseudo} is not supported`);
        }
      }
    }, "Test :pseudo-class syntax is supported without throwing a SyntaxError");

    promise_test(async (t) => {
      assert_equals(
        document.querySelector("video:muted"),
        null,
        "must know :muted"
      );
      const video = document.querySelector("video");
      await new Promise((r) => {
        video.addEventListener("canplay", r, { once: true });
        video.src = "/media/counting.mp4";
      });
      video.muted = false;
      assert_false(video.muted, "video is unmuted");
      assert_equals(document.querySelector("video:muted"), null);
      assert_equals(document.querySelector("video:not(:muted)"), video);
      video.muted = true;
      assert_equals(document.querySelector("video:muted"), video);
      assert_equals(document.querySelector("video:not(:muted)"), null);
    }, "Test :muted pseudo-class");
  </script>
</body>