dom/mobileconnection/tests/marionette/test_mobile_data_state.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_data_state.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     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 = 60000;
     1.8 +MARIONETTE_HEAD_JS = "head.js";
     1.9 +
    1.10 +const INITIAL_STATES = {
    1.11 +  state: "registered",
    1.12 +  connected: false,
    1.13 +  emergencyCallsOnly: false,
    1.14 +  roaming: false,
    1.15 +  signalStrength: -99,
    1.16 +  relSignalStrength: 44,
    1.17 +
    1.18 +  cell: {
    1.19 +    gsmLocationAreaCode: 65535,
    1.20 +    gsmCellId: 268435455,
    1.21 +    cdmaBaseStationId: -1,
    1.22 +    cdmaBaseStationLatitude: -2147483648,
    1.23 +    cdmaBaseStationLongitude: -2147483648,
    1.24 +    cdmaSystemId: -1,
    1.25 +    cdmaNetworkId: -1,
    1.26 +  }
    1.27 +};
    1.28 +
    1.29 +const TEST_DATA = [{
    1.30 +    // Test state becomes to "unregistered"
    1.31 +    state: "unregistered",
    1.32 +    expected: {
    1.33 +      state: "notSearching",
    1.34 +      connected: false,
    1.35 +      emergencyCallsOnly: true,
    1.36 +      roaming: false,
    1.37 +      signalStrength: null,
    1.38 +      relSignalStrength: null,
    1.39 +      cell: null
    1.40 +    }
    1.41 +  }, {
    1.42 +    // Test state becomes to "searching"
    1.43 +    state: "searching",
    1.44 +    expected: {
    1.45 +      state: "searching",
    1.46 +      connected: false,
    1.47 +      emergencyCallsOnly: true,
    1.48 +      roaming: false,
    1.49 +      signalStrength: null,
    1.50 +      relSignalStrength: null,
    1.51 +      cell: null
    1.52 +    }
    1.53 +  }, {
    1.54 +    // Test state becomes to "denied"
    1.55 +    state: "denied",
    1.56 +    expected: {
    1.57 +      state: "denied",
    1.58 +      connected: false,
    1.59 +      emergencyCallsOnly: true,
    1.60 +      roaming: false,
    1.61 +      signalStrength: null,
    1.62 +      relSignalStrength: null,
    1.63 +      cell: null
    1.64 +    }
    1.65 +  }, {
    1.66 +    // Test state becomes to "roaming"
    1.67 +    // Set emulator's data state to "roaming" won't change the operator's
    1.68 +    // long_name/short_name/mcc/mnc, so that the |data.roaming| will still
    1.69 +    // report false. Please see bug 787967.
    1.70 +    state: "roaming",
    1.71 +    expected: {
    1.72 +      state: "registered",
    1.73 +      connected: false,
    1.74 +      emergencyCallsOnly: false,
    1.75 +      roaming: false,
    1.76 +      signalStrength: -99,
    1.77 +      relSignalStrength: 44,
    1.78 +      cell: {
    1.79 +        gsmLocationAreaCode: 65535,
    1.80 +        gsmCellId: 268435455
    1.81 +      }
    1.82 +    }
    1.83 +  }, {
    1.84 +    // Reset state to default value.
    1.85 +    state: "home",
    1.86 +    expected: {
    1.87 +      state: "registered",
    1.88 +      connected: false,
    1.89 +      emergencyCallsOnly: false,
    1.90 +      roaming: false,
    1.91 +      signalStrength: -99,
    1.92 +      relSignalStrength: 44,
    1.93 +      cell: {
    1.94 +        gsmLocationAreaCode: 65535,
    1.95 +        gsmCellId: 268435455
    1.96 +      }
    1.97 +    }
    1.98 +  }
    1.99 +];
   1.100 +
   1.101 +function compareTo(aPrefix, aFrom, aTo) {
   1.102 +  for (let field in aTo) {
   1.103 +    let fullName = aPrefix + field;
   1.104 +
   1.105 +    let lhs = aFrom[field];
   1.106 +    let rhs = aTo[field];
   1.107 +    ok(true, "lhs=" + JSON.stringify(lhs) + ", rhs=" + JSON.stringify(rhs));
   1.108 +    if (typeof rhs !== "object") {
   1.109 +      is(lhs, rhs, fullName);
   1.110 +    } else if (rhs) {
   1.111 +      ok(lhs, fullName);
   1.112 +      compareTo(fullName + ".", lhs, rhs);
   1.113 +    } else {
   1.114 +      is(lhs, null, fullName);
   1.115 +    }
   1.116 +  }
   1.117 +}
   1.118 +
   1.119 +function verifyDataInfo(aExpected) {
   1.120 +  compareTo("data.", mobileConnection.data, aExpected);
   1.121 +}
   1.122 +
   1.123 +/* Test Data State Changed */
   1.124 +function testDataStateUpdate(aNewState, aExpected) {
   1.125 +  log("Test data info with state='" + aNewState + "'");
   1.126 +
   1.127 +  // Set emulator's lac/cid and wait for 'ondatachange' event.
   1.128 +  return setEmulatorVoiceDataStateAndWait("data", aNewState)
   1.129 +    .then(() => verifyDataInfo(aExpected));
   1.130 +}
   1.131 +
   1.132 +startTestCommon(function() {
   1.133 +  log("Test initial data connection info");
   1.134 +
   1.135 +  verifyDataInfo(INITIAL_STATES);
   1.136 +
   1.137 +  let promise = Promise.resolve();
   1.138 +  for (let i = 0; i < TEST_DATA.length; i++) {
   1.139 +    let entry = TEST_DATA[i];
   1.140 +    promise =
   1.141 +      promise.then(testDataStateUpdate.bind(null, entry.state, entry.expected));
   1.142 +  }
   1.143 +
   1.144 +  return promise;
   1.145 +});

mercurial