Bug 1101304 - Test that EME works with CORS - r=cpearce a=lmandel
authorEdwin Flores <eflores@mozilla.com>
Thu, 29 Jan 2015 20:30:38 +1300
changeset 250182 7bc573c193ea
parent 250181 00ac75ab182f
child 250183 7a0c7799b5ea
push id4521
push usercpearce@mozilla.com
push date2015-03-04 01:22 +0000
treeherdermozilla-beta@8abdbdecd2d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lmandel
bugs1101304
milestone37.0
Bug 1101304 - Test that EME works with CORS - r=cpearce a=lmandel
dom/media/test/allowed.sjs
dom/media/test/eme.js
dom/media/test/manifest.js
dom/media/test/mochitest.ini
dom/media/test/test_eme_access_control.html
dom/media/test/test_eme_playback.html
--- a/dom/media/test/allowed.sjs
+++ b/dom/media/test/allowed.sjs
@@ -8,16 +8,19 @@ function parseQuery(request, key) {
 	  return p.substring(key.length + 1);
 	if (p.indexOf("=") < 0 && key == "")
 	  return p;
   }
   return false;
 }
 
 var types = {
+  js: "text/javascript",
+  m4s: "video/mp4",
+  mp4: "video/mp4",
   ogg: "video/ogg",
   ogv: "video/ogg",
   oga: "audio/ogg",
   webm: "video/webm",
   wav: "audio/x-wav"
 };
 
 // Return file with name as per the query string with access control
--- a/dom/media/test/eme.js
+++ b/dom/media/test/eme.js
@@ -113,16 +113,25 @@ function UpdateSessionFunc(test, token, 
       resolve(ev.target);
     }).catch(function(reason) {
       bail(token + " MediaKeySession update failed")(reason);
       reject();
     });
   }
 }
 
