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: // Permission changes can't change existing Navigator.prototype michael@0: // objects, so grab our objects from a new Navigator michael@0: let ifr = document.createElement("iframe"); michael@0: let connection; michael@0: ifr.onload = function() { michael@0: connection = ifr.contentWindow.navigator.mozMobileConnections[0]; michael@0: michael@0: ok(connection instanceof ifr.contentWindow.MozMobileConnection, michael@0: "connection is instanceof " + connection.constructor); michael@0: michael@0: nextTest(); michael@0: }; michael@0: document.body.appendChild(ifr); michael@0: michael@0: let caseId = 0; michael@0: let options = [ michael@0: buildOption(5, true, '0000', 0), // invalid program. michael@0: michael@0: // test null. michael@0: buildOption(null, true, '0000', 0), michael@0: buildOption(0, null, '0000', 0), michael@0: buildOption(0, true, null, 0), michael@0: buildOption(0, true, '0000', null), michael@0: michael@0: // test undefined. michael@0: {'enabled': true, 'password': '0000', 'serviceClass': 0}, michael@0: {'program': 0, 'password': '0000', 'serviceClass': 0}, michael@0: {'program': 0, 'enabled': true, 'serviceClass': 0}, michael@0: {'program': 0, 'enabled': true, 'password': '0000'}, michael@0: ]; michael@0: michael@0: function buildOption(program, enabled, password, serviceClass) { michael@0: return { michael@0: 'program': program, michael@0: 'enabled': enabled, michael@0: 'password': password, michael@0: 'serviceClass': serviceClass michael@0: }; michael@0: } michael@0: michael@0: function testSetCallBarringOptionError(option) { michael@0: let request = connection.setCallBarringOption(option); michael@0: request.onsuccess = function() { michael@0: ok(false, michael@0: 'should not fire onsuccess for invaild call barring option: ' michael@0: + JSON.stringify(option)); michael@0: }; michael@0: request.onerror = function(event) { michael@0: is(event.target.error.name, 'InvalidParameter', JSON.stringify(option)); michael@0: nextTest(); michael@0: }; michael@0: } michael@0: michael@0: function nextTest() { michael@0: if (caseId >= options.length) { michael@0: cleanUp(); michael@0: } else { michael@0: let option = options[caseId++]; michael@0: log('test for ' + JSON.stringify(option)); michael@0: testSetCallBarringOptionError(option); michael@0: } michael@0: } michael@0: michael@0: function cleanUp() { michael@0: SpecialPowers.removePermission("mobileconnection", document); michael@0: finish(); michael@0: }