| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 std::vector<string16> DeserializeVector(const Pickle& pickle) const { | 36 std::vector<string16> DeserializeVector(const Pickle& pickle) const { |
| 37 return db_.DeserializeVector(pickle); | 37 return db_.DeserializeVector(pickle); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SetPublicSuffixMatching(bool enabled) { | 40 void SetPublicSuffixMatching(bool enabled) { |
| 41 db_.public_suffix_domain_matching_ = enabled; | 41 db_.public_suffix_domain_matching_ = enabled; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void FormsAreEqual(const PasswordForm& expected, const PasswordForm& actual) { |
| 45 PasswordForm expected_copy(expected); |
| 46 #if defined(OS_MACOSX) |
| 47 // On the Mac we should never be storing passwords in the database. |
| 48 expected_copy.password_value = ASCIIToUTF16(""); |
| 49 #endif |
| 50 EXPECT_EQ(expected_copy, actual); |
| 51 } |
| 52 |
| 44 base::ScopedTempDir temp_dir_; | 53 base::ScopedTempDir temp_dir_; |
| 45 base::FilePath file_; | 54 base::FilePath file_; |
| 46 LoginDatabase db_; | 55 LoginDatabase db_; |
| 47 }; | 56 }; |
| 48 | 57 |
| 49 TEST_F(LoginDatabaseTest, Logins) { | 58 TEST_F(LoginDatabaseTest, Logins) { |
| 50 std::vector<PasswordForm*> result; | 59 std::vector<PasswordForm*> result; |
| 51 | 60 |
| 52 // Verify the database is empty. | 61 // Verify the database is empty. |
| 53 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 62 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); |
| 54 EXPECT_EQ(0U, result.size()); | 63 EXPECT_EQ(0U, result.size()); |
| 55 | 64 |
| 56 // Example password form. | 65 // Example password form. |
| 57 PasswordForm form; | 66 PasswordForm form; |
| 58 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 67 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 59 form.action = GURL("http://accounts.google.com/Login"); | 68 form.action = GURL("http://accounts.google.com/Login"); |
| 60 form.username_element = ASCIIToUTF16("Email"); | 69 form.username_element = ASCIIToUTF16("Email"); |
| 61 form.username_value = ASCIIToUTF16("test@gmail.com"); | 70 form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 62 form.password_element = ASCIIToUTF16("Passwd"); | 71 form.password_element = ASCIIToUTF16("Passwd"); |
| 63 form.password_value = ASCIIToUTF16("test"); | 72 form.password_value = ASCIIToUTF16("test"); |
| 64 form.submit_element = ASCIIToUTF16("signIn"); | 73 form.submit_element = ASCIIToUTF16("signIn"); |
| 65 form.signon_realm = "http://www.google.com/"; | 74 form.signon_realm = "http://www.google.com/"; |
| 66 form.ssl_valid = false; | 75 form.ssl_valid = false; |
| 67 form.preferred = false; | 76 form.preferred = false; |
| 68 form.scheme = PasswordForm::SCHEME_HTML; | 77 form.scheme = PasswordForm::SCHEME_HTML; |
| 78 form.times_used = 1; |
| 79 form.form_data.name = ASCIIToUTF16("form_name"); |
| 80 form.form_data.method = ASCIIToUTF16("POST"); |
| 69 | 81 |
| 70 // Add it and make sure it is there. | 82 // Add it and make sure it is there and that all the fields were retrieved |
| 83 // correctly. |
| 71 EXPECT_TRUE(db_.AddLogin(form)); | 84 EXPECT_TRUE(db_.AddLogin(form)); |
| 72 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 85 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); |
| 73 EXPECT_EQ(1U, result.size()); | 86 EXPECT_EQ(1U, result.size()); |
| 87 FormsAreEqual(form, *result[0]); |
| 74 delete result[0]; | 88 delete result[0]; |
| 75 result.clear(); | 89 result.clear(); |
| 76 | 90 |
| 77 // Match against an exact copy. | 91 // Match against an exact copy. |
| 78 EXPECT_TRUE(db_.GetLogins(form, &result)); | 92 EXPECT_TRUE(db_.GetLogins(form, &result)); |
| 79 EXPECT_EQ(1U, result.size()); | 93 EXPECT_EQ(1U, result.size()); |
| 80 delete result[0]; | 94 delete result[0]; |
| 81 result.clear(); | 95 result.clear(); |
| 82 | 96 |
| 83 // The example site changes... | 97 // The example site changes... |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 // | 635 // |
| 622 // Only POSIX because GetPosixFilePermissions() only exists on POSIX. | 636 // Only POSIX because GetPosixFilePermissions() only exists on POSIX. |
| 623 // This tests that sql::Connection::set_restrict_to_user() was called, | 637 // This tests that sql::Connection::set_restrict_to_user() was called, |
| 624 // and that function is a noop on non-POSIX platforms in any case. | 638 // and that function is a noop on non-POSIX platforms in any case. |
| 625 TEST_F(LoginDatabaseTest, FilePermissions) { | 639 TEST_F(LoginDatabaseTest, FilePermissions) { |
| 626 int mode = file_util::FILE_PERMISSION_MASK; | 640 int mode = file_util::FILE_PERMISSION_MASK; |
| 627 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_, &mode)); | 641 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_, &mode)); |
| 628 EXPECT_EQ((mode & file_util::FILE_PERMISSION_USER_MASK), mode); | 642 EXPECT_EQ((mode & file_util::FILE_PERMISSION_USER_MASK), mode); |
| 629 } | 643 } |
| 630 #endif // defined(OS_POSIX) | 644 #endif // defined(OS_POSIX) |
| OLD | NEW |