Bug 994292 - 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>
Wed, 01 Oct 2014 22:16:00 +0200
changeset 216920 16bd77984527
parent 216917 9150826eaf1b
child 216921 3d1029947008
push id3969
push userryanvm@gmail.com
push date2014-10-03 01:38 +0000
treeherdermozilla-beta@7fefb97d2f75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, test-only
bugs994292
milestone33.0
Bug 994292 - 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_video_wakelock.html
--- a/content/html/content/test/test_video_wakelock.html
+++ b/content/html/content/test/test_video_wakelock.html
@@ -37,17 +37,17 @@ function testVideoPlayPause() {
     startDate = new Date();
 
     // The next step is to unlock the resource.
     lockState_cpu = false;
     lockState_screen = false;
     video.pause();
   });
 
-  navigator.mozPower.addWakeLockListener(function testVideoPlayPauseListener(topic, state) {
+  function testVideoPlayPauseListener(topic, state) {
     var locked = state == "locked-foreground" ||
                  state == "locked-background";
 
     if (topic == "cpu") {
       is(locked, lockState_cpu, "Video element locked the cpu - paused");
       count_cpu++;
     } else if (topic == "screen") {
       is(locked, lockState_screen, "Video element locked the screen - paused");
@@ -57,18 +57,19 @@ function testVideoPlayPause() {
     if (count_cpu == 2 && count_screen == 2) {
       var diffDate = (new Date() - startDate);
       ok(diffDate > 200, "There was at least 200 milliseconds between the stop and the wakelock release");
 
       content.removeChild(video);
       navigator.mozPower.removeWakeLockListener(testVideoPlayPauseListener);
       runTests();
     }
-  });
+  }
 
+  navigator.mozPower.addWakeLockListener(testVideoPlayPauseListener);
   video.play();
 }
 
 function testVideoPlay() {
   var lockState_cpu = true;
   var lockState_screen = true;
   var count_cpu = 0;
   var count_screen = 0;
@@ -79,17 +80,17 @@ function testVideoPlay() {
   video.src = "wakelock.ogv";
   content.appendChild(video);
 
   var startDate;
   video.addEventListener('progress', function() {
     startDate = new Date();
   });
 
-  navigator.mozPower.addWakeLockListener(function testVideoPlayListener(topic, state) {
+  function testVideoPlayListener(topic, state) {
     var locked = state == "locked-foreground" ||
                  state == "locked-background";
 
     if (topic == "cpu") {
       is(locked, lockState_cpu, "Video element locked the cpu - paused");
       count_cpu++;
     } else if (topic == "screen") {
       is(locked, lockState_screen, "Video element locked the screen - paused");
@@ -103,33 +104,37 @@ function testVideoPlay() {
     } else if (count_cpu == 2 && count_screen == 2) {
       var diffDate = (new Date() - startDate);
       ok(diffDate > 200, "There was at least milliseconds between the stop and the wakelock release");
 
       content.removeChild(video);
       navigator.mozPower.removeWakeLockListener(testVideoPlayListener);
       runTests();
     }
-  });
+  }
 
+  navigator.mozPower.addWakeLockListener(testVideoPlayListener);
   video.play();
 }
 
 var tests = [ testVideoPlayPause, testVideoPlay ];
 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>