Added some more BlackBerry 10 Unit Tests - tested: -- battery -- network -- camera -- device -- platform - fixed bug in battery - removed unused require in network
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/9c2f547d Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/9c2f547d Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/9c2f547d Branch: refs/heads/master Commit: 9c2f547d571f36414c336e8e39b234e164571406 Parents: 9799533 Author: Gord Tanner <[email protected]> Authored: Fri Nov 9 14:40:40 2012 -0500 Committer: Gord Tanner <[email protected]> Committed: Fri Nov 9 14:40:40 2012 -0500 ---------------------------------------------------------------------- lib/blackberry/plugin/qnx/battery.js | 3 +- lib/blackberry/plugin/qnx/network.js | 3 +- lib/test/blackberryplatform.js | 1 + test/blackberry/qnx/test.battery.js | 72 ++++++++++++++++++++ test/blackberry/qnx/test.camera.js | 59 +++++++++++++++++ test/blackberry/qnx/test.device.js | 48 ++++++++++++++ test/blackberry/qnx/test.network.js | 39 +++++++++++ test/blackberry/test.platform.js | 102 +++++++++++++++++++++++++++++ 8 files changed, 324 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/lib/blackberry/plugin/qnx/battery.js ---------------------------------------------------------------------- diff --git a/lib/blackberry/plugin/qnx/battery.js b/lib/blackberry/plugin/qnx/battery.js index 81a35fc..8bd9f44 100644 --- a/lib/blackberry/plugin/qnx/battery.js +++ b/lib/blackberry/plugin/qnx/battery.js @@ -34,6 +34,7 @@ module.exports = { }, stop: function (args, win, fail) { - window.stopInterval(interval); + window.clearInterval(interval); + return { "status" : cordova.callbackStatus.OK, "message" : "stopped" }; } }; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/lib/blackberry/plugin/qnx/network.js ---------------------------------------------------------------------- diff --git a/lib/blackberry/plugin/qnx/network.js b/lib/blackberry/plugin/qnx/network.js index 4df3e38..b640f75 100644 --- a/lib/blackberry/plugin/qnx/network.js +++ b/lib/blackberry/plugin/qnx/network.js @@ -19,8 +19,7 @@ * */ -var cordova = require('cordova'), - connection = require('cordova/plugin/Connection'); +var cordova = require('cordova'); module.exports = { getConnectionInfo: function (args, win, fail) { http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/lib/test/blackberryplatform.js ---------------------------------------------------------------------- diff --git a/lib/test/blackberryplatform.js b/lib/test/blackberryplatform.js new file mode 120000 index 0000000..7c28899 --- /dev/null +++ b/lib/test/blackberryplatform.js @@ -0,0 +1 @@ +../blackberry/platform.js \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/test/blackberry/qnx/test.battery.js ---------------------------------------------------------------------- diff --git a/test/blackberry/qnx/test.battery.js b/test/blackberry/qnx/test.battery.js new file mode 100644 index 0000000..c66c0ef --- /dev/null +++ b/test/blackberry/qnx/test.battery.js @@ -0,0 +1,72 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry qnx battery", function () { + var battery = require('cordova/plugin/qnx/battery'), + cordova = require('cordova'); + + beforeEach(function () { + spyOn(window, "setInterval").andReturn(1); + spyOn(window, "clearInterval"); + }); + + it("returns no_result when calling start", function () { + expect(battery.start()).toEqual({ + status: cordova.callbackStatus.NO_RESULT, + message: "WebWorks Is On It" + }); + }); + + it("sets an interval for 500 ms when calling start", function () { + battery.start(); + expect(window.setInterval).toHaveBeenCalledWith(jasmine.any(Function), 500); + }); + + it("calls the win callback with values from navigator.webkitBattery", function () { + global.navigator = window.navigator; + window.navigator.webkitBattery = { level: 0.12, charging: true }; + + var win = jasmine.createSpy("win"); + battery.start({}, win); + + window.setInterval.mostRecentCall.args[0](); + + expect(win).toHaveBeenCalledWith({ + level: 12, + isPlugged: true + }); + + delete window.navigator.webkitBattery; + }); + + it("returns ok when calling stop", function () { + expect(battery.stop()).toEqual({ + status: cordova.callbackStatus.OK, + message: "stopped" + }); + }); + + it("calls clearInterval when stopping", function () { + battery.start(); + battery.stop(); + expect(window.clearInterval).toHaveBeenCalledWith(1); + }); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/test/blackberry/qnx/test.camera.js ---------------------------------------------------------------------- diff --git a/test/blackberry/qnx/test.camera.js b/test/blackberry/qnx/test.camera.js new file mode 100644 index 0000000..1cedd6c --- /dev/null +++ b/test/blackberry/qnx/test.camera.js @@ -0,0 +1,59 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry qnx camera", function () { + var camera = require('cordova/plugin/qnx/camera'), + cordova = require('cordova'); + + beforeEach(function () { + global.blackberry = { + invoke: { + card: { + invokeCamera: jasmine.createSpy("invokeCamera") + } + } + }; + }); + + afterEach(function () { + delete global.blackberry; + }); + + it("returns no_result when calling takePicture", function () { + expect(camera.takePicture()).toEqual({ + status: cordova.callbackStatus.NO_RESULT, + message: "WebWorks Is On It" + }); + }); + + it("calls blackberry.invoke.card.invokeCamera", function () { + camera.takePicture(); + expect(blackberry.invoke.card.invokeCamera).toHaveBeenCalledWith("photo", jasmine.any(Function), jasmine.any(Function), jasmine.any(Function)); + }); + + it("adds file:// to the path provided to the callback and calls success", function () { + var win = jasmine.createSpy("win"); + camera.takePicture({}, win); + + blackberry.invoke.card.invokeCamera.mostRecentCall.args[1]("pics/ponies.jpg"); + expect(win).toHaveBeenCalledWith("file://pics/ponies.jpg"); + }); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/test/blackberry/qnx/test.device.js ---------------------------------------------------------------------- diff --git a/test/blackberry/qnx/test.device.js b/test/blackberry/qnx/test.device.js new file mode 100644 index 0000000..1595b4f --- /dev/null +++ b/test/blackberry/qnx/test.device.js @@ -0,0 +1,48 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry qnx device", function () { + var device = require('cordova/plugin/qnx/device'); + + it("calls the win callback with the device info", function () { + global.blackberry = { + system: { + softwareVersion: "NaN" + }, + identity: { + uuid: 1 + } + }; + + var info; + + //HACK: I know this is a sync call ;) + device.getDeviceInfo({}, function (i) { info = i; }); + + expect(info.platform).toBe("BB10"); + expect(info.version).toBe("NaN"); + expect(info.name).toBe("Dev Alpha"); + expect(info.uuid).toBe(1); + expect(info.cordova).toBeDefined(); + + delete global.blackberry; + }); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/test/blackberry/qnx/test.network.js ---------------------------------------------------------------------- diff --git a/test/blackberry/qnx/test.network.js b/test/blackberry/qnx/test.network.js new file mode 100644 index 0000000..63a224b --- /dev/null +++ b/test/blackberry/qnx/test.network.js @@ -0,0 +1,39 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry qnx network", function () { + var cordova = require('cordova'), + network = require('cordova/plugin/qnx/network'); + + it("returns the connection info", function () { + global.blackberry = { + connection: { + type: "pigeon" + } + }; + expect(network.getConnectionInfo()).toEqual({ + status: cordova.callbackStatus.OK, + message: "pigeon" + }); + + delete global.blackberry; + }); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9c2f547d/test/blackberry/test.platform.js ---------------------------------------------------------------------- diff --git a/test/blackberry/test.platform.js b/test/blackberry/test.platform.js new file mode 100644 index 0000000..4d909af --- /dev/null +++ b/test/blackberry/test.platform.js @@ -0,0 +1,102 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry platform", function () { + var platform = require('cordova/blackberryplatform'); + + describe("when getting the runtime", function () { + beforeEach(function () { + global.blackberry = { + system: { + softwareVersion: "" + } + }; + }); + + afterEach(function () { + delete global.blackberry; + }); + + it("returns qnx if webworks exists on window", function () { + window.webworks = {}; + expect(platform.runtime()).toBe("qnx"); + delete window.webworks; + }); + + it("returns air if softwareVersion starts with BlackBerry", function () { + blackberry.system.softwareVersion = "BlackBerry PlayBook OS" + expect(platform.runtime()).toBe("air"); + }); + + it("returns java if software version is anything else", function () { + blackberry.system.softwareVersion = "7.0" + expect(platform.runtime()).toBe("java"); + }); + }); + + describe("when initializing", function () { + var builder = require('cordova/builder'), + clobber = jasmine.createSpy("intoAndClobber"), + merge = jasmine.createSpy("intoAndMerge"); + + beforeEach(function () { + spyOn(builder, "build").andReturn({ + intoAndClobber: clobber, + intoAndMerge: merge + }); + }); + + it("calls initialize for the platform from the runtime", function () { + var air = require('cordova/plugin/air/platform'); + + spyOn(air, "initialize"); + spyOn(platform, "runtime").andReturn("air"); + + platform.initialize(); + + expect(air.initialize).toHaveBeenCalled(); + }); + + it("builds given platforms objects into window and clobbers them", function () { + var java = require('cordova/plugin/java/platform'); + + spyOn(java, "initialize"); + spyOn(platform, "runtime").andReturn("java"); + + platform.initialize(); + + expect(builder.build).toHaveBeenCalledWith(java.objects); + expect(clobber).toHaveBeenCalledWith(window); + }); + + it("builds given platforms merges into window and merges them", function () { + var qnx = require('cordova/plugin/qnx/platform'); + + spyOn(qnx, "initialize"); + spyOn(platform, "runtime").andReturn("qnx"); + + platform.initialize(); + + expect(builder.build).toHaveBeenCalledWith(qnx.merges); + expect(merge).toHaveBeenCalledWith(window); + }); + }); +});
