Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | MARIONETTE_TIMEOUT = 10000; |
michael@0 | 5 | |
michael@0 | 6 | let receivedEvent = false; |
michael@0 | 7 | let expectedEvent; |
michael@0 | 8 | |
michael@0 | 9 | function enableProximityListener() { |
michael@0 | 10 | // Setup device proximity event listener, expect defaults |
michael@0 | 11 | log("Enabling 'deviceproximity' event listener."); |
michael@0 | 12 | |
michael@0 | 13 | // Bug 814043: Device proximity event 'min' and 'max' attributes incorrect |
michael@0 | 14 | // Until that is fixed, expect 1:0:1 instead of 1:0:0 |
michael@0 | 15 | // expectedEvent = new DeviceProximityEvent("deviceproximity", |
michael@0 | 16 | // {value:1, min:0, max:0}); |
michael@0 | 17 | expectedEvent = new DeviceProximityEvent("deviceproximity", |
michael@0 | 18 | {value:1, min:0, max:1}); |
michael@0 | 19 | |
michael@0 | 20 | window.addEventListener('deviceproximity', listener); |
michael@0 | 21 | log("Waiting for device proximity event."); |
michael@0 | 22 | waitFor(changeProximity, function() { |
michael@0 | 23 | return(receivedEvent); |
michael@0 | 24 | }); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function listener(event) { |
michael@0 | 28 | // Received proximity update |
michael@0 | 29 | log("Received 'deviceproximity' event via listener (value:" |
michael@0 | 30 | + event.value + " min:" + event.min + " max:" + event.max + ")."); |
michael@0 | 31 | // Verify event values are as expected |
michael@0 | 32 | is(event.value, expectedEvent.value, "value"); |
michael@0 | 33 | is(event.min, expectedEvent.min, "min"); |
michael@0 | 34 | is(event.max, expectedEvent.max, "max"); |
michael@0 | 35 | receivedEvent = true; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function changeProximity() { |
michael@0 | 39 | // Change emulator's proximity and verify event attributes |
michael@0 | 40 | let newValue = "7:3:15"; |
michael@0 | 41 | |
michael@0 | 42 | // Bug 814043: Device proximity event 'min' and 'max' attributes won't change |
michael@0 | 43 | // Until fixed, expect proximity event min to be '0' and max to be '1' always |
michael@0 | 44 | // expectedEvent = new DeviceProximityEvent("deviceproximity", |
michael@0 | 45 | // {value: 7, min: 3, max: 15}); |
michael@0 | 46 | expectedEvent = new DeviceProximityEvent("deviceproximity", |
michael@0 | 47 | {value:7, min:0, max:1}); |
michael@0 | 48 | |
michael@0 | 49 | // Setup handler and verify 'ondeviceproximity' event |
michael@0 | 50 | window.ondeviceproximity = function(event) { |
michael@0 | 51 | log("Received 'ondeviceproximity' event via handler (value:" |
michael@0 | 52 | + event.value + " min:" + event.min + " max:" |
michael@0 | 53 | + event.max + ")."); |
michael@0 | 54 | is(event.value, expectedEvent.value, "value"); |
michael@0 | 55 | is(event.min, expectedEvent.min, "min"); |
michael@0 | 56 | is(event.max, expectedEvent.max, "max"); |
michael@0 | 57 | // Turn off event handler and listener |
michael@0 | 58 | window.ondeviceproximity = null; |
michael@0 | 59 | window.removeEventListener('deviceproximity', listener); |
michael@0 | 60 | restoreProximity(); |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | log("Sending emulator command to fake proximity change (" + newValue + ")."); |
michael@0 | 64 | runEmulatorCmd("sensor set proximity " + newValue, function(result) { |
michael@0 | 65 | log("Emulator callback."); |
michael@0 | 66 | }); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function restoreProximity() { |
michael@0 | 70 | // Set the emulator's proximity value back to original |
michael@0 | 71 | newValue = "1:0:0"; |
michael@0 | 72 | log("Sending emulator command to restore proximity (" + newValue + ")."); |
michael@0 | 73 | runEmulatorCmd("sensor set proximity " + newValue, function(result) { |
michael@0 | 74 | cleanUp(); |
michael@0 | 75 | }); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function cleanUp() { |
michael@0 | 79 | finish(); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | // Start the test |
michael@0 | 83 | enableProximityListener(); |