summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_eme_getstatusforpolicy.html
blob: 6e9503e33a507726c6073f70c88c8a98b56a4bd5 (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
90
91
92
93
<!DOCTYPE HTML>
<html>
<head>
  <title>Test getStatusForPolicy on ClearKey CDM</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="manifest.js"></script>
  <script type="text/javascript" src="eme.js"></script>
</head>
<body>
<pre id="test">
<video id="v" controls></video>
<script class="testbody" type="text/javascript">

add_task(async function setupTestingPrefs() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["media.eme.hdcp-policy-check.enabled", true],
    ],
  });
});

// We expect that ClearKey has HDCP 2.0 compliant.
const expectedResults = [
  {
    minHdcpVersion : "1.0",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "1.1",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "1.2",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "1.3",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "1.4",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "2.0",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "2.1",
    expectedResult : "usable"
  },
  {
    minHdcpVersion : "2.2",
    expectedResult : "output-restricted"
  },
  {
    minHdcpVersion : "2.3",
    expectedResult : "output-restricted"
  },
];

add_task(async function testGetStatusForPolicy() {
  for (let result of expectedResults) {
    let mediaKey = await createMediaKeysAndSet();
    let video = document.getElementById("v");
    is(video.mediaKeys, mediaKey,
      "Should have set MediaKeys on media element");
    let keyStatus = await
        video.mediaKeys.getStatusForPolicy({minHdcpVersion : result.minHdcpVersion})
        .catch(() => ok(false, "getStatusForPolicy failed!"));
    info(`getStatusForPolicy for HDCP ${result.minHdcpVersion} : ${keyStatus}`);
    is(keyStatus, result.expectedResult,
        `Expected ${result.expectedResult}, got ${keyStatus}`);
  }
});

// Helper function
function createMediaKeysAndSet() {
  return navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, gCencMediaKeySystemConfig)
  .then(function (access) {
    return access.createMediaKeys();
  })
  .then(function (mediaKeys) {
    document.getElementById("v").setMediaKeys(mediaKeys);
    return mediaKeys;
  });
}

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