Bug 1189196 - Update EME mochitest to use new navigator.requestMediaKeySystemAccess. r=jwwang,a=lizzard
authorChris Pearce <cpearce@mozilla.com>
Tue, 27 Oct 2015 14:10:51 +1300
changeset 296703 ba6b7797e925
parent 296702 83b2962d6861
child 296704 84b0b59ed1d2
push id5296
push usercpearce@mozilla.com
push date2015-11-12 01:32 +0000
treeherdermozilla-beta@ba6b7797e925 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, lizzard
bugs1189196
milestone43.0
Bug 1189196 - Update EME mochitest to use new navigator.requestMediaKeySystemAccess. r=jwwang,a=lizzard
dom/media/test/eme.js
dom/media/test/test_eme_non_mse_fails.html
dom/media/test/test_eme_persistent_sessions.html
dom/media/test/test_eme_requestKeySystemAccess.html
dom/media/test/test_eme_request_notifications.html
--- a/dom/media/test/eme.js
+++ b/dom/media/test/eme.js
@@ -364,24 +364,25 @@ function SetupEME(test, token, params)
         return promise.then(function(value) {
           return Promise.resolve(value);
         }).catch(function(reason) {
           onReject(reason);
           return Promise.reject();
         })
       }
 
-      var options = [
-         {
-           initDataType: ev.initDataType,
-           videoType: streamType("video"),
-           audioType: streamType("audio"),
-         }
-       ];
-      var p = navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE, options);
+      var options = { initDataTypes: [ev.initDataType] };
+      if (streamType("video")) {
+        options.videoCapabilities = [{contentType: streamType("video")}];
+      }
+      if (streamType("audio")) {
+        options.audioCapabilities = [{contentType: streamType("audio")}];
+      }
+
+      var p = navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE, [options]);
       var r = bail(token + " Failed to request key system access.");
       chain(p, r)
       .then(function(keySystemAccess) {
         var p = keySystemAccess.createMediaKeys();
         var r = bail(token +  " Failed to create MediaKeys object");
         return chain(p, r);
       })
 
