dom/mobileconnection/tests/marionette/test_mobile_roaming_preference.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/mobileconnection/tests/marionette/test_mobile_roaming_preference.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     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 +let connection = navigator.mozMobileConnections[0];
    1.12 +ok(connection instanceof MozMobileConnection,
    1.13 +   "connection is instanceof " + connection.constructor);
    1.14 +
    1.15 +function failedToSetRoamingPreference(mode, expectedErrorMessage, callback) {
    1.16 +  let request = connection.setRoamingPreference(mode);
    1.17 +
    1.18 +  ok(request instanceof DOMRequest,
    1.19 +     "request instanceof " + request.constructor);
    1.20 +
    1.21 +  request.onsuccess = function onsuccess() {
    1.22 +    ok(false, "Should not be here !!");
    1.23 +
    1.24 +    callback();
    1.25 +  }
    1.26 +
    1.27 +  request.onerror = function onerror() {
    1.28 +    is(request.error.name, expectedErrorMessage);
    1.29 +
    1.30 +    callback();
    1.31 +  }
    1.32 +}
    1.33 +
    1.34 +function testSetRoamingPreferenceWithNullValue() {
    1.35 +  log("test setRoamingPreference(null)");
    1.36 +
    1.37 +  failedToSetRoamingPreference(null, "InvalidParameter", runNextTest);
    1.38 +}
    1.39 +
    1.40 +function testSetRoamingPreferenceWithInvalidValue() {
    1.41 +  log("test setRoamingPreference(\"InvalidValue\")");
    1.42 +
    1.43 +  failedToSetRoamingPreference("InvalidValue", "InvalidParameter", runNextTest);
    1.44 +}
    1.45 +
    1.46 +function testSetRoamingPreferenceToHome() {
    1.47 +  log("test setRoamingPreference(\"home\")");
    1.48 +
    1.49 +  // TODO: Bug 896394.
    1.50 +  // Currently emulator run as GSM mode by default. So we expect to get a
    1.51 +  // 'RequestNotSupported' error here.
    1.52 +  failedToSetRoamingPreference("home", "RequestNotSupported", runNextTest);
    1.53 +}
    1.54 +
    1.55 +function testGetRoamingPreference() {
    1.56 +  log("test getRoamingPreference()");
    1.57 +
    1.58 +  // TODO: Bug 896394.
    1.59 +  // Currently emulator run as GSM mode by default. So we expect to get a
    1.60 +  // 'RequestNotSupported' error here.
    1.61 +  let request = connection.getRoamingPreference();
    1.62 +
    1.63 +  ok(request instanceof DOMRequest,
    1.64 +     "request instanceof " + request.constructor);
    1.65 +
    1.66 +  request.onsuccess = function onsuccess() {
    1.67 +    ok(false, "Should not be here !!");
    1.68 +
    1.69 +    runNextTest();
    1.70 +  }
    1.71 +
    1.72 +  request.onerror = function onerror() {
    1.73 +    is(request.error.name, "RequestNotSupported");
    1.74 +
    1.75 +    runNextTest();
    1.76 +  }
    1.77 +}
    1.78 +
    1.79 +let tests = [
    1.80 +  testSetRoamingPreferenceWithNullValue,
    1.81 +  testSetRoamingPreferenceWithInvalidValue,
    1.82 +  testSetRoamingPreferenceToHome,
    1.83 +  testGetRoamingPreference
    1.84 +];
    1.85 +
    1.86 +function runNextTest() {
    1.87 +  let test = tests.shift();
    1.88 +  if (!test) {
    1.89 +    cleanUp();
    1.90 +    return;
    1.91 +  }
    1.92 +
    1.93 +  test();
    1.94 +}
    1.95 +
    1.96 +function cleanUp() {
    1.97 +  SpecialPowers.removePermission("mobileconnection", document);
    1.98 +  finish();
    1.99 +}
   1.100 +
   1.101 +runNextTest();
   1.102 \ No newline at end of file

mercurial