Index: chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api_unittest.cc |
diff --git a/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api_unittest.cc b/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api_unittest.cc |
index b97b51a4116eaa15a80684c327af073db9df4918..e6c012b46ad3393b0c866a8cfc44526fc9bfc125 100644 |
--- a/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api_unittest.cc |
+++ b/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api_unittest.cc |
@@ -14,12 +14,14 @@ |
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
#include "chrome/browser/extensions/extension_api_unittest.h" |
+#include "chrome/common/pref_names.h" |
#include "chromeos/login/auth/fake_extended_authenticator.h" |
#include "extensions/browser/api_test_utils.h" |
#include "extensions/browser/extension_function_dispatcher.h" |
using namespace extensions; |
namespace quick_unlock_private = extensions::api::quick_unlock_private; |
+using PinState = quick_unlock_private::PinState; |
using QuickUnlockMode = quick_unlock_private::QuickUnlockMode; |
using QuickUnlockModeList = std::vector<QuickUnlockMode>; |
using CredentialList = std::vector<std::string>; |
@@ -129,6 +131,46 @@ class QuickUnlockPrivateUnitTest : public ExtensionApiUnittest { |
return modes; |
} |
+ // Helper function for checking whether |GetUsablePinUsingPassword| will |
+ // return the right message given a sets of organized pins. |
+ void CheckPins(const std::vector<std::string>& good_pins, |
+ const std::vector<std::string>& short_pins, |
+ const std::vector<std::string>& long_pins, |
+ const std::vector<std::string>& digit_same_pins, |
+ const std::vector<std::string>& digit_increaseing_pins) { |
+ for (const std::string& pin : good_pins) |
+ EXPECT_EQ(PinState::PIN_STATE_GOOD, GetUsablePinUsingPassword(pin)); |
+ |
+ for (const std::string& pin : short_pins) { |
+ EXPECT_EQ(PinState::PIN_STATE_SHORTER_THAN_MIN, |
+ GetUsablePinUsingPassword(pin)); |
+ } |
+ |
+ for (const std::string& pin : long_pins) { |
+ EXPECT_EQ(PinState::PIN_STATE_LONGER_THAN_MAX, |
+ GetUsablePinUsingPassword(pin)); |
+ } |
+ |
+ for (const std::string& pin : digit_same_pins) { |
+ EXPECT_EQ(PinState::PIN_STATE_ALL_SAME_NUM, |
+ GetUsablePinUsingPassword(pin)); |
+ } |
+ |
+ for (const std::string& pin : digit_increaseing_pins) |
+ EXPECT_EQ(PinState::PIN_STATE_INCREASING, GetUsablePinUsingPassword(pin)); |
+ } |
+ |
+ PinState GetUsablePinUsingPassword(const std::string& password) { |
+ auto params = base::MakeUnique<base::ListValue>(); |
+ params->AppendString(password); |
+ |
+ std::unique_ptr<base::Value> result = RunFunction( |
+ new QuickUnlockPrivateGetUsablePinFunction(), std::move(params)); |
+ std::string str_result; |
+ EXPECT_TRUE(result->GetAsString(&str_result)); |
+ return quick_unlock_private::ParsePinState(str_result); |
+ } |
+ |
// Wrapper for chrome.quickUnlockPrivate.setModes that automatically uses a |
// valid password. |
bool SetModes(const QuickUnlockModeList& modes, |
@@ -316,4 +358,36 @@ TEST_F(QuickUnlockPrivateUnitTest, ThrowErrorOnMismatchedParameterCount) { |
EXPECT_FALSE(SetModesWithError("[\"valid\", [], [\"11\"]]").empty()); |
} |
+// Verifies that unsubmitted pins give the right message to users. |
+TEST_F(QuickUnlockPrivateUnitTest, VerifyPinsAgainstPreferences) { |
+ PrefService* pref_service = profile()->GetPrefs(); |
+ |
+ std::vector<std::string> empty; |
+ // Verify the pin checks work with the default preferences which are minimum |
+ // length of 4, maximum length of 0 (no maximum) and no easy to guess check. |
+ CheckPins(std::vector<std::string>{"1243", "24569", "584934353422432"}, |
+ std::vector<std::string>{"1", "25", "236"}, empty, empty, empty); |
+ |
+ // Verify that now if the minimum is set to 3, pins of length 3 are accepted. |
+ pref_service->SetInteger(prefs::kPinUnlockMinimumLength, 3); |
+ CheckPins(std::vector<std::string>{"236", "1243", "24569", "584934353422432"}, |
+ std::vector<std::string>{"1", "25"}, empty, empty, empty); |
+ |
+ // Verify that now if the maximum is set to 5, pins longer than 5 are |
+ // considered as long pins. |
+ pref_service->SetInteger(prefs::kPinUnlockMaximumLength, 5); |
+ CheckPins(std::vector<std::string>{"236", "1243", "24569"}, |
+ std::vector<std::string>{"1", "25"}, |
+ std::vector<std::string>{"145253", "1353151414"}, empty, empty); |
+ |
+ // Set the pins minimum/maximum lengths back to their defaults. |
+ pref_service->SetInteger(prefs::kPinUnlockMinimumLength, 4); |
+ pref_service->SetInteger(prefs::kPinUnlockMaximumLength, 0); |
+ // Verify that pins that consists of the same character, or pins that are |
+ // increasing are considered same digit and increasing pins respectively. A 9 |
+ // followed by a 0 is not considered increasing. |
+ CheckPins(std::vector<std::string>{"7890"}, empty, empty, |
+ std::vector<std::string>{"1111", "2222", "9999"}, |
+ std::vector<std::string>{"0123", "1234", "6789"}); |
+} |
} // namespace chromeos |