--- a/dom/media/test/test_eme_non_mse_fails.html
+++ b/dom/media/test/test_eme_non_mse_fails.html
@@ -10,19 +10,19 @@
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 var manager = new MediaTestManager;
 
 function DoSetMediaKeys(v, test)
 {
   var options = [{
-    initDataType: "cenc",
-    audioType: test.audioType,
-    videoType: test.videoType,
+    initDataTypes: ["cenc"],
+    audioCapabilities: [{contentType: test.audioType}],
+    videoCapabilities: [{contentType: test.videoType}],
   }];
 
   return navigator.requestMediaKeySystemAccess("org.w3.clearkey", options)
 
   .then(function(keySystemAccess) {
     return keySystemAccess.createMediaKeys();
   })
 
--- a/dom/media/test/test_eme_persistent_sessions.html
+++ b/dom/media/test/test_eme_persistent_sessions.html
@@ -81,17 +81,17 @@ function startTest(test, token)
         .then(function() {
           sessionId = session.sessionId;
           Log(token, "Closing session with id=" + sessionId);
           return session.close();
         })
 
         // Once the session is closed, reload the MediaKeys and reload the session
         .then(function() {
-          return navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE);
+          return navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE, [{initDataTypes:["cenc"]}]);
         })
 
         .then(function(requestedKeySystemAccess) {
           keySystemAccess = requestedKeySystemAccess;
           return keySystemAccess.createMediaKeys();
         })
 
         .then(function(mediaKeys) {
--- a/dom/media/test/test_eme_requestKeySystemAccess.html
+++ b/dom/media/test/test_eme_requestKeySystemAccess.html
@@ -8,302 +8,504 @@
   <script type="text/javascript" src="eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 const CLEARKEY_ID = 'org.w3.clearkey';
 const CLEARKEY_VERSION = '1';
+const SUPPORTED_LABEL = "pass label";
+
+function ValidateConfig(name, expected, observed) {
+  info("ValidateConfig " + name);
+  info("expected cfg=" + JSON.stringify(expected));
+  info("observed cfg=" + JSON.stringify(observed));
+
+  is(observed.label, expected.label, name + " label should match");
+  if (expected.initDataTypes) {
+    ok(expected.initDataTypes.every((element, index, array) => observed.initDataTypes.includes(element)), name + " initDataTypes should match.");
+  }
+
+  if (expected.audioCapabilities) {
+    ok(expected.audioCapabilities.length == 1, "Test function can only handle one capability.");
+    ok(observed.audioCapabilities.length == 1, "Test function can only handle one capability.");
+    is(observed.audioCapabilities[0].contentType, expected.audioCapabilities[0].contentType, name + " audioCapabilities should match.");
+  }
+  if (typeof expected.videoCapabilities !== 'undefined') {
+    info("expected.videoCapabilities=" + expected.videoCapabilities);
+    dump("expected.videoCapabilities=" + expected.videoCapabilities + "\n");
+    ok(expected.videoCapabilities.length == 1, "Test function can only handle one capability.");
+    ok(observed.videoCapabilities.length == 1, "Test function can only handle one capability.");
+    is(observed.videoCapabilities[0].contentType, expected.videoCapabilities[0].contentType, name + " videoCapabilities should match.");
+  }
+}
 
 function Test(test) {
   var name = "'" + test.name + "'";
   return new Promise(function(resolve, reject) {
     var p;
     if (test.options) {
       p = navigator.requestMediaKeySystemAccess(test.keySystem, test.options);
     } else {
       p = navigator.requestMediaKeySystemAccess(test.keySystem);
     }
     p.then(
       function(keySystemAccess) {
         ok(test.shouldPass, name + " passed and was expected to " + (test.shouldPass ? "pass" : "fail"));
         is(keySystemAccess.keySystem, CLEARKEY_ID + "." + CLEARKEY_VERSION, "CDM version should be in MediaKeySystemAccess.keySystem");
+        ValidateConfig(name, test.expectedConfig, keySystemAccess.getConfiguration());
         resolve();
       },
       function(ex) {
         if (test.shouldPass) {
           info(name + " failed: " + ex);
         }
         ok(!test.shouldPass, name + " failed and was expected to " + (test.shouldPass ? "pass" : "fail"));
         resolve();
       });
   });
 }
 
 var tests = [
   {
     name: 'Empty keySystem string',
     keySystem: '',
-    options: [ ],
+    options: [
+      {
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
+      }
+    ],
     shouldPass: false,
   },
   {
     name: 'Empty options specified',
     keySystem: CLEARKEY_ID,
     options: [ ],
     shouldPass: false,
   },
   {
     name: 'Undefined options',
     keySystem: CLEARKEY_ID,
-    shouldPass: true,
+    shouldPass: false,
   },
   {
     name: 'Basic MP4 cenc',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
       }
     ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4'}],
+    },
     shouldPass: true,
   },
   {
     name: 'Invalid keysystem failure',
     keySystem: 'bogusKeySystem',
-    options: [],
+    options: [
+      {
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
+      }
+    ],
     shouldPass: false,
   },
   {
     name: 'Invalid initDataType',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'bogus',
+        initDataTypes: ['bogus'],
+      }
+    ],
+    shouldPass: false,
+  },
+  {
+    name: 'Valid initDataType after invalid',
+    keySystem: CLEARKEY_ID,
+    options: [
+      {
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['bogus', 'invalid', 'cenc'],
+      }
+    ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+    },
+    shouldPass: true,
+  },
+  {
+    name: 'Empty initDataTypes',
+    keySystem: CLEARKEY_ID,
+    options: [
+      {
+        initDataTypes: [],
       }
     ],
     shouldPass: false,
   },
   {
     name: 'Invalid videoType',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/bogus',
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/bogus'}],
       }
     ],
     shouldPass: false,
   },
   {
-    name: 'Invalid statefulness',
+    name: 'distinctiveIdentifier, persistentState, and robustness ignored',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4',
-        stateful: 'bogus',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4', robustness: 'somewhat'}],
+        distinctiveIdentifier: 'bogus',
+        persistentState: 'bogus',
+      }
+    ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4'}],
+    },
+    shouldPass: true,
+  },
+  {
+    name: 'Only unrecognised dict entries specified with unrecognised video type',
+    keySystem: CLEARKEY_ID,
+    options: [
+      {
+        videoCapabilities: [{robustness: 'very much so'}],
+        distinctiveIdentifier: 'required',
+        persistentState: 'required',
       }
     ],
     shouldPass: false,
   },
   {
-    name: 'Invalid uniqueidentifier',
-    keySystem: CLEARKEY_ID,
-    options: [
-      {
-        initDataType: 'cenc',
-        videoType: 'video/mp4',
-        uniqueidentifier: 'bogus',
-      }
-    ],
-    shouldPass: false,
-  },
-  {
-    name: 'Audio capabilities not supported by CLEARKEY_ID',
+    name: 'Only unrecognised dict entries specified should be ignored',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4',
-        audioCapability: 'bogus',
+        label: SUPPORTED_LABEL,
+        distinctiveIdentifier: 'required',
+        persistentState: 'required',
       }
     ],
