summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/marionette/test_network_active_changed.js
blob: 5886f37ed4e90eda01a4f825723cdae43e6514e6 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

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

var networkManager =
  Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager);
ok(networkManager,
   "networkManager.constructor is " + networkManager.constructor);

function testInitialState() {
  return getSettings(SETTINGS_KEY_DATA_ENABLED)
    .then((enabled) => {
      is(enabled, false, "data should be off by default");
      is(networkManager.activeNetworkInfo, null,
         "networkManager.activeNetworkInfo should be null by default");
    });
}

function testActiveNetworkChangedBySwitchingDataCall(aDataCallEnabled) {
  log("Test active network by switching dataCallEnabled to " + aDataCallEnabled);

  let promises = [];
  promises.push(waitForObserverEvent(TOPIC_NETWORK_ACTIVE_CHANGED));
  promises.push(setSettings(SETTINGS_KEY_DATA_ENABLED, aDataCallEnabled));

  return Promise.all(promises).then(function(results) {
    let subject = results[0];

    if (aDataCallEnabled) {
      ok(subject instanceof Ci.nsINetworkInfo,
         "subject should be an instance of nsINetworkInfo");
      ok(subject instanceof Ci.nsIRilNetworkInfo,
         "subject should be an instance of nsIRilNetworkInfo");
      is(subject.type, NETWORK_TYPE_MOBILE,
         "subject.type should be NETWORK_TYPE_MOBILE");
    }

    is(subject, networkManager.activeNetworkInfo,
       "subject should be equal with networkManager.activeNetworkInfo");
  });
}

// Start test
startTestBase(function() {
  return testInitialState()
    // Test active network changed by enabling data call.
    .then(() => testActiveNetworkChangedBySwitchingDataCall(true))
    // Test active network changed by disabling data call.
    .then(() => testActiveNetworkChangedBySwitchingDataCall(false));
});