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

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 windows UI 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
« no previous file with comments | « chrome/browser/autofill/password_generator.cc ('k') | chrome/browser/ui/browser_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 TEST(PasswordGeneratorTest, PasswordLength) {
14 // Not much to test, just make sure that the characters in a generated 13 PasswordGenerator pg1(10);
15 // password are reasonable. 14 std::string password = pg1.Generate();
16 PasswordGenerator pg; 15 EXPECT_EQ(password.size(), 10u);
16
17 PasswordGenerator pg2(-1);
18 password = pg2.Generate();
19 EXPECT_EQ(password.size(), PasswordGenerator::kDefaultPasswordLength);
20
21 PasswordGenerator pg3(100);
22 password = pg3.Generate();
23 EXPECT_EQ(password.size(), PasswordGenerator::kDefaultPasswordLength);
24 }
25
26 TEST(PasswordGeneratorTest, PasswordPattern) {
27 PasswordGenerator pg(12);
28 std::string password = pg.Generate();
29 int num_upper_case_letters = 0;
30 int num_lower_case_letters = 0;
31 int num_digits = 0;
32 int num_other_symbols = 0;
33 for (size_t i = 0; i < password.size(); i++) {
34 if (isupper(password[i]))
35 ++num_upper_case_letters;
36 else if (islower(password[i]))
37 ++num_lower_case_letters;
38 else if (isdigit(password[i]))
39 ++num_digits;
40 else
41 ++num_other_symbols;
42 }
43 EXPECT_GT(num_upper_case_letters, 0);
44 EXPECT_GT(num_lower_case_letters, 0);
45 EXPECT_GT(num_digits, 0);
46 EXPECT_GT(num_other_symbols, 0);
47 }
48
49 TEST(PasswordGeneratorTest, Printable) {
50 PasswordGenerator pg(12);
17 std::string password = pg.Generate(); 51 std::string password = pg.Generate();
18 for (size_t i = 0; i < password.size(); i++) { 52 for (size_t i = 0; i < password.size(); i++) {
19 // Make sure that the character is printable. 53 // Make sure that the character is printable.
20 EXPECT_TRUE(isgraph(password[i])); 54 EXPECT_TRUE(isgraph(password[i]));
21 } 55 }
22 } 56 }
23 57
24 } // namespace autofill 58 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/password_generator.cc ('k') | chrome/browser/ui/browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698