Chromium Code Reviews| Index: LayoutTests/http/tests/geofencing/event_triggering.html |
| diff --git a/LayoutTests/http/tests/geofencing/event_triggering.html b/LayoutTests/http/tests/geofencing/event_triggering.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cdab52560c11c50cc8a9dbc9e03d3290664f2a34 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/geofencing/event_triggering.html |
| @@ -0,0 +1,68 @@ |
| +<!DOCTYPE html> |
| +<title>Tests registering regions and receiving events.</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="../resources/testharness-helpers.js"></script> |
| +<script src="../serviceworker/resources/test-helpers.js"></script> |
| +<script> |
| +var sw_url = 'resources/worker-passes-events-back.js'; |
| +var sw_scope = 'resources/service-worker-scope' + window.location.pathname; |
| + |
|
scheib
2014/12/08 16:40:13
Maybe include a first test before anything that us
Marijn Kruisselbrink
2014/12/11 04:43:37
Done.
|
| +testRunner.setGeofencingMockProvider(true); |
| + |
| +// Returns a promise that resolves to the first message received by |port|. |
| +// Removes any message event handlers that might exist on the |port|. |
| +function wait_for_reply(t, port) { |
| + return new Promise(function(resolve) { |
| + port.onmessage = t.step_func(function(event) { |
| + port.onmessage = null; |
| + resolve(event.data); |
| + }); |
| + }); |
| +} |
| + |
| +promise_test(function(test) { |
| + var registration; |
| + var port; |
| + return service_worker_unregister_and_register(test, sw_url, sw_scope) |
| + .then(test.step_func(function(r) { |
| + registration = r; |
| + return wait_for_activated(test, registration); |
| + })).then(test.step_func(function() { |
| + var channel = new MessageChannel(); |
| + port = channel.port1; |
| + registration.active.postMessage({port: channel.port2}, [channel.port2]); |
| + return wait_for_reply(test, port); |
| + })).then(test.step_func(function(reply) { |
| + assert_equals(reply, 'setup'); |
| + return registration.geofencing.registerRegion( |
| + new CircularGeofencingRegion({id: 'myid', |
| + latitude: 37.421999, |
| + longitude: -122.084015, |
| + radius: 10})); |
| + })).then(test.step_func(function() { |
| + testRunner.setGeofencingMockPosition(37.422, -122.084015); |
|
scheib
2014/12/08 16:40:13
What is the initial position of the Mock? Should t
Marijn Kruisselbrink
2014/12/11 04:43:37
The initial position is "no position", which isn't
|
| + return wait_for_reply(test, port); |
| + })).then(test.step_func(function(reply) { |
| + assert_equals(reply.event, 'geofenceenter'); |
| + assert_equals(reply.id, 'myid'); |
| + testRunner.setGeofencingMockPosition(37.423, -122.084015); |
| + return wait_for_reply(test, port); |
| + })).then(test.step_func(function(reply) { |
| + assert_equals(reply.event, 'geofenceleave'); |
| + assert_equals(reply.id, 'myid'); |
| + return registration.geofencing.registerRegion( |
| + new CircularGeofencingRegion({id: 'bigregion', |
| + latitude: 37.421999, |
| + longitude: -122.084015, |
| + radius: 200})); |
| + })).then(test.step_func(function() { |
| + return wait_for_reply(test, port); |
| + })).then(test.step_func(function(reply) { |
| + assert_equals(reply.event, 'geofenceenter'); |
| + assert_equals(reply.id, 'bigregion'); |
| + return service_worker_unregister(test, sw_scope); |
| + })); |
| + }, 'Tests basic enter and leave events.'); |
| + |
| +</script> |