Bug 1023552 - Fix race between 'playing' and wakelock events. r=baku, a=test-only
authorJW Wang <jwwang@mozilla.com>
Wed, 08 Oct 2014 19:14:00 +0200
changeset 225540 26891990476e2ad2eac14b4bfb2db26343317633
parent 225539 ec5c2601e7f59dcfb2d5a68e3cbc87e99da5d372
child 225541 4aca8611439b63a0ae8fc06d060045c35c79bd0d
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, test-only
bugs1023552
milestone34.0a2
Bug 1023552 - Fix race between 'playing' and wakelock events. 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
@@ -26,38 +26,41 @@ function testAudioPlayPause() {
 
   var content = document.getElementById('content');
 
   var audio = document.createElement('audio');
   audio.src = "wakelock.ogg";
   content.appendChild(audio);
 
   var startDate;
-  audio.addEventListener('playing', function() {
-    startDate = new Date();
-
-    // The next step is to unlock the resource.
-    lockState = false;
-    audio.pause();
-  });
-
   function testAudioPlayListener(topic, state) {
-    is(topic, "cpu", "Audio element locked the target == cpu");
+    is(topic, "cpu", "#1 Audio element locked the target == cpu");
     var locked = state == "locked-foreground" ||
                  state == "locked-background";
 
-    is(locked, lockState, "Audio element locked the cpu - no paused");
+    var s = locked ? "locked" : "unlocked";
+    is(locked, lockState, "#1 Audio element " + s + " the cpu");
     count++;
 
     // count == 1 is when the cpu wakelock is created
     // count == 2 is when the cpu wakelock is released
 
+    if (count == 1) {
+      // The next step is to unlock the resource.
+      lockState = false;
+      audio.pause();
+      startDate = new Date();
+      return;
+    }
+
+    is(count, 2, "The count should be 2 which indicates wakelock release");
+
     if (count == 2) {
       var diffDate = (new Date() - startDate);
-      ok(diffDate > 200, "There was at least 200 milliseconds between the stop and the wakelock release");
+      ok(diffDate > 200, "#1 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);
@@ -69,40 +72,33 @@ function testAudioPlay() {
   var count = 0;
 
   var content = document.getElementById('content');
 
   var audio = document.createElement('audio');
   audio.src = "wakelock.ogg";
   content.appendChild(audio);
 
-  var startDate;
-  audio.addEventListener('progress', function() {
-    startDate = new Date();
-  });
-
   function testAudioPlayListener(topic, state) {
-    is(topic, "cpu", "Audio element locked the target == cpu");
+    is(topic, "cpu", "#2 Audio element locked the target == cpu");
     var locked = state == "locked-foreground" ||
                  state == "locked-background";
 
-    is(locked, lockState, "Audio element locked the cpu - no paused");
+    var s = locked ? "locked" : "unlocked";
+    is(locked, lockState, "#2 Audio element " + s + " the cpu");
     count++;
 
     // count == 1 is when the cpu wakelock is created: the wakelock must be
     // created when the media element starts playing.
     // count == 2 is when the cpu wakelock is released.
 
     if (count == 1) {
       // The next step is to unlock the resource.
       lockState = false;
     } 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();