diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/modules/tests/browser/browser_Battery.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/modules/tests/browser/browser_Battery.js')
-rw-r--r-- | toolkit/modules/tests/browser/browser_Battery.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/toolkit/modules/tests/browser/browser_Battery.js b/toolkit/modules/tests/browser/browser_Battery.js new file mode 100644 index 000000000..2d3ba5da1 --- /dev/null +++ b/toolkit/modules/tests/browser/browser_Battery.js @@ -0,0 +1,51 @@ +/* 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 imported = Components.utils.import("resource://gre/modules/Battery.jsm", this); +Cu.import("resource://gre/modules/Services.jsm", this); + +function test() { + waitForExplicitFinish(); + + is(imported.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"); + } + + imported.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. + imported.Debugging.fake = false; + finish(); + }); + }); +} |