1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/tests/marionette/test_proximity_init.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 10000; 1.8 + 1.9 +function testEventInit() { 1.10 + let initValue = 7; 1.11 + let initMin = 1; 1.12 + let initMax = 30; 1.13 + 1.14 + // Test DeviceProximityEvent initialization 1.15 + log("Verifying DeviceProximityEvent constructor."); 1.16 + let event = new DeviceProximityEvent("deviceproximity", 1.17 + {value: initValue, min: initMin, max: initMax}); 1.18 + is(event.type, "deviceproximity", "event type"); 1.19 + is(event.value, initValue, "value"); 1.20 + is(event.min, initMin, "min"); 1.21 + is(event.max, initMax, "max"); 1.22 + if (event.value !== initValue || 1.23 + event.min !== initMin || 1.24 + event.max !== initMax) { 1.25 + log("DeviceProximityEvent not initialized correctly."); 1.26 + } 1.27 + 1.28 + // Test UserProximityEvent initialization 1.29 + log("Verifying UserProximityEvent constructor."); 1.30 + let event = new UserProximityEvent("userproximity", {near: true}); 1.31 + is(event.type, "userproximity", "event type"); 1.32 + ok(event.near, "Initialization of UserProximityEvent"); 1.33 + verifyDefaultStatus(); 1.34 +} 1.35 + 1.36 +function verifyDefaultStatus() { 1.37 + let emulatorDone = false; 1.38 + 1.39 + // Ensure that device proximity is enabled by default 1.40 + log("Getting sensor status from emulator."); 1.41 + 1.42 + runEmulatorCmd("sensor status", function(result) { 1.43 + log("Received sensor status (" + result[4] + ")."); 1.44 + is(result[4], "proximity: enabled.", "Proximity sensor enabled by default"); 1.45 + emulatorDone = true; 1.46 + }); 1.47 + 1.48 + // Have this here so test doesn't drop out if emulator callback is slow 1.49 + waitFor(getDefaultProximity, function() { 1.50 + return(emulatorDone); 1.51 + }); 1.52 +} 1.53 + 1.54 +function getDefaultProximity() { 1.55 + let expected = "1:0:0"; 1.56 + 1.57 + // Get and verify the default emulator proximity value 1.58 + log("Getting device proximity from emulator."); 1.59 + 1.60 + runEmulatorCmd("sensor get proximity", function(result) { 1.61 + let values = result[0].split(" ")[2]; 1.62 + log("Received emulator proximity (" + values + ")."); 1.63 + is(values, "1:0:0", "Default proximity values"); 1.64 + cleanUp(); 1.65 + }); 1.66 +} 1.67 + 1.68 +function cleanUp() { 1.69 + finish(); 1.70 +} 1.71 + 1.72 +// Start the test 1.73 +testEventInit();