dom/mobileconnection/tests/marionette/test_call_barring_set_error.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/mobileconnection/tests/marionette/test_call_barring_set_error.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +MARIONETTE_TIMEOUT = 60000;
     1.8 +
     1.9 +SpecialPowers.addPermission("mobileconnection", true, document);
    1.10 +
    1.11 +// Permission changes can't change existing Navigator.prototype
    1.12 +// objects, so grab our objects from a new Navigator
    1.13 +let ifr = document.createElement("iframe");
    1.14 +let connection;
    1.15 +ifr.onload = function() {
    1.16 +  connection = ifr.contentWindow.navigator.mozMobileConnections[0];
    1.17 +
    1.18 +  ok(connection instanceof ifr.contentWindow.MozMobileConnection,
    1.19 +     "connection is instanceof " + connection.constructor);
    1.20 +
    1.21 +  nextTest();
    1.22 +};
    1.23 +document.body.appendChild(ifr);
    1.24 +
    1.25 +let caseId = 0;
    1.26 +let options = [
    1.27 +  buildOption(5, true, '0000', 0),  // invalid program.
    1.28 +
    1.29 +  // test null.
    1.30 +  buildOption(null, true, '0000', 0),
    1.31 +  buildOption(0, null, '0000', 0),
    1.32 +  buildOption(0, true, null, 0),
    1.33 +  buildOption(0, true, '0000', null),
    1.34 +
    1.35 +  // test undefined.
    1.36 +  {'enabled': true, 'password': '0000', 'serviceClass': 0},
    1.37 +  {'program': 0, 'password': '0000', 'serviceClass': 0},
    1.38 +  {'program': 0, 'enabled': true, 'serviceClass': 0},
    1.39 +  {'program': 0, 'enabled': true, 'password': '0000'},
    1.40 +];
    1.41 +
    1.42 +function buildOption(program, enabled, password, serviceClass) {
    1.43 +  return {
    1.44 +    'program': program,
    1.45 +    'enabled': enabled,
    1.46 +    'password': password,
    1.47 +    'serviceClass': serviceClass
    1.48 +  };
    1.49 +}
    1.50 +
    1.51 +function testSetCallBarringOptionError(option) {
    1.52 +  let request = connection.setCallBarringOption(option);
    1.53 +  request.onsuccess = function() {
    1.54 +    ok(false,
    1.55 +       'should not fire onsuccess for invaild call barring option: '
    1.56 +       + JSON.stringify(option));
    1.57 +  };
    1.58 +  request.onerror = function(event) {
    1.59 +    is(event.target.error.name, 'InvalidParameter', JSON.stringify(option));
    1.60 +    nextTest();
    1.61 +  };
    1.62 +}
    1.63 +
    1.64 +function nextTest() {
    1.65 +  if (caseId >= options.length) {
    1.66 +    cleanUp();
    1.67 +  } else {
    1.68 +    let option = options[caseId++];
    1.69 +    log('test for ' + JSON.stringify(option));
    1.70 +    testSetCallBarringOptionError(option);
    1.71 +  }
    1.72 +}
    1.73 +
    1.74 +function cleanUp() {
    1.75 +  SpecialPowers.removePermission("mobileconnection", document);
    1.76 +  finish();
    1.77 +}

mercurial