Bug 1351078 - Remove unused Battery.jsm. r=Yoric
authorFelipe Gomes <felipc@gmail.com>
Fri, 22 Feb 2019 16:51:26 +0000
changeset 521486 f79d064a028c5f7898da39a72e5573ec7c1b2fd2
parent 521485 d9d6968b7c2f682ee72cd0b4df5c8ada53a788f8
child 521487 0a1af025618899b3e8921b3b70a2533a176525df
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [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.ini
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',
--- a/toolkit/modules/tests/browser/browser.ini
+++ b/toolkit/modules/tests/browser/browser.ini
@@ -19,17 +19,16 @@ support-files =
   file_script_bad.js
   file_script_redirect.js
   file_script_xhr.js
   head.js
   WebRequest_dynamic.sjs
   WebRequest_redirection.sjs
 
 [browser_AsyncPrefs.js]
-[browser_Battery.js]
 [browser_BrowserUtils.js]
 [browser_CreditCard.js]
 [browser_Deprecated.js]
 [browser_Finder.js]
 [browser_Finder_hidden_textarea.js]
 skip-if = verify && debug
 [browser_Finder_offscreen_text.js]
 [browser_Finder_overflowed_onscreen.js]
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"],