Bug 902686 - Change manifest.js to use SpecialPowers.pushPrefEnv. r=jwwang
☠☠ backed out by b0cc3073ef81 ☠ ☠
authorMartijn Wargers <mwargers@mozilla.com>
Mon, 14 Jul 2014 12:18:16 +0200
changeset 216643 2ccde1bdcb7f9ddd757604fc65766184d9806bbe
parent 216642 87ae841e4f92c1cd0db5572e16a2a7747d758d47
child 216644 df278df1524f968923d102ae3e91c7e463475a4b
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs902686
milestone33.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 902686 - Change manifest.js to use SpecialPowers.pushPrefEnv. r=jwwang
content/media/test/manifest.js
content/media/test/test_access_control.html
content/media/test/test_closing_connections.html
content/media/test/test_error_in_video_document.html
content/media/test/test_error_on_404.html
content/media/test/test_load.html
content/media/test/test_load_source.html
content/media/test/test_mixed_principals.html
content/media/test/test_no_load_event.html
content/media/test/test_reset_src.html
content/media/test/test_seekable3.html
content/media/test/test_streams_gc.html
--- a/content/media/test/manifest.js
+++ b/content/media/test/manifest.js
@@ -661,17 +661,18 @@ function MediaTestManager() {
     this.testNum = 0;
     this.tests = tests;
     this.startTest = startTest;
     this.tokens = [];
     this.isShutdown = false;
     this.numTestsRunning = 0;
     // Always wait for explicit finish.
     SimpleTest.waitForExplicitFinish();
-    this.nextTest();
+
+    setMediaTestsPrefs(function() {this.nextTest()}.bind(this));
   }
 
   // Registers that the test corresponding to 'token' has been started.
   // Don't call more than once per token.
   this.started = function(token) {
     this.tokens.push(token);
     this.numTestsRunning++;
     is(this.numTestsRunning, this.tokens.length, "[started " + token + "] Length of array should match number of running tests");
@@ -766,47 +767,14 @@ function mediaTestCleanup() {
     var A = document.getElementsByTagName("audio");
     for (i=0; i<A.length; i++) {
       removeNodeAndSource(A[i]);
       A[i] = null;
     }
     SpecialPowers.forceGC();
 }
 
-(function() {
-  // Ensure that preload preferences are comsistent
-  var prefService = SpecialPowers.wrap(SpecialPowers.Components)
-                                 .classes["@mozilla.org/preferences-service;1"]
-                                 .getService(SpecialPowers.Ci.nsIPrefService);
-  var branch = prefService.getBranch("media.");
-  var oldDefault = 2;
-  var oldAuto = 3;
-  var oldAppleMedia = undefined;
-  var oldGStreamer = undefined;
-  var oldOpus = undefined;
-
-  try { oldAppleMedia = SpecialPowers.getBoolPref("media.apple.mp3.enabled"); } catch(ex) { }
-  try { oldGStreamer = SpecialPowers.getBoolPref("media.gstreamer.enabled"); } catch(ex) { }
-  try { oldDefault   = SpecialPowers.getIntPref("media.preload.default"); } catch(ex) { }
-  try { oldAuto      = SpecialPowers.getIntPref("media.preload.auto"); } catch(ex) { }
-  try { oldOpus      = SpecialPowers.getBoolPref("media.opus.enabled"); } catch(ex) { }
-
-  SpecialPowers.setIntPref("media.preload.default", 2); // preload_metadata
-  SpecialPowers.setIntPref("media.preload.auto", 3); // preload_enough
-  // test opus playback iff the pref exists
-  if (oldOpus !== undefined)
-    SpecialPowers.setBoolPref("media.opus.enabled", true);
-  if (oldGStreamer !== undefined)
-    SpecialPowers.setBoolPref("media.gstreamer.enabled", true);
-  if (oldAppleMedia !== undefined)
-    SpecialPowers.setBoolPref("media.apple.mp3.enabled", true);
-
-  window.addEventListener("unload", function() {
-    if (oldGStreamer !== undefined)
-      SpecialPowers.setBoolPref("media.gstreamer.enabled", oldGStreamer);
-    if (oldAppleMedia !== undefined)
-      SpecialPowers.setBoolPref("media.apple.mp3.enabled", oldAppleMedia);
-    SpecialPowers.setIntPref("media.preload.default", oldDefault);
-    SpecialPowers.setIntPref("media.preload.auto", oldAuto);
-    if (oldOpus !== undefined)
-      SpecialPowers.setBoolPref("media.opus.enabled", oldOpus);
-  }, false);
- })();
+function setMediaTestsPrefs(aCallback, aExtraPrefs) {
+    var prefs = [["media.preload.default", 2], ["media.preload.auto", 3]];
+    if (aExtraPrefs)
+      prefs = prefs.concat(aExtraPrefs);
+    SpecialPowers.pushPrefEnv({"set": prefs}, aCallback);
+}
--- a/content/media/test/test_access_control.html
+++ b/content/media/test/test_access_control.html
@@ -15,17 +15,19 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 451958 **/
 
 function run() {
-  window.open("http://example.org:80/tests/content/media/test/file_access_controls.html", "", "width=500,height=500");
+  setMediaTestsPrefs(function() {
+    window.open("http://example.org:80/tests/content/media/test/file_access_controls.html", "", "width=500,height=500");
+  });
 }
 
 function done() {
   mediaTestCleanup();
   SimpleTest.finish();
 }
 
 addLoadEvent(run);
--- a/content/media/test/test_closing_connections.html
+++ b/content/media/test/test_closing_connections.html
@@ -30,17 +30,19 @@ window.onload = function() {
      the others will be blocked by the per-domain HTTP connection limit. We
      pass this test by closing the connection for non-buffered videos after
      we've got the first frame.
 */
 
 var resource = getPlayableVideo(gSeekTests);
 
 SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, beginTest);
+
+setMediaTestsPrefs(beginTest, [["media.cache_size", 40000]]);
+
 function beginTest() {
   if (resource != null) {
     for (var i=0; i<20; ++i) {
       var v = document.createElement("video");
       v.src = resource.name;
       document.body.appendChild(v);
     }
   } else {
--- a/content/media/test/test_error_in_video_document.html
+++ b/content/media/test/test_error_in_video_document.html
@@ -40,18 +40,20 @@ function check() {
 // Find an error test that we'd think we should be able to play (if it
 // wasn't already known to fail).
 var t = getPlayableVideo(gErrorTests);
 if (!t) {
   todo(false, "No types supported");
 } else {
   SimpleTest.waitForExplicitFinish();
 
-  var f = document.createElement("iframe");
-  f.src = t.name;
-  f.addEventListener("load", function() { SimpleTest.executeSoon(check); }, false);
-  document.body.appendChild(f);
+  setMediaTestsPrefs(function() {
+    var f = document.createElement("iframe");
+    f.src = t.name;
+    f.addEventListener("load", function() { SimpleTest.executeSoon(check); }, false);
+    document.body.appendChild(f);
+  });
 }
 
 </script>
 </pre>
 </body>
 </html>
--- a/content/media/test/test_error_on_404.html
+++ b/content/media/test/test_error_on_404.html
@@ -49,36 +49,41 @@ function loadError(evt) {
 function loadedData(evt) {
   evt.target._loadedData = true;
 }
 
 function loadStart(evt) {
   evt.target._loadStart = true;
 }
 
-// Create all video objects.
-for (var i=0; i<g404Tests.length; ++i) {
-  var v = document.createElement("video");
-  v.preload = "auto";
-  var test = g404Tests[i];
-  if (!v.canPlayType(test.type)) {
-    continue;
-   }
-   v.src = test.name;
-   v._loadedData = false;
-   v._loadStart = false;
-   v._loadError = false;
-   v.addEventListener("error", loadError, false);
-   v.addEventListener("loadstart", loadStart, false);
-   v.addEventListener("loadeddata", loadedData, false);
-   document.body.appendChild(v); // Will start load.
-   videos.push(v);
+function startTest() {
+  // Create all video objects.
+  for (var i=0; i<g404Tests.length; ++i) {
+    var v = document.createElement("video");
+    v.preload = "auto";
+    var test = g404Tests[i];
+    if (!v.canPlayType(test.type)) {
+      continue;
+     }
+     v.src = test.name;
+     v._loadedData = false;
+     v._loadStart = false;
+     v._loadError = false;
+     v.addEventListener("error", loadError, false);
+     v.addEventListener("loadstart", loadStart, false);
+     v.addEventListener("loadeddata", loadedData, false);
+     document.body.appendChild(v); // Will start load.
+     videos.push(v);
+  }
+
+  if (videos.length == 0) {
+    todo(false, "No types supported");
+    SimpleTest.finish();
+  }
 }
 
-if (videos.length == 0) {
-  todo(false, "No types supported");
-} else {
-  SimpleTest.waitForExplicitFinish();
-}
+SimpleTest.waitForExplicitFinish();
+setMediaTestsPrefs(startTest);
+
 </script>
 </pre>
 </body>
 </html>
--- a/content/media/test/test_load.html
+++ b/content/media/test/test_load.html
@@ -198,17 +198,21 @@ function nextTest() {
 
   gTestName = "Test " + src + " " + (gTestNum - 1);
   log("Starting " + gTestName);
   gExpectedEvents = t.expectedEvents;
 
   t.create(src, type);
 }
 
-addLoadEvent(nextTest);
+function startTest() {
+  setMediaTestsPrefs(nextTest);
+}
+
+addLoadEvent(startTest);
 SimpleTest.waitForExplicitFinish();
 
 </script>
 </pre>
 
 <div id="log" style="font-size: small"></div>
 </body>
 </html>
--- a/content/media/test/test_load_source.html
+++ b/content/media/test/test_load_source.html
@@ -50,27 +50,33 @@ for (var i=0; i<gPlayTests.length; i++) 
   if (!first) {
     first = gPlayTests[i];
   } else if (!second) {
     second = gPlayTests[i];
     break;
   }
 }
 
-if (first && second) {
-  s = document.createElement('source');
-  s.type = first.type;
-  s.src = first.name;
-  v.appendChild(s);
-  v.autoplay = true;
-  v.addEventListener("ended", ended, false);
-  document.body.appendChild(v);
-  SimpleTest.waitForExplicitFinish();
-} else {
-  todo(false, "Need at least two media of supported types for this test!");
+function runTest() {
+  if (first && second) {
+    s = document.createElement('source');
+    s.type = first.type;
+    s.src = first.name;
+    v.appendChild(s);
+    v.autoplay = true;
+    v.addEventListener("ended", ended, false);
+    document.body.appendChild(v);
+  } else {
+    todo(false, "Need at least two media of supported types for this test!");
+    SimpleTest.finish();
+  }
 }
 
+function startTest() {
+  setMediaTestsPrefs(runTest);
+}
 
-
+addLoadEvent(startTest);
+SimpleTest.waitForExplicitFinish();
 </script>
 </pre>
 </body>
 </html>
--- a/content/media/test/test_mixed_principals.html
+++ b/content/media/test/test_mixed_principals.html
@@ -9,28 +9,29 @@ 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" autoplay onended="loaded('v1')"></video>
+<video id="v2" preload="metadata" autoplay onended="loaded('v2')"></video>
 
 <pre id="test">
 <script type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
 var v1 = document.getElementById("v1");
 var v2 = document.getElementById("v2");
 
 var resource = getPlayableVideo(gSeekTests);
 
+
 if (resource != null) {
   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);
@@ -59,17 +60,18 @@ if (resource != null) {
   // another origin.
   v1.src = "http://mochi.test:8888/tests/content/media/test/dynamic_redirect.sjs?key=v1_" + key + "&res=" + resource.name;
   v1.load();
 
   // In v2, try loading cross-origin first and then getting redirected to
   // our origin.
   v2.src = "http://example.org/tests/content/media/test/dynamic_redirect.sjs?key=v2_" + key + "&res=" + resource.name;
   v2.load();
-  
 } else {
   todo(false, "No types supported");
+  SimpleTest.finish();
 }
+
 </script>
 </pre>
 
 </body>
 </html>
--- a/content/media/test/test_no_load_event.html
+++ b/content/media/test/test_no_load_event.html
@@ -5,53 +5,58 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 715469</title>
   <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 onload="start();">
+<body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=715469">Mozilla Bug 715469</a>
 <p id="display"></p>
-<div id="content" style="display: none">
-  
-</div>
+<div id="content" style="display: none"></div>
 <pre id="test">
 
 <script type="application/javascript">
 
 /** Test for Bug 715469 **/
 
 var gotLoadEvent = false;
 
 function start() {
   var resource = getPlayableVideo(gSmallTests);
   if (resource == null) {
     todo(false, "No types supported");
+    SimpleTest.finish();
   } else {
-    SimpleTest.waitForExplicitFinish();
     var v = document.createElement("video");
     v.src = resource.name;
     v.addEventListener("loadeddata", function(){v.play();}, false);
     v.controls = "true";
-    
+
     v.addEventListener("load",
       function(){
         gotLoadEvent = true;
       },
       false);
-      
+
     v.addEventListener("ended", finished, false);
-    
+
     document.body.appendChild(v);
   }
 }
 
+function startTest() {
+  setMediaTestsPrefs(start);
+}
+
+addLoadEvent(startTest);
+SimpleTest.waitForExplicitFinish();
+
 function finished() {
   is(gotLoadEvent, false, "Should not receive a load on the video element");
   SimpleTest.finish();
 }
 
 
 </script>
 </pre>
--- a/content/media/test/test_reset_src.html
+++ b/content/media/test/test_reset_src.html
@@ -9,17 +9,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="manifest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank"
 href="https://bugzilla.mozilla.org/show_bug.cgi?id=804875">Mozilla Bug 804875</a>
 
-<video style="border: 4px solid red" controls></video>
+<video style="border: 4px solid red" preload="metadata" controls></video>
 <canvas></canvas>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 function onLoadedMetadata_Audio(e) {
   var t = e.target;
   is(t.videoHeight, 0, "videoHeight should be zero when there is no video.");
--- a/content/media/test/test_seekable3.html
+++ b/content/media/test/test_seekable3.html
@@ -25,12 +25,13 @@ function on_metadataloaded() {
 
   v.play();
 }
 
 SimpleTest.waitForExplicitFinish();
 </script>
 </pre>
 <video id='v'
+preload="metadata"
 src='noContentLength.sjs'
 onloadedmetadata='on_metadataloaded();'></video>
 </body>
 </html>
--- a/content/media/test/test_streams_gc.html
+++ b/content/media/test/test_streams_gc.html
@@ -2,17 +2,17 @@
 <html>
 <head>
   <title>Test garbage collection of captured stream (bug 806754)</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>
 </head>
 <body onload="doTest()">
-<audio id="a"></audio>
+<audio id="a" preload="metadata"></audio>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
 var a = document.getElementById('a');
 a.src = getPlayableAudio(gSmallTests).name;
 
 function forceGC() {
@@ -31,15 +31,15 @@ function doTest() {
       a.addEventListener("ended", function() {
         ok(true, "GC completed OK");
         SimpleTest.finish();
       }, false);
     }, false);
   }, false);
 
   a.currentTime = a.duration;
-  
+
   setTimeout(forceGC, 0);
 }
 </script>
 </pre>
 </body>
 </html>