tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

decodingInfoEncryptedMedia.https.html (7968B)


      1 <!DOCTYPE html>
      2 <title>MediaCapabilities.decodingInfo for encrypted media</title>
      3 <meta name="timeout" content="long">
      4 <script src=/resources/testharness.js></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script>
      7 
      8 // Minimal VideoConfiguration that will be allowed per spec. All optional
      9 // properties are missing.
     10 var minimalVideoConfiguration = {
     11  contentType: 'video/webm; codecs="vp09.00.10.08"',
     12  width: 800,
     13  height: 600,
     14  bitrate: 3000,
     15  framerate: 24,
     16 };
     17 
     18 // Minimal AudioConfiguration that will be allowed per spec. All optional
     19 // properties are missing.
     20 var minimalAudioConfiguration = {
     21  contentType: 'audio/webm; codecs="opus"',
     22 };
     23 
     24 // Minimal MediaCapabilitiesKeySystemConfiguration that will be allowed per
     25 // spec. All optional properties are missing.
     26 var minimalKeySystemConfiguration = {
     27  keySystem: 'org.w3.clearkey',
     28 };
     29 
     30 // Config with bogus name not provided by any UA.
     31 var bogusKeySystemConfiguration = {
     32  keySystem: 'bogus',
     33 };
     34 
     35 promise_test(t => {
     36  return navigator.mediaCapabilities.decodingInfo({
     37    type: 'file',
     38    video: minimalVideoConfiguration,
     39    keySystemConfiguration: minimalKeySystemConfiguration,
     40  });
     41 }, "Test that decodingInfo accepts a stub key system configuration (w/video).");
     42 
     43 promise_test(t => {
     44  return navigator.mediaCapabilities.decodingInfo({
     45    type: 'file',
     46    audio: minimalAudioConfiguration,
     47    keySystemConfiguration: minimalKeySystemConfiguration,
     48  });
     49 }, "Test that decodingInfo accepts a stub key system configuration (w/audio).");
     50 
     51 promise_test(t => {
     52  return navigator.mediaCapabilities.decodingInfo({
     53    type: 'file',
     54    video: minimalVideoConfiguration,
     55    keySystemConfiguration: {
     56      keySystem: 'org.w3.clearkey',
     57      video: {
     58        robustness: '',
     59      },
     60    },
     61  });
     62 }, "Test that decodingInfo accepts a key system configuration with video info.");
     63 
     64 promise_test(t => {
     65  return navigator.mediaCapabilities.decodingInfo({
     66    type: 'file',
     67    audio: minimalAudioConfiguration,
     68    keySystemConfiguration: {
     69      keySystem: 'org.w3.clearkey',
     70      audio : {
     71        robustness: '',
     72      },
     73    },
     74  });
     75 }, "Test that decodingInfo accepts a key system configuration with audio info.");
     76 
     77 promise_test(t => {
     78  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
     79    type: 'file',
     80    audio: minimalAudioConfiguration,
     81    keySystemConfiguration: {
     82      keySystem: 'org.w3.clearkey',
     83      video: {
     84        robustness: '',
     85      },
     86    },
     87  }));
     88 }, "Test that decodingInfo rejects if robustness and configuration do not match (1).");
     89 
     90 promise_test(t => {
     91  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
     92    type: 'file',
     93    video: minimalVideoConfiguration,
     94    keySystemConfiguration: {
     95      keySystem: 'org.w3.clearkey',
     96      audio : {
     97        robustness: '',
     98      },
     99    },
    100  }));
    101 }, "Test that decodingInfo rejects if robustness and configuration do not match (2).");
    102 
    103 promise_test(t => {
    104  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
    105    type: 'file',
    106    video: minimalVideoConfiguration,
    107    keySystemConfiguration: {
    108      keySystem: 'org.w3.clearkey',
    109      audio : {
    110        robustness: '',
    111      },
    112      video: {
    113        robustness: '',
    114      },
    115    },
    116  }));
    117 }, "Test that decodingInfo rejects if robustness and configuration do not match (3).");
    118 
    119 promise_test(t => {
    120  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
    121    type: 'file',
    122    audio: minimalAudioConfiguration,
    123    video: minimalVideoConfiguration,
    124    keySystemConfiguration: {
    125      keySystem: 'org.w3.clearkey',
    126      audio : {
    127        robustness: '',
    128      },
    129      video: {
    130        robustness: '',
    131      },
    132      persistentState: "foobar",
    133    },
    134  }));
    135 }, "Test that decodingInfo rejects if persistentState isn't valid.");
    136 
    137 promise_test(t => {
    138  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
    139    type: 'file',
    140    audio: minimalAudioConfiguration,
    141    video: minimalVideoConfiguration,
    142    keySystemConfiguration: {
    143      keySystem: 'org.w3.clearkey',
    144      audio : {
    145        robustness: '',
    146      },
    147      video: {
    148        robustness: '',
    149      },
    150      distinctiveIdentifier: "foobar",
    151    },
    152  }));
    153 }, "Test that decodingInfo rejects if distinctiveIdentifier isn't valid.");
    154 
    155 promise_test(t => {
    156  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
    157    type: 'file',
    158    audio: minimalAudioConfiguration,
    159    video: minimalVideoConfiguration,
    160    keySystemConfiguration: {
    161      keySystem: 'org.w3.clearkey',
    162      audio : {
    163        robustness: '',
    164      },
    165      video: {
    166        robustness: '',
    167      },
    168      sessionTypes: "foobar",
    169    },
    170  }));
    171 }, "Test that decodingInfo rejects if sessionTypes isn't a sequence.");
    172 
    173 promise_test(t => {
    174  return navigator.mediaCapabilities.decodingInfo({
    175    type: 'file',
    176    audio: minimalAudioConfiguration,
    177    video: minimalVideoConfiguration,
    178    keySystemConfiguration: {
    179      keySystem: {},
    180      initDataType: {},
    181      audio : {
    182        robustness: '',
    183      },
    184      video: {
    185        robustness: '',
    186      },
    187    },
    188  });
    189 }, "Test that decodingInfo does not reject when properties are set to unexpected values.");
    190 
    191 promise_test(t => {
    192  return navigator.mediaCapabilities.decodingInfo({
    193    type: 'file',
    194    video: minimalVideoConfiguration,
    195    audio: minimalAudioConfiguration,
    196    keySystemConfiguration: minimalKeySystemConfiguration,
    197  }).then(ability => {
    198    assert_equals(typeof ability.supported, "boolean");
    199    assert_equals(typeof ability.smooth, "boolean");
    200    assert_equals(typeof ability.powerEfficient, "boolean");
    201    assert_equals(typeof ability.keySystemAccess, "object");
    202  });
    203 }, "Test that decodingInfo returns a valid MediaCapabilitiesDecodingInfo objects with encrypted media");
    204 
    205 promise_test(t => {
    206  return navigator.mediaCapabilities.decodingInfo({
    207    type: 'file',
    208    video: minimalVideoConfiguration,
    209    keySystemConfiguration: {
    210      keySystem: 'foobar',
    211      video: {
    212        robustness: '',
    213      },
    214    }
    215  }).then(ability => {
    216    assert_false(ability.supported);
    217    assert_false(ability.smooth);
    218    assert_false(ability.powerEfficient);
    219    assert_equals(ability.keySystemAccess, null);
    220  });
    221 }, "Test that random key systems are reported as non supported.");
    222 
    223 // TODO(mlamouri): this test could be split in two tests for which codec support
    224 // across browsers is widely compatible: one when all browsers wouldn't support
    225 // and one where all browsers do support. The current approach is to check that
    226 // the answer is consistent to the spec.
    227 promise_test(t => {
    228  return navigator.mediaCapabilities.decodingInfo({
    229    type: 'file',
    230    video: minimalVideoConfiguration,
    231    audio: minimalAudioConfiguration,
    232    keySystemConfiguration: minimalKeySystemConfiguration,
    233  }).then(ability => {
    234    if (ability.supported)
    235      assert_not_equals(ability.keySystemAccess, null);
    236    else
    237      assert_equals(ability.keySystemAccess, null);
    238  });
    239 }, "Test that keySystemAccess is only null when not supported if keySystemConfiguration was used.");
    240 
    241 promise_test(t => {
    242  return navigator.mediaCapabilities.decodingInfo({
    243    type: 'file',
    244    video: minimalVideoConfiguration,
    245    audio: minimalAudioConfiguration,
    246    // Supply bogus config to reliably result in a null keySystemAccess.
    247    keySystemConfiguration: bogusKeySystemConfiguration,
    248  }).then(ability => {
    249    assert_equals(ability.keySystemAccess, null);
    250    assert_false(ability.supported);
    251  });
    252 }, "Test that supported=false when keySystemConfiguration is unsupported.");
    253 
    254 promise_test(t => {
    255  return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
    256    type: 'webrtc',
    257    video: minimalVideoConfiguration,
    258    keySystemConfiguration: minimalKeySystemConfiguration,
    259  }));
    260 }, "Test that decodingInfo with type webrtc rejects key system configuration.");
    261 
    262 </script>