Index: chrome/test/data/extensions/api_test/certificate_provider/request_pin/basic.js |
diff --git a/chrome/test/data/extensions/api_test/certificate_provider/request_pin/basic.js b/chrome/test/data/extensions/api_test/certificate_provider/request_pin/basic.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d176f715c3238176ef081160b0b5a803c89b6505 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/certificate_provider/request_pin/basic.js |
@@ -0,0 +1,56 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// The script requests pin infinitely when the dialog is closed, and requests |
+// the input again when the PIN is wrong till 3 times. When the correct |
+// PIN (1234) is given, the script requests to close the dialog. |
+function userInputCallback(codeValue) { |
+ if (chrome.runtime.lastError != null) { |
+ chrome.test.fail('Error: ' + chrome.runtime.lastError.message); |
Devlin
2016/11/01 16:24:30
We never actually check for test failures anywhere
igorcov
2016/11/04 15:51:42
Right, we don't have any test for that.
Devlin
2016/11/05 06:10:59
We should - having chrome.test.fail/chrome.test.su
igorcov
2016/11/22 13:50:47
I've changed the code to use the chrome.test.sendM
|
+ return; |
+ } |
+ |
+ if (attempts >= 3) { |
+ console.info('Returning after maximum attempts exceeded'); |
+ return; |
+ } |
+ |
+ console.info('UserInput received, value = ' + codeValue); |
+ if (!codeValue || !codeValue.userInput) { |
+ console.info('User closed the dialog'); |
+ chrome.certificateProvider.requestPin({signRequestId: 123}, |
+ userInputCallback); |
+ return; |
+ } |
+ |
+ var success = (codeValue.userInput == '1234'); // validatePIN(codeValue); |
Devlin
2016/11/01 16:24:30
parens unnecessary
Devlin
2016/11/01 16:24:30
what is this comment for?
igorcov
2016/11/04 15:51:42
Done.
igorcov
2016/11/04 15:51:42
It's just what that code is supposed to do. Fixed
|
+ if (success) { |
+ console.info('Success'); |
+ chrome.certificateProvider.stopPinRequest({signRequestId: 123}, |
+ closeCallback); |
+ } else { |
+ attempts++; |
+ console.info('Invalid PIN'); |
+ var code = attempts < 3 ? |
+ {signRequestId: 123, errorType: 'INVALID_PIN'} : |
+ {signRequestId: 123, requestType: 'PUK', |
+ errorType: 'MAX_ATTEMPTS_EXCEEDED', |
+ attemptsLeft: 0}; |
+ chrome.certificateProvider.requestPin(code, userInputCallback); |
+ } |
+} |
+ |
+function closeCallback() { |
+ console.info('Close finished on Chrome side'); |
+ if (chrome.runtime.lastError != null) { |
+ console.error('Error: ' + chrome.runtime.lastError.message); |
+ return; |
+ } |
+ |
+ // User authenticated. |
+ console.info('Successfully authenticated!'); |
+} |
+ |
+var attempts = 0; |
+chrome.certificateProvider.requestPin({signRequestId: 123}, userInputCallback); |