dom/mobileconnection/tests/marionette/test_mobile_signal_strength.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:70fd589afbf3
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 MARIONETTE_TIMEOUT = 30000;
5 MARIONETTE_HEAD_JS = "mobile_header.js";
6
7 /* Emulator command for GSM/UMTS signal strength */
8 function setEmulatorGsmSignalStrength(rssi) {
9 emulatorHelper.sendCommand("gsm signal " + rssi);
10 }
11
12 /* Emulator command for LTE signal strength */
13 function setEmulatorLteSignalStrength(rxlev, rsrp, rssnr) {
14 let lteSignal = rxlev + " " + rsrp + " " + rssnr;
15 emulatorHelper.sendCommand("gsm lte_signal " + lteSignal);
16 }
17
18 function waitForVoiceChangeEvent(callback) {
19 mobileConnection.addEventListener("voicechange", function onvoicechange() {
20 mobileConnection.removeEventListener("voicechange", onvoicechange);
21
22 if (callback && typeof callback === "function") {
23 callback();
24 }
25 });
26 }
27
28 /* Test Initial Signal Strength Info */
29 taskHelper.push(function testInitialSignalStrengthInfo() {
30 log("Test initial signal strength info");
31
32 let voice = mobileConnection.voice;
33 // Android emulator initializes the signal strength to -99 dBm
34 is(voice.signalStrength, -99, "check voice.signalStrength");
35 is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
36
37 taskHelper.runNext();
38 });
39
40 /* Test Unsolicited Signal Strength Events for LTE */
41 taskHelper.push(function testLteSignalStrength() {
42 // Set emulator's LTE signal strength and wait for 'onvoicechange' event.
43 function doTestLteSignalStrength(input, expect, callback) {
44 log("Test LTE signal info with data : " + JSON.stringify(input));
45
46 waitForVoiceChangeEvent(function() {
47 let voice = mobileConnection.voice;
48 is(voice.signalStrength, expect.signalStrength,
49 "check voice.signalStrength");
50 is(voice.relSignalStrength, expect.relSignalStrength,
51 "check voice.relSignalStrength");
52
53 if (callback && typeof callback === "function") {
54 callback();
55 }
56 });
57
58 setEmulatorLteSignalStrength(input.rxlev, input.rsrp, input.rssnr);
59 }
60
61 let testData = [
62 // All invalid case.
63 {input: {
64 rxlev: 99,
65 rsrp: 65535,
66 rssnr: 65535},
67 expect: {
68 signalStrength: null,
69 relSignalStrength: null}
70 },
71 // Valid rxlev with max value.
72 {input: {
73 rxlev: 63,
74 rsrp: 65535,
75 rssnr: 65535},
76 expect: {
77 signalStrength: -48,
78 relSignalStrength: 100}
79 },
80 // Valid rxlev.
81 {input: {
82 rxlev: 12,
83 rsrp: 65535,
84 rssnr: 65535},
85 expect: {
86 signalStrength: -99,
87 relSignalStrength: 100}
88 },
89 // Valid rxlev with min value.
90 {input: {
91 rxlev: 0,
92 rsrp: 65535,
93 rssnr: 65535},
94 expect: {
95 signalStrength: -111,
96 relSignalStrength: 0}
97 }
98 ];
99
100 // Run all test data.
101 (function do_call() {
102 let next = testData.shift();
103 if (!next) {
104 taskHelper.runNext();
105 return;
106 }
107 doTestLteSignalStrength(next.input, next.expect, do_call);
108 })();
109 });
110
111 /* Reset Signal Strength Info to default, and finsih the test */
112 taskHelper.push(function testResetSignalStrengthInfo() {
113 // Reset emulator's signal strength and wait for 'onvoicechange' event.
114 function doResetSignalStrength(rssi) {
115 waitForVoiceChangeEvent(function() {
116 let voice = mobileConnection.voice;
117 is(voice.signalStrength, -99, "check voice.signalStrength");
118 is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
119
120 taskHelper.runNext();
121 });
122
123 setEmulatorGsmSignalStrength(rssi);
124 }
125
126 // Emulator uses rssi = 7 as default value, and we need to reset it after
127 // finishing test in case other test cases need those values for testing.
128 doResetSignalStrength(7);
129 });
130
131 // Start test
132 taskHelper.runNext();

mercurial