diff --git a/dom/wifi/test/marionette/head.js b/dom/wifi/test/marionette/head.js index aad62536832..94ebe298150 100644 --- a/dom/wifi/test/marionette/head.js +++ b/dom/wifi/test/marionette/head.js @@ -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 }), ]); } diff --git a/dom/wifi/test/marionette/manifest.ini b/dom/wifi/test/marionette/manifest.ini index 8bf884db468..97123d10bff 100644 --- a/dom/wifi/test/marionette/manifest.ini +++ b/dom/wifi/test/marionette/manifest.ini @@ -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] diff --git a/dom/wifi/test/marionette/test_wifi_enable_api.js b/dom/wifi/test/marionette/test_wifi_enable_api.js new file mode 100644 index 00000000000..3728330a28c --- /dev/null +++ b/dom/wifi/test/marionette/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)); +});