mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1351078
- Remove unused Battery.jsm. r=Yoric
Differential Revision: https://phabricator.services.mozilla.com/D20756 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f1efb1c816
commit
29b4521b7a
@ -144,8 +144,6 @@ var whitelist = [
|
||||
platforms: ["linux"]},
|
||||
// Bug 1348559
|
||||
{file: "chrome://pippki/content/resetpassword.xul"},
|
||||
// Bug 1351078
|
||||
{file: "resource://gre/modules/Battery.jsm"},
|
||||
// Bug 1337345
|
||||
{file: "resource://gre/modules/Manifest.jsm"},
|
||||
// Bug 1351097
|
||||
|
@ -1,67 +0,0 @@
|
||||
// -*- 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.
|
||||
*/
|
||||
var EXPORTED_SYMBOLS = ["GetBattery", "Battery"];
|
||||
|
||||
// Load Services, for the BatteryManager API
|
||||
ChromeUtils.defineModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
|
||||
// Values for the fake battery. See the documentation of Navigator.battery for the meaning of each field.
|
||||
var gFakeBattery = {
|
||||
charging: false,
|
||||
chargingTime: 0,
|
||||
dischargingTime: Infinity,
|
||||
level: 1,
|
||||
};
|
||||
|
||||
// BackendPass-exported object for toggling spoofing
|
||||
var 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,
|
||||
};
|
||||
|
||||
var 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);
|
||||
});
|
||||
};
|
||||
|
||||
var Battery = {};
|
||||
|
||||
for (let k of ["charging", "chargingTime", "dischargingTime", "level"]) {
|
||||
let prop = k;
|
||||
Object.defineProperty(this.Battery, prop, {
|
||||
get() {
|
||||
// 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(fakeSetting) {
|
||||
if (!Debugging.fake) {
|
||||
throw new Error("Tried to set fake battery value when battery spoofing was disabled");
|
||||
}
|
||||
gFakeBattery[prop] = fakeSetting;
|
||||
},
|
||||
});
|
||||
}
|
@ -186,7 +186,6 @@ EXTRA_JS_MODULES += [
|
||||
'AsyncPrefs.jsm',
|
||||
'AutoCompletePopupContent.jsm',
|
||||
'AutoScrollController.jsm',
|
||||
'Battery.jsm',
|
||||
'BinarySearch.jsm',
|
||||
'BrowserUtils.jsm',
|
||||
'CanonicalJSON.jsm',
|
||||
|
@ -1,51 +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";
|
||||
var {GetBattery, Debugging} = ChromeUtils.import("resource://gre/modules/Battery.jsm", null);
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
is(Debugging.fake, false, "Battery spoofing is initially false");
|
||||
|
||||
GetBattery().then(function(battery) {
|
||||
for (let k of ["charging", "chargingTime", "dischargingTime", "level"]) {
|
||||
let backup = battery[k];
|
||||
try {
|
||||
battery[k] = "__magic__";
|
||||
} catch (e) {
|
||||
// We are testing that we cannot set battery to new values
|
||||
// when "use strict" is enabled, this throws a TypeError
|
||||
if (e.name != "TypeError")
|
||||
throw e;
|
||||
}
|
||||
is(battery[k], backup, "Setting battery " + k + " preference without spoofing enabled should fail");
|
||||
}
|
||||
|
||||
Debugging.fake = true;
|
||||
|
||||
// reload again to get the fake one
|
||||
GetBattery().then(function(battery) {
|
||||
battery.charging = true;
|
||||
battery.chargingTime = 100;
|
||||
battery.level = 0.5;
|
||||
ok(battery.charging, "Test for charging setter");
|
||||
is(battery.chargingTime, 100, "Test for chargingTime setter");
|
||||
is(battery.level, 0.5, "Test for level setter");
|
||||
|
||||
battery.charging = false;
|
||||
battery.dischargingTime = 50;
|
||||
battery.level = 0.7;
|
||||
ok(!battery.charging, "Test for charging setter");
|
||||
is(battery.dischargingTime, 50, "Test for dischargingTime setter");
|
||||
is(battery.level, 0.7, "Test for level setter");
|
||||
|
||||
// Resetting the value to make the test run successful
|
||||
// for multiple runs in same browser session.
|
||||
Debugging.fake = false;
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
@ -18,7 +18,6 @@
|
||||
"async.js": ["Async"],
|
||||
"AsyncSpellCheckTestHelper.jsm": ["onSpellCheck"],
|
||||
"base-loader.js": ["Loader", "resolveURI", "Module", "Require", "unload"],
|
||||
"Battery.jsm": ["GetBattery", "Battery"],
|
||||
"blocklist-clients.js": ["AddonBlocklistClient", "GfxBlocklistClient", "OneCRLBlocklistClient", "PluginBlocklistClient"],
|
||||
"blocklist-updater.js": ["checkVersions", "addTestBlocklistClient"],
|
||||
"bogus_element_type.jsm": [],
|
||||
|
Loading…
Reference in New Issue
Block a user