Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: chrome/test/data/extensions/api_test/certificate_provider/request_pin/basic.js

Issue 2094333002: Implementation for chrome.certificateProvider.requestPin/stopPinRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cf771acb5c4419650906961b7a80a717ee39f57e
--- /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) {
Devlin 2016/10/20 21:20:45 need a space after if (everywhere)
igorcov 2016/10/25 16:38:36 Done.
+ console.error("Error: " + chrome.runtime.lastError.message);
Devlin 2016/10/20 21:20:45 It seems like we should be using chrome.test metho
Devlin 2016/10/20 21:20:45 prefer single quotes in js
igorcov 2016/10/25 16:38:36 Done.
igorcov 2016/10/25 16:38:36 Done.
+ 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);
+ 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);

Powered by Google App Engine
This is Rietveld 408576698