You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2013/06/25 15:27:51 UTC

webworks commit: [CB-3455] Added Geolocation plugin

Updated Branches:
  refs/heads/master 1e8e7b162 -> 22ff2e409


[CB-3455] Added Geolocation plugin

Reviewed by Bryan Higgins <bh...@blackberry.com>
Tested by Tracy Li <tl...@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/22ff2e40
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/22ff2e40
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/22ff2e40

Branch: refs/heads/master
Commit: 22ff2e409f31fe3458dc4d6195fb01136a237644
Parents: 1e8e7b1
Author: Rosa Tse <rt...@blackberry.com>
Authored: Wed Jun 12 00:05:39 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Tue Jun 25 09:29:43 2013 -0400

----------------------------------------------------------------------
 .../bin/test/plugins/Geolocation/index.js       | 74 ++++++++++++++++++++
 blackberry10/plugins/Geolocation/plugin.xml     | 30 ++++++++
 .../Geolocation/src/blackberry10/index.js       | 64 +++++++++++++++++
 3 files changed, 168 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/22ff2e40/blackberry10/bin/test/plugins/Geolocation/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/plugins/Geolocation/index.js b/blackberry10/bin/test/plugins/Geolocation/index.js
new file mode 100644
index 0000000..5e06d83
--- /dev/null
+++ b/blackberry10/bin/test/plugins/Geolocation/index.js
@@ -0,0 +1,74 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed 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 ('geolocation', function () {
+    var _apiDir = __dirname + "./../../../../plugins/Geolocation/src/blackberry10/",
+        mockedPluginResult,
+        geolocationIndex,
+        mockedNavigator = {
+            geolocation: {
+                getCurrentPosition: jasmine.createSpy(),
+                watchPosition: jasmine.createSpy().andReturn('1337'),
+                clearWatch: jasmine.createSpy()
+            }
+        },
+        noop = function () {};	
+
+    beforeEach (function() {
+        mockedPluginResult = {
+            callbackOk: jasmine.createSpy(),
+            error: jasmine.createSpy(),
+            noResult: jasmine.createSpy(),
+            ok: jasmine.createSpy()
+        };
+		
+        GLOBAL.PluginResult = function () {
+            return mockedPluginResult;
+        };
+
+        GLOBAL.navigator = mockedNavigator;
+        geolocationIndex = require(_apiDir + 'index');
+    });
+
+    afterEach(function () {
+        delete require.cache[require.resolve(_apiDir + 'index')];
+        delete GLOBAL.PluginResult;
+    });
+
+    describe('getLocation property', function() {
+        it('calls navigator and result.noResult after declarations', function() {
+            geolocationIndex.getLocation(noop,noop,{});
+            expect(mockedNavigator.geolocation.getCurrentPosition).toHaveBeenCalled();
+            expect(mockedPluginResult.noResult).toHaveBeenCalledWith(true);
+        });
+    });
+
+    describe('addWatch property', function() {
+        it('calls navigator to initialize id and calls result.noResult(true)', function() {
+            geolocationIndex.addWatch(noop,noop,{});
+            expect(mockedNavigator.geolocation.watchPosition).toHaveBeenCalled();
+            expect(mockedPluginResult.noResult).toHaveBeenCalledWith(true);
+        });
+    });
+
+    describe('clearWatch property', function() {
+        it('calls navigator.geolocation.clearWatch(id) if id exists and calls result.ok', function () {
+            geolocationIndex.addWatch(noop,noop,{});
+            geolocationIndex.clearWatch(noop,noop,{});
+            expect(mockedNavigator.geolocation.clearWatch).toHaveBeenCalledWith('1337');
+            expect(mockedPluginResult.ok).toHaveBeenCalledWith(null, false); 
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/22ff2e40/blackberry10/plugins/Geolocation/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Geolocation/plugin.xml b/blackberry10/plugins/Geolocation/plugin.xml
new file mode 100644
index 0000000..1642e3a
--- /dev/null
+++ b/blackberry10/plugins/Geolocation/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed 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.
+
+-->
+
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="org.apache.cordova.core.Geolocation"
+    version="0.0.1">
+
+    <name>Geolocation</name>
+
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="Geolocation" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="Geolocation" value="Geolocation"/>
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/22ff2e40/blackberry10/plugins/Geolocation/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Geolocation/src/blackberry10/index.js b/blackberry10/plugins/Geolocation/src/blackberry10/index.js
new file mode 100644
index 0000000..c12c15f
--- /dev/null
+++ b/blackberry10/plugins/Geolocation/src/blackberry10/index.js
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2013 Research In Motion Limited.
+ *
+ * Licensed 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.
+ */
+var ids = {};
+
+module.exports = {
+    getLocation: function (success, fail, args, env) {
+        var result = new PluginResult(args, env),
+            options = {
+                "enableHighAccuracy": decodeURIComponent(args[0]),
+                "maximumAge": decodeURIComponent(args[1])
+            };
+
+        navigator.geolocation.getCurrentPosition(function (pos) {
+            result.callbackOk(pos.coords, false);
+        }, function (err) {
+            result.error(err, false);
+        }, options);
+
+        result.noResult(true);
+    },
+
+    addWatch: function (success, fail, args, env) {
+        var result = new PluginResult(args, env),
+            options = {
+                "enableHighAccuracy": decodeURIComponent(args[1])
+            },
+            clientId = decodeURIComponent(args[0]);
+            id = navigator.geolocation.watchPosition(function (pos) {
+                    result.callbackOk(pos.coords, false);
+                }, function (err) {
+                    result.error(err, false);
+                }, options);
+
+        ids[clientId] = id;
+
+        result.noResult(true);
+    },
+
+    clearWatch: function (success, fail, args, env) {
+        var result = new PluginResult(args, env),
+            clientId = decodeURIComponent(args[0]),
+            id = ids[clientId];
+
+        if (id) {
+            navigator.geolocation.clearWatch(id);
+            delete ids[clientId];
+        }
+
+        result.ok(null, false);
+    }
+};