Bug 963366 - Hide navigator.requestWakeLock behind pref dom.wakelock.enabled. r=ehsan

---
 b2g/app/b2g.js                                     |    3 +++
 .../mochitest/priority/test_HighPriority.html      |    3 ++-
 dom/power/test/browser_wakelocks.js                |    9 ++++++---
 dom/power/test/mochitest.ini                       |    2 ++
 dom/power/test/test_bug957893.html                 |   21 +++++++++++---------
 dom/power/test/test_bug957899.html                 |   11 +++++++---
 dom/power/test/test_wakelock_not_exposed.html      |   17 ++++++++++++++++
 dom/webidl/MozWakeLock.webidl                      |    2 +-
 dom/webidl/Navigator.webidl                        |    2 +-
 modules/libpref/src/init/all.js                    |    3 +++
 10 files changed, 55 insertions(+), 18 deletions(-)
 create mode 100644 dom/power/test/test_wakelock_not_exposed.html
This commit is contained in:
"Kan-Ru Chen (陳侃如)" 2014-02-11 13:57:24 +08:00
parent af08b27daf
commit dc131e7690
10 changed files with 55 additions and 18 deletions

View File

@ -885,3 +885,6 @@ pref("gfx.canvas.willReadFrequently.enable", true);
// Disable autofocus until we can have it not bring up the keyboard.
// https://bugzilla.mozilla.org/show_bug.cgi?id=965763
pref("browser.autofocus", false);
// Enable wakelock
pref("dom.wakelock.enabled", true);

View File

@ -119,7 +119,8 @@ const priorityChangeGracePeriod = 100;
addEventListener('testready', function() {
SpecialPowers.pushPrefEnv(
{set: [['dom.ipc.processPriorityManager.backgroundGracePeriodMS',
priorityChangeGracePeriod]]},
priorityChangeGracePeriod],
['dom.wakelock.enabled', true]]},
runTest);
});

View File

@ -222,12 +222,15 @@ function runNextStep() {
if (gCurStepIndex < gSteps.length) {
gSteps[gCurStepIndex]();
} else {
SpecialPowers.removePermission("power", kUrlSource);
finish();
}
}
function test() {
SpecialPowers.addPermission("power", true, kUrlSource);
runNextStep();
SpecialPowers.pushPermissions([
{type: "power", allow: true, context: kUrlSource}
], function () {
SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]},
runNextStep);
});
}

View File

@ -2,6 +2,8 @@
[test_bug957893.html]
[test_bug957899.html]
[test_wakelock_not_exposed.html]
skip-if = toolkit == "gonk"
[test_power_basics.html]
[test_power_set_cpusleepallowed.html]
[test_power_set_screen_brightness.html]

View File

@ -7,15 +7,18 @@
</head>
<body>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function test() {
try {
var wl = navigator.requestWakeLock('');
ok(false, "RequestWakeLock throws an exception!");
} catch(e) {
ok(true, "RequestWakeLock throws an exception!");
}
info("Still alive!");
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]}, test);
</script>
</body>
</html>

View File

@ -7,9 +7,14 @@
</head>
<body>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function test() {
var wl = navigator.requestWakeLock('a');
ok(wl, "WakeLock created!");
ok(!(wl instanceof XPathEvaluator), "Crashing?");
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]}, test);
</script>
</body>
</html>

View File

@ -0,0 +1,17 @@
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=963366
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test navigator.requestWakeLock is not exposed to non-B2G platform</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript">
ok(navigator.requestWakeLock === undefined,
"navigator.requestWakeLock is not exposed to non-B2G platform");
</script>
</body>
</html>

View File

@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
[Func="Navigator::HasWakeLockSupport"]
[Pref="dom.wakelock.enabled", Func="Navigator::HasWakeLockSupport"]
interface MozWakeLock
{
readonly attribute DOMString topic;

View File

@ -203,7 +203,7 @@ partial interface Navigator {
*
* @param aTopic resource name
*/
[Throws, Func="Navigator::HasWakeLockSupport"]
[Throws, Pref="dom.wakelock.enabled", Func="Navigator::HasWakeLockSupport"]
MozWakeLock requestWakeLock(DOMString aTopic);
};

View File

@ -4505,3 +4505,6 @@ pref("urlclassifier.download_allow_table", "");
// Turn off Spatial navigation by default.
pref("snav.enabled", false);
// Wakelock is disabled by default.
pref("dom.wakelock.enabled", false);