-    shouldPass: false,
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+    },
+    shouldPass: true,
   },
   {
-    name: 'Video capabilities not supported by CLEARKEY_ID',
+    name: 'Empty config dict',
+    keySystem: CLEARKEY_ID,
+    options: [{ label: SUPPORTED_LABEL }],
+    expectedConfig: {
+      label: SUPPORTED_LABEL
+    },
+    shouldPass: true,
+  },
+  {
+    name: 'Unexpected config entry should be ignored',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4',
-        videoCapability: 'bogus',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        unexpectedEntry: 'this should be ignored',
       }
     ],
-    shouldPass: false,
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+    },
+    shouldPass: true,
   },
   {
     name: 'Invalid option followed by valid',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        bogus: 'bogon',
+        label: "this config should not be supported",
+        initDataTypes: ['bogus'],
       },
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
       }
     ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4'}],
+    },
     shouldPass: true,
   },
   {
     name: 'MP4 audio container',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        audioType: 'audio/mp4',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        audioCapabilities: [{contentType: 'audio/mp4'}],
       }
     ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      audioCapabilities: [{contentType: 'audio/mp4'}],
+    },
     shouldPass: true,
   },
   {
     name: 'MP4 audio container with AAC-LC',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        audioType: 'audio/mp4; codecs="mp4a.40.2"',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}],
       }
     ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}],
+    },
     shouldPass: true,
   },
   {
     name: 'MP4 audio container with invalid codecs',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        audioType: 'audio/mp4; codecs="bogus"',
+        initDataTypes: ['cenc'],
+        audioCapabilities: [{contentType: 'audio/mp4; codecs="bogus"'}],
       }
     ],
     shouldPass: false,
   },
   {
     name: 'MP4 audio container with mp3 is unsupported',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        audioType: 'audio/mp4; codecs="mp3"',
+        initDataTypes: ['cenc'],
+        audioCapabilities: [{contentType: 'audio/mp4; codecs="mp3"'}],
       }
     ],
     shouldPass: false,
   },
   {
-    name: 'MP4 video container type with an audio codec is unsupported',
+    name: 'MP4 video container type with an mp3 codec is unsupported',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4; codecs="mp3"',
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4; codecs="mp3"'}],
       }
     ],
     shouldPass: false,
   },
   {
     name: 'MP4 audio container type with a video codec is unsupported',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        audioType: 'audio/mp4; codecs="avc1.42E01E"',
+        initDataTypes: ['cenc'],
+        audioCapabilities: [{contentType: 'audio/mp4; codecs="avc1.42E01E"'}],
       }
     ],
     shouldPass: false,
   },
   {
     name: 'MP4 video container with constrained baseline h.264',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4; codecs="avc1.42E01E"',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}],
       }
     ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}],
+    },
     shouldPass: true,
   },
   {
     name: 'MP4 video container with invalid codecs',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4; codecs="bogus"',
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4; codecs="bogus"'}],
       }
     ],
     shouldPass: false,
   },
   {
     name: 'MP4 video container with both audio and video codec type in videoType',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4; codecs="avc1.42E01E,mp4a.40.2"',
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E,mp4a.40.2"'}],
       }
     ],
     shouldPass: false,
   },
   {
     name: 'MP4 audio and video type both specified',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'cenc',
-        videoType: 'video/mp4; codecs="avc1.42E01E"',
-        audioType: 'audio/mp4; codecs="mp4a.40.2"',
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}],
+        audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}],
       }
     ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}],
