summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/marionette/test_data_connection.js
blob: 5a53b1e5f04cde7e29dd6e3c90d8e9f0005ac8a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";

function setEmulatorAPN() {
  let apn = [
    [{"carrier":"T-Mobile US",
      "apn":"epc.tmobile.com",
      "mmsc":"http://mms.msg.eng.t-mobile.com/mms/wapenc",
      "types":["default","supl","mms","ims","dun", "fota"]}]
  ];

  return setSettings(SETTINGS_KEY_DATA_APN_SETTINGS, apn);
}

// Test initial State
function testInitialState() {
  log("= testInitialState =");

  // Data should be off before starting any test.
  return getSettings(SETTINGS_KEY_DATA_ENABLED)
    .then(value => {
      is(value, false, "Data must be off");
    });
}

// Test default data Connection
function testDefaultDataConnection() {
  log("= testDefaultDataConnection =");

  // Enable default data
  return setDataEnabledAndWait(true)
    // Disable default data
    .then(() => setDataEnabledAndWait(false));
}

// Test non default data connection
function testNonDefaultDataConnection() {
  log("= testNonDefaultDataConnection =");

  function doTestNonDefaultDataConnection(type) {
    log("doTestNonDefaultDataConnection: " + type);

    return setupDataCallAndWait(type)
      .then(() => deactivateDataCallAndWait(type));
  }

  let currentApn;
  return getSettings(SETTINGS_KEY_DATA_APN_SETTINGS)
    .then(value => {
      currentApn = value;
    })
    .then(setEmulatorAPN)
    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_MMS))
    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_SUPL))
    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_IMS))
    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_DUN))
    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_FOTA))
    // Restore APN settings
    .then(() => setSettings(SETTINGS_KEY_DATA_APN_SETTINGS, currentApn));
}

// Start test
startTestBase(function() {
  return testInitialState()
    .then(() => testDefaultDataConnection())
    .then(() => testNonDefaultDataConnection());
});