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: michael@0: SpecialPowers.addPermission("mobileconnection", true, document); michael@0: michael@0: let connection = navigator.mozMobileConnections[0]; michael@0: ok(connection instanceof MozMobileConnection, michael@0: "connection is instanceof " + connection.constructor); michael@0: michael@0: function failedToSetRoamingPreference(mode, expectedErrorMessage, callback) { michael@0: let request = connection.setRoamingPreference(mode); michael@0: michael@0: ok(request instanceof DOMRequest, michael@0: "request instanceof " + request.constructor); michael@0: michael@0: request.onsuccess = function onsuccess() { michael@0: ok(false, "Should not be here !!"); michael@0: michael@0: callback(); michael@0: } michael@0: michael@0: request.onerror = function onerror() { michael@0: is(request.error.name, expectedErrorMessage); michael@0: michael@0: callback(); michael@0: } michael@0: } michael@0: michael@0: function testSetRoamingPreferenceWithNullValue() { michael@0: log("test setRoamingPreference(null)"); michael@0: michael@0: failedToSetRoamingPreference(null, "InvalidParameter", runNextTest); michael@0: } michael@0: michael@0: function testSetRoamingPreferenceWithInvalidValue() { michael@0: log("test setRoamingPreference(\"InvalidValue\")"); michael@0: michael@0: failedToSetRoamingPreference("InvalidValue", "InvalidParameter", runNextTest); michael@0: } michael@0: michael@0: function testSetRoamingPreferenceToHome() { michael@0: log("test setRoamingPreference(\"home\")"); michael@0: michael@0: // TODO: Bug 896394. michael@0: // Currently emulator run as GSM mode by default. So we expect to get a michael@0: // 'RequestNotSupported' error here. michael@0: failedToSetRoamingPreference("home", "RequestNotSupported", runNextTest); michael@0: } michael@0: michael@0: function testGetRoamingPreference() { michael@0: log("test getRoamingPreference()"); michael@0: michael@0: // TODO: Bug 896394. michael@0: // Currently emulator run as GSM mode by default. So we expect to get a michael@0: // 'RequestNotSupported' error here. michael@0: let request = connection.getRoamingPreference(); michael@0: michael@0: ok(request instanceof DOMRequest, michael@0: "request instanceof " + request.constructor); michael@0: michael@0: request.onsuccess = function onsuccess() { michael@0: ok(false, "Should not be here !!"); michael@0: michael@0: runNextTest(); michael@0: } michael@0: michael@0: request.onerror = function onerror() { michael@0: is(request.error.name, "RequestNotSupported"); michael@0: michael@0: runNextTest(); michael@0: } michael@0: } michael@0: michael@0: let tests = [ michael@0: testSetRoamingPreferenceWithNullValue, michael@0: testSetRoamingPreferenceWithInvalidValue, michael@0: testSetRoamingPreferenceToHome, michael@0: testGetRoamingPreference michael@0: ]; michael@0: michael@0: function runNextTest() { michael@0: let test = tests.shift(); michael@0: if (!test) { michael@0: cleanUp(); michael@0: return; michael@0: } michael@0: michael@0: test(); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: SpecialPowers.removePermission("mobileconnection", document); michael@0: finish(); michael@0: } michael@0: michael@0: runNextTest();