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

Unified Diff: chrome/browser/autofill/password_generator_unittest.cc

Issue 10458018: This CL does the following: (1) Pass the max_length attribute to the password generator; (2) Update… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some changes based on the code review. Created 8 years, 7 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/browser/autofill/password_generator_unittest.cc
diff --git a/chrome/browser/autofill/password_generator_unittest.cc b/chrome/browser/autofill/password_generator_unittest.cc
index 4efbc8bc8636481d77e16ed7fb0fd7e7af6d55d1..257ec0e418fe17e4232457eb5f9feed36ab6509f 100644
--- a/chrome/browser/autofill/password_generator_unittest.cc
+++ b/chrome/browser/autofill/password_generator_unittest.cc
@@ -10,9 +10,44 @@
namespace autofill {
-TEST(PasswordGeneratorTest, PasswordGeneratorSimpleTest) {
- // Not much to test, just make sure that the characters in a generated
- // password are reasonable.
+TEST(PasswordGeneratorTest, PasswordLength) {
+ PasswordGenerator pg1(10);
+ std::string password = pg1.Generate();
+ EXPECT_EQ(password.size(), 10u);
+
+ PasswordGenerator pg2(-1);
+ password = pg2.Generate();
+ EXPECT_EQ(password.size(), kDefaultPasswordLength);
+
+ PasswordGenerator pg3(100);
+ password = pg3.Generate();
+ EXPECT_EQ(password.size(), kDefaultPasswordLength);
+}
+
+TEST(PasswordGeneratorTest, PasswordPattern) {
+ PasswordGenerator pg;
+ std::string password = pg.Generate();
+ int num_upper_case_letters = 0;
+ int num_lower_case_letters = 0;
+ int num_digits = 0;
+ int num_other_symbols = 0;
+ for (size_t i = 0; i < password.size(); i++) {
+ if (isupper(password[i]))
+ ++num_upper_case_letters;
+ else if (islower(password[i]))
+ ++num_lower_case_letters;
+ else if (isdigit(password[i]))
+ ++num_digits;
+ else
+ ++num_other_symbols;
+ }
+ EXPECT_GT(num_upper_case_letters, 0);
+ EXPECT_GT(num_lower_case_letters, 0);
+ EXPECT_GT(num_digits, 0);
+ EXPECT_GT(num_other_symbols, 0);
+}
+
+TEST(PasswordGeneratorTest, Printable) {
PasswordGenerator pg;
std::string password = pg.Generate();
for (size_t i = 0; i < password.size(); i++) {

Powered by Google App Engine
This is Rietveld 408576698