Skip to content
Permalink
Browse files
Merge branch 'master' into ffos_privileged_compatible
  • Loading branch information
zalun committed May 19, 2014
2 parents 0de5e95 + b0ef368 commit 5570976581ec6983d11ba498453788ad9f205c4f
Showing 3 changed files with 261 additions and 46 deletions.
@@ -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();
});
});

});
@@ -4425,6 +4425,25 @@ describe('File API', function() {
expect(validateFile).toHaveBeenCalled();
});
});

it("file.spec.129 cordova.file.*Directory are set", function() {
var expectedPaths = [
'applicationDirectory',
'applicationStorageDirectory',
'dataDirectory',
'cacheDirectory'
];
if (cordova.platformId == 'android') {
expectedPaths.push('externalApplicationStorageDirectory', 'externalRootDirectory', 'externalCacheDirectory', 'externalDataDirectory');
} else if (cordova.platformId == 'ios') {
expectedPaths.push('syncedDataDirectory', 'documentsDirectory', 'tempDirectory');
} else {
console.log('Skipping test due on unsupported platform.');
return;
}
for (var i = 0; i < expectedPaths.length; ++i) {
expect(typeof cordova.file[expectedPaths[i]]).toBe('string');
expect(cordova.file[expectedPaths[i]]).toMatch(/\/$/, 'Path should end with a slash');
}
});
});
});

0 comments on commit 5570976

Please sign in to comment.