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

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

Issue 2094333002: Implementation for chrome.certificateProvider.requestPin/stopPinRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small fix Created 4 years, 5 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/show_pin_dialog/basic.js
diff --git a/chrome/test/data/extensions/api_test/certificate_provider/show_pin_dialog/basic.js b/chrome/test/data/extensions/api_test/certificate_provider/show_pin_dialog/basic.js
new file mode 100644
index 0000000000000000000000000000000000000000..384bf07e0a9f005f0563648c29816575a9487f6b
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/certificate_provider/show_pin_dialog/basic.js
@@ -0,0 +1,52 @@
+// 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 asks to show pin dialog infinitely when it's 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) {
+ console.error("Error: " + chrome.runtime.lastError.message);
+ 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.showPinDialog(userInputCallback);
+ return;
+ }
+
+ var success = (codeValue.userInput == "1234"); //validatePIN(codeValue);
+ if (success) {
+ console.info("Success");
+ chrome.certificateProvider.closePinDialog(closeCallback);
+ } else {
+ attempts++;
+ console.info("Invalid PIN");
+ var code = attempts < 3 ?
+ {errorMessage: "Invalid PIN"} :
+ {type: "PUK", errorMessage: "Max attempts reached", acceptInput: false};
+ chrome.certificateProvider.showPinDialog(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.showPinDialog(userInputCallback);

Powered by Google App Engine
This is Rietveld 408576698