Bug 567954 - Use onloadeddata to contorl the suspend and resume of MediaResource. r=jwwang.
authorChia-hung Tai <ctai@mozilla.com>
Mon, 03 Oct 2016 17:48:03 +0800
changeset 318747 626eb0f05882b181c8b75b8a331af432b2b564dc
parent 318746 170c0f7ef959d0bdf452a585ff7eb2c25c744d07
child 318748 a2eba9924352f418c7323dd602fc7fdde5514c3e
push id82995
push usercbook@mozilla.com
push dateThu, 20 Oct 2016 14:50:53 +0000
treeherdermozilla-inbound@1bbe7ddb93da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs567954
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 567954 - Use onloadeddata to contorl the suspend and resume of MediaResource. r=jwwang. MozReview-Commit-ID: CSHDXuEf5pD
dom/media/test/mochitest.ini
dom/media/test/test_mixed_principals.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -487,16 +487,17 @@ support-files =
   owl-funnier-id3.mp3^headers^
   owl-funny-id3.mp3
   owl-funny-id3.mp3^headers^
   owl.mp3
   owl.mp3^headers^
   owl-short.mp3
   owl-short.mp3^headers^
   parser.vtt
+  pixel_aspect_ratio.mp4
   r11025_msadpcm_c1.wav
   r11025_msadpcm_c1.wav^headers^
   r11025_s16_c1.wav
   r11025_s16_c1.wav^headers^
   r11025_s16_c1_trailing.wav
   r11025_s16_c1_trailing.wav^headers^
   r11025_s16_c1-short.wav
   r11025_s16_c1-short.wav^headers^
@@ -791,17 +792,17 @@ tags=msg capturestream
 [test_mediatrack_consuming_mediastream.html]
 tags=msg
 [test_mediatrack_events.html]
 skip-if = toolkit == 'gonk' && debug # bug 1065924
 [test_mediatrack_parsing_ogg.html]
 [test_mediatrack_replay_from_end.html]
 [test_metadata.html]
 [test_mixed_principals.html]
-skip-if = true # bug 567954 and intermittent leaks
+skip-if = os == 'win' && os_version == '5.1' # Skip XP. See bug Bug 1311231
 [test_mozHasAudio.html]
 [test_multiple_mediastreamtracks.html]
 [test_networkState.html]
 [test_new_audio.html]
 [test_no_load_event.html]
 [test_paused.html]
 [test_paused_after_ended.html]
 [test_play_events.html]
--- a/dom/media/test/test_mixed_principals.html
+++ b/dom/media/test/test_mixed_principals.html
@@ -9,67 +9,86 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/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>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=489415">Mozilla Bug 489415</a>
 <p id="display"></p>
 
-<video id="v1" autoplay onended="loaded('v1')"></video>
-<video id="v2" autoplay onended="loaded('v2')"></video>
+<video id="v1" preload="metadata" onended="onendedcb('v1')"></video>
+<video id="v2" preload="metadata" onended="onendedcb('v2')"></video>
 
 <pre id="test">
 <script type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
+var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));
+var throwOutside = e => setTimeout(() => { throw e; });
+
 var v1 = document.getElementById("v1");
 var v2 = document.getElementById("v2");
-
-var resource = getPlayableVideo(gSeekTests);
-
-if (resource != null) {
-  var count = 0;
+var count = 0;
 
-  function loaded(id) {
-    var c = document.createElement("canvas");
-    var ctx = c.getContext("2d");
-    var v = document.getElementById(id);
-    ctx.drawImage(v, 0, 0);
-    try {
-      c.toDataURL();
-      ok(false, "Failed to throw exception in toDataURL for " + id);
-    } catch (ex) {
-      ok(true, "Threw exception in toDataURL for " + id);
-    }
-    if (++count == 2) {
-      SimpleTest.finish();
-    }
+function onendedcb(id) {
+  var c = document.createElement("canvas");
+  var ctx = c.getContext("2d");
+  var v = document.getElementById(id);
+  ctx.drawImage(v, 0, 0);
+  try {
+    c.toDataURL();
+    ok(false, "Failed to throw exception in toDataURL for " + id);
+  } catch (ex) {
+    ok(true, "Threw exception in toDataURL for " + id);
   }
+  if (++count == 2) {
+    SimpleTest.finish();
+  }
+}
+
+function testMixedPrincipals(resource) {
+  if (!resource) {
+    todo(false, "No types supported");
+    return;
+  }
+  // Make sure the media cache size(50MB) is large enough that the data could
+  // be download in MediaCache completely.
+  return pushPrefs(['media.cache_size', 50*1024])
+  .then(() => {
 
-  // Generate a random key. The first load with that key will return
-  // data, the second and subsequent loads with that key will return a redirect
-  // to a different origin ('localhost:8888' will be redirected to 'example.org',
-  // and 'example.org' will be redirected to 'localhost:8888'). We rely on the
-  // fact that Ogg will do a seek to the end of the resource, triggering a new
-  // load with the same key which will return a same-origin resource.
-  // Loading data from two different origins should be detected by the media
-  // cache and result in a null principal so that the canvas usage above fails.
-  var key = Math.floor(Math.random()*100000000);
+    // Generate a random key. The first load with that key will return
+    // data, the second and subsequent loads with that key will return a redirect
+    // to a different origin ('localhost:8888' will be redirected to 'example.org',
+    // and 'example.org' will be redirected to 'localhost:8888'). We rely on the
+    // fact that Ogg will do a seek to the end of the resource, triggering a new
+    // load with the same key which will return a same-origin resource.
+    // Loading data from two different origins should be detected by the media
+    // cache and result in a null principal so that the canvas usage above fails.
+    var key = Math.floor(Math.random()*100000000);
 
-  // In v1, try loading from same-origin first and then getting redirected to
-  // another origin.
-  v1.src = "http://mochi.test:8888/tests/dom/media/test/dynamic_redirect.sjs?key=v1_" + key + "&res=" + resource.name;
-  v1.load();
+    // In v1, try loading from same-origin first and then getting redirected to
+    // another origin.
+    v1.src =
+        "http://mochi.test:8888/tests/dom/media/test/dynamic_redirect.sjs?key=v1_" +
+        key + "&res=" + resource.name;
+    v1.onloadeddata = function () {
+      // To limit readahead, avoid racing with playback and "catching up" mode.
+      v1.play();
+    }
 
-  // In v2, try loading cross-origin first and then getting redirected to
-  // our origin.
-  v2.src = "http://example.org/tests/dom/media/test/dynamic_redirect.sjs?key=v2_" + key + "&res=" + resource.name;
-  v2.load();
-  
-} else {
-  todo(false, "No types supported");
+    // In v2, try loading cross-origin first and then getting redirected to
+    // our origin.
+    v2.src = "http://example.org/tests/dom/media/test/dynamic_redirect.sjs?key=v2_" + key + "&res=" + resource.name;
+    v2.onloadeddata = function () {
+      // To limit readahead, avoid racing with playback and "catching up" mode.
+      v2.play();
+    }
+  });
 }
+
+testMixedPrincipals({ name:"pixel_aspect_ratio.mp4", type:"video/mp4", duration:28})
+.catch(e => throwOutside(e));
+
 </script>
 </pre>
 
 </body>
 </html>