You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by gt...@apache.org on 2012/11/13 20:13:42 UTC
[7/16] js commit: Corrections and further test expansions
Corrections and further test expansions
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/80517616
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/80517616
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/80517616
Branch: refs/heads/master
Commit: 805176165a754f65790dcc46e96c989111256060
Parents: 82dc004
Author: Matt Lantz <ma...@rim.com>
Authored: Mon Nov 12 09:37:53 2012 -0500
Committer: Gord Tanner <gt...@gmail.com>
Committed: Mon Nov 12 09:42:29 2012 -0500
----------------------------------------------------------------------
lib/blackberry/plugin/webworks/media.js | 1 -
test/blackberry/webworks/test.accelerometer.js | 11 +-
test/blackberry/webworks/test.media.js | 246 ++++++++++++++++++-
test/blackberry/webworks/test.notification.js | 44 ++--
4 files changed, 266 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/80517616/lib/blackberry/plugin/webworks/media.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/webworks/media.js b/lib/blackberry/plugin/webworks/media.js
index 2499aea..82404c5 100644
--- a/lib/blackberry/plugin/webworks/media.js
+++ b/lib/blackberry/plugin/webworks/media.js
@@ -98,7 +98,6 @@ module.exports = {
result = {"status" : 1, "message" : "Seek to audio succeeded" };
}
-
return result;
},
pausePlayingAudio: function (args, win, fail) {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/80517616/test/blackberry/webworks/test.accelerometer.js
----------------------------------------------------------------------
diff --git a/test/blackberry/webworks/test.accelerometer.js b/test/blackberry/webworks/test.accelerometer.js
index 8c726d7..b315108 100644
--- a/test/blackberry/webworks/test.accelerometer.js
+++ b/test/blackberry/webworks/test.accelerometer.js
@@ -27,9 +27,8 @@ describe("accelerometer", function () {
spyOn(window, "removeEventListener");
spyOn(window, "addEventListener");
- var callback = function(motion){},
- win = function(){},
- fail = function(){},
+ var win = jasmine.createSpy('win'),
+ fail = jasmine.createSpy('fail'),
args = {x:1,y:2,z:3},
aStart = accelerometer.start(args, win, fail);
@@ -51,7 +50,10 @@ describe("accelerometer", function () {
spyOn(window, "removeEventListener");
var aStop = accelerometer.stop();
- expect(window.removeEventListener).toHaveBeenCalled();
+ expect(window.removeEventListener).toHaveBeenCalledWith("devicemotion", jasmine.any(Function));
+
+ window.removeEventListener.reset();
+
expect(aStop.status).toBe(0);
expect(aStop.message).toBe('WebWorks Is On It');
@@ -59,4 +61,3 @@ describe("accelerometer", function () {
});
});
-
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/80517616/test/blackberry/webworks/test.media.js
----------------------------------------------------------------------
diff --git a/test/blackberry/webworks/test.media.js b/test/blackberry/webworks/test.media.js
index 6ef95a3..ca35da8 100644
--- a/test/blackberry/webworks/test.media.js
+++ b/test/blackberry/webworks/test.media.js
@@ -21,32 +21,254 @@
describe("media", function () {
var media = require('cordova/plugin/webworks/media'),
- exec = require('cordova/exec');
+ m;
+
+ beforeEach(function(){
+ global.Audio = function(src){
+ var funcs = {
+ play: function(){},
+ pause: function(){},
+ currentTime: 800,
+ duration: 2100
+ }
+ return funcs;
+ }
+ });
+
+ afterEach(function(){
+ delete global.Audio;
+ });
describe("create", function() {
-
it("should fail to create a media object", function() {
- var m = media.create(8);
+ m = media.create({});
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+ it("should fail to create a media object", function() {
+ m = media.create(9);
expect(m.status).toBe(9);
expect(m.message).toBe('Media Object id was not sent in arguments');
});
it("should create a media object", function() {
-
- var Audio = jasmine.createSpy('Audio');
- window.Audio = new Audio;
+ m = media.create(["jammin", "tunes/wejammin.mp3"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe('Audio object created');
+ });
+ });
- // spyOn(window, "Audio");
+ describe("startPlayingAudio", function(){
+ it("should fail to find the media Object", function() {
+ m = media.startPlayingAudio({});
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
- // var m = media.create(["jammin", "yeah man!"]);
+ it("should fail to find media Source ", function() {
+ m = media.startPlayingAudio(["jammin"]);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media source argument not found');
+ });
+
+ it("should create a media object ", function() {
+ m = media.startPlayingAudio(["jammin", "tunes/wejammin.mp3"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe('Audio play started');
+ });
+ });
- // expect(window.Audio).toHaveBeenCalled();
-
- // expect(m.status).toBe(1);
- // expect(m.message).toBe('Audio object created');
+ describe("stopPlayingAudio", function(){
+ it("should fail to find the media Object", function() {
+ m = media.stopPlayingAudio(0);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+
+ it("should stop the audio playback ", function() {
+ m = media.stopPlayingAudio(["jammin", "tunes/wejammin.mp3"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe('Audio play stopped');
+ });
+
+ it("should find that the Audio Object failed to initialze", function() {
+ global.audio = undefined;
+ m = media.stopPlayingAudio(["jammin"]);
+ expect(m.status).toBe(2);
+ expect(m.message).toBe('Audio Object has not been initialized');
+ delete global.audio;
});
});
+ describe("seekToAudio", function(){
+ it("should fail to find the media Object", function() {
+ m = media.seekToAudio(0);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+
+ it("should find that the Audio Object failed to initialze", function() {
+ global.audio = undefined;
+ m = media.seekToAudio(["jammin"]);
+ expect(m.status).toBe(2);
+ expect(m.message).toBe('Audio Object has not been initialized');
+ delete global.audio;
+ });
+
+ it("should find that there is no time argument in the function", function() {
+ media.create(["jammin", "tunes/wejammin.mp3"]);
+ m = media.seekToAudio(["jammin"]);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media seek time argument not found');
+ media.release(["jammin"]);
+ });
+
+ // TODO: review error generators!!! It should have a listener to see when it changes and make calls based on those changes of that particular variable.
+ // it("should result in an error seeking audio", function() {
+ // media.create(["jammin", "tunes/wejammin.mp3"]);
+ // m = media.seekToAudio(["jammin", 9000]);
+
+ // // expect(m.status).toBe(3);
+ // expect(m.message).toBe('Seek to audio succeeded');
+
+ // media.release(["jammin"]);
+ // });
+
+ it("should successfully seek to audio", function() {
+ media.create(["jammin", "tunes/wejammin.mp3"]);
+ m = media.seekToAudio(["jammin", 800]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe('Seek to audio succeeded');
+ media.release(["jammin"]);
+ });
+
+
+ });
+
+ describe("pausePlayingAudio", function(){
+ it("should fail to find the media Object", function() {
+ m = media.pausePlayingAudio(0);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+
+ it("should find that the Audio Object failed to initialze", function() {
+ global.audio = undefined;
+ m = media.pausePlayingAudio(["jammin"]);
+ expect(m.status).toBe(2);
+ expect(m.message).toBe('Audio Object has not been initialized');
+ delete global.audio;
+ });
+
+ it("should successfully pause the audio", function() {
+ media.create(["jammin", "tunes/wejammin.mp3"]);
+ m = media.pausePlayingAudio(["jammin"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe('Audio paused');
+ media.release(["jammin"]);
+ });
+
+ });
+
+ describe("getCurrentPositionAudio", function(){
+ it("should fail to find the media Object", function() {
+ m = media.getCurrentPositionAudio(0);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+
+ it("should find that the Audio Object failed to initialze", function() {
+ global.audio = undefined;
+ m = media.getCurrentPositionAudio(["jammin"]);
+ expect(m.status).toBe(2);
+ expect(m.message).toBe('Audio Object has not been initialized');
+ delete global.audio;
+ });
+
+ it("should successfully pause the audio", function() {
+ media.create(["jammin", "tunes/wejammin.mp3"]);
+ m = media.getCurrentPositionAudio(["jammin"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe(800);
+ media.release(["jammin"]);
+ });
+
+ });
+
+ describe("getDuration", function(){
+ it("should fail to find the media Object", function() {
+ m = media.getDuration(0);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+
+ it("should find that the Audio Object failed to initialze", function() {
+ global.audio = undefined;
+ m = media.getDuration(["jammin"]);
+ expect(m.status).toBe(2);
+ expect(m.message).toBe('Audio Object has not been initialized');
+ delete global.audio;
+ });
+
+ it("should successfully pause the audio", function() {
+ media.create(["jammin", "tunes/wejammin.mp3"]);
+ m = media.getDuration(["jammin"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe(2100);
+ media.release(["jammin"]);
+ });
+
+ });
+
+ describe("startRecordingAudio", function(){
+ it("should fail to find the media Object", function() {
+ m = media.startRecordingAudio(0);
+ expect(m.status).toBe(9);
+ expect(m.message).toBe('Media Object id was not sent in arguments');
+ });
+
+ it("should find that the Audio Object failed to initialze", function() {
+ global.audio = undefined;
+ m = media.startRecordingAudio(["jammin"]);
+ expect(m.status).toBe(2);
+ expect(m.message).toBe('Media start recording, insufficient arguments');
+ delete global.audio;
+ });
+
+ it("should successfully pause the audio", function() {
+ media.create(["jammin", "tunes/wejammin.mp3"]);
+ m = media.startRecordingAudio(["jammin"]);
+ expect(m.status).toBe(1);
+ expect(m.message).toBe(2100);
+ media.release(["jammin"]);
+ });
+
+ });
+
+ // describe("getDuration", function(){
+ // it("should fail to find the media Object", function() {
+ // m = media.getDuration(0);
+ // expect(m.status).toBe(9);
+ // expect(m.message).toBe('Media Object id was not sent in arguments');
+ // });
+
+ // it("should find that the Audio Object failed to initialze", function() {
+ // global.audio = undefined;
+ // m = media.getDuration(["jammin"]);
+ // expect(m.status).toBe(2);
+ // expect(m.message).toBe('Audio Object has not been initialized');
+ // delete global.audio;
+ // });
+
+ // it("should successfully pause the audio", function() {
+ // media.create(["jammin", "tunes/wejammin.mp3"]);
+ // m = media.getDuration(["jammin"]);
+ // expect(m.status).toBe(1);
+ // expect(m.message).toBe(2100);
+ // media.release(["jammin"]);
+ // });
+
+ // });
});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/80517616/test/blackberry/webworks/test.notification.js
----------------------------------------------------------------------
diff --git a/test/blackberry/webworks/test.notification.js b/test/blackberry/webworks/test.notification.js
index 75c7102..a3375dd 100644
--- a/test/blackberry/webworks/test.notification.js
+++ b/test/blackberry/webworks/test.notification.js
@@ -20,10 +20,24 @@
*/
describe("notification", function () {
- var notification = require('cordova/plugin/webworks/notification'),
- exec = require('cordova/exec');
+ var notification = require('cordova/plugin/webworks/notification');
+
+ beforeEach(function(){
+ global.blackberry = {
+ ui:{
+ dialog:{
+ customAskAsync: {
+ apply: function(args){ return args; }
+ }
+ }
+ }
+ }
+ });
+
+ afterEach(function(){
+ delete global.blackberry;
+ });
- // alerts handled by cordova
describe("alert - arguments not equal to three", function() {
it("should provide an alert notification", function() {
@@ -36,24 +50,17 @@ describe("notification", function () {
});
});
- // alerts handled by webworks
describe("alert - arguments equal to three", function() {
- it("should call blackberry.ui.dialog.customAskAsync", function() {
-
- // spyOn(blackberry.ui.dialog.customAskAsync, "apply");
+ it("should call a webworks action", function() {
- // var args = ["Danger, danger Will Robinson", "Panic, is my middle name", "PANIC"],
- // n = notification.alert(args);
-
+ var n = notification.alert(["Danger, danger Will Robinson", "Panic, is my middle name", "PANIC"]);
- // expect(args.length).toBe(3);
- // expect(n.status).toBe(9);
- // expect(n.message).toBe('Notification action - alert arguments not found');
+ expect(n.status).toBe(0);
+ expect(n.message).toBe('WebWorks Is On It');
});
});
- // confirm handled by cordova
describe("confirm - arguments not equal to three", function() {
it("should provide a confirm notification", function() {
@@ -68,11 +75,12 @@ describe("notification", function () {
// confirm handled by webworks
describe("alert - arguments equal to three", function() {
- it("should call blackberry", function() {
+ it("should call a webworks action", function() {
- // var args = ["Danger, danger Will Robinson", "Panic, is my middle name", "PANIC"];
- // var n = notification.alert(args);
- // TALK TO GORD!!!!!
+ var n = notification.confirm(["Danger, danger Will Robinson", "Panic, is my middle name", "PANIC"]);
+
+ expect(n.status).toBe(0);
+ expect(n.message).toBe('WebWorks Is On It');
});
});