summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_eme_special_key_system.html
blob: 0addc06ebc17a9b5d7147ce68b98e338f10b0788 (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
<!DOCTYPE html>
<html>
<head>
  <title>Test Encrypted Media Extensions - Special key system</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
function requestProtectionQueryKeySystemAccess() {
  const kKeySystemOptions = [
    {
      initDataTypes: ["cenc"],
      videoCapabilities: [{ contentType: 'video/mp4; codecs="avc1.4d4015"' }],
    },
  ];
  const kClearKeyWithProtectionQuery =
    "org.mozilla.clearkey_with_protection_query";
  return navigator.requestMediaKeySystemAccess(
    kClearKeyWithProtectionQuery,
    kKeySystemOptions
  );
}
// Tests that org.mozilla.clearkey_with_protection_query cannot be accessed from JS if not preffed on.
add_task(async function protectionQueryKeySystemShouldBeHidden() {
  try {
    // Should throw since special key systems are not enabled.
    await requestProtectionQueryKeySystemAccess();
    ok(
      false,
      "Test should have thrown by default because media.clearkey.test-key-systems.enabled should not be set"
    );
  } catch (e) {
    is(e.name, "NotSupportedError", "Should get not supported error");
    is(
      e.message,
      "Key system is unsupported",
      "Should get message that key system is unsupported"
    );
  }
});

// Tests that org.mozilla.clearkey_with_protection_query can be accessed from JS if preffed on.
add_task(async function protectionQueryKeySystemShouldBeExposed() {
  await SpecialPowers.pushPrefEnv({
    set: [["media.clearkey.test-key-systems.enabled", true]],
  });
  try {
    // Should not throw since special key systems are enabled.
    let access = await requestProtectionQueryKeySystemAccess();
    ok(
      access,
      "Should get access to protection query key system when preffed on"
    );
  } catch (e) {
    ok(false, "Test should not have thrown and key system should be available");
  }
});
</script>
</pre>
</body>
</html>