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
Родитель 8d8c2f503e
Коммит 6b2cbe2ff6
3 изменённых файлов: 30 добавлений и 6 удалений

Просмотреть файл

@ -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 }),
]);
}

Просмотреть файл

@ -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]

Просмотреть файл

@ -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));
});