dom/icc/tests/marionette/test_icc_card_lock.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 30000;
     5 MARIONETTE_HEAD_JS = "icc_header.js";
     7 /* Test PIN code changes fail */
     8 taskHelper.push(function testPinChangeFailed() {
     9   // The default pin is '0000' in emulator
    10   let request = icc.setCardLock(
    11     {lockType: "pin",
    12      pin: "1111",
    13      newPin: "0000"});
    15   ok(request instanceof DOMRequest,
    16      "request instanceof " + request.constructor);
    18   request.onerror = function onerror() {
    19     is(request.error.name, "IncorrectPassword");
    20     is(request.error.lockType, "pin");
    21     // The default pin retries is 3, failed once becomes to 2
    22     is(request.error.retryCount, 2);
    24     // Reset pin retries by passing correct pin code.
    25     let resetRequest = icc.setCardLock(
    26       {lockType: "pin",
    27        pin: "0000",
    28        newPin: "0000"});
    30     resetRequest.onsuccess = function onsuccess() {
    31       taskHelper.runNext();
    32     };
    34     resetRequest.onerror = function onerror() {
    35       ok(false, "Reset pin retries got error: " + request.error.name);
    36       taskHelper.runNext();
    37     };
    38   };
    39 });
    41 /* Test PIN code changes success */
    42 taskHelper.push(function testPinChangeSuccess() {
    43   // The default pin is '0000' in emulator
    44   let request = icc.setCardLock(
    45     {lockType: "pin",
    46      pin: "0000",
    47      newPin: "0000"});
    49   ok(request instanceof DOMRequest,
    50      "request instanceof " + request.constructor);
    52   request.onerror = function onerror() {
    53     ok(false, "Should not fail, got error: " + request.error.name);
    55     taskHelper.runNext();
    56   };
    58   request.onsuccess = function onsuccess() {
    59     is(request.result.lockType, "pin");
    60     is(request.result.success, true);
    62     taskHelper.runNext();
    63   };
    64 });
    66 /* Read PIN-lock retry count */
    67 taskHelper.push(function testPinCardLockRetryCount() {
    68   let request = icc.getCardLockRetryCount('pin');
    70   ok(request instanceof DOMRequest,
    71      'request instanceof ' + request.constructor);
    73   request.onsuccess = function onsuccess() {
    74     is(request.result.lockType, 'pin',
    75         'lockType is ' + request.result.lockType);
    76     ok(request.result.retryCount >= 0,
    77         'retryCount is ' + request.result.retryCount);
    78     taskHelper.runNext();
    79   };
    80   request.onerror = function onerror() {
    81     // The operation is optional any might not be supported for all
    82     // all locks. In this case, we generate 'NotSupportedError' for
    83     // the valid lock types.
    84     is(request.error.name, 'RequestNotSupported',
    85         'error name is ' + request.error.name);
    86     taskHelper.runNext();
    87   };
    88 });
    90 /* Read PUK-lock retry count */
    91 taskHelper.push(function testPukCardLockRetryCount() {
    92   let request = icc.getCardLockRetryCount('puk');
    94   ok(request instanceof DOMRequest,
    95      'request instanceof ' + request.constructor);
    97   request.onsuccess = function onsuccess() {
    98     is(request.result.lockType, 'puk',
    99         'lockType is ' + request.result.lockType);
   100     ok(request.result.retryCount >= 0,
   101         'retryCount is ' + request.result.retryCount);
   102     taskHelper.runNext();
   103   };
   104   request.onerror = function onerror() {
   105     // The operation is optional any might not be supported for all
   106     // all locks. In this case, we generate 'NotSupportedError' for
   107     // the valid lock types.
   108     is(request.error.name, 'RequestNotSupported',
   109         'error name is ' + request.error.name);
   110     taskHelper.runNext();
   111   };
   112 });
   114 /* Read lock retry count for an invalid entries  */
   115 taskHelper.push(function testInvalidCardLockRetryCount() {
   116   let request = icc.getCardLockRetryCount('invalid-lock-type');
   118   ok(request instanceof DOMRequest,
   119      'request instanceof ' + request.constructor);
   121   request.onsuccess = function onsuccess() {
   122     ok(false,
   123         'request should never return success for an invalid lock type');
   124     taskHelper.runNext();
   125   };
   126   request.onerror = function onerror() {
   127     is(request.error.name, 'GenericFailure',
   128         'error name is ' + request.error.name);
   129     taskHelper.runNext();
   130   };
   131 });
   133 // Start test
   134 taskHelper.runNext();

mercurial