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

Side by Side 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: Fix a bug. Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
10 9
11 namespace autofill { 10 namespace autofill {
12 11
13 TEST(PasswordGeneratorTest, PasswordGeneratorSimpleTest) { 12 class PasswordGeneratorTest : public testing::Test {
14 // Not much to test, just make sure that the characters in a generated 13 public:
15 // password are reasonable. 14 size_t DefaultPasswordLength(const PasswordGenerator& pg) {
16 PasswordGenerator pg; 15 return pg.kDefaultPasswordLength_;
16 }
17 };
18
19 TEST_F(PasswordGeneratorTest, PasswordLength) {
20 PasswordGenerator pg1(10);
21 std::string password = pg1.Generate();
22 EXPECT_EQ(password.size(), 10u);
23
24 PasswordGenerator pg2(-1);
25 password = pg2.Generate();
26 EXPECT_EQ(password.size(), DefaultPasswordLength(pg2));
27
28 PasswordGenerator pg3(100);
29 password = pg3.Generate();
30 EXPECT_EQ(password.size(), DefaultPasswordLength(pg3));
31 }
32
33 TEST_F(PasswordGeneratorTest, PasswordPattern) {
34 PasswordGenerator pg(12);
35 std::string password = pg.Generate();
36 int num_upper_case_letters = 0;
37 int num_lower_case_letters = 0;
38 int num_digits = 0;
39 int num_other_symbols = 0;
40 for (size_t i = 0; i < password.size(); i++) {
41 if (isupper(password[i]))
42 ++num_upper_case_letters;
43 else if (islower(password[i]))
44 ++num_lower_case_letters;
45 else if (isdigit(password[i]))
46 ++num_digits;
47 else
48 ++num_other_symbols;
49 }
50 EXPECT_GT(num_upper_case_letters, 0);
51 EXPECT_GT(num_lower_case_letters, 0);
52 EXPECT_GT(num_digits, 0);
53 EXPECT_GT(num_other_symbols, 0);
54 }
55
56 TEST_F(PasswordGeneratorTest, Printable) {
57 PasswordGenerator pg(12);
17 std::string password = pg.Generate(); 58 std::string password = pg.Generate();
18 for (size_t i = 0; i < password.size(); i++) { 59 for (size_t i = 0; i < password.size(); i++) {
19 // Make sure that the character is printable. 60 // Make sure that the character is printable.
20 EXPECT_TRUE(isgraph(password[i])); 61 EXPECT_TRUE(isgraph(password[i]));
21 } 62 }
22 } 63 }
23 64
24 } // namespace autofill 65 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698