dom/system/tests/marionette/test_proximity_init.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2766635843e6
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 MARIONETTE_TIMEOUT = 10000;
5
6 function testEventInit() {
7 let initValue = 7;
8 let initMin = 1;
9 let initMax = 30;
10
11 // Test DeviceProximityEvent initialization
12 log("Verifying DeviceProximityEvent constructor.");
13 let event = new DeviceProximityEvent("deviceproximity",
14 {value: initValue, min: initMin, max: initMax});
15 is(event.type, "deviceproximity", "event type");
16 is(event.value, initValue, "value");
17 is(event.min, initMin, "min");
18 is(event.max, initMax, "max");
19 if (event.value !== initValue ||
20 event.min !== initMin ||
21 event.max !== initMax) {
22 log("DeviceProximityEvent not initialized correctly.");
23 }
24
25 // Test UserProximityEvent initialization
26 log("Verifying UserProximityEvent constructor.");
27 let event = new UserProximityEvent("userproximity", {near: true});
28 is(event.type, "userproximity", "event type");
29 ok(event.near, "Initialization of UserProximityEvent");
30 verifyDefaultStatus();
31 }
32
33 function verifyDefaultStatus() {
34 let emulatorDone = false;
35
36 // Ensure that device proximity is enabled by default
37 log("Getting sensor status from emulator.");
38
39 runEmulatorCmd("sensor status", function(result) {
40 log("Received sensor status (" + result[4] + ").");
41 is(result[4], "proximity: enabled.", "Proximity sensor enabled by default");
42 emulatorDone = true;
43 });
44
45 // Have this here so test doesn't drop out if emulator callback is slow
46 waitFor(getDefaultProximity, function() {
47 return(emulatorDone);
48 });
49 }
50
51 function getDefaultProximity() {
52 let expected = "1:0:0";
53
54 // Get and verify the default emulator proximity value
55 log("Getting device proximity from emulator.");
56
57 runEmulatorCmd("sensor get proximity", function(result) {
58 let values = result[0].split(" ")[2];
59 log("Received emulator proximity (" + values + ").");
60 is(values, "1:0:0", "Default proximity values");
61 cleanUp();
62 });
63 }
64
65 function cleanUp() {
66 finish();
67 }
68
69 // Start the test
70 testEventInit();

mercurial