File: mediasource-worker-duration.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (86 lines) | stat: -rw-r--r-- 4,040 bytes parent folder | download | duplicates (18)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<title>Test MediaSource-in-Worker duration updates before and after HAVE_METADATA</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-message-util.js"></script>
<body>
<script>

function awaitDuration(t, video, worker, requestingMessage, expectedDuration) {
  let durationAwaiter = t.step_func(() => {
    if ((!Number.isNaN(expectedDuration) && video.duration === expectedDuration) ||
        (Number.isNaN(expectedDuration) && Number.isNaN(video.duration))) {
      worker.postMessage({ subject: messageSubject.ACK_VERIFIED, info: requestingMessage });
      return;
    }

    // Otherwise, wait for one or more 'durationchange' events to see if video
    // eventually has the expectedDuration.
    video.addEventListener('durationchange', durationAwaiter, { once: true });
  });

  durationAwaiter();
}

async_test(t => {
  // Fail fast if MSE-in-Workers is not supported.
  assert_true(MediaSource.hasOwnProperty("canConstructInDedicatedWorker"), "MediaSource hasOwnProperty 'canConstructInDedicatedWorker'");
  assert_true(MediaSource.canConstructInDedicatedWorker, "MediaSource.canConstructInDedicatedWorker");

  const video = document.createElement("video");
  document.body.appendChild(video);
  video.onerror = t.unreached_func("video element error");
  video.onended = t.unreached_func("video element ended");
  assert_equals(video.duration, NaN, "initial video duration before attachment should be NaN");
  assert_equals(video.readyState, HTMLMediaElement.HAVE_NOTHING, "initial video readyState before attachment should be HAVE_NOTHING");

  let worker = new Worker("mediasource-worker-duration.js");
  worker.onerror = t.step_func(e => {
    assert_unreached("worker error: [" + e.filename + ":" + e.lineno + ":" + e.colno + ":" + e.error + ":" + e.message + "]");
  });
  worker.onmessage = t.step_func(e => {
    let subject = e.data.subject;
    assert_true(subject !== undefined, "message must have a subject field");
    switch (subject) {
      case messageSubject.ERROR:
        assert_unreached("Worker error: " + e.data.info);
        break;
      case messageSubject.HANDLE:
        const handle = e.data.info;
        assert_equals(video.duration, NaN, "initial video duration before attachment should still be NaN");
        assert_equals(video.readyState, HTMLMediaElement.HAVE_NOTHING,
                      "initial video readyState before attachment should still be HAVE_NOTHING");
        video.srcObject = handle;
        break;
      case messageSubject.VERIFY_DURATION:
        assert_equals(video.duration, e.data.info, "duration should match expectation");
        worker.postMessage({ subject: messageSubject.ACK_VERIFIED, info: e.data });
        break;
      case messageSubject.AWAIT_DURATION:
        awaitDuration(t, video, worker, e.data, e.data.info);
        break;
      case messageSubject.VERIFY_HAVE_NOTHING:
        assert_equals(video.readyState, HTMLMediaElement.HAVE_NOTHING, "readyState should match expectation");
        worker.postMessage({ subject: messageSubject.ACK_VERIFIED, info: e.data });
        break;
      case messageSubject.VERIFY_AT_LEAST_HAVE_METADATA:
        assert_greater_than_equal(video.readyState, HTMLMediaElement.HAVE_METADATA, "readyState should match expectation");
        worker.postMessage({ subject: messageSubject.ACK_VERIFIED, info: e.data });
        break;
      case messageSubject.WORKER_DONE:
        // This test is a worker-driven set of verifications, and it will send
        // this message when it is complete. See comment in the worker script
        // that describes the phases of this test case.
        assert_not_equals(video.srcObject, null, "test should at least have set srcObject.");
        t.done();
        break;
      default:
        assert_unreached("Unexpected message subject: " + subject);
    }
  });
}, "Test worker MediaSource duration updates before and after HAVE_METADATA");

</script>
</body>
</html>