michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 60000; michael@0: MARIONETTE_HEAD_JS = "head.js"; michael@0: michael@0: const SETTINGS_KEY_DATA_ENABLED = "ril.data.enabled"; michael@0: const TOPIC_NETWORK_ACTIVE_CHANGED = "network-active-changed"; michael@0: michael@0: let networkManager = michael@0: Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager); michael@0: ok(networkManager, michael@0: "networkManager.constructor is " + networkManager.constructor); michael@0: michael@0: function testInitialState() { michael@0: return Promise.resolve() michael@0: .then(() => getSettings(SETTINGS_KEY_DATA_ENABLED)) michael@0: .then((enabled) => { michael@0: is(enabled, false, "data should be off by default"); michael@0: is(networkManager.active, null, michael@0: "networkManager.active should be null by default"); michael@0: }); michael@0: } michael@0: michael@0: function testActiveNetworkChangedBySwitchingDataCall(aDataCallEnabled) { michael@0: log("Test active network by switching dataCallEnabled to " + aDataCallEnabled); michael@0: michael@0: return Promise.resolve() michael@0: .then(() => setSettings(SETTINGS_KEY_DATA_ENABLED, aDataCallEnabled)) michael@0: .then(() => waitForObserverEvent(TOPIC_NETWORK_ACTIVE_CHANGED)) michael@0: .then((subject) => { michael@0: if (aDataCallEnabled) { michael@0: ok(subject instanceof Ci.nsINetworkInterface, michael@0: "subject should be an instance of nsINetworkInterface"); michael@0: ok(subject instanceof Ci.nsIRilNetworkInterface, michael@0: "subject should be an instance of nsIRILNetworkInterface"); michael@0: is(subject.type, Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, michael@0: "subject.type should be NETWORK_TYPE_MOBILE"); michael@0: } michael@0: michael@0: is(subject, networkManager.active, michael@0: "subject should be equal with networkManager.active"); michael@0: }); michael@0: } michael@0: michael@0: // Start test michael@0: startTestBase(function() { michael@0: return Promise.resolve() michael@0: .then(() => testInitialState()) michael@0: // Test active network changed by enabling data call. michael@0: .then(() => testActiveNetworkChangedBySwitchingDataCall(true)) michael@0: // Test active network changed by disabling data call. michael@0: .then(() => testActiveNetworkChangedBySwitchingDataCall(false)); michael@0: });