Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | MARIONETTE_TIMEOUT = 60000; |
michael@0 | 5 | MARIONETTE_HEAD_JS = "head.js"; |
michael@0 | 6 | |
michael@0 | 7 | const SETTINGS_KEY_DATA_ENABLED = "ril.data.enabled"; |
michael@0 | 8 | const TOPIC_NETWORK_ACTIVE_CHANGED = "network-active-changed"; |
michael@0 | 9 | |
michael@0 | 10 | let networkManager = |
michael@0 | 11 | Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager); |
michael@0 | 12 | ok(networkManager, |
michael@0 | 13 | "networkManager.constructor is " + networkManager.constructor); |
michael@0 | 14 | |
michael@0 | 15 | function testInitialState() { |
michael@0 | 16 | return Promise.resolve() |
michael@0 | 17 | .then(() => getSettings(SETTINGS_KEY_DATA_ENABLED)) |
michael@0 | 18 | .then((enabled) => { |
michael@0 | 19 | is(enabled, false, "data should be off by default"); |
michael@0 | 20 | is(networkManager.active, null, |
michael@0 | 21 | "networkManager.active should be null by default"); |
michael@0 | 22 | }); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function testActiveNetworkChangedBySwitchingDataCall(aDataCallEnabled) { |
michael@0 | 26 | log("Test active network by switching dataCallEnabled to " + aDataCallEnabled); |
michael@0 | 27 | |
michael@0 | 28 | return Promise.resolve() |
michael@0 | 29 | .then(() => setSettings(SETTINGS_KEY_DATA_ENABLED, aDataCallEnabled)) |
michael@0 | 30 | .then(() => waitForObserverEvent(TOPIC_NETWORK_ACTIVE_CHANGED)) |
michael@0 | 31 | .then((subject) => { |
michael@0 | 32 | if (aDataCallEnabled) { |
michael@0 | 33 | ok(subject instanceof Ci.nsINetworkInterface, |
michael@0 | 34 | "subject should be an instance of nsINetworkInterface"); |
michael@0 | 35 | ok(subject instanceof Ci.nsIRilNetworkInterface, |
michael@0 | 36 | "subject should be an instance of nsIRILNetworkInterface"); |
michael@0 | 37 | is(subject.type, Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, |
michael@0 | 38 | "subject.type should be NETWORK_TYPE_MOBILE"); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | is(subject, networkManager.active, |
michael@0 | 42 | "subject should be equal with networkManager.active"); |
michael@0 | 43 | }); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | // Start test |
michael@0 | 47 | startTestBase(function() { |
michael@0 | 48 | return Promise.resolve() |
michael@0 | 49 | .then(() => testInitialState()) |
michael@0 | 50 | // Test active network changed by enabling data call. |
michael@0 | 51 | .then(() => testActiveNetworkChangedBySwitchingDataCall(true)) |
michael@0 | 52 | // Test active network changed by disabling data call. |
michael@0 | 53 | .then(() => testActiveNetworkChangedBySwitchingDataCall(false)); |
michael@0 | 54 | }); |