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