reworking geolocation contacts and updated tests
diff --git a/Res/mobile-spec/tests/accelerometer.tests.js b/Res/mobile-spec/tests/accelerometer.tests.js
index 6fede33..3a3f0d5 100644
--- a/Res/mobile-spec/tests/accelerometer.tests.js
+++ b/Res/mobile-spec/tests/accelerometer.tests.js
@@ -11,7 +11,7 @@
});
test("getCurrentAcceleration success callback should be called with an Acceleration object", function() {
expect(7);
- QUnit.stop(tests.TEST_TIMEOUT);
+ QUnit.stop(this.TEST_TIMEOUT);
var win = function(a) {
ok(typeof a == 'object', "Acceleration object returned in getCurrentAcceleration success callback should be of type 'object'.");
ok(a.x != null, "Acceleration object returned in getCurrentAcceleration success callback should have an 'x' property.");
@@ -52,4 +52,4 @@
equals(a.z, z, "new Acceleration object should have 'z' property equal to third parameter passed in Acceleration constructor.");
ok(a.timestamp != null, "new Acceleration object should have a 'timestamp' property.");
});
-};
\ No newline at end of file
+};
diff --git a/Res/mobile-spec/tests/contacts.tests.js b/Res/mobile-spec/tests/contacts.tests.js
index 5502f43..65cc1ba 100644
--- a/Res/mobile-spec/tests/contacts.tests.js
+++ b/Res/mobile-spec/tests/contacts.tests.js
@@ -11,7 +11,7 @@
});
test("contacts.find success callback should be called with an array", function() {
expect(2);
- QUnit.stop(tests.TEST_TIMEOUT);
+ QUnit.stop(this.TEST_TIMEOUT);
var win = function(result) {
ok(typeof result == 'object', "Object returned in contacts.find success callback is of type 'object' (actually array).");
ok(typeof result.length == 'number', "Object returned in contacts.find success callback has a length property which is numerical.");
@@ -19,7 +19,7 @@
};
var fail = function() { QUnit.start(); };
var obj = new ContactFindOptions();
- obj.filter="";
+ obj.filter="test";
obj.multiple=true;
navigator.service.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, obj);
});
@@ -146,7 +146,7 @@
ok(typeof contact.remove == 'function', "contact.remove should be a function.");
});
test("calling remove on a contact has an id of null should return ContactError.NOT_FOUND_ERROR", function() {
- QUnit.stop(tests.TEST_TIMEOUT);
+ QUnit.stop(this.TEST_TIMEOUT);
expect(2);
var win = function(result) {
};
@@ -159,7 +159,7 @@
rmContact.remove(win, fail);
});
test("calling remove on a contact that does not exist should return ContactError.NOT_FOUND_ERROR", function() {
- QUnit.stop(tests.TEST_TIMEOUT);
+ QUnit.stop(this.TEST_TIMEOUT);
expect(2);
var win = function(result) {
};
diff --git a/Res/mobile-spec/tests/geolocation.tests.js b/Res/mobile-spec/tests/geolocation.tests.js
index d84cbf5..df7cdd5 100644
--- a/Res/mobile-spec/tests/geolocation.tests.js
+++ b/Res/mobile-spec/tests/geolocation.tests.js
@@ -21,7 +21,7 @@
});
test("getCurrentPosition success callback should be called with a Position object", function() {
expect(2);
- QUnit.stop(tests.TEST_TIMEOUT);
+ QUnit.stop(this.TEST_TIMEOUT);
var win = function(p) {
ok(p.coords != null, "Position object returned in getCurrentPosition success callback has a 'coords' property.");
ok(p.timestamp != null, "Position object returned in getCurrentPosition success callback has a 'timestamp' property.");
@@ -54,4 +54,4 @@
ok(typeof coords.speed != 'undefined' && coords.speed != null, "new Coordinates() should include a 'speed' property.");
ok(typeof coords.altitudeAccuracy != 'undefined' && coords.altitudeAccuracy != null, "new Coordinates() should include a 'altitudeAccuracy' property.");
});
-};
\ No newline at end of file
+};
diff --git a/Res/phonegap/geolocation.js b/Res/phonegap/geolocation.js
index e24d552..f43a062 100644
--- a/Res/phonegap/geolocation.js
+++ b/Res/phonegap/geolocation.js
@@ -15,9 +15,7 @@
// The last known GPS position.
this.lastPosition = null;
-
- // Geolocation listeners
- this.listeners = {};
+ this.id = null;
};
/**
@@ -44,17 +42,7 @@
* @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
*/
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
- console.log('enter');
- var id = "global";
- if (navigator._geo.listeners[id]) {
- console.log("Geolocation Error: Still waiting for previous getCurrentPosition() request.");
- try {
- errorCallback(new PositionError(PositionError.TIMEOUT, "Geolocation Error: Still waiting for previous getCurrentPosition() request."));
- } catch (e) {
- }
- return;
- }
-
+ this.id = PhoneGap.createUUID();
// default maximumAge value should be 0, and set if positive
var maximumAge = 0;
@@ -73,8 +61,7 @@
timeout = (options.timeout < 0) ? 0 : options.timeout;
}
}
- navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
- PhoneGap.exec(null, errorCallback, "com.phonegap.Geolocation", "getCurrentPosition", [id, maximumAge, timeout, enableHighAccuracy]);
+ PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Geolocation", "getCurrentPosition", [maximumAge, timeout, enableHighAccuracy]);
}
/**
@@ -108,54 +95,9 @@
timeout = (options.timeout < 0) ? 0 : options.timeout;
}
}
- var id = PhoneGap.createUUID();
- navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
- PhoneGap.exec(null, errorCallback, "com.phonegap.Geolocation", "watchPosition", [id, maximumAge, timeout, enableHighAccuracy]);
- return id;
-};
-
-/*
- * Native callback when watch position has a new position.
- */
-Geolocation.prototype.success = function(id, result) {
-
- var p = result.message;
- var coords = new Coordinates(p.latitude, p.longitude, p.altitude, p.accuracy, p.heading, p.speed, p.alt_accuracy);
- var loc = new Position(coords, p.timestamp);
- try {
- navigator._geo.lastPosition = loc;
- navigator._geo.listeners[id].success(loc);
- }
- catch (e) {
- debugPrint("Geolocation Error: "+e.message);
- console.log("Geolocation Error: Error calling success callback function.");
- }
-
- if (id == "global") {
- delete navigator._geo.listeners["global"];
- }
-};
-
-/**
- * Native callback when watch position has an error.
- *
- * @param {String} id The ID of the watch
- * @param {Object} result The result containing status and message
- */
-Geolocation.prototype.fail = function(id, result) {
- var code = result.status;
- var msg = result.message;
- try {
- navigator._geo.listeners[id].fail(new PositionError(code, msg));
- }
- catch (e) {
- debugPrint("Geolocation Error: Error calling error callback function: "+e.message);
- console.log("Geolocation Error: Error calling error callback function.");
- }
-
- if (id == "global") {
- delete navigator._geo.listeners["global"];
- }
+ this.id = PhoneGap.createUUID();
+ PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Geolocation", "watchPosition", [maximumAge, timeout, enableHighAccuracy]);
+ return this.id;
};
/**
@@ -164,8 +106,8 @@
* @param {String} id The ID of the watch returned from #watchPosition
*/
Geolocation.prototype.clearWatch = function(id) {
- PhoneGap.exec(null, null, "com.phonegap.Geolocation", "stop", [id]);
- delete navigator._geo.listeners[id];
+ PhoneGap.exec(null, null, "com.phonegap.Geolocation", "stop", []);
+ this.id = null;
};
/**
diff --git a/inc/GeoLocation.h b/inc/GeoLocation.h
index 1b2864b..3f637b5 100755
--- a/inc/GeoLocation.h
+++ b/inc/GeoLocation.h
@@ -17,7 +17,7 @@
private:
LocationProvider* locProvider;
bool watching;
- String uuid;
+ String callbackId;
public:
GeoLocation();
GeoLocation(Web* pWeb);
diff --git a/src/Contacts.cpp b/src/Contacts.cpp
index 2d6387c..3feb854 100755
--- a/src/Contacts.cpp
+++ b/src/Contacts.cpp
@@ -570,12 +570,13 @@
AppLogDebug("Trying to remove contact with ID %S", idStr.GetPointer());
r = addressbook.RemoveContact(id);
if(IsFailed(r)) {
- AppLogDebug("Contact Could be removed %s", GetErrorMessage(r), r);
- eval.Format(128, L"PhoneGap.callbacks['%S'].fail({message:'%s', code:%d})", callbackId.GetPointer(), GetErrorMessage(r), r);
+ AppLogDebug("Contact Could not be removed %s %d", GetErrorMessage(r), r);
+ eval.Format(256, L"PhoneGap.callbacks['%S'].fail({message:'%s', code:ContactError.NOT_FOUND_ERROR})",
+ callbackId.GetPointer(), GetErrorMessage(r));
pWeb->EvaluateJavascriptN(eval);
} else {
AppLogDebug("Contact %S removed", idStr.GetPointer());
- eval.Format(128, L"PhoneGap.callbacks['%S'].success({message:'Contact with ID %d removed', code:01})", callbackId.GetPointer(), id);
+ eval.Format(256, L"PhoneGap.callbacks['%S'].success({message:'Contact with ID %d removed', code:01})", callbackId.GetPointer(), id);
pWeb->EvaluateJavascriptN(eval);
}
}
diff --git a/src/GeoLocation.cpp b/src/GeoLocation.cpp
index 51d7f4c..da9c673 100755
--- a/src/GeoLocation.cpp
+++ b/src/GeoLocation.cpp
@@ -25,25 +25,25 @@
void
GeoLocation::Run(const String& command) {
if(!command.IsEmpty()) {
- String args;
- String delim(L"/");
- command.SubString(String(L"gap://").GetLength(), args);
- StringTokenizer strTok(args, delim);
- String method;
- strTok.GetNextToken(method);
- // Getting UUID
- for(int i = 0 ; i < 2 && strTok.HasMoreTokens() ; i++, strTok.GetNextToken(uuid));
- AppLogDebug("Method %S, UUID: %S", method.GetPointer(), uuid.GetPointer());
+ Uri commandUri;
+ commandUri.SetUri(command);
+ String method = commandUri.GetHost();
+ StringTokenizer strTok(commandUri.GetPath(), L"/");
+ if(strTok.GetTokenCount() > 1) {
+ strTok.GetNextToken(callbackId);
+ AppLogDebug("Method %S, CallbackId: %S", method.GetPointer(), callbackId.GetPointer());
+ }
+ AppLogDebug("Method %S, Callback: %S", method.GetPointer(), callbackId.GetPointer());
// used to determine callback ID
- if(method == L"com.phonegap.Geolocation.watchPosition" && !uuid.IsEmpty() && !IsWatching()) {
+ if(method == L"com.phonegap.Geolocation.watchPosition" && !callbackId.IsEmpty() && !IsWatching()) {
AppLogDebug("watching position...");
StartWatching();
}
- if(method == L"com.phonegap.Geolocation.stop" && !uuid.IsEmpty() && IsWatching()) {
+ if(method == L"com.phonegap.Geolocation.stop" && IsWatching()) {
AppLogDebug("stop watching position...");
StopWatching();
}
- if(method == L"com.phonegap.Geolocation.getCurrentPosition" && !uuid.IsEmpty() && !IsWatching()) {
+ if(method == L"com.phonegap.Geolocation.getCurrentPosition" && !callbackId.IsEmpty() && !IsWatching()) {
AppLogDebug("getting current position...");
GetLastKnownLocation();
}
@@ -82,18 +82,16 @@
float heading = q->GetVerticalAccuracy();
float speed = location->GetSpeed();
long long timestamp = location->GetTimestamp();
- AppLogDebug("{latitude:%d,longitude:%d,altitude:%f,speed:%f,accuracy:%f,heading:%f,timestamp:%d}", latitude, longitude, altitude,
- speed, accuracy, heading, timestamp);
- String pos;
- pos.Format(256, L"{latitude:%d,longitude:%d,altitude:%f,speed:%f,accuracy:%f,heading:%f,timestamp:%d}", latitude, longitude, altitude,
- speed, accuracy, heading, timestamp);
+ AppLogDebug("new Coordinates(%d,%d,%f,%f,%f,%f)", latitude, longitude, altitude, speed, accuracy, heading);
+ String coordinates;
+ coordinates.Format(256, L"new Coordinates(%d,%d,%f,%f,%f,%f)", latitude, longitude, altitude, speed, accuracy, heading);
String res;
- res.Format(512, L"navigator.geolocation.success('%S', {message:%S})", uuid.GetPointer(), pos.GetPointer());
+ res.Format(512, L"PhoneGap.callbacks['%S'].success(new Position(%S,%d))", callbackId.GetPointer(), coordinates.GetPointer(), timestamp);
pWeb->EvaluateJavascriptN(res);
} else {
- AppLogDebug("navigator.geolocation.fail('%S', {status: '001',message:'Could not get location'});", uuid.GetPointer());
+ AppLogDebug("PhoneGap.callbacks['%S'].fail(new PositionError(0001,'Could not get location'))", callbackId.GetPointer());
String res;
- res.Format(256, L"navigator.geolocation.fail('%S', {status: '001',message:'Could not get location'});", uuid.GetPointer());
+ res.Format(256, L"PhoneGap.callbacks['%S'].fail(new PositionError(0001,'Could not get location'))", callbackId.GetPointer());
pWeb->EvaluateJavascriptN(res);
}
}
@@ -109,19 +107,16 @@
float heading = q->GetVerticalAccuracy();
float speed = location.GetSpeed();
long long timestamp = location.GetTimestamp();
- AppLogDebug("{latitude:%d,longitude:%d,altitude:%f,speed:%f,accuracy:%f,heading:%f,timestamp:%d}", latitude, longitude, altitude,
- speed, accuracy, heading, timestamp);
- String pos;
- pos.Format(256, L"{latitude:%d,longitude:%d,altitude:%f,speed:%f,accuracy:%f,heading:%f,timestamp:%d}", latitude, longitude, altitude,
- speed, accuracy, heading, timestamp);
+ AppLogDebug("new Coordinates(%d,%d,%f,%f,%f,%f)", latitude, longitude, altitude, speed, accuracy, heading);
+ String coordinates;
+ coordinates.Format(256, L"new Coordinates(%d,%d,%f,%f,%f,%f)", latitude, longitude, altitude, speed, accuracy, heading);
String res;
- res.Format(512, L"navigator.geolocation.success('%S', {message:%S})", uuid.GetPointer(), pos.GetPointer());
- AppLogDebug("%S", res.GetPointer());
+ res.Format(512, L"PhoneGap.callbacks['%S'].success(new Position(%S,%d))", callbackId.GetPointer(), coordinates.GetPointer(), timestamp);
pWeb->EvaluateJavascriptN(res);
} else {
- AppLogDebug("navigator.geolocation.fail('%S', {status: '001',message:'Could not get location'});", uuid.GetPointer());
+ AppLogDebug("PhoneGap.callbacks['%S'].fail(new PositionError(0001,'Could not get location'))", callbackId.GetPointer());
String res;
- res.Format(256, L"navigator.geolocation.fail('%S', {status: '001',message:'Could not get location'});", uuid.GetPointer());
+ res.Format(256, L"PhoneGap.callbacks['%S'].fail(new PositionError(0001,'Could not get location'))", callbackId.GetPointer());
pWeb->EvaluateJavascriptN(res);
}
}
diff --git a/src/WebForm.cpp b/src/WebForm.cpp
index b0dd1bf..87c922a 100755
--- a/src/WebForm.cpp
+++ b/src/WebForm.cpp
@@ -36,6 +36,7 @@
}
__pWeb->LoadUrl("file:///Res/index.html");
+ //__pWeb->LoadUrl("file:///Res/mobile-spec/index.html");
return r;