Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <locale> | 5 #include <locale> |
| 6 | 6 |
| 7 #include "chrome/browser/autofill/password_generator.h" | 7 #include "chrome/browser/autofill/password_generator.h" |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace autofill { | 11 namespace autofill { |
| 12 | 12 |
| 13 TEST(PasswordGeneratorTest, PasswordGeneratorSimpleTest) { | 13 TEST(PasswordGeneratorTest, TestPasswordLength) { |
|
Ilya Sherman
2012/06/01 01:09:55
nit: "TestPasswordLength" -> "PasswordLength" (and
zysxqn
2012/06/01 19:01:32
Done.
| |
| 14 // Not much to test, just make sure that the characters in a generated | 14 PasswordGenerator pg1(10); |
| 15 // password are reasonable. | 15 std::string password = pg1.Generate(); |
| 16 EXPECT_EQ(password.size(), 10u); | |
|
Ilya Sherman
2012/06/01 01:09:55
nit: Please add a blank line after this line.
zysxqn
2012/06/01 19:01:32
Done.
| |
| 17 PasswordGenerator pg2(-1); | |
| 18 password = pg2.Generate(); | |
| 19 EXPECT_EQ(password.size(), kDefaultPasswordLength); | |
|
Ilya Sherman
2012/06/01 01:09:55
nit: Please add a blank line after this line.
zysxqn
2012/06/01 19:01:32
Done.
| |
| 20 PasswordGenerator pg3(100); | |
| 21 password = pg3.Generate(); | |
| 22 EXPECT_EQ(password.size(), kDefaultPasswordLength); | |
| 23 } | |
| 24 | |
| 25 TEST(PasswordGeneratorTest, TestPasswordPattern) { | |
| 26 PasswordGenerator pg; | |
| 27 std::string password = pg.Generate(); | |
| 28 int num_upper_case_letters = 0; | |
| 29 int num_lower_case_letters = 0; | |
| 30 int num_digits = 0; | |
| 31 int num_other_symbols = 0; | |
| 32 for (size_t i = 0; i < password.size(); i++) { | |
| 33 if (isupper(password[i])) | |
| 34 ++num_upper_case_letters; | |
| 35 else if (islower(password[i])) | |
| 36 ++num_lower_case_letters; | |
| 37 else if (isdigit(password[i])) | |
| 38 ++num_digits; | |
| 39 else | |
| 40 ++num_other_symbols; | |
| 41 } | |
| 42 EXPECT_GT(num_upper_case_letters, 0); | |
| 43 EXPECT_GT(num_lower_case_letters, 0); | |
| 44 EXPECT_GT(num_digits, 0); | |
| 45 EXPECT_GT(num_other_symbols, 0); | |
| 46 } | |
| 47 | |
| 48 TEST(PasswordGeneratorTest, TestPrintable) { | |
| 16 PasswordGenerator pg; | 49 PasswordGenerator pg; |
| 17 std::string password = pg.Generate(); | 50 std::string password = pg.Generate(); |
| 18 for (size_t i = 0; i < password.size(); i++) { | 51 for (size_t i = 0; i < password.size(); i++) { |
| 19 // Make sure that the character is printable. | 52 // Make sure that the character is printable. |
| 20 EXPECT_TRUE(isgraph(password[i])); | 53 EXPECT_TRUE(isgraph(password[i])); |
| 21 } | 54 } |
| 22 } | 55 } |
| 23 | 56 |
| 24 } // namespace autofill | 57 } // namespace autofill |
| OLD | NEW |