summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/media-source/mediasource-changetype-play-implicit.html
blob: c186361e791b303e958c93171ba58a260e20d5fa (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<!-- Copyright © 2019 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Exercise implicit changeType for supported test types, using mime types WITH and WITHOUT codecs for addSourceBuffer.</title>
        <meta name="timeout" content="long">
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
        <script src="mediasource-changetype-util.js"></script>
    </head>
    <body>
        <div id="log"></div>
        <script>

// Helper that generates implicit codec switching tests for a pair of media
// types, with full codecs in the original addSourceBuffer calls, and
// separately without full codecs parameters in the original addSourceBuffer
// calls.
function generateTestsForMediaPair(type1, type2) {
  // Implicit changeType across bytestream formats is not expected to be
  // supported, so skip those tests' generation.
  if (type1.mime_subtype != type2.mime_subtype)
    return;

  assert_equals(type1.is_video, type2.is_video,
      "Types must both be audio or both be video");
  test_description_prefix = "Test " + (type1.is_video ? "video" : "audio") +
      "-only implicit changeType for " + type1.type + " <-> " + type2.type;

  mediaSourceChangeTypeTest(
      type1, type2,
      test_description_prefix,
      { implicit_changetype: true } );

  // Skip test generation if the relaxed types are already fully specified and
  // tested, above.
  if (type1.type == type1.relaxed_type &&
      type2.type == type2.relaxed_type) {
    return;
  }

  mediaSourceChangeTypeTest(
      type1, type2,
      test_description_prefix +
          " (using types without codecs parameters for addSourceBuffer)",
      { use_relaxed_mime_types: true, implicit_changetype: true } );
}

function generateImplicitChangeTypeTests(audio_types, video_types) {
  async_test((test) => {
    // Require at least 1 pair of different audio-only or video-only test media
    // files sharing same bytestream format.
    assert_true(audio_types.length > 1 || video_types.length > 1,
        "Browser doesn't support enough test media");

    // Count the number of unique bytestream formats used in each of audio_types
    // and video_types.
    let audio_formats = new Set(Array.from(audio_types, t => t.mime_subtype));
    let video_formats = new Set(Array.from(video_types, t => t.mime_subtype));
    assert_true(audio_types.length > audio_formats.size ||
                video_types.length > video_formats.size,
        "Browser doesn't support at least 2 audio-only or 2 video-only test " +
            "media with same bytestream format");

    test.done();
  }, "Check if browser supports enough test media types and pairs of " +
         "audio-only or video-only media with same bytestream format");

  // Generate audio-only tests
  for (let audio1 of audio_types) {
    for (let audio2 of audio_types) {
      generateTestsForMediaPair(audio1, audio2);
    }
  }

  // Generate video-only tests
  for (let video1 of video_types) {
    for (let video2 of video_types) {
      generateTestsForMediaPair(video1, video2);
    }
  }
}

findSupportedChangeTypeTestTypes(generateImplicitChangeTypeTests);

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