diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/system/tests/marionette/test_proximity_change.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/system/tests/marionette/test_proximity_change.js')
-rw-r--r-- | dom/system/tests/marionette/test_proximity_change.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/dom/system/tests/marionette/test_proximity_change.js b/dom/system/tests/marionette/test_proximity_change.js new file mode 100644 index 000000000..a4c54f12b --- /dev/null +++ b/dom/system/tests/marionette/test_proximity_change.js @@ -0,0 +1,83 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +MARIONETTE_TIMEOUT = 10000; + +var receivedEvent = false; +var expectedEvent; + +function enableProximityListener() { + // Setup device proximity event listener, expect defaults + log("Enabling 'deviceproximity' event listener."); + + // Bug 814043: Device proximity event 'min' and 'max' attributes incorrect + // Until that is fixed, expect 1:0:1 instead of 1:0:0 + // expectedEvent = new DeviceProximityEvent("deviceproximity", + // {value:1, min:0, max:0}); + expectedEvent = new DeviceProximityEvent("deviceproximity", + {value:1, min:0, max:1}); + + window.addEventListener('deviceproximity', listener); + log("Waiting for device proximity event."); + waitFor(changeProximity, function() { + return(receivedEvent); + }); +} + +function listener(event) { + // Received proximity update + log("Received 'deviceproximity' event via listener (value:" + + event.value + " min:" + event.min + " max:" + event.max + ")."); + // Verify event values are as expected + is(event.value, expectedEvent.value, "value"); + is(event.min, expectedEvent.min, "min"); + is(event.max, expectedEvent.max, "max"); + receivedEvent = true; +} + +function changeProximity() { + // Change emulator's proximity and verify event attributes + let newValue = "7:3:15"; + + // Bug 814043: Device proximity event 'min' and 'max' attributes won't change + // Until fixed, expect proximity event min to be '0' and max to be '1' always + // expectedEvent = new DeviceProximityEvent("deviceproximity", + // {value: 7, min: 3, max: 15}); + expectedEvent = new DeviceProximityEvent("deviceproximity", + {value:7, min:0, max:1}); + + // Setup handler and verify 'ondeviceproximity' event + window.ondeviceproximity = function(event) { + log("Received 'ondeviceproximity' event via handler (value:" + + event.value + " min:" + event.min + " max:" + + event.max + ")."); + is(event.value, expectedEvent.value, "value"); + is(event.min, expectedEvent.min, "min"); + is(event.max, expectedEvent.max, "max"); + // Turn off event handler and listener + window.ondeviceproximity = null; + window.removeEventListener('deviceproximity', listener); + restoreProximity(); + }; + + log("Sending emulator command to fake proximity change (" + newValue + ")."); + runEmulatorCmd("sensor set proximity " + newValue, function(result) { + log("Emulator callback."); + }); +} + +function restoreProximity() { + // Set the emulator's proximity value back to original + newValue = "1:0:0"; + log("Sending emulator command to restore proximity (" + newValue + ")."); + runEmulatorCmd("sensor set proximity " + newValue, function(result) { + cleanUp(); + }); +} + +function cleanUp() { + finish(); +} + +// Start the test +enableProximityListener(); |