cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject spec commit: CB-6695 Added tests to verify CB-4520 + CB-4519
Date Thu, 15 May 2014 00:16:10 GMT
Repository: cordova-mobile-spec
Updated Branches:
  refs/heads/master 508f29f4c -> b5b80a6ff


CB-6695 Added tests to verify CB-4520 + CB-4519


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/b5b80a6f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/b5b80a6f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/b5b80a6f

Branch: refs/heads/master
Commit: b5b80a6ff80d3c8b3d7618fe051c824ec0d3771f
Parents: 508f29f
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed May 14 17:14:57 2014 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed May 14 17:15:53 2014 -0700

----------------------------------------------------------------------
 autotest/tests/battery.tests.js | 153 ++++++++++++++++++++++++++++++++++-
 1 file changed, 152 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/b5b80a6f/autotest/tests/battery.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/battery.tests.js b/autotest/tests/battery.tests.js
index 6646429..dc9f77e 100644
--- a/autotest/tests/battery.tests.js
+++ b/autotest/tests/battery.tests.js
@@ -19,8 +19,159 @@
  *
 */
 
-describe('Battery (navigator.battery)', function () {;
+describe('Battery (navigator.battery)', function () {
+
+
+    beforeEach(function () {
+
+    });
+
+    afterEach(function () {
+        
+
+
+    });
+
+
     it("battery.spec.1 should exist", function() {
         expect(navigator.battery).toBeDefined();
     });
+
+    it("battery.spec.2 should fire batterystatus events", function () {
+
+        // batterystatus
+        var onEvent;
+        
+        runs(function () {
+            onEvent = jasmine.createSpy().andCallFake(function () {
+                window.removeEventListener("batterystatus", onEvent, false);
+            });
+            window.addEventListener("batterystatus", onEvent, false);
+            navigator.battery._status({ level: 30, isPlugged: false });
+        });
+        waitsFor(function () { return onEvent.wasCalled; }, "batterystatus onEvent was not
called", 100);
+        runs(function () {
+            expect(onEvent).toHaveBeenCalled();
+        });
+
+    });
+
+    it("battery.spec.3 should fire batterylow events", function () {
+
+        var onEvent;
+        
+        // batterylow 30 -> 20
+        runs(function () {
+            onEvent = jasmine.createSpy().andCallFake(function () {
+                //console.log("batterylow fake callback called");
+                window.removeEventListener("batterylow", onEvent, false);
+            });
+            window.addEventListener("batterylow", onEvent, false);
+            navigator.battery._status({ level: 20, isPlugged: false });
+        });
+        waitsFor(function () { return onEvent.wasCalled; }, "batterylow onEvent was not called
when level goes from 30->20", 100);
+        runs(function () {
+            expect(onEvent).toHaveBeenCalled();
+        });
+
+        // batterylow 30 -> 19
+        runs(function () {
+            onEvent = jasmine.createSpy().andCallFake(function () {
+                //console.log("batterylow fake callback called");
+                window.removeEventListener("batterylow", onEvent, false);
+            });
+            navigator.battery._status({ level: 30, isPlugged: false });
+            window.addEventListener("batterylow", onEvent, false);
+            navigator.battery._status({ level: 19, isPlugged: false });
+        });
+        waitsFor(function () { return onEvent.wasCalled; }, "batterylow onEvent was not called
when level goes from 30->19", 100);
+        runs(function () {
+            expect(onEvent).toHaveBeenCalled();
+        });
+
+    });
+
+    it("battery.spec.4 should fire batterycritical events", function () {
+
+        var onEvent;
+
+        // batterycritical 19->5
+        runs(function () {
+            onEvent = jasmine.createSpy().andCallFake(function () {
+                window.removeEventListener("batterycritical", onEvent, false);
+            });
+            window.addEventListener("batterycritical", onEvent, false);
+            navigator.battery._status({ level: 5, isPlugged: false });
+        });
+        waitsFor(function () { return onEvent.wasCalled; }, "batterycritical onEvent was
not called  when level goes from 19->5", 100);
+        runs(function () {
+            expect(onEvent).toHaveBeenCalled();
+        });
+        
+        // batterycritical 19->4
+        runs(function () {
+            onEvent = jasmine.createSpy().andCallFake(function () {
+                window.removeEventListener("batterycritical", onEvent, false);
+            });
+            navigator.battery._status({ level: 19, isPlugged: false });
+            window.addEventListener("batterycritical", onEvent, false);
+            navigator.battery._status({ level: 4, isPlugged: false });
+        });
+        waitsFor(function () { return onEvent.wasCalled; }, "batterycritical onEvent was
not called  when level goes from 19->4", 100);
+        runs(function () {
+            expect(onEvent).toHaveBeenCalled();
+        });
+    });
+
+    it("battery.spec.5 should NOT fire events when charging or level is increasing", function
() {
+        // batterycritical should not fire when level increases to 5 ( CB-4519 )
+        var onEvent;
+        runs(function () {
+            onEvent = jasmine.createSpy("onbatterycritical");
+            navigator.battery._status({ level: 4, isPlugged: false });
+            window.addEventListener("batterycritical", onEvent, false);
+            navigator.battery._status({ level: 5, isPlugged: false });
+        });
+        waits(100);
+        runs(function () {
+            expect(onEvent).not.toHaveBeenCalled();
+        });
+
+        // batterylow should not fire when level increases to 5 ( CB-4519 )
+        runs(function () {
+            onEvent = jasmine.createSpy("onbatterylow");
+            window.addEventListener("batterylow", onEvent, false);
+            navigator.battery._status({ level: 20, isPlugged: false });
+        });
+        waits(100);
+        runs(function () {
+            expect(onEvent).not.toHaveBeenCalled();
+        });
+
+        // batterylow should NOT fire if we are charging   ( CB-4520 )
+        runs(function () {
+            onEvent = jasmine.createSpy("onbatterylow");
+            navigator.battery._status({ level: 21, isPlugged: true });
+            window.addEventListener("batterylow", onEvent, false);
+            navigator.battery._status({ level: 20, isPlugged: true });
+        });
+        waits(100);
+        runs(function () {
+            expect(onEvent).not.toHaveBeenCalled();
+        });
+
+        // batterycritical should NOT fire if we are charging   ( CB-4520 )
+        runs(function () {
+            onEvent = jasmine.createSpy("onbatterycritical");
+            navigator.battery._status({ level: 6, isPlugged: true });
+            window.addEventListener("batterycritical", onEvent, false);
+            navigator.battery._status({ level: 5, isPlugged: true });
+            
+        });
+        waits(100);
+        runs(function () {
+            expect(onEvent).not.toHaveBeenCalled();
+        });
+    });
+
 });


Mime
View raw message