dom/icc/tests/marionette/test_icc_card_lock.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d85eb6c546d4
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 MARIONETTE_TIMEOUT = 30000;
5 MARIONETTE_HEAD_JS = "icc_header.js";
6
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"});
14
15 ok(request instanceof DOMRequest,
16 "request instanceof " + request.constructor);
17
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);
23
24 // Reset pin retries by passing correct pin code.
25 let resetRequest = icc.setCardLock(
26 {lockType: "pin",
27 pin: "0000",
28 newPin: "0000"});
29
30 resetRequest.onsuccess = function onsuccess() {
31 taskHelper.runNext();
32 };
33
34 resetRequest.onerror = function onerror() {
35 ok(false, "Reset pin retries got error: " + request.error.name);
36 taskHelper.runNext();
37 };
38 };
39 });
40
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"});
48
49 ok(request instanceof DOMRequest,
50 "request instanceof " + request.constructor);
51
52 request.onerror = function onerror() {
53 ok(false, "Should not fail, got error: " + request.error.name);
54
55 taskHelper.runNext();
56 };
57
58 request.onsuccess = function onsuccess() {
59 is(request.result.lockType, "pin");
60 is(request.result.success, true);
61
62 taskHelper.runNext();
63 };
64 });
65
66 /* Read PIN-lock retry count */
67 taskHelper.push(function testPinCardLockRetryCount() {
68 let request = icc.getCardLockRetryCount('pin');
69
70 ok(request instanceof DOMRequest,
71 'request instanceof ' + request.constructor);
72
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 });
89
90 /* Read PUK-lock retry count */
91 taskHelper.push(function testPukCardLockRetryCount() {
92 let request = icc.getCardLockRetryCount('puk');
93
94 ok(request instanceof DOMRequest,
95 'request instanceof ' + request.constructor);
96
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 });
113
114 /* Read lock retry count for an invalid entries */
115 taskHelper.push(function testInvalidCardLockRetryCount() {
116 let request = icc.getCardLockRetryCount('invalid-lock-type');
117
118 ok(request instanceof DOMRequest,
119 'request instanceof ' + request.constructor);
120
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 });
132
133 // Start test
134 taskHelper.runNext();

mercurial