| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>Tests registering regions and receiving events.</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="../serviceworker/resources/test-helpers.js"></script> | |
| 6 <script> | |
| 7 var sw_url = 'resources/worker-passes-events-back.js'; | |
| 8 var sw_scope = 'resources/service-worker-scope' + window.location.pathname; | |
| 9 | |
| 10 test(function(test) { | |
| 11 assert_true(window.testRunner instanceof Object); | |
| 12 test.done(); | |
| 13 }, 'window.testRunner is required for the following tests.'); | |
| 14 | |
| 15 testRunner.setGeofencingMockProvider(true); | |
| 16 | |
| 17 // Returns a promise that resolves to the first message received by |port|. | |
| 18 // Removes any message event handlers that might exist on the |port|. | |
| 19 function wait_for_reply(t, port) { | |
| 20 return new Promise(function(resolve) { | |
| 21 port.onmessage = t.step_func(function(event) { | |
| 22 port.onmessage = null; | |
| 23 resolve(event.data); | |
| 24 }); | |
| 25 }); | |
| 26 } | |
| 27 | |
| 28 promise_test(function(test) { | |
| 29 var registration; | |
| 30 var port; | |
| 31 return service_worker_unregister_and_register(test, sw_url, sw_scope) | |
| 32 .then(test.step_func(function(r) { | |
| 33 registration = r; | |
| 34 return wait_for_state(test, r.installing, 'activated'); | |
| 35 })).then(test.step_func(function() { | |
| 36 var channel = new MessageChannel(); | |
| 37 port = channel.port1; | |
| 38 registration.active.postMessage({port: channel.port2}, [channel.port2]
); | |
| 39 return wait_for_reply(test, port); | |
| 40 })).then(test.step_func(function(reply) { | |
| 41 assert_equals(reply, 'setup'); | |
| 42 return registration.geofencing.registerRegion( | |
| 43 new CircularGeofencingRegion({id: 'myid', | |
| 44 latitude: 37.421999, | |
| 45 longitude: -122.084015, | |
| 46 radius: 10})); | |
| 47 })).then(test.step_func(function() { | |
| 48 testRunner.setGeofencingMockPosition(37.422, -122.084015); | |
| 49 return wait_for_reply(test, port); | |
| 50 })).then(test.step_func(function(reply) { | |
| 51 assert_equals(reply.event, 'geofenceenter'); | |
| 52 assert_equals(reply.id, 'myid'); | |
| 53 testRunner.setGeofencingMockPosition(37.423, -122.084015); | |
| 54 return wait_for_reply(test, port); | |
| 55 })).then(test.step_func(function(reply) { | |
| 56 assert_equals(reply.event, 'geofenceleave'); | |
| 57 assert_equals(reply.id, 'myid'); | |
| 58 return registration.geofencing.registerRegion( | |
| 59 new CircularGeofencingRegion({id: 'bigregion', | |
| 60 latitude: 37.421999, | |
| 61 longitude: -122.084015, | |
| 62 radius: 200})); | |
| 63 })).then(test.step_func(function() { | |
| 64 return wait_for_reply(test, port); | |
| 65 })).then(test.step_func(function(reply) { | |
| 66 assert_equals(reply.event, 'geofenceenter'); | |
| 67 assert_equals(reply.id, 'bigregion'); | |
| 68 return service_worker_unregister(test, sw_scope); | |
| 69 })); | |
| 70 }, 'Tests basic enter and leave events.'); | |
| 71 | |
| 72 </script> | |
| OLD | NEW |