Bug 1051660 - 0002. Test case for Wifi Enable API. r=hchang

This commit is contained in:
Chuck Lee 2014-08-18 15:10:27 +08:00
parent ebc687e577
commit 89e5b88b70
3 changed files with 30 additions and 6 deletions

View File

@ -258,29 +258,39 @@ let gTestSuite = (function() {
*
* @return a resolved promise or deferred promise.
*/
function ensureWifiEnabled(aEnabled) {
function ensureWifiEnabled(aEnabled, useAPI) {
if (wifiManager.enabled === aEnabled) {
log('Already ' + (aEnabled ? 'enabled' : 'disabled'));
return Promise.resolve();
}
return requestWifiEnabled(aEnabled);
return requestWifiEnabled(aEnabled, useAPI);
}
/**
* Issue a request to enable/disable wifi.
*
* For current design, this function will attempt to enable/disable wifi by
* writing 'wifi.enabled' regardless of the wifi state.
* This function will attempt to enable/disable wifi, by calling API or by
* writing settings 'wifi.enabled' regardless of the wifi state, based on the
* value of |userAPI| parameter.
* Default is using settings.
*
* Note there's a limitation of co-existance of both method, per bug 930355,
* that once enable/disable wifi by API, the settings method won't work until
* reboot. So the test of wifi enable API should be executed last.
* TODO: Remove settings method after enable/disable wifi by settings is
* removed after bug 1050147.
*
* Fulfill params: (none)
* Reject params: (none)
*
* @return A deferred promise.
*/
function requestWifiEnabled(aEnabled) {
function requestWifiEnabled(aEnabled, useAPI) {
return Promise.all([
waitForWifiManagerEventOnce(aEnabled ? 'enabled' : 'disabled'),
setSettings({ 'wifi.enabled': aEnabled }),
useAPI ?
wrapDomRequestAsPromise(wifiManager.setWifiEnabled(aEnabled)) :
setSettings({ 'wifi.enabled': aEnabled }),
]);
}

View File

@ -11,3 +11,4 @@ qemu = true
[test_wifi_tethering_wifi_disabled.js]
[test_wifi_tethering_wifi_inactive.js]
[test_wifi_tethering_wifi_active.js]
[test_wifi_enable_api.js]

View File

@ -0,0 +1,13 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
gTestSuite.doTest(function() {
return Promise.resolve()
.then(() => gTestSuite.ensureWifiEnabled(false, true))
.then(() => gTestSuite.requestWifiEnabled(true, true))
.then(() => gTestSuite.requestWifiEnabled(false, true))
.then(() => gTestSuite.ensureWifiEnabled(true, true));
});