dom/mobileconnection/tests/marionette/test_mobile_signal_strength.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/mobileconnection/tests/marionette/test_mobile_signal_strength.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     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 = 30000;
     1.8 +MARIONETTE_HEAD_JS = "mobile_header.js";
     1.9 +
    1.10 +/* Emulator command for GSM/UMTS signal strength */
    1.11 +function setEmulatorGsmSignalStrength(rssi) {
    1.12 +  emulatorHelper.sendCommand("gsm signal " + rssi);
    1.13 +}
    1.14 +
    1.15 +/* Emulator command for LTE signal strength */
    1.16 +function setEmulatorLteSignalStrength(rxlev, rsrp, rssnr) {
    1.17 +  let lteSignal = rxlev + " " + rsrp + " " + rssnr;
    1.18 +  emulatorHelper.sendCommand("gsm lte_signal " + lteSignal);
    1.19 +}
    1.20 +
    1.21 +function waitForVoiceChangeEvent(callback) {
    1.22 +  mobileConnection.addEventListener("voicechange", function onvoicechange() {
    1.23 +    mobileConnection.removeEventListener("voicechange", onvoicechange);
    1.24 +
    1.25 +    if (callback && typeof callback === "function") {
    1.26 +      callback();
    1.27 +    }
    1.28 +  });
    1.29 +}
    1.30 +
    1.31 +/* Test Initial Signal Strength Info */
    1.32 +taskHelper.push(function testInitialSignalStrengthInfo() {
    1.33 +  log("Test initial signal strength info");
    1.34 +
    1.35 +  let voice = mobileConnection.voice;
    1.36 +  // Android emulator initializes the signal strength to -99 dBm
    1.37 +  is(voice.signalStrength, -99, "check voice.signalStrength");
    1.38 +  is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
    1.39 +
    1.40 +  taskHelper.runNext();
    1.41 +});
    1.42 +
    1.43 +/* Test Unsolicited Signal Strength Events for LTE */
    1.44 +taskHelper.push(function testLteSignalStrength() {
    1.45 +  // Set emulator's LTE signal strength and wait for 'onvoicechange' event.
    1.46 +  function doTestLteSignalStrength(input, expect, callback) {
    1.47 +    log("Test LTE signal info with data : " + JSON.stringify(input));
    1.48 +
    1.49 +    waitForVoiceChangeEvent(function() {
    1.50 +      let voice = mobileConnection.voice;
    1.51 +      is(voice.signalStrength, expect.signalStrength,
    1.52 +         "check voice.signalStrength");
    1.53 +      is(voice.relSignalStrength, expect.relSignalStrength,
    1.54 +         "check voice.relSignalStrength");
    1.55 +
    1.56 +      if (callback && typeof callback === "function") {
    1.57 +        callback();
    1.58 +      }
    1.59 +    });
    1.60 +
    1.61 +    setEmulatorLteSignalStrength(input.rxlev, input.rsrp, input.rssnr);
    1.62 +  }
    1.63 +
    1.64 +  let testData = [
    1.65 +    // All invalid case.
    1.66 +    {input: {
    1.67 +      rxlev: 99,
    1.68 +      rsrp: 65535,
    1.69 +      rssnr: 65535},
    1.70 +     expect: {
    1.71 +      signalStrength: null,
    1.72 +      relSignalStrength: null}
    1.73 +    },
    1.74 +    // Valid rxlev with max value.
    1.75 +    {input: {
    1.76 +      rxlev: 63,
    1.77 +      rsrp: 65535,
    1.78 +      rssnr: 65535},
    1.79 +     expect: {
    1.80 +      signalStrength: -48,
    1.81 +      relSignalStrength: 100}
    1.82 +    },
    1.83 +    // Valid rxlev.
    1.84 +    {input: {
    1.85 +      rxlev: 12,
    1.86 +      rsrp: 65535,
    1.87 +      rssnr: 65535},
    1.88 +     expect: {
    1.89 +      signalStrength: -99,
    1.90 +      relSignalStrength: 100}
    1.91 +    },
    1.92 +    // Valid rxlev with min value.
    1.93 +    {input: {
    1.94 +      rxlev: 0,
    1.95 +      rsrp: 65535,
    1.96 +      rssnr: 65535},
    1.97 +     expect: {
    1.98 +      signalStrength: -111,
    1.99 +      relSignalStrength: 0}
   1.100 +    }
   1.101 +  ];
   1.102 +
   1.103 +  // Run all test data.
   1.104 +  (function do_call() {
   1.105 +    let next = testData.shift();
   1.106 +    if (!next) {
   1.107 +      taskHelper.runNext();
   1.108 +      return;
   1.109 +    }
   1.110 +    doTestLteSignalStrength(next.input, next.expect, do_call);
   1.111 +  })();
   1.112 +});
   1.113 +
   1.114 +/* Reset Signal Strength Info to default, and finsih the test */
   1.115 +taskHelper.push(function testResetSignalStrengthInfo() {
   1.116 +  // Reset emulator's signal strength and wait for 'onvoicechange' event.
   1.117 +  function doResetSignalStrength(rssi) {
   1.118 +    waitForVoiceChangeEvent(function() {
   1.119 +      let voice = mobileConnection.voice;
   1.120 +      is(voice.signalStrength, -99, "check voice.signalStrength");
   1.121 +      is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
   1.122 +
   1.123 +      taskHelper.runNext();
   1.124 +    });
   1.125 +
   1.126 +    setEmulatorGsmSignalStrength(rssi);
   1.127 +  }
   1.128 +
   1.129 +  // Emulator uses rssi = 7 as default value, and we need to reset it after
   1.130 +  // finishing test in case other test cases need those values for testing.
   1.131 +  doResetSignalStrength(7);
   1.132 +});
   1.133 +
   1.134 +// Start test
   1.135 +taskHelper.runNext();

mercurial