You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/05/08 21:52:09 UTC

spec commit: added watchPosition tests

Updated Branches:
  refs/heads/master c420addea -> df55b0d14


added watchPosition tests


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

Branch: refs/heads/master
Commit: df55b0d14cb5b9b697293db24470041ac882bb0c
Parents: c420add
Author: Fil Maj <ma...@gmail.com>
Authored: Tue May 8 12:31:10 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue May 8 12:31:10 2012 -0700

----------------------------------------------------------------------
 autotest/tests/geolocation.tests.js |  157 ++++++++++++++++++-----------
 1 files changed, 97 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/df55b0d1/autotest/tests/geolocation.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/geolocation.tests.js b/autotest/tests/geolocation.tests.js
index 9d81425..6cb7650 100644
--- a/autotest/tests/geolocation.tests.js
+++ b/autotest/tests/geolocation.tests.js
@@ -1,82 +1,119 @@
 describe('Geolocation (navigator.geolocation)', function () {
-	it("should exist", function() {
+    it("should exist", function() {
         expect(navigator.geolocation).toBeDefined();
-	});
-
-	it("should contain a getCurrentPosition function", function() {
-		expect(typeof navigator.geolocation.getCurrentPosition).toBeDefined();
-		expect(typeof navigator.geolocation.getCurrentPosition == 'function').toBe(true);
-	});
-
-	it("should contain a watchPosition function", function() {
-		expect(typeof navigator.geolocation.watchPosition).toBeDefined();
-		expect(typeof navigator.geolocation.watchPosition == 'function').toBe(true);
-	});
-
-	it("should contain a clearWatch function", function() {
-		expect(typeof navigator.geolocation.clearWatch).toBeDefined();
-		expect(typeof navigator.geolocation.clearWatch == 'function').toBe(true);
-	});
-
-	it("getCurrentPosition success callback should be called with a Position object", function() {
-		var win = jasmine.createSpy().andCallFake(function(p) {
-                expect(p.coords).toBeDefined();
-                expect(p.timestamp).toBeDefined();
-            }),
-            fail = jasmine.createSpy();
-
-        runs(function () {
-            navigator.geolocation.getCurrentPosition(win, fail, {
-                maximumAge:300000 // 5 minutes maximum age of cached position
-            });
-        });
+    });
 
-        waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+    it("should contain a getCurrentPosition function", function() {
+        expect(typeof navigator.geolocation.getCurrentPosition).toBeDefined();
+        expect(typeof navigator.geolocation.getCurrentPosition == 'function').toBe(true);
+    });
 
-        runs(function () {
-            expect(fail).not.toHaveBeenCalled();
-        });
-	});
+    it("should contain a watchPosition function", function() {
+        expect(typeof navigator.geolocation.watchPosition).toBeDefined();
+        expect(typeof navigator.geolocation.watchPosition == 'function').toBe(true);
+    });
+
+    it("should contain a clearWatch function", function() {
+        expect(typeof navigator.geolocation.clearWatch).toBeDefined();
+        expect(typeof navigator.geolocation.clearWatch == 'function').toBe(true);
+    });
+
+    describe('getCurrentPosition method', function() {
+        describe('error callback', function() {
+            it("should be called if we set timeout to 0 and maximumAge to a very small number", function() {
+                var win = jasmine.createSpy(),
+                    fail = jasmine.createSpy();
 
-	it("getCurrentPosition success callback should be called with a cached Position", function() {
-		var win = jasmine.createSpy().andCallFake(function(p) {
-                expect(p.coords instanceof Position).toBe(true);
-            }),
-            fail = jasmine.createSpy();
+                runs(function () {
+                    navigator.geolocation.getCurrentPosition(win, fail, {
+                        maximumAge: 0,
+                        timeout: 0
+                    });
+                });
 
-        runs(function () {
-            navigator.geolocation.getCurrentPosition(win, fail, {
-                maximumAge:300000 // 5 minutes 
+                waitsFor(function () { return fail.wasCalled; }, "fail never called", 250); //small timeout as this should fire very fast
+
+                runs(function () {
+                    expect(win).not.toHaveBeenCalled();
+                });
             });
         });
 
-        waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+        describe('success callback', function() {
+            it("should be called with a Position object", function() {
+                var win = jasmine.createSpy().andCallFake(function(p) {
+                          expect(p.coords).toBeDefined();
+                          expect(p.timestamp).toBeDefined();
+                          expect(typeof p.timestamp).toBe('number');
+                      }),
+                      fail = jasmine.createSpy();
+
+                runs(function () {
+                    navigator.geolocation.getCurrentPosition(win, fail, {
+                        maximumAge:300000 // 5 minutes maximum age of cached position
+                    });
+                });
+
+                waitsFor(function () { return win.wasCalled; }, "win never called", 20000);
+
+                runs(function () {
+                    expect(fail).not.toHaveBeenCalled();
+                });
+            });
+        });
+    });
 
-        runs(function () {
-            expect(fail).not.toHaveBeenCalled();
+    describe('watchPosition method', function() {
+        var watch = null;
+        
+        afterEach(function() {
+            navigator.geolocation.clearWatch(watch);
         });
-	});
 
-    it("getCurrentPosition error callback should be called if we set timeout to 0 and maximumAge to a very small number", function() {
-        var win = jasmine.createSpy(),
-            fail = jasmine.createSpy();
+        describe('error callback', function() {
+            it("should be called if we set timeout to 0 and maximumAge to a very small number", function() {
+                var win = jasmine.createSpy(),
+                    fail = jasmine.createSpy();
 
-        runs(function () {
-            navigator.geolocation.getCurrentPosition(win, fail, {
-                maximumAge: 0,
-                timeout: 0
+                runs(function () {
+                    watch = navigator.geolocation.watchPosition(win, fail, {
+                        maximumAge: 0,
+                        timeout: 0
+                    });
+                });
+
+                waitsFor(function () { return fail.wasCalled; }, "fail never called", 250); // small timeout as this hsould fire very quickly
+
+                runs(function () {
+                    expect(win).not.toHaveBeenCalled();
+                });
             });
         });
 
-        waitsFor(function () { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
-
-        runs(function () {
-            expect(win).not.toHaveBeenCalled();
+        describe('success callback', function() {
+            it("should be called with a Position object", function() {
+                var win = jasmine.createSpy().andCallFake(function(p) {
+                          expect(p.coords).toBeDefined();
+                          expect(p.timestamp).toBeDefined();
+                          expect(typeof p.timestamp).toBe('number');
+                      }),
+                      fail = jasmine.createSpy();
+
+                runs(function () {
+                    watch = navigator.geolocation.watchPosition(win, fail, {
+                        maximumAge:300000 // 5 minutes maximum age of cached position
+                    });
+                });
+
+                waitsFor(function () { return win.wasCalled; }, "win never called", 20000);
+
+                runs(function () {
+                    expect(fail).not.toHaveBeenCalled();
+                });
+            });
         });
     });
 
-	// TODO: Need to test error callback... how?
-	// TODO: Need to test watchPosition success callback, test that makes sure clearPosition works (how to test that a timer is getting cleared?)
     describe("Geolocation model", function () {
         it("should be able to define a Position object with coords and timestamp properties", function() {
             var pos = new Position({}, new Date());