summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_eme_non_mse_fails.html
blob: 6ff17d59ffc19c5e0d0fd0db187afb6e57e6e667 (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
94
95
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1131392 - Test that EME does not work for non-MSE media</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">
<script class="testbody" type="text/javascript">
/* import-globals-from eme.js */
var manager = new MediaTestManager;

function DoSetMediaKeys(v, test, token)
{
  var options = [{
    initDataTypes: ["cenc"],
    audioCapabilities: [{contentType: test.audioType}],
    videoCapabilities: [{contentType: test.videoType}],
  }];

  return navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, options)

  .then(function(keySystemAccess) {
    return keySystemAccess.createMediaKeys();
  })

  .catch(function() {
    ok(false, token + " was not expecting failure (yet)");
  })

  .then(function(mediaKeys) {
    return v.setMediaKeys(mediaKeys);
  });
}

function TestSetMediaKeys(test, token)
{
  manager.started(token);

  var v = document.createElement("video");

  v.addEventListener("encrypted", function() {
    ok(false, token + " should not fire encrypted event");
  });

  var loadedMetadata = false;
  v.addEventListener("loadedmetadata", function() {
    loadedMetadata = true;
  });

  v.addEventListener("error", function() {
    ok(true, token + " expected error event");
    ok(loadedMetadata, token + " expected loadedmetadata to have fired");
    manager.finished(token);
  });

  v.src = test.name;
}

function TestSetSrc(test, token)
{
  manager.started(token);

  var v = document.createElement("video");
  v.addEventListener("error", function(err) {
    ok(true, token + " got error setting src on video element, as expected");
    manager.finished(token);
  });

  DoSetMediaKeys(v, test, token)

  .then(function() {
    v.src = test.name;
  })

  .catch(function() {
    ok(false, token + " got error setting media keys");
  });
}

function startTest(test, token)
{
  TestSetMediaKeys(test, token + "_setMediaKeys");
  TestSetSrc(test, token + "_setSrc");
}

SimpleTest.waitForExplicitFinish();
manager.runTests(gEMENonMSEFailTests, startTest);
</script>
</pre>
</body>
</html>