+      audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}],
+    },
     shouldPass: true,
   },
   {
     name: 'WebM CLEARKEY_ID not supported',
     keySystem: CLEARKEY_ID,
     options: [
       {
-        initDataType: 'webm',
-        videoType: 'video/webm',
+        initDataTypes: ['webm'],
+        videoCapabilities: [{contentType: 'video/webm'}],
       }
     ],
     shouldPass: false,
   },
   {
     name: "CDM version less than",
     keySystem: CLEARKEY_ID + ".0",
+    options: [
+      {
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
+      }
+    ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4'}],
+    },
     shouldPass: true
   },
   {
     name: "CDM version equal to",
     keySystem: CLEARKEY_ID + ".1",
+    options: [
+      {
+        label: SUPPORTED_LABEL,
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
+      }
+    ],
+    expectedConfig: {
+      label: SUPPORTED_LABEL,
+      initDataTypes: ['cenc'],
+      videoCapabilities: [{contentType: 'video/mp4'}],
+    },
     shouldPass: true
   },
   {
     name: "CDM version greater than",
     keySystem: CLEARKEY_ID + ".2",
+    options: [
+      {
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
+      }
+    ],
     shouldPass: false
   },
   {
     name: "Non-whole number CDM version",
     keySystem: CLEARKEY_ID + ".0.1",
+    options: [
+      {
+        initDataTypes: ['cenc'],
+        videoCapabilities: [{contentType: 'video/mp4'}],
+      }
+    ],
     shouldPass: false
   },
