summaryrefslogtreecommitdiffstats
path: root/dom/wifi/test/marionette/test_wifi_static_ip.js
blob: 90436b6fe031148369649baf72d2caeccbddd6fe (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

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

const STATIC_IP_CONFIG = {
  enabled: true,
  ipaddr: "192.168.111.222",
  proxy: "",
  maskLength: 24,
  gateway: "192.168.111.1",
  dns1: "8.8.8.8",
  dns2: "8.8.4.4",
};

const TESTING_HOSTAPD = [{ ssid: 'ap0' }];

function testAssociateWithStaticIp(aNetwork, aStaticIpConfig) {
  return gTestSuite.setStaticIpMode(aNetwork, aStaticIpConfig)
    .then(() => gTestSuite.testAssociate(aNetwork))
    // Check ip address and prefix.
    .then(() => gTestSuite.exeAndParseNetcfg())
    .then((aResult) => {
      is(aResult["wlan0"].ip, aStaticIpConfig.ipaddr, "Check ip address");
      is(aResult["wlan0"].prefix, aStaticIpConfig.maskLength, "Check prefix");
    })
    // Check routing.
    .then(() => gTestSuite.exeAndParseIpRoute())
    .then((aResult) => {
      is(aResult["wlan0"].src, aStaticIpConfig.ipaddr, "Check ip address");
      is(aResult["wlan0"].default, true, "Check default route");
      is(aResult["wlan0"].gateway, aStaticIpConfig.gateway, "Check gateway");
    });
}

function findDesireNetwork(aNetworks) {
  let i = gTestSuite.getFirstIndexBySsid(TESTING_HOSTAPD[0].ssid, aNetworks);

  if (-1 !== i) {
    return aNetworks[i];
  }

  return aNetworks[0];
}

// Start test.
gTestSuite.doTestWithoutStockAp(function() {
  return gTestSuite.ensureWifiEnabled(true)

    // Start custom hostapd for testing.
    .then(() => gTestSuite.startHostapds(TESTING_HOSTAPD))
    .then(() => gTestSuite.verifyNumOfProcesses('hostapd',
                                                TESTING_HOSTAPD.length))

    // Perform a wifi scan, and then run the static ip test
    .then(() => gTestSuite.requestWifiScan())
    .then((aNetworks) => findDesireNetwork(aNetworks))
    .then((aNetwork) => testAssociateWithStaticIp(aNetwork,
                                                   STATIC_IP_CONFIG))

    // Kill running hostapd.
    .then(gTestSuite.killAllHostapd)
    .then(() => gTestSuite.verifyNumOfProcesses('hostapd', 0));
});