Bug 1351078 - Remove unused Battery.jsm. r=Yoric
☠☠ backed out by 176ff7c8871e ☠ ☠
authorFelipe Gomes <felipc@gmail.com>
Fri, 22 Feb 2019 12:52:27 +0000
changeset 460603 3607e50ad27a07aea93c2e8b81d8ae05d34fc148
parent 460602 49828e666e4dd7bb1656b68e80c08070d7047d1e
child 460604 176ff7c8871e7df2977659d1f7c9107241bb6318
push id35596
push userrmaries@mozilla.com
push dateSat, 23 Feb 2019 04:13:22 +0000
treeherdermozilla-central@fdd04819e350 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1351078
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1351078 - Remove unused Battery.jsm. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D20756
browser/base/content/test/static/browser_all_files_referenced.js
toolkit/modules/Battery.jsm
toolkit/modules/moz.build
toolkit/modules/tests/browser/browser_Battery.js
tools/lint/eslint/modules.json
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -139,18 +139,16 @@ var whitelist = [
   // Bug 1348533
   {file: "chrome://mozapps/skin/downloads/buttons.png", platforms: ["macosx"]},
   {file: "chrome://mozapps/skin/downloads/downloadButtons.png", platforms: ["linux", "win"]},
   // Bug 1348558
   {file: "chrome://mozapps/skin/update/downloadButtons.png",
    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
   {file: "resource://gre/modules/accessibility/AccessFu.jsm"},
   // Bug 1356043
   {file: "resource://gre/modules/PerfMeasurement.jsm"},
   // Bug 1356045
   {file: "chrome://global/content/test-ipc.xul"},
deleted file mode 100644
--- a/toolkit/modules/Battery.jsm
+++ /dev/null
@@ -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;
-    },
-  });
-}
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -181,17 +181,16 @@ EXTRA_JS_MODULES += [
     'addons/WebRequest.jsm',
     'addons/WebRequestCommon.jsm',
     'addons/WebRequestContent.js',
     'addons/WebRequestUpload.jsm',
     'AppMenuNotifications.jsm',
     'AsyncPrefs.jsm',
     'AutoCompletePopupContent.jsm',
     'AutoScrollController.jsm',
-    'Battery.jsm',
     'BinarySearch.jsm',
     'BrowserUtils.jsm',
     'CanonicalJSON.jsm',
     'CertUtils.jsm',
     'CharsetMenu.jsm',
     'ClientID.jsm',
     'Color.jsm',
     'Console.jsm',
deleted file mode 100644
--- a/toolkit/modules/tests/browser/browser_Battery.js
+++ /dev/null
@@ -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();
-    });
-  });
-}
--- a/tools/lint/eslint/modules.json
+++ b/tools/lint/eslint/modules.json
@@ -13,17 +13,16 @@
   "ajv-4.1.1.js": ["Ajv"],
   "AlertsHelper.jsm": [],
   "AppData.jsm": ["makeFakeAppDir"],
   "AppInfo.jsm": ["newAppInfo", "getAppInfo", "updateAppInfo"],
   "ASRouterTargeting.jsm": ["ASRouterTargeting", "QueryCache", "CachedTargetingGetter"],
   "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": [],
   "bookmarks.js": ["BookmarksEngine", "PlacesItem", "Bookmark", "BookmarkFolder", "BookmarkQuery", "Livemark", "BookmarkSeparator", "BufferedBookmarksEngine"],
   "bookmarks.jsm": ["PlacesItem", "Bookmark", "Separator", "Livemark", "BookmarkFolder", "DumpBookmarks"],
   "bookmark_repair.js": ["BookmarkRepairRequestor", "BookmarkRepairResponder"],
   "bookmark_validator.js": ["BookmarkValidator", "BookmarkProblemData"],
   "browser-loader.js": ["BrowserLoader"],