+
+  // Test legacy support. Remove when we remove backwards compatibility.
+  {
+    name: 'Legacy CENC',
+    keySystem: CLEARKEY_ID,
+    options: [
+      {
+        initDataType: 'cenc',
+      }
+    ],
+    expectedConfig: {
+      label: ''
+    },
+    shouldPass: true,
+  },
+  {
+    name: 'Legacy CENC + MP4 video',
+    keySystem: CLEARKEY_ID,
+    options: [
+      {
+        initDataType: 'cenc',
+        videoType: 'video/mp4; codecs="avc1.42E01E"',
+      }
+    ],
+    expectedConfig: {
+      label: ''
+    },
+    shouldPass: true,
+  },
+  {
+    name: 'Legacy CENC + MP4 video + MP4 audio',
+    keySystem: CLEARKEY_ID,
+    options: [
+      {
+        initDataType: 'cenc',
+        videoType: 'video/mp4; codecs="avc1.42E01E"',
+        audioType: 'audio/mp4; codecs="mp4a.40.2"',
+      }
+    ],
+    expectedConfig: {
+      label: ''
+    },
+    shouldPass: true,
+  },
 ];
 
 function beginTest() {
   Promise.all(tests.map(Test)).then(function() { SimpleTest.finish(); });
 }
 
 if (!IsMacOSSnowLeopardOrEarlier()) {
   SimpleTest.waitForExplicitFinish();
--- a/dom/media/test/test_eme_request_notifications.html
+++ b/dom/media/test/test_eme_request_notifications.html
@@ -1,109 +1,109 @@
-<!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;
-
-var observedStatus = "nothing";
-
-var observer = function(subject, topic, data) {
-  observedStatus = JSON.parse(data).status;
-  info("Observed: " + observedStatus);  
-};
-SpecialPowers.Services.obs.addObserver(observer, "mediakeys-request", false);
-
-SimpleTest.registerCleanupFunction(function() {
-  SpecialPowers.Services.obs.removeObserver(observer, "mediakeys-request");
-});
-
-function SetPrefs(prefs) {
-  return new Promise(function(resolve, reject) {
-    SpecialPowers.pushPrefEnv({"set": prefs}, function() { resolve(); });
-  });
-}
-
-function Test(test) {
-  var p = test.prefs ? SetPrefs(test.prefs) : Promise.resolve();
-  observedStatus = "nothing";
-  var name = "'" + test.keySystem + "'";
-  return p.then(function() {
-    return new Promise(function(resolve, reject) {
-      navigator.requestMediaKeySystemAccess(test.keySystem)
-      .then(
-        function(keySystemAccess) {
-          return keySystemAccess.createMediaKeys();
-        })
-      .then(
-        function(mediaKeys) {
-          ok(test.shouldPass, name + " passed and was expected to " + (test.shouldPass ? "pass" : "fail"));
-          is(observedStatus, test.expectedStatus, name + " observer service result");
-          resolve();
-        }
-      )
-      .catch(
-        function() {
-          ok(!test.shouldPass, name + " failed and was expected to " + (test.shouldPass ? "pass" : "fail"));
-          is(observedStatus, test.expectedStatus, name + " observer service result");
-          resolve();
-        }
-      );
-    });
-  });
-}
-
-const CLEARKEY_ID = 'org.w3.clearkey';
-
-var tests = [
-  {
-    keySystem: CLEARKEY_ID,
-    shouldPass: false,
-    expectedStatus: 'api-disabled',
-    prefs: [["media.eme.enabled", false], ["media.eme.clearkey.enabled", true]]
-  },
-  {
-    keySystem: CLEARKEY_ID,
-    shouldPass: false,
-    expectedStatus: 'cdm-disabled',
-    prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", false]]
-  },
-  {
-    keySystem: 'unsupported-keysystem',
-    shouldPass: false,
-    expectedStatus: 'cdm-not-supported'
-  },
-  {
-    keySystem: CLEARKEY_ID + '.10000' , // A stupendously high min CDM version, presumably not installed.
-    shouldPass: false,
-    expectedStatus: 'cdm-insufficient-version',
-    prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", true]]
-  },
-  {
-    keySystem: CLEARKEY_ID,
-    shouldPass: true,
-    expectedStatus: 'cdm-created',
-    prefs: [["media.eme.enabled", true], ["media.eme.clearkey.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>
-
+<!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;
+
+var observedStatus = "nothing";
+
+var observer = function(subject, topic, data) {
+  observedStatus = JSON.parse(data).status;
+  info("Observed: " + observedStatus);
+};
+SpecialPowers.Services.obs.addObserver(observer, "mediakeys-request", false);
+
+SimpleTest.registerCleanupFunction(function() {
+  SpecialPowers.Services.obs.removeObserver(observer, "mediakeys-request");
+});
+
+function SetPrefs(prefs) {
+  return new Promise(function(resolve, reject) {
+    SpecialPowers.pushPrefEnv({"set": prefs}, function() { resolve(); });
+  });
+}
+
+function Test(test) {
+  var p = test.prefs ? SetPrefs(test.prefs) : Promise.resolve();
+  observedStatus = "nothing";
+  var name = "'" + test.keySystem + "'";
+  return p.then(function() {
+    return new Promise(function(resolve, reject) {
+      navigator.requestMediaKeySystemAccess(test.keySystem, [{initDataTypes:["cenc"]}])
+      .then(
+        function(keySystemAccess) {
+          return keySystemAccess.createMediaKeys();
+        })
+      .then(
+        function(mediaKeys) {
+          ok(test.shouldPass, name + " passed and was expected to " + (test.shouldPass ? "pass" : "fail"));
+          is(observedStatus, test.expectedStatus, name + " observer service result");
+          resolve();
+        }
+      )
+      .catch(
+        function() {
+          ok(!test.shouldPass, name + " failed and was expected to " + (test.shouldPass ? "pass" : "fail"));
+          is(observedStatus, test.expectedStatus, name + " observer service result");
+          resolve();
+        }
+      );
+    });
+  });
+}
+
+const CLEARKEY_ID = 'org.w3.clearkey';
+
+var tests = [
+  {
+    keySystem: CLEARKEY_ID,
+    shouldPass: false,
+    expectedStatus: 'api-disabled',
+    prefs: [["media.eme.enabled", false], ["media.eme.clearkey.enabled", true]]
+  },
+  {
+    keySystem: CLEARKEY_ID,
+    shouldPass: false,
+    expectedStatus: 'cdm-disabled',
+    prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", false]]
+  },
+  {
+    keySystem: 'unsupported-keysystem',
+    shouldPass: false,
+    expectedStatus: 'cdm-not-supported'
+  },
+  {
+    keySystem: CLEARKEY_ID + '.10000' , // A stupendously high min CDM version, presumably not installed.
+    shouldPass: false,
+    expectedStatus: 'cdm-insufficient-version',
+    prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", true]]
+  },
+  {
+    keySystem: CLEARKEY_ID,
+    shouldPass: true,
+    expectedStatus: 'cdm-created',
+    prefs: [["media.eme.enabled", true], ["media.eme.clearkey.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>
+