Bug 995438 - Call SpecialPowers.pushPermissions() to ensure permission change is completed before continuing the rest of the tests. r=baku, a=test-only
authorJW Wang <jwwang@mozilla.com>
Tue, 30 Sep 2014 06:45:00 -0400
changeset 216893 145ef3fe7204
parent 216892 583cc1307044
child 216894 449e9b0c1780
push id3959
push userryanvm@gmail.com
push date2014-10-01 19:28 +0000
treeherdermozilla-beta@6326278b28ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, test-only
bugs995438
milestone33.0
Bug 995438 - Call SpecialPowers.pushPermissions() to ensure permission change is completed before continuing the rest of the tests. r=baku, a=test-only
content/html/content/test/test_audio_wakelock.html
--- a/content/html/content/test/test_audio_wakelock.html
+++ b/content/html/content/test/test_audio_wakelock.html
@@ -34,17 +34,17 @@ function testAudioPlayPause() {
   audio.addEventListener('playing', function() {
     startDate = new Date();
 
     // The next step is to unlock the resource.
     lockState = false;
     audio.pause();
   });
 
-  navigator.mozPower.addWakeLockListener(function testAudioPlayListener(topic, state) {
+  function testAudioPlayListener(topic, state) {
     is(topic, "cpu", "Audio element locked the target == cpu");
     var locked = state == "locked-foreground" ||
                  state == "locked-background";
 
     is(locked, lockState, "Audio element locked the cpu - no paused");
     count++;
 
     // count == 1 is when the cpu wakelock is created
@@ -53,18 +53,19 @@ function testAudioPlayPause() {
     if (count == 2) {
       var diffDate = (new Date() - startDate);
       ok(diffDate > 200, "There was at least 200 milliseconds between the stop and the wakelock release");
 
       content.removeChild(audio);
       navigator.mozPower.removeWakeLockListener(testAudioPlayListener);
       runTests();
     }
-  });
+  };
 
+  navigator.mozPower.addWakeLockListener(testAudioPlayListener);
   audio.play();
 }
 
 function testAudioPlay() {
   var lockState = true;
   var count = 0;
 
   var content = document.getElementById('content');
@@ -73,17 +74,17 @@ function testAudioPlay() {
   audio.src = "wakelock.ogg";
   content.appendChild(audio);
 
   var startDate;
   audio.addEventListener('progress', function() {
     startDate = new Date();
   });
 
-  navigator.mozPower.addWakeLockListener(function testAudioPlayListener(topic, state) {
+  function testAudioPlayListener(topic, state) {
     is(topic, "cpu", "Audio element locked the target == cpu");
     var locked = state == "locked-foreground" ||
                  state == "locked-background";
 
     is(locked, lockState, "Audio element locked the cpu - no paused");
     count++;
 
     // count == 1 is when the cpu wakelock is created: the wakelock must be
@@ -96,33 +97,37 @@ function testAudioPlay() {
     } else if (count == 2) {
       var diffDate = (new Date() - startDate);
       ok(diffDate > 200, "There was at least 200 milliseconds between the stop and the wakelock release");
 
       content.removeChild(audio);
       navigator.mozPower.removeWakeLockListener(testAudioPlayListener);
       runTests();
     }
-  });
+  };
 
+  navigator.mozPower.addWakeLockListener(testAudioPlayListener);
   audio.play();
 }
 
 var tests = [ testAudioPlayPause, testAudioPlay ];
 function runTests() {
   if (!tests.length) {
     SimpleTest.finish();
     return;
   }
 
   var test =  tests.pop();
   test();
 };
 
-SpecialPowers.addPermission("power", true, document);
-SpecialPowers.pushPrefEnv({"set": [["media.wakelock_timeout", 500]]}, runTests);
+SpecialPowers.pushPermissions(
+  [{'type': 'power', 'allow': true, 'context': document}],
+  function() {
+    SpecialPowers.pushPrefEnv({"set": [["media.wakelock_timeout", 500]]}, runTests);
+  });
 
 SimpleTest.waitForExplicitFinish();
 
 </script>
 </pre>
 </body>
 </html>