1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/icc/tests/marionette/test_icc_card_lock.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 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 = 30000; 1.8 +MARIONETTE_HEAD_JS = "icc_header.js"; 1.9 + 1.10 +/* Test PIN code changes fail */ 1.11 +taskHelper.push(function testPinChangeFailed() { 1.12 + // The default pin is '0000' in emulator 1.13 + let request = icc.setCardLock( 1.14 + {lockType: "pin", 1.15 + pin: "1111", 1.16 + newPin: "0000"}); 1.17 + 1.18 + ok(request instanceof DOMRequest, 1.19 + "request instanceof " + request.constructor); 1.20 + 1.21 + request.onerror = function onerror() { 1.22 + is(request.error.name, "IncorrectPassword"); 1.23 + is(request.error.lockType, "pin"); 1.24 + // The default pin retries is 3, failed once becomes to 2 1.25 + is(request.error.retryCount, 2); 1.26 + 1.27 + // Reset pin retries by passing correct pin code. 1.28 + let resetRequest = icc.setCardLock( 1.29 + {lockType: "pin", 1.30 + pin: "0000", 1.31 + newPin: "0000"}); 1.32 + 1.33 + resetRequest.onsuccess = function onsuccess() { 1.34 + taskHelper.runNext(); 1.35 + }; 1.36 + 1.37 + resetRequest.onerror = function onerror() { 1.38 + ok(false, "Reset pin retries got error: " + request.error.name); 1.39 + taskHelper.runNext(); 1.40 + }; 1.41 + }; 1.42 +}); 1.43 + 1.44 +/* Test PIN code changes success */ 1.45 +taskHelper.push(function testPinChangeSuccess() { 1.46 + // The default pin is '0000' in emulator 1.47 + let request = icc.setCardLock( 1.48 + {lockType: "pin", 1.49 + pin: "0000", 1.50 + newPin: "0000"}); 1.51 + 1.52 + ok(request instanceof DOMRequest, 1.53 + "request instanceof " + request.constructor); 1.54 + 1.55 + request.onerror = function onerror() { 1.56 + ok(false, "Should not fail, got error: " + request.error.name); 1.57 + 1.58 + taskHelper.runNext(); 1.59 + }; 1.60 + 1.61 + request.onsuccess = function onsuccess() { 1.62 + is(request.result.lockType, "pin"); 1.63 + is(request.result.success, true); 1.64 + 1.65 + taskHelper.runNext(); 1.66 + }; 1.67 +}); 1.68 + 1.69 +/* Read PIN-lock retry count */ 1.70 +taskHelper.push(function testPinCardLockRetryCount() { 1.71 + let request = icc.getCardLockRetryCount('pin'); 1.72 + 1.73 + ok(request instanceof DOMRequest, 1.74 + 'request instanceof ' + request.constructor); 1.75 + 1.76 + request.onsuccess = function onsuccess() { 1.77 + is(request.result.lockType, 'pin', 1.78 + 'lockType is ' + request.result.lockType); 1.79 + ok(request.result.retryCount >= 0, 1.80 + 'retryCount is ' + request.result.retryCount); 1.81 + taskHelper.runNext(); 1.82 + }; 1.83 + request.onerror = function onerror() { 1.84 + // The operation is optional any might not be supported for all 1.85 + // all locks. In this case, we generate 'NotSupportedError' for 1.86 + // the valid lock types. 1.87 + is(request.error.name, 'RequestNotSupported', 1.88 + 'error name is ' + request.error.name); 1.89 + taskHelper.runNext(); 1.90 + }; 1.91 +}); 1.92 + 1.93 +/* Read PUK-lock retry count */ 1.94 +taskHelper.push(function testPukCardLockRetryCount() { 1.95 + let request = icc.getCardLockRetryCount('puk'); 1.96 + 1.97 + ok(request instanceof DOMRequest, 1.98 + 'request instanceof ' + request.constructor); 1.99 + 1.100 + request.onsuccess = function onsuccess() { 1.101 + is(request.result.lockType, 'puk', 1.102 + 'lockType is ' + request.result.lockType); 1.103 + ok(request.result.retryCount >= 0, 1.104 + 'retryCount is ' + request.result.retryCount); 1.105 + taskHelper.runNext(); 1.106 + }; 1.107 + request.onerror = function onerror() { 1.108 + // The operation is optional any might not be supported for all 1.109 + // all locks. In this case, we generate 'NotSupportedError' for 1.110 + // the valid lock types. 1.111 + is(request.error.name, 'RequestNotSupported', 1.112 + 'error name is ' + request.error.name); 1.113 + taskHelper.runNext(); 1.114 + }; 1.115 +}); 1.116 + 1.117 +/* Read lock retry count for an invalid entries */ 1.118 +taskHelper.push(function testInvalidCardLockRetryCount() { 1.119 + let request = icc.getCardLockRetryCount('invalid-lock-type'); 1.120 + 1.121 + ok(request instanceof DOMRequest, 1.122 + 'request instanceof ' + request.constructor); 1.123 + 1.124 + request.onsuccess = function onsuccess() { 1.125 + ok(false, 1.126 + 'request should never return success for an invalid lock type'); 1.127 + taskHelper.runNext(); 1.128 + }; 1.129 + request.onerror = function onerror() { 1.130 + is(request.error.name, 'GenericFailure', 1.131 + 'error name is ' + request.error.name); 1.132 + taskHelper.runNext(); 1.133 + }; 1.134 +}); 1.135 + 1.136 +// Start test 1.137 +taskHelper.runNext();