summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_eme_request_notifications.html
blob: c2fab5b15249093e551b2184e49ca0c76ed6b22a (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test Encrypted Media Extensions</title>
  <script type="text/javascript" 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">
var manager = new MediaTestManager;

function SetPrefs(prefs) {
  return new Promise(function(resolve, reject) {
    SpecialPowers.pushPrefEnv({"set": prefs}, function() { resolve(); });
  });
}

function observe() {
  return new Promise(function(resolve, reject) {
    var observer = function(subject, topic, data) {
      SpecialPowers.Services.obs.removeObserver(observer, "mediakeys-request");
      resolve(JSON.parse(data).status);
    };
    SpecialPowers.Services.obs.addObserver(observer, "mediakeys-request", false);
  });
}

function Test(test) {
  var p = test.prefs ? SetPrefs(test.prefs) : Promise.resolve();
  observedStatus = "nothing";
  var name = "'" + test.keySystem + "'";

  var res = observe().then((status) => {
    is(status, test.expectedStatus, name + " expected status");
  });

  p.then(() => navigator.requestMediaKeySystemAccess(test.keySystem, gCencMediaKeySystemConfig))
   .then((keySystemAccess) => keySystemAccess.createMediaKeys());

  return res;
}

const isWinXP = navigator.userAgent.indexOf("Windows NT 5.1") != -1;

var tests = [
  {
    keySystem: CLEARKEY_KEYSYSTEM,
    expectedStatus: 'cdm-created',
    prefs: [["media.eme.enabled", false]]
  },
  {
    keySystem: "com.widevine.alpha",
    expectedStatus: 'api-disabled',
    prefs: [["media.eme.enabled", false]]
  },
  {
    keySystem: "com.widevine.alpha",
    expectedStatus: (isWinXP ? 'cdm-not-supported' : 'cdm-disabled'),
    prefs: [["media.eme.enabled", true], ["media.gmp-widevinecdm.enabled", false]]
  },
  {
    keySystem: "com.widevine.alpha",
    expectedStatus: (isWinXP ? 'cdm-not-supported' : 'cdm-not-installed'),
    prefs: [["media.eme.enabled", true], , ["media.gmp-widevinecdm.enabled", true]]
  },
  {
    keySystem: CLEARKEY_KEYSYSTEM,
    expectedStatus: 'cdm-created',
    prefs: [["media.eme.enabled", true]]
  }
];

SetupEMEPref(function() {
  tests.reduce(function(p,c,i,array) {
    return p.then(function() { return Test(c); });
  }, Promise.resolve()).then(SimpleTest.finish);
});


SimpleTest.waitForExplicitFinish();

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