Hello andreip,
I'd like you to do a code review. Please execute
g4 diff -c 9144509
or point your web browser to
http://mondrian/9144509
to review the following code:
Change 9144509 by [EMAIL PROTECTED] on 2008/11/25 00:56:12 *pending*
Adds a further Geolocation timeout test.
R=andreip
[EMAIL PROTECTED]
DELTA=102 (102 added, 0 deleted, 0 changed)
OCL=9144509
Affected files ...
... //depot/googleclient/gears/opensource/gears/cctests/test.cc#88 edit
... //depot/googleclient/gears/opensource/gears/cctests/test.h#29 edit
...
//depot/googleclient/gears/opensource/gears/geolocation/geolocation_test.cc#35
edit
...
//depot/googleclient/gears/opensource/gears/geolocation/geolocation_test.h#12
edit
...
//depot/googleclient/gears/opensource/gears/test/testcases/internal_geolocation_tests.js#11
edit
102 delta lines: 102 added, 0 deleted, 0 changed
Also consider running:
g4 lint -c 9144509
which verifies that the changelist doesn't introduce new style violations.
If you can't do the review, please let me know as soon as possible. During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately. Visit
http://www/eng/code_review.html for more information.
This is a semiautomated message from "g4 mail". Complaints or suggestions?
Mail [EMAIL PROTECTED]
Change 9144509 by [EMAIL PROTECTED] on 2008/11/25 00:56:12 *pending*
Adds a further Geolocation timeout test.
Affected files ...
... //depot/googleclient/gears/opensource/gears/cctests/test.cc#88 edit
... //depot/googleclient/gears/opensource/gears/cctests/test.h#29 edit
...
//depot/googleclient/gears/opensource/gears/geolocation/geolocation_test.cc#35
edit
...
//depot/googleclient/gears/opensource/gears/geolocation/geolocation_test.h#12
edit
...
//depot/googleclient/gears/opensource/gears/test/testcases/internal_geolocation_tests.js#11
edit
==== //depot/googleclient/gears/opensource/gears/cctests/test.cc#88 -
c:\MyDocs\Gears2/googleclient/gears/opensource/gears/cctests/test.cc ====
# action=edit type=text
--- googleclient/gears/opensource/gears/cctests/test.cc 2008-11-20
17:26:07.000000000 +0000
+++ googleclient/gears/opensource/gears/cctests/test.cc 2008-11-25
00:36:49.000000000 +0000
@@ -89,6 +89,8 @@
&GearsTest::ConfigureGeolocationWifiDataProviderForTest);
RegisterMethod("configureGeolocationMockLocationProviderForTest",
&GearsTest::ConfigureGeolocationMockLocationProviderForTest);
+ RegisterMethod("reportMovementInMockLocationProvider",
+ &GearsTest::ReportMovementInMockLocationProvider);
RegisterMethod("removeGeolocationMockLocationProvider",
&GearsTest::RemoveGeolocationMockLocationProvider);
#ifdef OS_ANDROID
@@ -2160,6 +2162,10 @@
::ConfigureGeolocationMockLocationProviderForTest(context);
}
+void GearsTest::ReportMovementInMockLocationProvider(JsCallContext *context) {
+ ::ReportMovementInMockLocationProvider(context);
+}
+
void GearsTest::RemoveGeolocationMockLocationProvider(
JsCallContext * /* context */) {
::RemoveGeolocationMockLocationProvider();
==== //depot/googleclient/gears/opensource/gears/cctests/test.h#29 -
c:\MyDocs\Gears2/googleclient/gears/opensource/gears/cctests/test.h ====
# action=edit type=text
--- googleclient/gears/opensource/gears/cctests/test.h 2008-11-25
12:35:16.000000000 +0000
+++ googleclient/gears/opensource/gears/cctests/test.h 2008-11-25
00:46:18.000000000 +0000
@@ -182,8 +182,16 @@
// OUT: nothing
void ConfigureGeolocationMockLocationProviderForTest(JsCallContext *context);
+ // Causes the mock location provider to report movement to the arbitrator.
+ // This can be used to test the timeout parameter.
+ // IN: nothing
+ // OUT: nothing
+ void ReportMovementInMockLocationProvider(JsCallContext *context);
+
// Configures the location provider pool to not use the mock location
// provider.
+ // IN: nothing
+ // OUT: nothing
void RemoveGeolocationMockLocationProvider(JsCallContext *context);
#ifdef OS_ANDROID
====
//depot/googleclient/gears/opensource/gears/geolocation/geolocation_test.cc#35
-
c:\MyDocs\Gears2/googleclient/gears/opensource/gears/geolocation/geolocation_test.cc
====
# action=edit type=text
--- googleclient/gears/opensource/gears/geolocation/geolocation_test.cc
2008-11-25 12:35:17.000000000 +0000
+++ googleclient/gears/opensource/gears/geolocation/geolocation_test.cc
2008-11-25 12:17:43.000000000 +0000
@@ -186,6 +186,11 @@
worker_event_.Signal();
}
+ static void ReportMovement() {
+ is_movement_detected_ = true;
+ worker_event_.Signal();
+ }
+
private:
// LocationProviderBase implementation.
virtual void GetPosition(Position *position) {
@@ -203,6 +208,9 @@
UpdateListeners();
is_new_position_available_ = false;
is_new_listener_waiting_ = false;
+ } else if (is_movement_detected_) {
+ InformListenersOfMovement();
+ is_movement_detected_ = false;
}
}
}
@@ -210,6 +218,7 @@
static Position position_;
static Mutex position_mutex_;
static bool is_new_position_available_;
+ static bool is_movement_detected_;
static Event worker_event_;
bool is_shutting_down_;
@@ -228,6 +237,9 @@
// static
bool MockLocationProvider::is_new_position_available_ = false;
+
+// static
+bool MockLocationProvider::is_movement_detected_ = false;
// static
Event MockLocationProvider::worker_event_;
@@ -598,6 +610,10 @@
LocationProviderPool::GetInstance()->UseMockLocationProvider(true);
}
+void ReportMovementInMockLocationProvider(JsCallContext *context) {
+ MockLocationProvider::ReportMovement();
+}
+
void RemoveGeolocationMockLocationProvider() {
LocationProviderPool::GetInstance()->UseMockLocationProvider(false);
}
====
//depot/googleclient/gears/opensource/gears/geolocation/geolocation_test.h#12 -
c:\MyDocs\Gears2/googleclient/gears/opensource/gears/geolocation/geolocation_test.h
====
# action=edit type=text
--- googleclient/gears/opensource/gears/geolocation/geolocation_test.h
2008-11-25 12:35:17.000000000 +0000
+++ googleclient/gears/opensource/gears/geolocation/geolocation_test.h
2008-11-25 00:49:08.000000000 +0000
@@ -110,7 +110,15 @@
// OUT: nothing
void ConfigureGeolocationMockLocationProviderForTest(JsCallContext *context);
+// Causes the mock location provider to report movement to the arbitrator. This
+// can be used to test the timeout parameter.
+// IN: nothing
+// OUT: nothing
+void ReportMovementInMockLocationProvider(JsCallContext *context);
+
// Configures the location provider pool to not use the mock location provider.
+// IN: nothing
+// OUT: nothing
void RemoveGeolocationMockLocationProvider();
// Configures the GPS location provider to use a mock GPS device and sets the
====
//depot/googleclient/gears/opensource/gears/test/testcases/internal_geolocation_tests.js#11
-
c:\MyDocs\Gears2/googleclient/gears/opensource/gears/test/testcases/internal_geolocation_tests.js
====
# action=edit type=text
---
googleclient/gears/opensource/gears/test/testcases/internal_geolocation_tests.js
2008-11-25 12:35:17.000000000 +0000
+++
googleclient/gears/opensource/gears/test/testcases/internal_geolocation_tests.js
2008-11-25 12:17:49.000000000 +0000
@@ -25,6 +25,7 @@
// Error code values. These values must match those in geolocation.h.
var ERROR_CODE_POSITION_UNAVAILABLE = 2;
+var ERROR_CODE_TIMEOUT = 3;
if (isUsingCCTests) {
var internalTests = google.gears.factory.create('beta.test');
@@ -575,3 +576,66 @@
geolocation.getCurrentPosition(locationAvailable, null, options);
}
}
+
+function testWatchTimeout() {
+ // Here we test that in the case of a watch, we get a success callback if a
+ // position fix is obtained within the timeout, and an error callback if it
is
+ // not. We use the mock location provider to do this.
+ if (isUsingCCTests) {
+ var options = {
+ timeout: 200,
+ gearsLocationProviderUrls: []
+ };
+ var mockPosition1 = {
+ latitude: 51.0,
+ longitude: -0.1,
+ accuracy: 100.1
+ };
+ var mockPosition2 = {
+ latitude: 52.0,
+ longitude: -1.1,
+ accuracy: 101.1
+ };
+ var expectedError = {
+ code: ERROR_CODE_TIMEOUT,
+ message: 'A position fix was not obtained within the specified time ' +
+ 'limit.'
+ }
+ var state = 0;
+ function successCallback(position) {
+ assert(state == 0 || state == 1,
+ 'Success callback should be called first.');
+ delete position.timestamp;
+ if (state == 0) {
+ state = 1;
+ assertObjectEqual(mockPosition1, position);
+ // Report movement then schedule a position update within the timeout
+ // period.
+ internalTests.reportMovementInMockLocationProvider();
+ timer.setTimeout(function() {
+ internalTests.configureGeolocationMockLocationProviderForTest(
+ mockPosition2);
+ }, 100);
+ } else {
+ state = 2;
+ assertObjectEqual(mockPosition2, position);
+ // Report movement but do not follow with a position update.
+ internalTests.reportMovementInMockLocationProvider();
+ }
+ };
+ function errorCallback(error) {
+ assert(state == 2, 'Error callback should be called last.');
+ assertObjectEqual(expectedError, error);
+ geolocation.clearWatch(watchId);
+ internalTests.removeGeolocationMockLocationProvider();
+ completeAsync();
+ };
+ var geolocation = google.gears.factory.create('beta.geolocation');
+ var timer = google.gears.factory.create('beta.timer');
+ internalTests.configureGeolocationMockLocationProviderForTest(
+ mockPosition1);
+ startAsync();
+ var watchId =
+ geolocation.watchPosition(successCallback, errorCallback, options);
+ }
+}