OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // The script requests pin and checks the input. If correct PIN (1234) is |
| 6 // provided, the script requests to close the dialog and stops there. If wrong |
| 7 // PIN is provided, the request is repeated until the limit of 3 bad tries is |
| 8 // reached. If the dialog is closed, the request is repeated without considering |
| 9 // it a wrong attempt. This allows the testing of quota limit of closed dialogs |
| 10 // (3 closed dialogs per 10 minutes). |
| 11 function userInputCallback(codeValue) { |
| 12 if (chrome.runtime.lastError) { |
| 13 // Should end up here only when quota is exceeded. |
| 14 lastError = chrome.runtime.lastError.message; |
| 15 return; |
| 16 } |
| 17 |
| 18 if (attempts >= 3) { |
| 19 chrome.test.sendMessage('No attempt left'); |
| 20 return; |
| 21 } |
| 22 |
| 23 if (!codeValue || !codeValue.userInput) { |
| 24 chrome.certificateProvider.requestPin( |
| 25 {signRequestId: 123}, userInputCallback); |
| 26 chrome.test.sendMessage('User closed the dialog', function(message) { |
| 27 if (message == 'GetLastError') { |
| 28 chrome.test.sendMessage(lastError); |
| 29 } |
| 30 }); |
| 31 return; |
| 32 } |
| 33 |
| 34 var success = codeValue.userInput == '1234'; // Validate the code. |
| 35 if (success) { |
| 36 chrome.certificateProvider.stopPinRequest( |
| 37 {signRequestId: 123}, closeCallback); |
| 38 chrome.test.sendMessage(lastError == '' ? 'Success' : lastError); |
| 39 } else { |
| 40 attempts++; |
| 41 var code = attempts < 3 ? {signRequestId: 123, errorType: 'INVALID_PIN'} : { |
| 42 signRequestId: 123, |
| 43 requestType: 'PUK', |
| 44 errorType: 'MAX_ATTEMPTS_EXCEEDED', |
| 45 attemptsLeft: 0 |
| 46 }; |
| 47 chrome.certificateProvider.requestPin(code, userInputCallback); |
| 48 chrome.test.sendMessage(lastError == '' ? 'Invalid PIN' : lastError); |
| 49 } |
| 50 } |
| 51 |
| 52 function closeCallback() { |
| 53 if (chrome.runtime.lastError != null) { |
| 54 console.error('Error: ' + chrome.runtime.lastError.message); |
| 55 lastError = chrome.runtime.lastError.message; |
| 56 return; |
| 57 } |
| 58 } |
| 59 |
| 60 var attempts = 0; |
| 61 var lastError = ''; |
| 62 chrome.certificateProvider.requestPin({signRequestId: 123}, userInputCallback); |
OLD | NEW |