mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
9e4ed9857d
- Bug 1183825 - Hide PushMessageData methods until we support sending push data. r=mt,smaug (c07f6b6c9) - Bug 1186880 - Performance timing api in workers should output entries if preference is enabled. r=baku (642bd335a) - Bug 1188091 - Fix the exposure of Push interfaces; r=dougt,bzbarsky,nsm Currently we don't check the dom.push.enabled pref in some cases for some of these interfaces. This patch unifies how all of these interfaces are exposed to Window, Worker, and ServiceWorker. (dbe4ebfcc) - Bug 1188062 - Unship Request.context; r=baku (6ca2ebcf6) - Bug 1162714 - Don't let YCM generate machc. r=ehsan (7c5f36c12) - Bug 1160897 - Fixing .ycm_extra_conf for Fennec. r=ehsan (22adf0705) - goanna->gecko (94b69bd6c) - improve (e87b53162) - Bug 1147939 - The expression decompiler can't assume that it's called directly from script. (r=bhackett) (4759a5210) - Bug 1188609 - Remove mirroring support from RokuApp (Toolkit) r=snorp (81a0bb66a) - Bug 1050749 - Expose BatteryManager via getBattery() returning a Promise. r=bz, r=baku, r=jgraham (67d2dd502) - Bug 1182347 - Remove nsIPrincipal::cookieJar. r=sicking (855d0e8ce) - remove double method, probably misspach (3c256c5b4) - Bug 1182357 - Add an API to mint nsExpandedPrincipals. r=mrbkap (42de17cfd) - Bug 1172080 - Part 1: Throw when requesting origin for poorly behaved URIs, r=bholley (c8410f3c6) - Bug 1124126 - Retry database connection for the case of corrupted permissions.sqlite. r=bsmedberg (748e9205a)
74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
// -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
// 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";
|
|
|
|
/** This module wraps around navigator.getBattery (https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getBattery).
|
|
* and provides a framework for spoofing battery values in test code.
|
|
* To spoof the battery values, set `Debugging.fake = true` after exporting this with a BackstagePass,
|
|
* after which you can spoof a property yb setting the relevant property of the BatteryManager object.
|
|
*/
|
|
this.EXPORTED_SYMBOLS = ["GetBattery", "Battery"];
|
|
|
|
const Ci = Components.interfaces;
|
|
const Cc = Components.classes;
|
|
const Cu = Components.utils;
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
|
|
|
// Load Services, for the BatteryManager API
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
|
"resource://gre/modules/Services.jsm");
|
|
|
|
// Values for the fake battery. See the documentation of Navigator.battery for the meaning of each field.
|
|
let gFakeBattery = {
|
|
charging: false,
|
|
chargingTime: 0,
|
|
dischargingTime: Infinity,
|
|
level: 1,
|
|
}
|
|
|
|
// BackendPass-exported object for toggling spoofing
|
|
this.Debugging = {
|
|
/**
|
|
* If `false`, use the DOM Battery implementation.
|
|
* Set it to `true` if you need to fake battery values
|
|
* for testing or debugging purposes.
|
|
*/
|
|
fake: false
|
|
}
|
|
|
|
this.GetBattery = function () {
|
|
return new Services.appShell.hiddenDOMWindow.Promise(function (resolve, reject) {
|
|
// Return fake values if spoofing is enabled, otherwise fetch the real values from the BatteryManager API
|
|
if (Debugging.fake) {
|
|
resolve(gFakeBattery);
|
|
return;
|
|
}
|
|
Services.appShell.hiddenDOMWindow.navigator.getBattery().then(resolve, reject);
|
|
});
|
|
};
|
|
|
|
this.Battery = {};
|
|
|
|
for (let k of ["charging", "chargingTime", "dischargingTime", "level"]) {
|
|
let prop = k;
|
|
Object.defineProperty(this.Battery, prop, {
|
|
get: function() {
|
|
// Return fake value if spoofing is enabled, otherwise fetch the real value from the BatteryManager API
|
|
if (Debugging.fake) {
|
|
return gFakeBattery[prop];
|
|
}
|
|
return Services.appShell.hiddenDOMWindow.navigator.battery[prop];
|
|
},
|
|
set: function(fakeSetting) {
|
|
if (!Debugging.fake) {
|
|
throw new Error("Tried to set fake battery value when battery spoofing was disabled");
|
|
}
|
|
gFakeBattery[prop] = fakeSetting;
|
|
}
|
|
})
|
|
}
|