2013-05-10 12:42:39 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=868943
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 868943</title>
|
|
|
|
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=868943">Mozilla Bug 868943</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 868943 **/
|
|
|
|
|
|
|
|
function testVideoPlayPause() {
|
2014-10-05 23:21:00 +00:00
|
|
|
info("#1 testVideoPlayPause");
|
|
|
|
|
2014-03-18 08:44:41 +00:00
|
|
|
var lockState_cpu = true;
|
|
|
|
var lockState_screen = true;
|
|
|
|
var count_cpu = 0;
|
|
|
|
var count_screen = 0;
|
2013-05-10 12:42:39 +00:00
|
|
|
|
|
|
|
var content = document.getElementById('content');
|
|
|
|
|
|
|
|
var video = document.createElement('video');
|
|
|
|
video.src = "wakelock.ogv";
|
|
|
|
content.appendChild(video);
|
|
|
|
|
2013-05-28 17:30:17 +00:00
|
|
|
var startDate;
|
2014-10-01 20:16:00 +00:00
|
|
|
function testVideoPlayPauseListener(topic, state) {
|
2014-10-05 23:21:00 +00:00
|
|
|
info("#1 topic=" + topic + ", state=" + state);
|
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
var locked = state == "locked-foreground" ||
|
|
|
|
state == "locked-background";
|
|
|
|
|
2014-03-18 08:44:41 +00:00
|
|
|
if (topic == "cpu") {
|
2014-10-05 23:21:00 +00:00
|
|
|
is(locked, lockState_cpu, "#1 Video element locked the cpu");
|
2014-03-18 08:44:41 +00:00
|
|
|
count_cpu++;
|
|
|
|
} else if (topic == "screen") {
|
2014-10-05 23:21:00 +00:00
|
|
|
is(locked, lockState_screen, "#1 Video element locked the screen");
|
2014-03-18 08:44:41 +00:00
|
|
|
count_screen++;
|
|
|
|
}
|
2013-05-10 12:42:39 +00:00
|
|
|
|
2014-10-05 23:21:00 +00:00
|
|
|
if (count_cpu == 1 && count_screen == 1) {
|
|
|
|
info("#1 Both cpu and screen are locked");
|
|
|
|
// The next step is to unlock the resource.
|
|
|
|
lockState_cpu = false;
|
|
|
|
lockState_screen = false;
|
|
|
|
video.pause();
|
|
|
|
startDate = new Date();
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:44:41 +00:00
|
|
|
if (count_cpu == 2 && count_screen == 2) {
|
2013-05-28 17:30:17 +00:00
|
|
|
var diffDate = (new Date() - startDate);
|
2014-10-05 23:21:00 +00:00
|
|
|
ok(diffDate > 200, "#1 There was at least 200 milliseconds between the stop and the wakelock release");
|
2013-05-28 17:30:17 +00:00
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
content.removeChild(video);
|
|
|
|
navigator.mozPower.removeWakeLockListener(testVideoPlayPauseListener);
|
|
|
|
runTests();
|
|
|
|
}
|
2014-10-01 20:16:00 +00:00
|
|
|
}
|
2013-05-10 12:42:39 +00:00
|
|
|
|
2014-10-01 20:16:00 +00:00
|
|
|
navigator.mozPower.addWakeLockListener(testVideoPlayPauseListener);
|
2013-05-10 12:42:39 +00:00
|
|
|
video.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testVideoPlay() {
|
2014-10-05 23:21:00 +00:00
|
|
|
info("#2 testVideoPlay");
|
|
|
|
|
2014-03-18 08:44:41 +00:00
|
|
|
var lockState_cpu = true;
|
|
|
|
var lockState_screen = true;
|
|
|
|
var count_cpu = 0;
|
|
|
|
var count_screen = 0;
|
2013-05-10 12:42:39 +00:00
|
|
|
|
|
|
|
var content = document.getElementById('content');
|
|
|
|
|
|
|
|
var video = document.createElement('video');
|
|
|
|
video.src = "wakelock.ogv";
|
|
|
|
content.appendChild(video);
|
|
|
|
|
2013-05-28 17:30:17 +00:00
|
|
|
var startDate;
|
|
|
|
video.addEventListener('progress', function() {
|
|
|
|
startDate = new Date();
|
|
|
|
});
|
|
|
|
|
2014-10-01 20:16:00 +00:00
|
|
|
function testVideoPlayListener(topic, state) {
|
2014-10-05 23:21:00 +00:00
|
|
|
info("#2 topic=" + topic + ", state=" + state);
|
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
var locked = state == "locked-foreground" ||
|
|
|
|
state == "locked-background";
|
|
|
|
|
2014-03-18 08:44:41 +00:00
|
|
|
if (topic == "cpu") {
|
2014-10-05 23:21:00 +00:00
|
|
|
is(locked, lockState_cpu, "#2 Video element locked the cpu");
|
2014-03-18 08:44:41 +00:00
|
|
|
count_cpu++;
|
|
|
|
} else if (topic == "screen") {
|
2014-10-05 23:21:00 +00:00
|
|
|
is(locked, lockState_screen, "#2 Video element locked the screen");
|
2014-03-18 08:44:41 +00:00
|
|
|
count_screen++;
|
|
|
|
}
|
2013-05-10 12:42:39 +00:00
|
|
|
|
2014-03-18 08:44:41 +00:00
|
|
|
if (count_cpu == 1 && count_screen == 1) {
|
2014-10-05 23:21:00 +00:00
|
|
|
info("#2 Both cpu and screen are locked");
|
2013-05-10 12:42:39 +00:00
|
|
|
// The next step is to unlock the resource.
|
2014-03-18 08:44:41 +00:00
|
|
|
lockState_cpu = false;
|
|
|
|
lockState_screen = false;
|
|
|
|
} else if (count_cpu == 2 && count_screen == 2) {
|
2013-05-28 17:30:17 +00:00
|
|
|
var diffDate = (new Date() - startDate);
|
2014-10-05 23:21:00 +00:00
|
|
|
ok(diffDate > 200, "#2 There was at least milliseconds between the stop and the wakelock release");
|
2013-05-28 17:30:17 +00:00
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
content.removeChild(video);
|
|
|
|
navigator.mozPower.removeWakeLockListener(testVideoPlayListener);
|
|
|
|
runTests();
|
|
|
|
}
|
2014-10-01 20:16:00 +00:00
|
|
|
}
|
2013-05-10 12:42:39 +00:00
|
|
|
|
2014-10-01 20:16:00 +00:00
|
|
|
navigator.mozPower.addWakeLockListener(testVideoPlayListener);
|
2013-05-10 12:42:39 +00:00
|
|
|
video.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
var tests = [ testVideoPlayPause, testVideoPlay ];
|
|
|
|
function runTests() {
|
|
|
|
if (!tests.length) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var test = tests.pop();
|
|
|
|
test();
|
|
|
|
};
|
|
|
|
|
2014-10-01 20:16:00 +00:00
|
|
|
SpecialPowers.pushPermissions(
|
|
|
|
[{'type': 'power', 'allow': true, 'context': document}],
|
|
|
|
function() {
|
|
|
|
SpecialPowers.pushPrefEnv({"set": [["media.wakelock_timeout", 500]]}, runTests);
|
|
|
|
});
|
2013-05-28 17:30:17 +00:00
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|