+function MaybeCrossOriginURI(test, uri)
+{
+  if (test.crossOrigin) {
+    return "http://test2.mochi.test:8888/tests/dom/media/test/allowed.sjs?" + uri;
+  } else {
+    return uri;
+  }
+}
+
 function PlayFragmented(test, elem, token)
 {
   return new Promise(function(resolve, reject) {
     var ms = new MediaSource();
     elem.src = URL.createObjectURL(ms);
 
     var sb;
     var curFragment = 0;
@@ -139,17 +148,17 @@ function PlayFragmented(test, elem, toke
 
       if (curFragment >= test.fragments.length) {
         Log(token, "addNextFragment() end of stream");
         ms.endOfStream();
         resolve();
         return;
       }
 
-      var fragmentFile = test.fragments[curFragment++];
+      var fragmentFile = MaybeCrossOriginURI(test, test.fragments[curFragment++]);
 
       var req = new XMLHttpRequest();
       req.open("GET", fragmentFile);
       req.responseType = "arraybuffer";
 
       req.addEventListener("load", function() {
         Log(token, "fetch of " + fragmentFile + " complete, appending");
         sb.appendBuffer(new Uint8Array(req.response));
@@ -178,24 +187,25 @@ function PlayFragmented(test, elem, toke
 function LoadTest(test, elem, token)
 {
   if (test.fragments) {
     return PlayFragmented(test, elem, token);
   }
 
   // This file isn't fragmented; set the media source normally.
   return new Promise(function(resolve, reject) {
-    elem.src = test.name;
+    elem.src = MaybeCrossOriginURI(test, test.name);
     resolve();
   });
 }
 
 function SetupEME(test, token, params)
 {
   var v = document.createElement("video");
+  v.crossOrigin = test.crossOrigin || false;
 
   // Log events dispatched to make debugging easier...
   [ "canplay", "canplaythrough", "ended", "error", "loadeddata",
     "loadedmetadata", "loadstart", "pause", "play", "playing", "progress",
     "stalled", "suspend", "waiting",
   ].forEach(function (e) {
     v.addEventListener(e, function(event) {
       Log(token, "" + e);
--- a/dom/media/test/manifest.js
+++ b/dom/media/test/manifest.js
@@ -646,27 +646,52 @@ var gEMETests = [
       // "keyid" : "key"
       "7e571d017e571d017e571d017e571d01" : "7e5711117e5711117e5711117e571111",
       "7e571d027e571d027e571d027e571d02" : "7e5722227e5722227e5722227e572222",
     },
     sessionType:"temporary",
     duration:0.47
   },
   {
+    name:"short-cenc.mp4",
+    type:"video/mp4; codecs=\"avc1.64000d,mp4a.40.2\"",
+    keys: {
+      // "keyid" : "key"
+      "7e571d017e571d017e571d017e571d01" : "7e5711117e5711117e5711117e571111",
+      "7e571d027e571d027e571d027e571d02" : "7e5722227e5722227e5722227e572222",
+    },
+    sessionType:"temporary",
+    duration:0.47,
+    crossOrigin:true,
+  },
+  {
     name:"gizmo-frag-cencinit.mp4",
     fragments: [ "gizmo-frag-cencinit.mp4", "gizmo-frag-cenc1.m4s", "gizmo-frag-cenc2.m4s" ],
     type:"video/mp4; codecs=\"avc1.64000d,mp4a.40.2\"",
     keys: {
       // "keyid" : "key"
       "7e571d037e571d037e571d037e571d03" : "7e5733337e5733337e5733337e573333",
       "7e571d047e571d047e571d047e571d04" : "7e5744447e5744447e5744447e574444",
     },
     sessionType:"temporary",
     duration:2.00,
   },
+  {
+    name:"gizmo-frag-cencinit.mp4",
+    fragments: [ "gizmo-frag-cencinit.mp4", "gizmo-frag-cenc1.m4s", "gizmo-frag-cenc2.m4s" ],
+    type:"video/mp4; codecs=\"avc1.64000d,mp4a.40.2\"",
+    keys: {
+      // "keyid" : "key"
+      "7e571d037e571d037e571d037e571d03" : "7e5733337e5733337e5733337e573333",
+      "7e571d047e571d047e571d047e571d04" : "7e5744447e5744447e5744447e574444",
+    },
+    sessionType:"temporary",
+    duration:2.00,
+    crossOrigin:true,
+  },
 ];
 
 function checkMetadata(msg, e, test) {
   if (test.width) {
     is(e.videoWidth, test.width, msg + " video width");
   }
   if (test.height) {
     is(e.videoHeight, test.height, msg + " video height");
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -359,16 +359,18 @@ skip-if = (toolkit == 'android' && proce
 [test_contentDuration7.html]
 [test_controls.html]
 [test_currentTime.html]
 [test_decode_error.html]
 [test_decoder_disable.html]
 [test_defaultMuted.html]
 [test_delay_load.html]
 skip-if = buildapp == 'b2g' && toolkit != 'gonk' # bug 1082984
+[test_eme_access_control.html]
+skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908
 [test_eme_canvas_blocked.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908
 [test_eme_persistent_sessions.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908
 [test_eme_playback.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908
 [test_eme_requestKeySystemAccess.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_eme_access_control.html
@@ -0,0 +1,112 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test EME blocked cross-origin</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 TestNoCORS(test, token)
+{
+  var token = token + "_nocors";
+
+  manager.started(token);
+
+  var v = document.createElement("video");
+
+  v.addEventListener("encrypted", function(ev) {
+    is(ev.initDataType, "", "initDataType should be empty for CORS cross-origin media");
+    is(ev.initData, null, "initData should be null for CORS cross-origin media");
+
+    manager.finished(token);
+  });
+
+  v.addEventListener("error", function() {
+    ok(false, "Should not receive error loading cross-origin media without crossorigin attribute");
+  });
+
+  v.src = test.uri;
+}
+
+function TestCORSFailure(test, token)
+{
+  var token = token + "_corsfail";
+
+  manager.started(token);
+
+  var v = document.createElement("video");
+  v.crossOrigin = true;
+
+  v.addEventListener("error", function(ev) {
+    ok(true, "Should get error loading cross-origin media");
+    manager.finished(token);
+  });
+
+  v.addEventListener("encrypted", function() {
+    ok(false, "Should not receive encrypted event loading cross-origin media");
+  });
+
+  v.src = test.uri;
+}
+
+function TestCORSSuccess(test, token)
+{
+  var token = token + "_corsok";
+
+  manager.started(token);
+
+  var v = document.createElement("video");
+  v.crossOrigin = true;
+
+  v.addEventListener("error", function(ev) {
+    ok(false, "Should not get error loading cross-origin media");
+  });
+
+  v.addEventListener("encrypted", function(ev) {
+    ok(ev.initData.byteLength > 0, "Should get encryption initData loading cross-origin media");
+    is(ev.initDataType, "cenc", "Should get correct encryption initDataType loading cross-origin media");
+    manager.finished(token);
+  });
+
+  v.src = test.uri;
+}
+
+function startTest(test, token)
+{
+  test.uri = "http://test1.mochi.test:8888/tests/dom/media/test/" + test.name;
+  TestNoCORS(test, token);
+  TestCORSFailure(test, token);
+
+  test.uri = "http://test1.mochi.test:8888/tests/dom/media/test/allowed.sjs?" + test.name;
+  TestCORSSuccess(test, token);
+}
+
+function beginTest() {
+  manager.runTests(gEMETests.filter(t => t.crossOrigin), startTest);
+}
+
+var prefs = [
+  [ "media.mediasource.enabled", true ],
+  [ "media.mediasource.youtubeonly", false ],
+  [ "media.mediasource.mp4.enabled", true ],
+];
+
+if (/Linux/.test(navigator.userAgent) ||
+    !document.createElement('video').canPlayType("video/mp4")) {
+  // XXX remove once we have mp4 PlatformDecoderModules on all platforms.
+  prefs.push([ "media.fragmented-mp4.exposed", true ]);
+  prefs.push([ "media.fragmented-mp4.use-blank-decoder", true ]);
+}
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv({ "set" : prefs }, beginTest);
+</script>
+</pre>
+</body>
+</html>
--- a/dom/media/test/test_eme_playback.html
+++ b/dom/media/test/test_eme_playback.html
@@ -1,16 +1,16 @@
 <!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>
+  <script type="text/javascript" src="http://test1.mochi.test:8888/tests/dom/media/test/eme.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 var manager = new MediaTestManager;
 
 
 function KeysChangeFunc(session, keys, token) {