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