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..428bc9977d0132105e5ae911726c87ccf6dccd0c |
--- /dev/null |
+++ b/LayoutTests/http/tests/geofencing/event_triggering.html |
@@ -0,0 +1,73 @@ |
+<!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; |
+ |
+test(function(test) { |
+ assert_exists(window, 'testRunner'); |
+ test.done(); |
+ }, 'window.testRunner is required for the following tests.'); |
+ |
+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_state(test, r.installing, 'activated'); |
+ })).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); |
+ 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> |