Bug 902686 - Change manifest.js to use SpecialPowers.pushPrefEnv. r=edwin
authorMartijn Wargers <mwargers@mozilla.com>
Mon, 14 Jul 2014 12:18:16 +0200
changeset 238099 f8cbccdf1945ec1a2ecc9fd4e4ade5c8e718ceb2
parent 238098 3082c3a0823f98a7dd21f52544f3a100d333cf58
child 238100 778141c3e5fc4e0d699ed86bd5201e029d690e8c
push id28554
push userryanvm@gmail.com
push dateWed, 08 Apr 2015 16:15:39 +0000
treeherdermozilla-central@256b307c35ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs902686
milestone40.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=edwin
dom/media/test/manifest.js
dom/media/test/test_access_control.html
dom/media/test/test_error_on_404.html
dom/media/test/test_load.html
dom/media/test/test_no_load_event.html
dom/media/test/test_seekable3.html
--- a/dom/media/test/manifest.js
+++ b/dom/media/test/manifest.js
@@ -836,16 +836,18 @@ function once(target, name, cb) {
 
 // Number of tests to run in parallel.
 var PARALLEL_TESTS = 2;
 
 // Prefs to set before running tests.  Use this to improve coverage of
 // conditions that might not otherwise be encountered on the test data.
 var gTestPrefs = [
   ['media.recorder.max_memory', 1024],
+  ["media.preload.default", 2], // default preload = metadata
+  ["media.preload.auto", 3] // auto preload = enough
 ];
 
 // When true, we'll loop forever on whatever test we run. Use this to debug
 // intermittent test failures.
 const DEBUG_TEST_LOOP_FOREVER = false;
 
 // Manages a run of media tests. Runs them in chunks in order to limit
 // the number of media elements/threads running in parallel. This limits peak
@@ -987,49 +989,17 @@ function mediaTestCleanup(callback) {
     var cb = function() {
       if (callback) {
         callback();
       }
     }
     SpecialPowers.exactGC(window, cb);
 }
 
-(function() {
-  SimpleTest.requestFlakyTimeout("untriaged");
-
-  // 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) { }
+function setMediaTestsPrefs(callback, extraPrefs) {
+  var prefs = gTestPrefs;
+  if (extraPrefs) {
+    prefs = prefs.concat(extraPrefs);
+  }
+  SpecialPowers.pushPrefEnv({"set": prefs}, callback);
+}
 
-  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);
- })();
+SimpleTest.requestFlakyTimeout("untriaged");
\ No newline at end of file
--- a/dom/media/test/test_access_control.html
+++ b/dom/media/test/test_access_control.html
@@ -23,17 +23,19 @@ function run() {
   window.open("http://example.org:80/tests/dom/media/test/file_access_controls.html", "", "width=500,height=500");
 }
 
 function done() {
   mediaTestCleanup();
   SimpleTest.finish();
 }
 
-addLoadEvent(run);
+addLoadEvent(function() {
+  setMediaTestsPrefs(run);
+});
 SimpleTest.waitForExplicitFinish();
 
 
 window.addEventListener("message", receiveMessage, false);
 
 function receiveMessage(event)
 {
   if (event.origin !== "http://example.org") {
--- a/dom/media/test/test_error_on_404.html
+++ b/dom/media/test/test_error_on_404.html
@@ -52,17 +52,17 @@ function loadedData(evt) {
 
 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";
+  v.preload = "metadata";
   var test = g404Tests[i];
   if (!v.canPlayType(test.type)) {
     continue;
    }
    v.src = test.name;
    v._loadedData = false;
    v._loadStart = false;
    v._loadError = false;
--- a/dom/media/test/test_load.html
+++ b/dom/media/test/test_load.html
@@ -57,17 +57,17 @@ function source_error(evt) {
     setTimeout(nextTest, 0); 
   }
 }
 
 var gMedia = null;
 
 function createMedia(tag) {
   gMedia = document.createElement(tag);
-  gMedia.preload = "auto";
+  gMedia.preload = "metadata";
   for (var i=0; i<gEventTypes.length; i++) {
     gMedia.addEventListener(gEventTypes[i], listener, false);
   }
 }
 
 function addSource(src, type) {
   var s = document.createElement("source");
   s.addEventListener("error", source_error, false);
--- a/dom/media/test/test_no_load_event.html
+++ b/dom/media/test/test_no_load_event.html
@@ -9,17 +9,16 @@ 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 onload="start();">
 <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>
 <pre id="test">
 
 <script type="application/javascript">
 
 /** Test for Bug 715469 **/
 
 var gotLoadEvent = false;
@@ -27,33 +26,28 @@ var gotLoadEvent = false;
 function start() {
   var resource = getPlayableVideo(gSmallTests);
   if (resource == null) {
     todo(false, "No types supported");
   } 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("load", function() {
+      gotLoadEvent = true;
+    }, false);
+
     v.addEventListener("ended", finished, false);
-    
     document.body.appendChild(v);
+    v.play();
   }
 }
 
 function finished() {
   is(gotLoadEvent, false, "Should not receive a load on the video element");
   SimpleTest.finish();
 }
 
-
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/test/test_seekable3.html
+++ b/dom/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>