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, PasswordLength) { |
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); |
| 17 |
| 18 PasswordGenerator pg2(-1); |
| 19 password = pg2.Generate(); |
| 20 EXPECT_EQ(password.size(), kDefaultPasswordLength); |
| 21 |
| 22 PasswordGenerator pg3(100); |
| 23 password = pg3.Generate(); |
| 24 EXPECT_EQ(password.size(), kDefaultPasswordLength); |
| 25 } |
| 26 |
| 27 TEST(PasswordGeneratorTest, PasswordPattern) { |
| 28 PasswordGenerator pg; |
| 29 std::string password = pg.Generate(); |
| 30 int num_upper_case_letters = 0; |
| 31 int num_lower_case_letters = 0; |
| 32 int num_digits = 0; |
| 33 int num_other_symbols = 0; |
| 34 for (size_t i = 0; i < password.size(); i++) { |
| 35 if (isupper(password[i])) |
| 36 ++num_upper_case_letters; |
| 37 else if (islower(password[i])) |
| 38 ++num_lower_case_letters; |
| 39 else if (isdigit(password[i])) |
| 40 ++num_digits; |
| 41 else |
| 42 ++num_other_symbols; |
| 43 } |
| 44 EXPECT_GT(num_upper_case_letters, 0); |
| 45 EXPECT_GT(num_lower_case_letters, 0); |
| 46 EXPECT_GT(num_digits, 0); |
| 47 EXPECT_GT(num_other_symbols, 0); |
| 48 } |
| 49 |
| 50 TEST(PasswordGeneratorTest, Printable) { |
16 PasswordGenerator pg; | 51 PasswordGenerator pg; |
17 std::string password = pg.Generate(); | 52 std::string password = pg.Generate(); |
18 for (size_t i = 0; i < password.size(); i++) { | 53 for (size_t i = 0; i < password.size(); i++) { |
19 // Make sure that the character is printable. | 54 // Make sure that the character is printable. |
20 EXPECT_TRUE(isgraph(password[i])); | 55 EXPECT_TRUE(isgraph(password[i])); |
21 } | 56 } |
22 } | 57 } |
23 | 58 |
24 } // namespace autofill | 59 } // namespace autofill |
OLD | NEW |