summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/media/media-playback-state.html
blob: c034dbbdc08bda87832c36c57b0db4cd6cfc0c73 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<title>
  Media Playback State: the :playing, :paused, and :seeking pseudo-classes
</title>
<link
  rel="help"
  href="https://drafts.csswg.org/selectors/#video-state"
/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
  <video width="300" height="300" muted loop></video>
  <script>
    test((t) => {
      for (const pseudo of [":playing", ":paused", ":seeking"]) {
        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) => {
      const video = document.querySelector("video");
      await new Promise((r) => {
        video.addEventListener("canplay", r, { once: true });
        video.src = "/media/counting.mp4";
      });
      video.muted = true; // allows us to play the video
      assert_true(video.muted, "video is muted");
      assert_true(video.paused, "video is paused");
      await new Promise((r) => {
        video.addEventListener("playing", r, { once: true });
        video.play();
      });
      assert_false(video.paused, "video is playing");
      assert_equals(document.querySelector("video:playing"), video);
      assert_equals(document.querySelector("video:not(:playing)"), null);
      assert_equals(document.querySelector("video:paused"), null);
      assert_equals(document.querySelector("video:not(:paused)"), video);
    }, "Test :playing pseudo-classes");

    promise_test(async (t) => {
      const video = document.querySelector("video");
      await new Promise((r) => {
        video.addEventListener("canplay", r, { once: true });
        video.src = "/media/counting.mp4";
      });
      assert_equals(video.paused, true);
      assert_equals(document.querySelector("video:playing"), null);
      assert_equals(document.querySelector("video:not(:playing)"), video);
      assert_equals(document.querySelector("video:paused"), video);
      assert_equals(document.querySelector("video:not(:paused)"), null);
    }, "Test :paused pseudo-classes");

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