Bug 1382955 (part 1) - Remove MozPowerManager and related things. r=bz,gsvelto.

This includes the FactoryReset stuff.
This commit is contained in:
Nicholas Nethercote 2017-08-02 10:04:36 +10:00
parent 16c9a58ee8
commit f5c5231809
24 changed files with 0 additions and 1077 deletions

View File

@ -35,7 +35,6 @@
#include "BatteryManager.h"
#include "mozilla/dom/CredentialsContainer.h"
#include "mozilla/dom/GamepadServiceTest.h"
#include "mozilla/dom/PowerManager.h"
#include "mozilla/dom/WakeLock.h"
#include "mozilla/dom/power/PowerManagerService.h"
#include "mozilla/dom/FlyWebPublishedServer.h"
@ -203,7 +202,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryPromise)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStorageManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCredentials)
@ -256,11 +254,6 @@ Navigator::Invalidate()
mBatteryPromise = nullptr;
if (mPowerManager) {
mPowerManager->Shutdown();
mPowerManager = nullptr;
}
if (mConnection) {
mConnection->Shutdown();
mConnection = nullptr;
@ -1417,24 +1410,6 @@ Navigator::PublishServer(const nsAString& aName,
return domPromise.forget();
}
PowerManager*
Navigator::GetMozPower(ErrorResult& aRv)
{
if (!mPowerManager) {
if (!mWindow) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
mPowerManager = PowerManager::CreateInstance(mWindow);
if (!mPowerManager) {
// We failed to get the power manager service?
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
return mPowerManager;
}
already_AddRefed<WakeLock>
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
{

View File

@ -73,7 +73,6 @@ namespace network {
class Connection;
} // namespace network
class PowerManager;
class Presentation;
class LegacyMozTCPSocket;
class VRDisplay;
@ -175,7 +174,6 @@ public:
bool CookieEnabled();
void GetBuildID(nsAString& aBuildID, CallerType aCallerType,
ErrorResult& aRv) const;
PowerManager* GetMozPower(ErrorResult& aRv);
bool JavaEnabled(CallerType aCallerType, ErrorResult& aRv);
uint64_t HardwareConcurrency();
bool CpuHasSSE2();
@ -292,7 +290,6 @@ private:
RefPtr<DesktopNotificationCenter> mNotification;
RefPtr<battery::BatteryManager> mBatteryManager;
RefPtr<Promise> mBatteryPromise;
RefPtr<PowerManager> mPowerManager;
RefPtr<network::Connection> mConnection;
RefPtr<CredentialsContainer> mCredentials;
RefPtr<MediaDevices> mMediaDevices;

View File

@ -612,10 +612,6 @@ DOMInterfaces = {
'notflattened': True
},
'MozPowerManager': {
'nativeType': 'mozilla::dom::PowerManager',
},
'MozWakeLock': {
'nativeType': 'mozilla::dom::WakeLock',
},

View File

@ -1,12 +1,6 @@
[DEFAULT]
support-files =
file_anchor_ping.html
wakelock.ogg
wakelock.ogv
[test_anchor_ping.html]
skip-if = os == 'android'
[test_audio_wakelock.html]
skip-if = os == 'android' && processor == 'x86' # bug 1315749
[test_video_wakelock.html]
skip-if = os == 'android' && processor == 'x86' # bug 1315749

View File

@ -1,124 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=868943
-->
<head>
<title>Test for Bug 868943</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/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 testAudioPlayPause() {
var lockState = true;
var count = 0;
var content = document.getElementById('content');
var audio = document.createElement('audio');
audio.src = "wakelock.ogg";
content.appendChild(audio);
var startDate;
function testAudioPlayListener(topic, state) {
is(topic, "cpu", "#1 Audio element locked the target == cpu");
var locked = state == "locked-foreground" ||
state == "locked-background";
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, "#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);
audio.play();
}
function testAudioPlay() {
var lockState = true;
var count = 0;
var content = document.getElementById('content');
var audio = document.createElement('audio');
audio.src = "wakelock.ogg";
content.appendChild(audio);
function testAudioPlayListener(topic, state) {
is(topic, "cpu", "#2 Audio element locked the target == cpu");
var locked = state == "locked-foreground" ||
state == "locked-background";
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) {
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.pushPrefEnv({"set": [["media.wakelock_timeout", 500]]}, runTests);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -1,197 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=868943
-->
<head>
<title>Test for Bug 868943</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/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() {
info("#1 testVideoPlayPause");
var lockState_cpu = true;
var lockState_screen = true;
var count_cpu = 0;
var count_screen = 0;
var content = document.getElementById('content');
var video = document.createElement('video');
ok(video.mozUseScreenWakeLock, "#1 Video element uses screen wake lock by default");
video.src = "wakelock.ogv";
content.appendChild(video);
var startDate;
function testVideoPlayPauseListener(topic, state) {
info("#1 topic=" + topic + ", state=" + state);
var locked = state == "locked-foreground" ||
state == "locked-background";
if (topic == "cpu") {
is(locked, lockState_cpu, "#1 Video element locked the cpu");
count_cpu++;
} else if (topic == "screen") {
is(locked, lockState_screen, "#1 Video element locked the screen");
count_screen++;
}
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();
}
if (count_cpu == 2 && count_screen == 2) {
var diffDate = (new Date() - startDate);
ok(diffDate > 200, "#1 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() {
info("#2 testVideoPlay");
var lockState_cpu = true;
var lockState_screen = true;
var count_cpu = 0;
var count_screen = 0;
var content = document.getElementById('content');
var video = document.createElement('video');
ok(video.mozUseScreenWakeLock, "#2 Video element uses screen wake lock by default");
video.src = "wakelock.ogv";
content.appendChild(video);
var startDate;
video.addEventListener('progress', function() {
startDate = new Date();
});
function testVideoPlayListener(topic, state) {
info("#2 topic=" + topic + ", state=" + state);
var locked = state == "locked-foreground" ||
state == "locked-background";
if (topic == "cpu") {
is(locked, lockState_cpu, "#2 Video element locked the cpu");
count_cpu++;
} else if (topic == "screen") {
is(locked, lockState_screen, "#2 Video element locked the screen");
count_screen++;
}
if (count_cpu == 1 && count_screen == 1) {
info("#2 Both cpu and screen are locked");
// The next step is to unlock the resource.
lockState_cpu = false;
lockState_screen = false;
} else if (count_cpu == 2 && count_screen == 2) {
var diffDate = (new Date() - startDate);
ok(diffDate > 200, "#2 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();
}
function testVideoNoScreenWakeLock() {
info("#3 testVideoNoScreenWakeLock");
var lockState_cpu = true;
var lockState_screen = false;
var count_cpu = 0;
var content = document.getElementById('content');
var video = document.createElement('video');
video.mozUseScreenWakeLock = false;
video.src = "wakelock.ogv";
content.appendChild(video);
var startDate;
function testVideoNoScreenWakeLockListener(topic, state) {
info("#3 topic=" + topic + ", state=" + state);
var locked = state == "locked-foreground" ||
state == "locked-background";
if (topic == "cpu") {
is(locked, lockState_cpu, "#3 Video element locked the cpu");
count_cpu++;
} else if (topic == "screen") {
is(locked, lockState_screen, "#3 Video element locked the screen");
}
if (count_cpu == 1) {
info("#3 Cpu is locked");
// The next step is to unlock the resource.
lockState_cpu = false;
video.pause();
startDate = new Date();
}
if (count_cpu == 2) {
var diffDate = (new Date() - startDate);
ok(diffDate > 200, "#3 There was at least 200 milliseconds between the stop and the wakelock release");
content.removeChild(video);
navigator.mozPower.removeWakeLockListener(testVideoNoScreenWakeLockListener);
runTests();
}
}
navigator.mozPower.addWakeLockListener(testVideoNoScreenWakeLockListener);
video.play();
}
var tests = [ testVideoPlayPause, testVideoPlay, testVideoNoScreenWakeLock ];
function runTests() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.pop();
test();
};
SpecialPowers.pushPrefEnv({"set": [["media.wakelock_timeout", 500],
["dom.wakelock.enabled", true]]}, runTests);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

Binary file not shown.

Binary file not shown.

View File

@ -1,210 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "mozilla/dom/PowerManager.h"
#include "mozilla/Hal.h"
#include "WakeLock.h"
#include "nsDOMClassInfoID.h"
#include "nsIDOMWakeLockListener.h"
#include "nsIDocument.h"
#include "nsIPermissionManager.h"
#include "nsIPowerManagerService.h"
#include "nsIPrincipal.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsError.h"
#include "mozilla/dom/MozPowerManagerBinding.h"
#include "mozilla/Services.h"
namespace mozilla {
namespace dom {
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PowerManager)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozWakeLockListener)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PowerManager, mListeners, mWindow)
NS_IMPL_CYCLE_COLLECTING_ADDREF(PowerManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PowerManager)
/* virtual */ JSObject*
PowerManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return MozPowerManagerBinding::Wrap(aCx, this, aGivenProto);
}
nsresult
PowerManager::Init(nsPIDOMWindowInner* aWindow)
{
mWindow = aWindow;
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
NS_ENSURE_STATE(pmService);
// Add ourself to the global notification list.
pmService->AddWakeLockListener(this);
return NS_OK;
}
nsresult
PowerManager::Shutdown()
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
NS_ENSURE_STATE(pmService);
// Remove ourself from the global notification list.
pmService->RemoveWakeLockListener(this);
return NS_OK;
}
void
PowerManager::Reboot(ErrorResult& aRv)
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
if (pmService) {
pmService->Reboot();
} else {
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
void
PowerManager::FactoryReset(mozilla::dom::FactoryResetReason& aReason)
{
hal::FactoryReset(aReason);
}
void
PowerManager::PowerOff(ErrorResult& aRv)
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
if (pmService) {
pmService->PowerOff();
} else {
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
void
PowerManager::AddWakeLockListener(nsIDOMMozWakeLockListener *aListener)
{
if (!mListeners.Contains(aListener)) {
mListeners.AppendElement(aListener);
}
}
void
PowerManager::RemoveWakeLockListener(nsIDOMMozWakeLockListener *aListener)
{
mListeners.RemoveElement(aListener);
}
void
PowerManager::GetWakeLockState(const nsAString& aTopic,
nsAString& aState,
ErrorResult& aRv)
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
if (pmService) {
aRv = pmService->GetWakeLockState(aTopic, aState);
} else {
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
NS_IMETHODIMP
PowerManager::Callback(const nsAString &aTopic, const nsAString &aState)
{
/**
* We maintain a local listener list instead of using the global
* list so that when the window is destroyed we don't have to
* cleanup the mess.
* Copy the listeners list before we walk through the callbacks
* because the callbacks may install new listeners. We expect no
* more than one listener per window, so it shouldn't be too long.
*/
AutoTArray<nsCOMPtr<nsIDOMMozWakeLockListener>, 2> listeners(mListeners);
for (uint32_t i = 0; i < listeners.Length(); ++i) {
listeners[i]->Callback(aTopic, aState);
}
return NS_OK;
}
bool
PowerManager::ScreenEnabled()
{
return hal::GetScreenEnabled();
}
void
PowerManager::SetScreenEnabled(bool aEnabled)
{
hal::SetScreenEnabled(aEnabled);
}
bool
PowerManager::KeyLightEnabled()
{
return hal::GetKeyLightEnabled();
}
void
PowerManager::SetKeyLightEnabled(bool aEnabled)
{
hal::SetKeyLightEnabled(aEnabled);
}
double
PowerManager::ScreenBrightness()
{
return hal::GetScreenBrightness();
}
void
PowerManager::SetScreenBrightness(double aBrightness, ErrorResult& aRv)
{
if (0 <= aBrightness && aBrightness <= 1) {
hal::SetScreenBrightness(aBrightness);
} else {
aRv.Throw(NS_ERROR_INVALID_ARG);
}
}
bool
PowerManager::CpuSleepAllowed()
{
return hal::GetCpuSleepAllowed();
}
void
PowerManager::SetCpuSleepAllowed(bool aAllowed)
{
hal::SetCpuSleepAllowed(aAllowed);
}
already_AddRefed<PowerManager>
PowerManager::CreateInstance(nsPIDOMWindowInner* aWindow)
{
RefPtr<PowerManager> powerManager = new PowerManager();
if (NS_FAILED(powerManager->Init(aWindow))) {
powerManager = nullptr;
}
return powerManager.forget();
}
} // namespace dom
} // namespace mozilla

View File

@ -1,70 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#ifndef mozilla_dom_power_PowerManager_h
#define mozilla_dom_power_PowerManager_h
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIDOMWakeLockListener.h"
#include "nsIDOMWindow.h"
#include "nsWeakReference.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/MozPowerManagerBinding.h"
class nsPIDOMWindowInner;
namespace mozilla {
class ErrorResult;
namespace dom {
class PowerManager final : public nsIDOMMozWakeLockListener
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PowerManager)
NS_DECL_NSIDOMMOZWAKELOCKLISTENER
nsresult Init(nsPIDOMWindowInner* aWindow);
nsresult Shutdown();
static already_AddRefed<PowerManager> CreateInstance(nsPIDOMWindowInner*);
// WebIDL
nsPIDOMWindowInner* GetParentObject() const
{
return mWindow;
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
void Reboot(ErrorResult& aRv);
void FactoryReset(mozilla::dom::FactoryResetReason& aReason);
void PowerOff(ErrorResult& aRv);
void AddWakeLockListener(nsIDOMMozWakeLockListener* aListener);
void RemoveWakeLockListener(nsIDOMMozWakeLockListener* aListener);
void GetWakeLockState(const nsAString& aTopic, nsAString& aState,
ErrorResult& aRv);
bool ScreenEnabled();
void SetScreenEnabled(bool aEnabled);
bool KeyLightEnabled();
void SetKeyLightEnabled(bool aEnabled);
double ScreenBrightness();
void SetScreenBrightness(double aBrightness, ErrorResult& aRv);
bool CpuSleepAllowed();
void SetCpuSleepAllowed(bool aAllowed);
private:
~PowerManager() {}
nsCOMPtr<nsPIDOMWindowInner> mWindow;
nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener> > mListeners;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_power_PowerManager_h

View File

@ -15,7 +15,6 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'dom_power'
EXPORTS.mozilla.dom += [
'PowerManager.h',
'WakeLock.h',
]
@ -25,7 +24,6 @@ EXPORTS.mozilla.dom.power += [
]
UNIFIED_SOURCES += [
'PowerManager.cpp',
'PowerManagerService.cpp',
'WakeLock.cpp',
]
@ -35,5 +33,3 @@ include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']

View File

@ -1,4 +0,0 @@
[DEFAULT]
[browser_wakelocks.js]
skip-if = e10s # Bug ?????? - SpecialPowers issues ({file: "chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js" line: 759}]'[JavaScript Error: "content.window is undefined" {file: "chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js" line: 759}]' when calling method: [nsIObserver::observe]")

View File

@ -1,225 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
"use strict";
waitForExplicitFinish();
var kUrlSource = "http://mochi.test:8888/";
var kDataSource = "data:text/html,";
var gOldPref;
var gWin, gWin1, gWin2;
var gTab, gTab1, gTab2;
var gLock, gLock1, gLock2;
var gCurStepIndex = -1;
var gSteps = [
function basicWakeLock() {
gTab = BrowserTestUtils.addTab(gBrowser, kUrlSource);
gWin = gBrowser.getBrowserForTab(gTab).contentWindow;
let browser = gBrowser.getBrowserForTab(gTab);
browser.addEventListener("load", function(e) {
let nav = gWin.navigator;
let power = nav.mozPower;
gLock = nav.requestWakeLock("test");
ok(gLock != null,
"navigator.requestWakeLock should return a wake lock");
is(gLock.topic, "test",
"wake lock should remember the locked topic");
isnot(power.getWakeLockState("test"), "unlocked",
"topic is locked");
gLock.unlock();
is(gLock.topic, "test",
"wake lock should remember the locked topic even after unlock");
is(power.getWakeLockState("test"), "unlocked",
"topic is unlocked");
try {
gLock.unlock();
ok(false, "Should have thrown an error.");
} catch (e) {
is(e.name, "InvalidStateError", "double unlock should throw InvalidStateError");
is(e.code, DOMException.INVALID_STATE_ERR, "double unlock should throw InvalidStateError");
}
gBrowser.removeTab(gTab);
executeSoon(runNextStep);
}, {capture: true, once: true});
},
function multiWakeLock() {
gTab = BrowserTestUtils.addTab(gBrowser, kUrlSource);
gWin = gBrowser.getBrowserForTab(gTab).contentWindow;
let browser = gBrowser.getBrowserForTab(gTab);
browser.addEventListener("load", function(e) {
let nav = gWin.navigator;
let power = nav.mozPower;
let count = 0;
power.addWakeLockListener(function onWakeLockEvent(topic, state) {
is(topic, "test", "gLock topic is test");
ok(state == "unlocked" ||
state == "locked-foreground" ||
state == "locked-background",
"wake lock should be either locked or unlocked");
count++;
if (state == "locked-foreground" ||
state == "locked-background") {
is(count, 1,
"wake lock should be locked and the listener should only fire once");
}
if (state == "unlocked") {
is(count, 2,
"wake lock should be unlocked and the listener should only fire once");
ok(power.getWakeLockState("test") == "unlocked",
"topic is unlocked");
power.removeWakeLockListener(onWakeLockEvent);
gBrowser.removeTab(gTab);
executeSoon(runNextStep);
}
});
gLock1 = nav.requestWakeLock("test");
isnot(power.getWakeLockState("test"), "unlocked",
"topic is locked");
gLock2 = nav.requestWakeLock("test");
isnot(power.getWakeLockState("test"), "unlocked",
"topic is locked");
gLock1.unlock();
isnot(power.getWakeLockState("test"), "unlocked",
"topic is locked");
gLock2.unlock();
}, {capture: true, once: true});
},
function crossTabWakeLock1() {
gTab1 = BrowserTestUtils.addTab(gBrowser, kUrlSource);
gWin1 = gBrowser.getBrowserForTab(gTab1).contentWindow;
gTab2 = BrowserTestUtils.addTab(gBrowser, kUrlSource);
gWin2 = gBrowser.getBrowserForTab(gTab2).contentWindow;
gBrowser.selectedTab = gTab1;
let browser = gBrowser.getBrowserForTab(gTab2);
browser.addEventListener("load", function(e) {
gLock2 = gWin2.navigator.requestWakeLock("test");
is(gWin2.document.hidden, true,
"window is background")
is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-background",
"wake lock is background");
let doc2 = gWin2.document;
doc2.addEventListener("visibilitychange", function onVisibilityChange(e) {
if (!doc2.hidden) {
doc2.removeEventListener("visibilitychange", onVisibilityChange);
executeSoon(runNextStep);
}
});
gBrowser.selectedTab = gTab2;
}, {capture: true, once: true});
},
function crossTabWakeLock2() {
is(gWin2.document.hidden, false,
"window is foreground")
is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
"wake lock is foreground");
gWin2.addEventListener("pagehide", function(e) {
executeSoon(runNextStep);
}, {capture: true, once: true});
gWin2.addEventListener("pageshow", function(e) {
executeSoon(runNextStep);
}, {capture: true, once: true});
gWin2.location = kDataSource;
},
function crossTabWakeLock3() {
is(gWin1.navigator.mozPower.getWakeLockState("test"), "unlocked",
"wake lock should auto-unlock when page is unloaded");
gWin2.back();
// runNextStep called in onPageShow
},
function crossTabWakeLock4() {
is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
"wake lock should auto-reacquire when page is available again");
gBrowser.selectedTab = gTab1;
executeSoon(runNextStep);
},
function crossTabWakeLock5() {
// Test again in background tab
is(gWin2.document.hidden, true,
"window is background")
is(gWin2.navigator.mozPower.getWakeLockState("test"), "locked-background",
"wake lock is background");
gWin2.addEventListener("pagehide", function(e) {
executeSoon(runNextStep);
}, {capture: true, once: true});
gWin2.addEventListener("pageshow", function(e) {
executeSoon(runNextStep);
}, {capture: true, once: true});
gWin2.location = kDataSource;
},
function crossTabWakeLock6() {
is(gWin1.navigator.mozPower.getWakeLockState("test"), "unlocked",
"wake lock should auto-unlock when page is unloaded");
gWin2.back();
// runNextStep called in onPageShow
},
function crossTabWakeLock7() {
is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-background",
"wake lock should auto-reacquire when page is available again");
gLock2.unlock();
gBrowser.selectedTab = gTab2;
executeSoon(runNextStep);
},
function crossTabWakeLock8() {
is(gWin1.document.hidden, true,
"gWin1 is background");
is(gWin2.document.hidden, false,
"gWin2 is foreground");
gLock1 = gWin1.navigator.requestWakeLock("test");
gLock2 = gWin2.navigator.requestWakeLock("test");
is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
"topic is locked-foreground when one page is foreground and one is background");
gLock2.unlock();
is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-background",
"topic is locked-background when all locks are background");
gLock2 = gWin2.navigator.requestWakeLock("test");
is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
"topic is locked-foreground when one page is foreground and one is background");
gLock1.unlock();
is(gWin1.navigator.mozPower.getWakeLockState("test"), "locked-foreground",
"topic is locked-foreground");
gBrowser.removeTab(gTab1);
gBrowser.removeTab(gTab2);
executeSoon(runNextStep);
},
];
function runNextStep() {
gCurStepIndex++;
if (gCurStepIndex < gSteps.length) {
gSteps[gCurStepIndex]();
} else {
finish();
}
}
function test() {
SpecialPowers.pushPrefEnv({"set": [["dom.wakelock.enabled", true]]},
runNextStep);
}

View File

@ -1 +0,0 @@
[test_power_basics.html]

View File

@ -1,40 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Power API</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Power API **/
SimpleTest.waitForExplicitFinish();
function startTest() {
doTest1();
}
function doTest1() {
window.frames[0].frameElement.setAttribute('onload', 'doTest3()');
power = window.frames[0].navigator.mozPower;
ok(power, "Should be able to access power manager with permission.");
window.frames[0].location.reload();
}
function doTest3() {
power = window.frames[0].navigator.mozPower;
ok(power, "Should be able to access power manager with permission.");
SimpleTest.finish();
}
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<iframe onload="startTest()"></iframe>
<pre id="test">
</pre>
</body>
</html>

View File

@ -1,97 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
interface MozWakeLockListener;
/**
* The reason for the factory reset.
* "normal" : simple factory reset.
* "wipe" : will also attempt to wipe all user storage areas.
* "root" : simple factory reset that also root the phone to get more
* privileges when using devtools.
*/
enum FactoryResetReason {
"normal",
"wipe",
"root"
};
/**
* This interface implements navigator.mozPower
*/
[ChromeOnly]
interface MozPowerManager
{
[Throws]
void powerOff();
[Throws]
void reboot();
void factoryReset(optional FactoryResetReason reason = "normal");
/**
* The listeners are notified when a resource changes its lock state to:
* - unlocked
* - locked but not visible
* - locked and visible
*/
void addWakeLockListener(MozWakeLockListener aListener);
void removeWakeLockListener(MozWakeLockListener aListener);
/**
* Query the wake lock state of the topic.
*
* Possible states are:
*
* - "unlocked" - nobody holds the wake lock.
*
* - "locked-foreground" - at least one window holds the wake lock,
* and it is visible.
*
* - "locked-background" - at least one window holds the wake lock,
* but all of them are hidden.
*
* @param aTopic The resource name related to the wake lock.
*/
[Throws]
DOMString getWakeLockState(DOMString aTopic);
/**
* Is the device's screen currently enabled? This attribute controls the
* device's screen, so setting it to false will turn off the screen.
*/
attribute boolean screenEnabled;
/**
* Is the device's keypad/button backlight enabled? Setting it to false will
* turn off the device's keypad/button backlight. And the brightness level
* is the same as |screenBrightness|.
*/
attribute boolean keyLightEnabled;
/**
* How bright is the screen's backlight, on a scale from 0 (very dim) to 1
* (full brightness)? Setting this attribute modifies the screen's
* brightness.
*
* You can read and write this attribute even when the screen is disabled,
* but the backlight is off while the screen is disabled.
*
* If you write a value of X into this attribute, the attribute may not have
* the same value X when you later read it. Most screens don't support as
* many different brightness levels as there are doubles between 0 and 1, so
* we may reduce the value's precision before storing it.
*
* @throw NS_ERROR_INVALID_ARG if brightness is not in the range [0, 1].
*/
[SetterThrows]
attribute double screenBrightness;
/**
* Is it possible that the device's CPU will sleep after the screen is
* disabled? Setting this attribute to false will prevent the device
* entering suspend state.
*/
attribute boolean cpuSleepAllowed;
};

View File

@ -188,8 +188,6 @@ partial interface Navigator {
readonly attribute boolean cookieEnabled;
[Throws, Constant, Cached, NeedsCallerType]
readonly attribute DOMString buildID;
[Throws, ChromeOnly, UnsafeInPrerendering]
readonly attribute MozPowerManager mozPower;
// WebKit/Blink/Trident/Presto support this.
[Throws, NeedsCallerType]

View File

@ -698,7 +698,6 @@ WEBIDL_FILES = [
'MimeTypeArray.webidl',
'MouseEvent.webidl',
'MouseScrollEvent.webidl',
'MozPowerManager.webidl',
'MozSelfSupport.webidl',
'MozTimeManager.webidl',
'MozWakeLock.webidl',

View File

@ -910,12 +910,6 @@ ThreadPriorityToString(ThreadPriority aPriority)
}
}
void FactoryReset(mozilla::dom::FactoryResetReason& aReason)
{
AssertMainThread();
PROXY_IF_SANDBOXED(FactoryReset(aReason));
}
void
StartDiskSpaceWatcher()
{

View File

@ -11,7 +11,6 @@
#include "base/platform_thread.h"
#include "nsTArray.h"
#include "mozilla/dom/battery/Types.h"
#include "mozilla/dom/MozPowerManagerBinding.h"
#include "mozilla/dom/network/Types.h"
#include "mozilla/dom/power/Types.h"
#include "mozilla/dom/ScreenOrientation.h"
@ -470,11 +469,6 @@ void SetThreadPriority(PlatformThreadId aThreadId,
*/
void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
/**
* Perform Factory Reset to wipe out all user data.
*/
void FactoryReset(mozilla::dom::FactoryResetReason& aReason);
/**
* Start monitoring disk space for low space situations.
*

View File

@ -1,18 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#include "Hal.h"
namespace mozilla {
namespace hal_impl {
void
FactoryReset(mozilla::dom::FactoryResetReason&)
{}
} // namespace hal_impl
} // namespace mozilla

View File

@ -110,7 +110,6 @@ else:
# Fallbacks for backends implemented on Gonk only.
UNIFIED_SOURCES += [
'fallback/FallbackDiskSpaceWatcher.cpp',
'fallback/FallbackFactoryReset.cpp',
'fallback/FallbackProcessPriority.cpp',
'fallback/FallbackScreenPower.cpp',
'fallback/FallbackSwitch.cpp',

View File

@ -141,8 +141,6 @@ parent:
sync GetCurrentSwitchState(SwitchDevice aDevice)
returns (SwitchState aState);
async FactoryReset(nsString aReason);
child:
async NotifySensorChange(SensorData aSensorData);

View File

@ -374,18 +374,6 @@ SetThreadPriority(PlatformThreadId aThreadId,
NS_RUNTIMEABORT("Setting thread priority cannot be called from sandboxed contexts.");
}
void
FactoryReset(FactoryResetReason& aReason)
{
if (aReason == FactoryResetReason::Normal) {
Hal()->SendFactoryReset(NS_LITERAL_STRING("normal"));
} else if (aReason == FactoryResetReason::Wipe) {
Hal()->SendFactoryReset(NS_LITERAL_STRING("wipe"));
} else if (aReason == FactoryResetReason::Root) {
Hal()->SendFactoryReset(NS_LITERAL_STRING("root"));
}
}
void
StartDiskSpaceWatcher()
{
@ -773,25 +761,6 @@ public:
{
Unused << SendNotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
}
virtual mozilla::ipc::IPCResult
RecvFactoryReset(const nsString& aReason) override
{
FactoryResetReason reason = FactoryResetReason::Normal;
if (aReason.EqualsLiteral("normal")) {
reason = FactoryResetReason::Normal;
} else if (aReason.EqualsLiteral("wipe")) {
reason = FactoryResetReason::Wipe;
} else if (aReason.EqualsLiteral("root")) {
reason = FactoryResetReason::Root;
} else {
// Invalid factory reset reason. That should never happen.
return IPC_FAIL_NO_REASON(this);
}
hal::FactoryReset(reason);
return IPC_OK();
}
};
class HalChild : public PHalChild {