Bug 1069795 - Use promise and pushEnv instead of setEnv. r=jwwang
authorAlfredo Yang <ayang@mozilla.com>
Mon, 22 Sep 2014 02:21:00 -0400
changeset 206452 7fef64119cf40061d8cbfcfb0ed3ec458ff53c27
parent 206451 91fb84885bcda62b7a38b984792c256bb9bc6cc8
child 206453 9152ac14bc927648d244a2a6763194f868b53672
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjwwang
bugs1069795
milestone35.0a1
Bug 1069795 - Use promise and pushEnv instead of setEnv. r=jwwang
content/media/test/can_play_type_ogg.js
content/media/test/mochitest.ini
content/media/test/test_can_play_type_no_ogg.html
content/media/test/test_can_play_type_ogg.html
--- a/content/media/test/can_play_type_ogg.js
+++ b/content/media/test/can_play_type_ogg.js
@@ -1,38 +1,78 @@
-function check_ogg(v, enabled) {
+
+function check_ogg(v, enabled, finish) {
   function check(type, expected) {
     is(v.canPlayType(type), enabled ? expected : "", type);
   }
 
-  // Ogg types
-  check("video/ogg", "maybe");
-  check("audio/ogg", "maybe");
-  check("application/ogg", "maybe");
+  function basic_test() {
+    return new Promise(function(resolve, reject) {
+      // Ogg types
+      check("video/ogg", "maybe");
+      check("audio/ogg", "maybe");
+      check("application/ogg", "maybe");
 
-  // Supported Ogg codecs
-  check("audio/ogg; codecs=vorbis", "probably");
-  check("video/ogg; codecs=vorbis", "probably");
-  check("video/ogg; codecs=vorbis,theora", "probably");
-  check("video/ogg; codecs=\"vorbis, theora\"", "probably");
-  check("video/ogg; codecs=theora", "probably");
+      // Supported Ogg codecs
+      check("audio/ogg; codecs=vorbis", "probably");
+      check("video/ogg; codecs=vorbis", "probably");
+      check("video/ogg; codecs=vorbis,theora", "probably");
+      check("video/ogg; codecs=\"vorbis, theora\"", "probably");
+      check("video/ogg; codecs=theora", "probably");
+
+      resolve();
+    });
+  }
 
   // Verify Opus support
-  var OpusEnabled = undefined;
-  try {
-    OpusEnabled = SpecialPowers.getBoolPref("media.opus.enabled");
-  } catch (ex) {
-    // SpecialPowers failed, perhaps because Opus isn't compiled in
-    console.log("media.opus.enabled pref not found; skipping Opus validation");
+  function verify_opus_support() {
+    return new Promise(function(resolve, reject) {
+      var OpusEnabled = undefined;
+      try {
+        OpusEnabled = SpecialPowers.getBoolPref("media.opus.enabled");
+      } catch (ex) {
+        // SpecialPowers failed, perhaps because Opus isn't compiled in
+        console.log("media.opus.enabled pref not found; skipping Opus validation");
+      }
+      if (OpusEnabled != undefined) {
+        resolve();
+      } else {
+        reject();
+      }
+    });
   }
-  if (OpusEnabled !== undefined) {
-    SpecialPowers.setBoolPref("media.opus.enabled", true);
-    check("audio/ogg; codecs=opus", "probably");
-    SpecialPowers.setBoolPref("media.opus.enabled", false);
-    check("audio/ogg; codecs=opus", "");
-    SpecialPowers.setBoolPref("media.opus.enabled", OpusEnabled);
+
+  function opus_enable() {
+    return new Promise(function(resolve, reject) {
+      SpecialPowers.pushPrefEnv({"set": [['media.opus.enabled', true]]},
+                                function() {
+                                  check("audio/ogg; codecs=opus", "probably");
+                                  resolve();
+                                });
+    });
   }
 
-  // Unsupported Ogg codecs
-  check("video/ogg; codecs=xyz", "");
-  check("video/ogg; codecs=xyz,vorbis", "");
-  check("video/ogg; codecs=vorbis,xyz", "");
+  function opus_disable() {
+    return new Promise(function(resolve, reject) {
+      SpecialPowers.pushPrefEnv({"set": [['media.opus.enabled', false]]},
+                                function() {
+                                  check("audio/ogg; codecs=opus", "");
+                                  resolve();
+                                });
+    });
+  }
+
+  function unspported_ogg() {
+    // Unsupported Ogg codecs
+    check("video/ogg; codecs=xyz", "");
+    check("video/ogg; codecs=xyz,vorbis", "");
+    check("video/ogg; codecs=vorbis,xyz", "");
+
+    finish.call();
+  }
+
+  basic_test()
+  .then(verify_opus_support)
+  .then(opus_enable)
+  .then(opus_disable)
+  .then(unspported_ogg, unspported_ogg);
+
 }
--- a/content/media/test/mochitest.ini
+++ b/content/media/test/mochitest.ini
@@ -315,17 +315,16 @@ skip-if = buildapp == 'mulet' || os == '
 [test_bug919265.html]
 [test_bug957847.html]
 [test_bug1018933.html]
 [test_can_play_type.html]
 [test_can_play_type_mpeg.html]
 skip-if = buildapp == 'b2g' # bug 1021675
 [test_can_play_type_no_ogg.html]
 [test_can_play_type_ogg.html]
-skip-if = buildapp == 'b2g' || e10s # b2g(bug 1021675)
 [test_chaining.html]
 [test_clone_media_element.html]
 [test_closing_connections.html]
 [test_constants.html]
 [test_contentDuration1.html]
 [test_contentDuration2.html]
 [test_contentDuration3.html]
 [test_contentDuration4.html]
--- a/content/media/test/test_can_play_type_no_ogg.html
+++ b/content/media/test/test_can_play_type_no_ogg.html
@@ -19,20 +19,24 @@ a Bug 469247</a>
 
 <video id="v"></video>
 
 <pre id="test">
 <script src="can_play_type_ogg.js"></script>
 <script>
 
 SimpleTest.waitForExplicitFinish();
+
+function finish() {
+  mediaTestCleanup();
+  SimpleTest.finish();
+}
+
 SpecialPowers.pushPrefEnv({"set": [["media.ogg.enabled", false]]},
   function() {
-    check_ogg(document.getElementById('v'), false);
-    mediaTestCleanup();
-    SimpleTest.finish();
+    check_ogg(document.getElementById('v'), false, finish);
   }
 );
 
 </script>
 </pre>
 </body>
 </html>
--- a/content/media/test/test_can_play_type_ogg.html
+++ b/content/media/test/test_can_play_type_ogg.html
@@ -16,15 +16,22 @@ a Bug 469247</a>
 <div id="content" style="display: none">
 </div>
 
 <video id="v"></video>
 
 <pre id="test">
 <script src="can_play_type_ogg.js"></script>
 <script>
-check_ogg(document.getElementById('v'), true);
+
+SimpleTest.waitForExplicitFinish();
 
-mediaTestCleanup();
+function finish() {
+  mediaTestCleanup();
+  SimpleTest.finish();
+}
+
+check_ogg(document.getElementById('v'), true, finish);
+
 </script>
 </pre>
 </body>
 </html>