| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/core/browser/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/histogram_tester.h" | 15 #include "base/test/histogram_tester.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
| 17 #include "components/password_manager/core/browser/psl_matching_helper.h" | 18 #include "components/password_manager/core/browser/psl_matching_helper.h" |
| 18 #include "sql/connection.h" | 19 #include "sql/connection.h" |
| 19 #include "sql/statement.h" | 20 #include "sql/statement.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // Serialization routines for vectors implemented in login_database.cc. | 73 // Serialization routines for vectors implemented in login_database.cc. |
| 73 Pickle SerializeVector(const std::vector<base::string16>& vec); | 74 Pickle SerializeVector(const std::vector<base::string16>& vec); |
| 74 std::vector<base::string16> DeserializeVector(const Pickle& pickle); | 75 std::vector<base::string16> DeserializeVector(const Pickle& pickle); |
| 75 | 76 |
| 76 class LoginDatabaseTest : public testing::Test { | 77 class LoginDatabaseTest : public testing::Test { |
| 77 protected: | 78 protected: |
| 78 void SetUp() override { | 79 void SetUp() override { |
| 79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 80 file_ = temp_dir_.path().AppendASCII("TestMetadataStoreMacDatabase"); | 81 file_ = temp_dir_.path().AppendASCII("TestMetadataStoreMacDatabase"); |
| 81 | 82 |
| 82 ASSERT_TRUE(db_.Init(file_)); | 83 db_.reset(new LoginDatabase(file_)); |
| 84 ASSERT_TRUE(db_->Init()); |
| 83 } | 85 } |
| 84 | 86 |
| 87 LoginDatabase& db() { return *db_; } |
| 88 |
| 85 void TestNonHTMLFormPSLMatching(const PasswordForm::Scheme& scheme) { | 89 void TestNonHTMLFormPSLMatching(const PasswordForm::Scheme& scheme) { |
| 86 ScopedVector<PasswordForm> result; | 90 ScopedVector<PasswordForm> result; |
| 87 | 91 |
| 88 base::Time now = base::Time::Now(); | 92 base::Time now = base::Time::Now(); |
| 89 | 93 |
| 90 // Simple non-html auth form. | 94 // Simple non-html auth form. |
| 91 PasswordForm non_html_auth; | 95 PasswordForm non_html_auth; |
| 92 non_html_auth.origin = GURL("http://example.com"); | 96 non_html_auth.origin = GURL("http://example.com"); |
| 93 non_html_auth.username_value = ASCIIToUTF16("test@gmail.com"); | 97 non_html_auth.username_value = ASCIIToUTF16("test@gmail.com"); |
| 94 non_html_auth.password_value = ASCIIToUTF16("test"); | 98 non_html_auth.password_value = ASCIIToUTF16("test"); |
| 95 non_html_auth.signon_realm = "http://example.com/Realm"; | 99 non_html_auth.signon_realm = "http://example.com/Realm"; |
| 96 non_html_auth.scheme = scheme; | 100 non_html_auth.scheme = scheme; |
| 97 non_html_auth.date_created = now; | 101 non_html_auth.date_created = now; |
| 98 | 102 |
| 99 // Simple password form. | 103 // Simple password form. |
| 100 PasswordForm html_form(non_html_auth); | 104 PasswordForm html_form(non_html_auth); |
| 101 html_form.action = GURL("http://example.com/login"); | 105 html_form.action = GURL("http://example.com/login"); |
| 102 html_form.username_element = ASCIIToUTF16("username"); | 106 html_form.username_element = ASCIIToUTF16("username"); |
| 103 html_form.username_value = ASCIIToUTF16("test2@gmail.com"); | 107 html_form.username_value = ASCIIToUTF16("test2@gmail.com"); |
| 104 html_form.password_element = ASCIIToUTF16("password"); | 108 html_form.password_element = ASCIIToUTF16("password"); |
| 105 html_form.submit_element = ASCIIToUTF16(""); | 109 html_form.submit_element = ASCIIToUTF16(""); |
| 106 html_form.signon_realm = "http://example.com/"; | 110 html_form.signon_realm = "http://example.com/"; |
| 107 html_form.scheme = PasswordForm::SCHEME_HTML; | 111 html_form.scheme = PasswordForm::SCHEME_HTML; |
| 108 html_form.date_created = now; | 112 html_form.date_created = now; |
| 109 | 113 |
| 110 // Add them and make sure they are there. | 114 // Add them and make sure they are there. |
| 111 EXPECT_EQ(AddChangeForForm(non_html_auth), db_.AddLogin(non_html_auth)); | 115 EXPECT_EQ(AddChangeForForm(non_html_auth), db().AddLogin(non_html_auth)); |
| 112 EXPECT_EQ(AddChangeForForm(html_form), db_.AddLogin(html_form)); | 116 EXPECT_EQ(AddChangeForForm(html_form), db().AddLogin(html_form)); |
| 113 EXPECT_TRUE(db_.GetAutofillableLogins(&result.get())); | 117 EXPECT_TRUE(db().GetAutofillableLogins(&result.get())); |
| 114 EXPECT_EQ(2U, result.size()); | 118 EXPECT_EQ(2U, result.size()); |
| 115 result.clear(); | 119 result.clear(); |
| 116 | 120 |
| 117 PasswordForm second_non_html_auth(non_html_auth); | 121 PasswordForm second_non_html_auth(non_html_auth); |
| 118 second_non_html_auth.origin = GURL("http://second.example.com"); | 122 second_non_html_auth.origin = GURL("http://second.example.com"); |
| 119 second_non_html_auth.signon_realm = "http://second.example.com/Realm"; | 123 second_non_html_auth.signon_realm = "http://second.example.com/Realm"; |
| 120 | 124 |
| 121 // This shouldn't match anything. | 125 // This shouldn't match anything. |
| 122 EXPECT_TRUE(db_.GetLogins(second_non_html_auth, &result.get())); | 126 EXPECT_TRUE(db().GetLogins(second_non_html_auth, &result.get())); |
| 123 EXPECT_EQ(0U, result.size()); | 127 EXPECT_EQ(0U, result.size()); |
| 124 | 128 |
| 125 // non-html auth still matches against itself. | 129 // non-html auth still matches against itself. |
| 126 EXPECT_TRUE(db_.GetLogins(non_html_auth, &result.get())); | 130 EXPECT_TRUE(db().GetLogins(non_html_auth, &result.get())); |
| 127 ASSERT_EQ(1U, result.size()); | 131 ASSERT_EQ(1U, result.size()); |
| 128 EXPECT_EQ(result[0]->signon_realm, "http://example.com/Realm"); | 132 EXPECT_EQ(result[0]->signon_realm, "http://example.com/Realm"); |
| 129 | 133 |
| 130 // Clear state. | 134 // Clear state. |
| 131 db_.RemoveLoginsCreatedBetween(now, base::Time()); | 135 db().RemoveLoginsCreatedBetween(now, base::Time()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 // Checks that a form of a given |scheme|, once stored, can be successfully | 138 // Checks that a form of a given |scheme|, once stored, can be successfully |
| 135 // retrieved from the database. | 139 // retrieved from the database. |
| 136 void TestRetrievingIPAddress(const PasswordForm::Scheme& scheme) { | 140 void TestRetrievingIPAddress(const PasswordForm::Scheme& scheme) { |
| 137 SCOPED_TRACE(testing::Message() << "scheme = " << scheme); | 141 SCOPED_TRACE(testing::Message() << "scheme = " << scheme); |
| 138 ScopedVector<PasswordForm> result; | 142 ScopedVector<PasswordForm> result; |
| 139 | 143 |
| 140 base::Time now = base::Time::Now(); | 144 base::Time now = base::Time::Now(); |
| 141 std::string origin("http://56.7.8.90"); | 145 std::string origin("http://56.7.8.90"); |
| 142 | 146 |
| 143 PasswordForm ip_form; | 147 PasswordForm ip_form; |
| 144 ip_form.origin = GURL(origin); | 148 ip_form.origin = GURL(origin); |
| 145 ip_form.username_value = ASCIIToUTF16("test@gmail.com"); | 149 ip_form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 146 ip_form.password_value = ASCIIToUTF16("test"); | 150 ip_form.password_value = ASCIIToUTF16("test"); |
| 147 ip_form.signon_realm = origin; | 151 ip_form.signon_realm = origin; |
| 148 ip_form.scheme = scheme; | 152 ip_form.scheme = scheme; |
| 149 ip_form.date_created = now; | 153 ip_form.date_created = now; |
| 150 | 154 |
| 151 EXPECT_EQ(AddChangeForForm(ip_form), db_.AddLogin(ip_form)); | 155 EXPECT_EQ(AddChangeForForm(ip_form), db().AddLogin(ip_form)); |
| 152 EXPECT_TRUE(db_.GetLogins(ip_form, &result.get())); | 156 EXPECT_TRUE(db().GetLogins(ip_form, &result.get())); |
| 153 ASSERT_EQ(1U, result.size()); | 157 ASSERT_EQ(1U, result.size()); |
| 154 EXPECT_EQ(result[0]->signon_realm, origin); | 158 EXPECT_EQ(result[0]->signon_realm, origin); |
| 155 | 159 |
| 156 // Clear state. | 160 // Clear state. |
| 157 db_.RemoveLoginsCreatedBetween(now, base::Time()); | 161 db().RemoveLoginsCreatedBetween(now, base::Time()); |
| 158 } | 162 } |
| 159 | 163 |
| 160 base::ScopedTempDir temp_dir_; | 164 base::ScopedTempDir temp_dir_; |
| 161 base::FilePath file_; | 165 base::FilePath file_; |
| 162 LoginDatabase db_; | 166 scoped_ptr<LoginDatabase> db_; |
| 163 }; | 167 }; |
| 164 | 168 |
| 165 TEST_F(LoginDatabaseTest, Logins) { | 169 TEST_F(LoginDatabaseTest, Logins) { |
| 166 std::vector<PasswordForm*> result; | 170 std::vector<PasswordForm*> result; |
| 167 | 171 |
| 168 // Verify the database is empty. | 172 // Verify the database is empty. |
| 169 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 173 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 170 EXPECT_EQ(0U, result.size()); | 174 EXPECT_EQ(0U, result.size()); |
| 171 | 175 |
| 172 // Example password form. | 176 // Example password form. |
| 173 PasswordForm form; | 177 PasswordForm form; |
| 174 GenerateExamplePasswordForm(&form); | 178 GenerateExamplePasswordForm(&form); |
| 175 | 179 |
| 176 // Add it and make sure it is there and that all the fields were retrieved | 180 // Add it and make sure it is there and that all the fields were retrieved |
| 177 // correctly. | 181 // correctly. |
| 178 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 182 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 179 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 183 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 180 ASSERT_EQ(1U, result.size()); | 184 ASSERT_EQ(1U, result.size()); |
| 181 FormsAreEqual(form, *result[0]); | 185 FormsAreEqual(form, *result[0]); |
| 182 delete result[0]; | 186 delete result[0]; |
| 183 result.clear(); | 187 result.clear(); |
| 184 | 188 |
| 185 // Match against an exact copy. | 189 // Match against an exact copy. |
| 186 EXPECT_TRUE(db_.GetLogins(form, &result)); | 190 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 187 ASSERT_EQ(1U, result.size()); | 191 ASSERT_EQ(1U, result.size()); |
| 188 FormsAreEqual(form, *result[0]); | 192 FormsAreEqual(form, *result[0]); |
| 189 delete result[0]; | 193 delete result[0]; |
| 190 result.clear(); | 194 result.clear(); |
| 191 | 195 |
| 192 // The example site changes... | 196 // The example site changes... |
| 193 PasswordForm form2(form); | 197 PasswordForm form2(form); |
| 194 form2.origin = GURL("http://www.google.com/new/accounts/LoginAuth"); | 198 form2.origin = GURL("http://www.google.com/new/accounts/LoginAuth"); |
| 195 form2.submit_element = ASCIIToUTF16("reallySignIn"); | 199 form2.submit_element = ASCIIToUTF16("reallySignIn"); |
| 196 | 200 |
| 197 // Match against an inexact copy | 201 // Match against an inexact copy |
| 198 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 202 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 199 EXPECT_EQ(1U, result.size()); | 203 EXPECT_EQ(1U, result.size()); |
| 200 delete result[0]; | 204 delete result[0]; |
| 201 result.clear(); | 205 result.clear(); |
| 202 | 206 |
| 203 // Uh oh, the site changed origin & action URLs all at once! | 207 // Uh oh, the site changed origin & action URLs all at once! |
| 204 PasswordForm form3(form2); | 208 PasswordForm form3(form2); |
| 205 form3.action = GURL("http://www.google.com/new/accounts/Login"); | 209 form3.action = GURL("http://www.google.com/new/accounts/Login"); |
| 206 | 210 |
| 207 // signon_realm is the same, should match. | 211 // signon_realm is the same, should match. |
| 208 EXPECT_TRUE(db_.GetLogins(form3, &result)); | 212 EXPECT_TRUE(db().GetLogins(form3, &result)); |
| 209 EXPECT_EQ(1U, result.size()); | 213 EXPECT_EQ(1U, result.size()); |
| 210 delete result[0]; | 214 delete result[0]; |
| 211 result.clear(); | 215 result.clear(); |
| 212 | 216 |
| 213 // Imagine the site moves to a secure server for login. | 217 // Imagine the site moves to a secure server for login. |
| 214 PasswordForm form4(form3); | 218 PasswordForm form4(form3); |
| 215 form4.signon_realm = "https://www.google.com/"; | 219 form4.signon_realm = "https://www.google.com/"; |
| 216 form4.ssl_valid = true; | 220 form4.ssl_valid = true; |
| 217 | 221 |
| 218 // We have only an http record, so no match for this. | 222 // We have only an http record, so no match for this. |
| 219 EXPECT_TRUE(db_.GetLogins(form4, &result)); | 223 EXPECT_TRUE(db().GetLogins(form4, &result)); |
| 220 EXPECT_EQ(0U, result.size()); | 224 EXPECT_EQ(0U, result.size()); |
| 221 | 225 |
| 222 // Let's imagine the user logs into the secure site. | 226 // Let's imagine the user logs into the secure site. |
| 223 EXPECT_EQ(AddChangeForForm(form4), db_.AddLogin(form4)); | 227 EXPECT_EQ(AddChangeForForm(form4), db().AddLogin(form4)); |
| 224 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 228 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 225 EXPECT_EQ(2U, result.size()); | 229 EXPECT_EQ(2U, result.size()); |
| 226 delete result[0]; | 230 delete result[0]; |
| 227 delete result[1]; | 231 delete result[1]; |
| 228 result.clear(); | 232 result.clear(); |
| 229 | 233 |
| 230 // Now the match works | 234 // Now the match works |
| 231 EXPECT_TRUE(db_.GetLogins(form4, &result)); | 235 EXPECT_TRUE(db().GetLogins(form4, &result)); |
| 232 EXPECT_EQ(1U, result.size()); | 236 EXPECT_EQ(1U, result.size()); |
| 233 delete result[0]; | 237 delete result[0]; |
| 234 result.clear(); | 238 result.clear(); |
| 235 | 239 |
| 236 // The user chose to forget the original but not the new. | 240 // The user chose to forget the original but not the new. |
| 237 EXPECT_TRUE(db_.RemoveLogin(form)); | 241 EXPECT_TRUE(db().RemoveLogin(form)); |
| 238 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 242 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 239 EXPECT_EQ(1U, result.size()); | 243 EXPECT_EQ(1U, result.size()); |
| 240 delete result[0]; | 244 delete result[0]; |
| 241 result.clear(); | 245 result.clear(); |
| 242 | 246 |
| 243 // The old form wont match the new site (http vs https). | 247 // The old form wont match the new site (http vs https). |
| 244 EXPECT_TRUE(db_.GetLogins(form, &result)); | 248 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 245 EXPECT_EQ(0U, result.size()); | 249 EXPECT_EQ(0U, result.size()); |
| 246 | 250 |
| 247 // The user's request for the HTTPS site is intercepted | 251 // The user's request for the HTTPS site is intercepted |
| 248 // by an attacker who presents an invalid SSL cert. | 252 // by an attacker who presents an invalid SSL cert. |
| 249 PasswordForm form5(form4); | 253 PasswordForm form5(form4); |
| 250 form5.ssl_valid = 0; | 254 form5.ssl_valid = 0; |
| 251 | 255 |
| 252 // It will match in this case. | 256 // It will match in this case. |
| 253 EXPECT_TRUE(db_.GetLogins(form5, &result)); | 257 EXPECT_TRUE(db().GetLogins(form5, &result)); |
| 254 EXPECT_EQ(1U, result.size()); | 258 EXPECT_EQ(1U, result.size()); |
| 255 delete result[0]; | 259 delete result[0]; |
| 256 result.clear(); | 260 result.clear(); |
| 257 | 261 |
| 258 // User changes his password. | 262 // User changes his password. |
| 259 PasswordForm form6(form5); | 263 PasswordForm form6(form5); |
| 260 form6.password_value = ASCIIToUTF16("test6"); | 264 form6.password_value = ASCIIToUTF16("test6"); |
| 261 form6.preferred = true; | 265 form6.preferred = true; |
| 262 | 266 |
| 263 // We update, and check to make sure it matches the | 267 // We update, and check to make sure it matches the |
| 264 // old form, and there is only one record. | 268 // old form, and there is only one record. |
| 265 EXPECT_EQ(UpdateChangeForForm(form6), db_.UpdateLogin(form6)); | 269 EXPECT_EQ(UpdateChangeForForm(form6), db().UpdateLogin(form6)); |
| 266 // matches | 270 // matches |
| 267 EXPECT_TRUE(db_.GetLogins(form5, &result)); | 271 EXPECT_TRUE(db().GetLogins(form5, &result)); |
| 268 EXPECT_EQ(1U, result.size()); | 272 EXPECT_EQ(1U, result.size()); |
| 269 delete result[0]; | 273 delete result[0]; |
| 270 result.clear(); | 274 result.clear(); |
| 271 // Only one record. | 275 // Only one record. |
| 272 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 276 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 273 EXPECT_EQ(1U, result.size()); | 277 EXPECT_EQ(1U, result.size()); |
| 274 // Password element was updated. | 278 // Password element was updated. |
| 275 #if defined(OS_MACOSX) && !defined(OS_IOS) | 279 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 276 // On the Mac we should never be storing passwords in the database. | 280 // On the Mac we should never be storing passwords in the database. |
| 277 EXPECT_EQ(base::string16(), result[0]->password_value); | 281 EXPECT_EQ(base::string16(), result[0]->password_value); |
| 278 #else | 282 #else |
| 279 EXPECT_EQ(form6.password_value, result[0]->password_value); | 283 EXPECT_EQ(form6.password_value, result[0]->password_value); |
| 280 #endif | 284 #endif |
| 281 // Preferred login. | 285 // Preferred login. |
| 282 EXPECT_TRUE(form6.preferred); | 286 EXPECT_TRUE(form6.preferred); |
| 283 delete result[0]; | 287 delete result[0]; |
| 284 result.clear(); | 288 result.clear(); |
| 285 | 289 |
| 286 // Make sure everything can disappear. | 290 // Make sure everything can disappear. |
| 287 EXPECT_TRUE(db_.RemoveLogin(form4)); | 291 EXPECT_TRUE(db().RemoveLogin(form4)); |
| 288 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 292 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 289 EXPECT_EQ(0U, result.size()); | 293 EXPECT_EQ(0U, result.size()); |
| 290 } | 294 } |
| 291 | 295 |
| 292 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatching) { | 296 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatching) { |
| 293 std::vector<PasswordForm*> result; | 297 std::vector<PasswordForm*> result; |
| 294 | 298 |
| 295 // Verify the database is empty. | 299 // Verify the database is empty. |
| 296 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 300 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 297 EXPECT_EQ(0U, result.size()); | 301 EXPECT_EQ(0U, result.size()); |
| 298 | 302 |
| 299 // Example password form. | 303 // Example password form. |
| 300 PasswordForm form; | 304 PasswordForm form; |
| 301 form.origin = GURL("https://foo.com/"); | 305 form.origin = GURL("https://foo.com/"); |
| 302 form.action = GURL("https://foo.com/login"); | 306 form.action = GURL("https://foo.com/login"); |
| 303 form.username_element = ASCIIToUTF16("username"); | 307 form.username_element = ASCIIToUTF16("username"); |
| 304 form.username_value = ASCIIToUTF16("test@gmail.com"); | 308 form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 305 form.password_element = ASCIIToUTF16("password"); | 309 form.password_element = ASCIIToUTF16("password"); |
| 306 form.password_value = ASCIIToUTF16("test"); | 310 form.password_value = ASCIIToUTF16("test"); |
| 307 form.submit_element = ASCIIToUTF16(""); | 311 form.submit_element = ASCIIToUTF16(""); |
| 308 form.signon_realm = "https://foo.com/"; | 312 form.signon_realm = "https://foo.com/"; |
| 309 form.ssl_valid = true; | 313 form.ssl_valid = true; |
| 310 form.preferred = false; | 314 form.preferred = false; |
| 311 form.scheme = PasswordForm::SCHEME_HTML; | 315 form.scheme = PasswordForm::SCHEME_HTML; |
| 312 | 316 |
| 313 // Add it and make sure it is there. | 317 // Add it and make sure it is there. |
| 314 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 318 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 315 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 319 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 316 EXPECT_EQ(1U, result.size()); | 320 EXPECT_EQ(1U, result.size()); |
| 317 delete result[0]; | 321 delete result[0]; |
| 318 result.clear(); | 322 result.clear(); |
| 319 | 323 |
| 320 // Match against an exact copy. | 324 // Match against an exact copy. |
| 321 EXPECT_TRUE(db_.GetLogins(form, &result)); | 325 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 322 EXPECT_EQ(1U, result.size()); | 326 EXPECT_EQ(1U, result.size()); |
| 323 delete result[0]; | 327 delete result[0]; |
| 324 result.clear(); | 328 result.clear(); |
| 325 | 329 |
| 326 // We go to the mobile site. | 330 // We go to the mobile site. |
| 327 PasswordForm form2(form); | 331 PasswordForm form2(form); |
| 328 form2.origin = GURL("https://mobile.foo.com/"); | 332 form2.origin = GURL("https://mobile.foo.com/"); |
| 329 form2.action = GURL("https://mobile.foo.com/login"); | 333 form2.action = GURL("https://mobile.foo.com/login"); |
| 330 form2.signon_realm = "https://mobile.foo.com/"; | 334 form2.signon_realm = "https://mobile.foo.com/"; |
| 331 | 335 |
| 332 // Match against the mobile site. | 336 // Match against the mobile site. |
| 333 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 337 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 334 EXPECT_EQ(1U, result.size()); | 338 EXPECT_EQ(1U, result.size()); |
| 335 EXPECT_EQ("https://mobile.foo.com/", result[0]->signon_realm); | 339 EXPECT_EQ("https://mobile.foo.com/", result[0]->signon_realm); |
| 336 EXPECT_EQ("https://foo.com/", result[0]->original_signon_realm); | 340 EXPECT_EQ("https://foo.com/", result[0]->original_signon_realm); |
| 337 | 341 |
| 338 // Try to remove PSL matched form | 342 // Try to remove PSL matched form |
| 339 EXPECT_FALSE(db_.RemoveLogin(*result[0])); | 343 EXPECT_FALSE(db().RemoveLogin(*result[0])); |
| 340 delete result[0]; | 344 delete result[0]; |
| 341 result.clear(); | 345 result.clear(); |
| 342 // Ensure that the original form is still there | 346 // Ensure that the original form is still there |
| 343 EXPECT_TRUE(db_.GetLogins(form, &result)); | 347 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 344 EXPECT_EQ(1U, result.size()); | 348 EXPECT_EQ(1U, result.size()); |
| 345 delete result[0]; | 349 delete result[0]; |
| 346 result.clear(); | 350 result.clear(); |
| 347 } | 351 } |
| 348 | 352 |
| 349 TEST_F(LoginDatabaseTest, TestPublicSuffixDisabledForNonHTMLForms) { | 353 TEST_F(LoginDatabaseTest, TestPublicSuffixDisabledForNonHTMLForms) { |
| 350 TestNonHTMLFormPSLMatching(PasswordForm::SCHEME_BASIC); | 354 TestNonHTMLFormPSLMatching(PasswordForm::SCHEME_BASIC); |
| 351 TestNonHTMLFormPSLMatching(PasswordForm::SCHEME_DIGEST); | 355 TestNonHTMLFormPSLMatching(PasswordForm::SCHEME_DIGEST); |
| 352 TestNonHTMLFormPSLMatching(PasswordForm::SCHEME_OTHER); | 356 TestNonHTMLFormPSLMatching(PasswordForm::SCHEME_OTHER); |
| 353 } | 357 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 365 } | 369 } |
| 366 | 370 |
| 367 TEST_F(LoginDatabaseTest, TestIPAddressMatches_other) { | 371 TEST_F(LoginDatabaseTest, TestIPAddressMatches_other) { |
| 368 TestRetrievingIPAddress(PasswordForm::SCHEME_OTHER); | 372 TestRetrievingIPAddress(PasswordForm::SCHEME_OTHER); |
| 369 } | 373 } |
| 370 | 374 |
| 371 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingShouldMatchingApply) { | 375 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingShouldMatchingApply) { |
| 372 std::vector<PasswordForm*> result; | 376 std::vector<PasswordForm*> result; |
| 373 | 377 |
| 374 // Verify the database is empty. | 378 // Verify the database is empty. |
| 375 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 379 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 376 EXPECT_EQ(0U, result.size()); | 380 EXPECT_EQ(0U, result.size()); |
| 377 | 381 |
| 378 // Example password form. | 382 // Example password form. |
| 379 PasswordForm form; | 383 PasswordForm form; |
| 380 form.origin = GURL("https://accounts.google.com/"); | 384 form.origin = GURL("https://accounts.google.com/"); |
| 381 form.action = GURL("https://accounts.google.com/login"); | 385 form.action = GURL("https://accounts.google.com/login"); |
| 382 form.username_element = ASCIIToUTF16("username"); | 386 form.username_element = ASCIIToUTF16("username"); |
| 383 form.username_value = ASCIIToUTF16("test@gmail.com"); | 387 form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 384 form.password_element = ASCIIToUTF16("password"); | 388 form.password_element = ASCIIToUTF16("password"); |
| 385 form.password_value = ASCIIToUTF16("test"); | 389 form.password_value = ASCIIToUTF16("test"); |
| 386 form.submit_element = ASCIIToUTF16(""); | 390 form.submit_element = ASCIIToUTF16(""); |
| 387 form.signon_realm = "https://accounts.google.com/"; | 391 form.signon_realm = "https://accounts.google.com/"; |
| 388 form.ssl_valid = true; | 392 form.ssl_valid = true; |
| 389 form.preferred = false; | 393 form.preferred = false; |
| 390 form.scheme = PasswordForm::SCHEME_HTML; | 394 form.scheme = PasswordForm::SCHEME_HTML; |
| 391 | 395 |
| 392 // Add it and make sure it is there. | 396 // Add it and make sure it is there. |
| 393 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 397 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 394 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 398 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 395 EXPECT_EQ(1U, result.size()); | 399 EXPECT_EQ(1U, result.size()); |
| 396 delete result[0]; | 400 delete result[0]; |
| 397 result.clear(); | 401 result.clear(); |
| 398 | 402 |
| 399 // Match against an exact copy. | 403 // Match against an exact copy. |
| 400 EXPECT_TRUE(db_.GetLogins(form, &result)); | 404 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 401 EXPECT_EQ(1U, result.size()); | 405 EXPECT_EQ(1U, result.size()); |
| 402 delete result[0]; | 406 delete result[0]; |
| 403 result.clear(); | 407 result.clear(); |
| 404 | 408 |
| 405 // We go to a different site on the same domain where feature is not needed. | 409 // We go to a different site on the same domain where feature is not needed. |
| 406 PasswordForm form2(form); | 410 PasswordForm form2(form); |
| 407 form2.origin = GURL("https://some.other.google.com/"); | 411 form2.origin = GURL("https://some.other.google.com/"); |
| 408 form2.action = GURL("https://some.other.google.com/login"); | 412 form2.action = GURL("https://some.other.google.com/login"); |
| 409 form2.signon_realm = "https://some.other.google.com/"; | 413 form2.signon_realm = "https://some.other.google.com/"; |
| 410 | 414 |
| 411 // Match against the other site. Should not match since feature should not be | 415 // Match against the other site. Should not match since feature should not be |
| 412 // enabled for this domain. | 416 // enabled for this domain. |
| 413 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 417 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 414 EXPECT_EQ(0U, result.size()); | 418 EXPECT_EQ(0U, result.size()); |
| 415 } | 419 } |
| 416 | 420 |
| 417 // This test fails if the implementation of GetLogins uses GetCachedStatement | 421 // This test fails if the implementation of GetLogins uses GetCachedStatement |
| 418 // instead of GetUniqueStatement, since REGEXP is in use. See | 422 // instead of GetUniqueStatement, since REGEXP is in use. See |
| 419 // http://crbug.com/248608. | 423 // http://crbug.com/248608. |
| 420 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) { | 424 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) { |
| 421 std::vector<PasswordForm*> result; | 425 std::vector<PasswordForm*> result; |
| 422 | 426 |
| 423 // Verify the database is empty. | 427 // Verify the database is empty. |
| 424 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 428 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 425 EXPECT_EQ(0U, result.size()); | 429 EXPECT_EQ(0U, result.size()); |
| 426 | 430 |
| 427 // Example password form. | 431 // Example password form. |
| 428 PasswordForm form; | 432 PasswordForm form; |
| 429 form.origin = GURL("https://foo.com/"); | 433 form.origin = GURL("https://foo.com/"); |
| 430 form.action = GURL("https://foo.com/login"); | 434 form.action = GURL("https://foo.com/login"); |
| 431 form.username_element = ASCIIToUTF16("username"); | 435 form.username_element = ASCIIToUTF16("username"); |
| 432 form.username_value = ASCIIToUTF16("test@gmail.com"); | 436 form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 433 form.password_element = ASCIIToUTF16("password"); | 437 form.password_element = ASCIIToUTF16("password"); |
| 434 form.password_value = ASCIIToUTF16("test"); | 438 form.password_value = ASCIIToUTF16("test"); |
| 435 form.submit_element = ASCIIToUTF16(""); | 439 form.submit_element = ASCIIToUTF16(""); |
| 436 form.signon_realm = "https://foo.com/"; | 440 form.signon_realm = "https://foo.com/"; |
| 437 form.ssl_valid = true; | 441 form.ssl_valid = true; |
| 438 form.preferred = false; | 442 form.preferred = false; |
| 439 form.scheme = PasswordForm::SCHEME_HTML; | 443 form.scheme = PasswordForm::SCHEME_HTML; |
| 440 | 444 |
| 441 // Add it and make sure it is there. | 445 // Add it and make sure it is there. |
| 442 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 446 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 443 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 447 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 444 EXPECT_EQ(1U, result.size()); | 448 EXPECT_EQ(1U, result.size()); |
| 445 delete result[0]; | 449 delete result[0]; |
| 446 result.clear(); | 450 result.clear(); |
| 447 | 451 |
| 448 // Match against an exact copy. | 452 // Match against an exact copy. |
| 449 EXPECT_TRUE(db_.GetLogins(form, &result)); | 453 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 450 EXPECT_EQ(1U, result.size()); | 454 EXPECT_EQ(1U, result.size()); |
| 451 delete result[0]; | 455 delete result[0]; |
| 452 result.clear(); | 456 result.clear(); |
| 453 | 457 |
| 454 // We go to the mobile site. | 458 // We go to the mobile site. |
| 455 PasswordForm form2(form); | 459 PasswordForm form2(form); |
| 456 form2.origin = GURL("https://mobile.foo.com/"); | 460 form2.origin = GURL("https://mobile.foo.com/"); |
| 457 form2.action = GURL("https://mobile.foo.com/login"); | 461 form2.action = GURL("https://mobile.foo.com/login"); |
| 458 form2.signon_realm = "https://mobile.foo.com/"; | 462 form2.signon_realm = "https://mobile.foo.com/"; |
| 459 | 463 |
| 460 // Match against the mobile site. | 464 // Match against the mobile site. |
| 461 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 465 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 462 EXPECT_EQ(1U, result.size()); | 466 EXPECT_EQ(1U, result.size()); |
| 463 EXPECT_EQ("https://mobile.foo.com/", result[0]->signon_realm); | 467 EXPECT_EQ("https://mobile.foo.com/", result[0]->signon_realm); |
| 464 EXPECT_EQ("https://foo.com/", result[0]->original_signon_realm); | 468 EXPECT_EQ("https://foo.com/", result[0]->original_signon_realm); |
| 465 delete result[0]; | 469 delete result[0]; |
| 466 result.clear(); | 470 result.clear(); |
| 467 | 471 |
| 468 // Add baz.com desktop site. | 472 // Add baz.com desktop site. |
| 469 form.origin = GURL("https://baz.com/login/"); | 473 form.origin = GURL("https://baz.com/login/"); |
| 470 form.action = GURL("https://baz.com/login/"); | 474 form.action = GURL("https://baz.com/login/"); |
| 471 form.username_element = ASCIIToUTF16("email"); | 475 form.username_element = ASCIIToUTF16("email"); |
| 472 form.username_value = ASCIIToUTF16("test@gmail.com"); | 476 form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 473 form.password_element = ASCIIToUTF16("password"); | 477 form.password_element = ASCIIToUTF16("password"); |
| 474 form.password_value = ASCIIToUTF16("test"); | 478 form.password_value = ASCIIToUTF16("test"); |
| 475 form.submit_element = ASCIIToUTF16(""); | 479 form.submit_element = ASCIIToUTF16(""); |
| 476 form.signon_realm = "https://baz.com/"; | 480 form.signon_realm = "https://baz.com/"; |
| 477 form.ssl_valid = true; | 481 form.ssl_valid = true; |
| 478 form.preferred = false; | 482 form.preferred = false; |
| 479 form.scheme = PasswordForm::SCHEME_HTML; | 483 form.scheme = PasswordForm::SCHEME_HTML; |
| 480 | 484 |
| 481 // Add it and make sure it is there. | 485 // Add it and make sure it is there. |
| 482 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 486 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 483 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 487 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 484 EXPECT_EQ(2U, result.size()); | 488 EXPECT_EQ(2U, result.size()); |
| 485 delete result[0]; | 489 delete result[0]; |
| 486 delete result[1]; | 490 delete result[1]; |
| 487 result.clear(); | 491 result.clear(); |
| 488 | 492 |
| 489 // We go to the mobile site of baz.com. | 493 // We go to the mobile site of baz.com. |
| 490 PasswordForm form3(form); | 494 PasswordForm form3(form); |
| 491 form3.origin = GURL("https://m.baz.com/login/"); | 495 form3.origin = GURL("https://m.baz.com/login/"); |
| 492 form3.action = GURL("https://m.baz.com/login/"); | 496 form3.action = GURL("https://m.baz.com/login/"); |
| 493 form3.signon_realm = "https://m.baz.com/"; | 497 form3.signon_realm = "https://m.baz.com/"; |
| 494 | 498 |
| 495 // Match against the mobile site of baz.com. | 499 // Match against the mobile site of baz.com. |
| 496 EXPECT_TRUE(db_.GetLogins(form3, &result)); | 500 EXPECT_TRUE(db().GetLogins(form3, &result)); |
| 497 EXPECT_EQ(1U, result.size()); | 501 EXPECT_EQ(1U, result.size()); |
| 498 EXPECT_EQ("https://m.baz.com/", result[0]->signon_realm); | 502 EXPECT_EQ("https://m.baz.com/", result[0]->signon_realm); |
| 499 EXPECT_EQ("https://baz.com/", result[0]->original_signon_realm); | 503 EXPECT_EQ("https://baz.com/", result[0]->original_signon_realm); |
| 500 delete result[0]; | 504 delete result[0]; |
| 501 result.clear(); | 505 result.clear(); |
| 502 } | 506 } |
| 503 | 507 |
| 504 PasswordForm GetFormWithNewSignonRealm(PasswordForm form, | 508 PasswordForm GetFormWithNewSignonRealm(PasswordForm form, |
| 505 std::string signon_realm) { | 509 std::string signon_realm) { |
| 506 PasswordForm form2(form); | 510 PasswordForm form2(form); |
| 507 form2.origin = GURL(signon_realm); | 511 form2.origin = GURL(signon_realm); |
| 508 form2.action = GURL(signon_realm); | 512 form2.action = GURL(signon_realm); |
| 509 form2.signon_realm = signon_realm; | 513 form2.signon_realm = signon_realm; |
| 510 return form2; | 514 return form2; |
| 511 } | 515 } |
| 512 | 516 |
| 513 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingRegexp) { | 517 TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingRegexp) { |
| 514 std::vector<PasswordForm*> result; | 518 std::vector<PasswordForm*> result; |
| 515 | 519 |
| 516 // Verify the database is empty. | 520 // Verify the database is empty. |
| 517 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 521 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 518 EXPECT_EQ(0U, result.size()); | 522 EXPECT_EQ(0U, result.size()); |
| 519 | 523 |
| 520 // Example password form. | 524 // Example password form. |
| 521 PasswordForm form; | 525 PasswordForm form; |
| 522 form.origin = GURL("http://foo.com/"); | 526 form.origin = GURL("http://foo.com/"); |
| 523 form.action = GURL("http://foo.com/login"); | 527 form.action = GURL("http://foo.com/login"); |
| 524 form.username_element = ASCIIToUTF16("username"); | 528 form.username_element = ASCIIToUTF16("username"); |
| 525 form.username_value = ASCIIToUTF16("test@gmail.com"); | 529 form.username_value = ASCIIToUTF16("test@gmail.com"); |
| 526 form.password_element = ASCIIToUTF16("password"); | 530 form.password_element = ASCIIToUTF16("password"); |
| 527 form.password_value = ASCIIToUTF16("test"); | 531 form.password_value = ASCIIToUTF16("test"); |
| 528 form.submit_element = ASCIIToUTF16(""); | 532 form.submit_element = ASCIIToUTF16(""); |
| 529 form.signon_realm = "http://foo.com/"; | 533 form.signon_realm = "http://foo.com/"; |
| 530 form.ssl_valid = false; | 534 form.ssl_valid = false; |
| 531 form.preferred = false; | 535 form.preferred = false; |
| 532 form.scheme = PasswordForm::SCHEME_HTML; | 536 form.scheme = PasswordForm::SCHEME_HTML; |
| 533 | 537 |
| 534 // Add it and make sure it is there. | 538 // Add it and make sure it is there. |
| 535 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 539 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 536 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 540 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 537 EXPECT_EQ(1U, result.size()); | 541 EXPECT_EQ(1U, result.size()); |
| 538 delete result[0]; | 542 delete result[0]; |
| 539 result.clear(); | 543 result.clear(); |
| 540 | 544 |
| 541 // Example password form that has - in the domain name. | 545 // Example password form that has - in the domain name. |
| 542 PasswordForm form_dash = | 546 PasswordForm form_dash = |
| 543 GetFormWithNewSignonRealm(form, "http://www.foo-bar.com/"); | 547 GetFormWithNewSignonRealm(form, "http://www.foo-bar.com/"); |
| 544 | 548 |
| 545 // Add it and make sure it is there. | 549 // Add it and make sure it is there. |
| 546 EXPECT_EQ(AddChangeForForm(form_dash), db_.AddLogin(form_dash)); | 550 EXPECT_EQ(AddChangeForForm(form_dash), db().AddLogin(form_dash)); |
| 547 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 551 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 548 EXPECT_EQ(2U, result.size()); | 552 EXPECT_EQ(2U, result.size()); |
| 549 delete result[0]; | 553 delete result[0]; |
| 550 delete result[1]; | 554 delete result[1]; |
| 551 result.clear(); | 555 result.clear(); |
| 552 | 556 |
| 553 // Match against an exact copy. | 557 // Match against an exact copy. |
| 554 EXPECT_TRUE(db_.GetLogins(form, &result)); | 558 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 555 EXPECT_EQ(1U, result.size()); | 559 EXPECT_EQ(1U, result.size()); |
| 556 delete result[0]; | 560 delete result[0]; |
| 557 result.clear(); | 561 result.clear(); |
| 558 | 562 |
| 559 // www.foo.com should match. | 563 // www.foo.com should match. |
| 560 PasswordForm form2 = GetFormWithNewSignonRealm(form, "http://www.foo.com/"); | 564 PasswordForm form2 = GetFormWithNewSignonRealm(form, "http://www.foo.com/"); |
| 561 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 565 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 562 EXPECT_EQ(1U, result.size()); | 566 EXPECT_EQ(1U, result.size()); |
| 563 delete result[0]; | 567 delete result[0]; |
| 564 result.clear(); | 568 result.clear(); |
| 565 | 569 |
| 566 // a.b.foo.com should match. | 570 // a.b.foo.com should match. |
| 567 form2 = GetFormWithNewSignonRealm(form, "http://a.b.foo.com/"); | 571 form2 = GetFormWithNewSignonRealm(form, "http://a.b.foo.com/"); |
| 568 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 572 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 569 EXPECT_EQ(1U, result.size()); | 573 EXPECT_EQ(1U, result.size()); |
| 570 delete result[0]; | 574 delete result[0]; |
| 571 result.clear(); | 575 result.clear(); |
| 572 | 576 |
| 573 // a-b.foo.com should match. | 577 // a-b.foo.com should match. |
| 574 form2 = GetFormWithNewSignonRealm(form, "http://a-b.foo.com/"); | 578 form2 = GetFormWithNewSignonRealm(form, "http://a-b.foo.com/"); |
| 575 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 579 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 576 EXPECT_EQ(1U, result.size()); | 580 EXPECT_EQ(1U, result.size()); |
| 577 delete result[0]; | 581 delete result[0]; |
| 578 result.clear(); | 582 result.clear(); |
| 579 | 583 |
| 580 // foo-bar.com should match. | 584 // foo-bar.com should match. |
| 581 form2 = GetFormWithNewSignonRealm(form, "http://foo-bar.com/"); | 585 form2 = GetFormWithNewSignonRealm(form, "http://foo-bar.com/"); |
| 582 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 586 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 583 EXPECT_EQ(1U, result.size()); | 587 EXPECT_EQ(1U, result.size()); |
| 584 delete result[0]; | 588 delete result[0]; |
| 585 result.clear(); | 589 result.clear(); |
| 586 | 590 |
| 587 // www.foo-bar.com should match. | 591 // www.foo-bar.com should match. |
| 588 form2 = GetFormWithNewSignonRealm(form, "http://www.foo-bar.com/"); | 592 form2 = GetFormWithNewSignonRealm(form, "http://www.foo-bar.com/"); |
| 589 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 593 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 590 EXPECT_EQ(1U, result.size()); | 594 EXPECT_EQ(1U, result.size()); |
| 591 delete result[0]; | 595 delete result[0]; |
| 592 result.clear(); | 596 result.clear(); |
| 593 | 597 |
| 594 // a.b.foo-bar.com should match. | 598 // a.b.foo-bar.com should match. |
| 595 form2 = GetFormWithNewSignonRealm(form, "http://a.b.foo-bar.com/"); | 599 form2 = GetFormWithNewSignonRealm(form, "http://a.b.foo-bar.com/"); |
| 596 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 600 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 597 EXPECT_EQ(1U, result.size()); | 601 EXPECT_EQ(1U, result.size()); |
| 598 delete result[0]; | 602 delete result[0]; |
| 599 result.clear(); | 603 result.clear(); |
| 600 | 604 |
| 601 // a-b.foo-bar.com should match. | 605 // a-b.foo-bar.com should match. |
| 602 form2 = GetFormWithNewSignonRealm(form, "http://a-b.foo-bar.com/"); | 606 form2 = GetFormWithNewSignonRealm(form, "http://a-b.foo-bar.com/"); |
| 603 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 607 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 604 EXPECT_EQ(1U, result.size()); | 608 EXPECT_EQ(1U, result.size()); |
| 605 delete result[0]; | 609 delete result[0]; |
| 606 result.clear(); | 610 result.clear(); |
| 607 | 611 |
| 608 // foo.com with port 1337 should not match. | 612 // foo.com with port 1337 should not match. |
| 609 form2 = GetFormWithNewSignonRealm(form, "http://foo.com:1337/"); | 613 form2 = GetFormWithNewSignonRealm(form, "http://foo.com:1337/"); |
| 610 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 614 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 611 EXPECT_EQ(0U, result.size()); | 615 EXPECT_EQ(0U, result.size()); |
| 612 | 616 |
| 613 // http://foo.com should not match since the scheme is wrong. | 617 // http://foo.com should not match since the scheme is wrong. |
| 614 form2 = GetFormWithNewSignonRealm(form, "https://foo.com/"); | 618 form2 = GetFormWithNewSignonRealm(form, "https://foo.com/"); |
| 615 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 619 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 616 EXPECT_EQ(0U, result.size()); | 620 EXPECT_EQ(0U, result.size()); |
| 617 | 621 |
| 618 // notfoo.com should not match. | 622 // notfoo.com should not match. |
| 619 form2 = GetFormWithNewSignonRealm(form, "http://notfoo.com/"); | 623 form2 = GetFormWithNewSignonRealm(form, "http://notfoo.com/"); |
| 620 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 624 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 621 EXPECT_EQ(0U, result.size()); | 625 EXPECT_EQ(0U, result.size()); |
| 622 | 626 |
| 623 // baz.com should not match. | 627 // baz.com should not match. |
| 624 form2 = GetFormWithNewSignonRealm(form, "http://baz.com/"); | 628 form2 = GetFormWithNewSignonRealm(form, "http://baz.com/"); |
| 625 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 629 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 626 EXPECT_EQ(0U, result.size()); | 630 EXPECT_EQ(0U, result.size()); |
| 627 | 631 |
| 628 // foo-baz.com should not match. | 632 // foo-baz.com should not match. |
| 629 form2 = GetFormWithNewSignonRealm(form, "http://foo-baz.com/"); | 633 form2 = GetFormWithNewSignonRealm(form, "http://foo-baz.com/"); |
| 630 EXPECT_TRUE(db_.GetLogins(form2, &result)); | 634 EXPECT_TRUE(db().GetLogins(form2, &result)); |
| 631 EXPECT_EQ(0U, result.size()); | 635 EXPECT_EQ(0U, result.size()); |
| 632 } | 636 } |
| 633 | 637 |
| 634 static bool AddTimestampedLogin(LoginDatabase* db, | 638 static bool AddTimestampedLogin(LoginDatabase* db, |
| 635 std::string url, | 639 std::string url, |
| 636 const std::string& unique_string, | 640 const std::string& unique_string, |
| 637 const base::Time& time, | 641 const base::Time& time, |
| 638 bool date_is_creation) { | 642 bool date_is_creation) { |
| 639 // Example password form. | 643 // Example password form. |
| 640 PasswordForm form; | 644 PasswordForm form; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 660 for (size_t i = 0; i < results->size(); ++i) { | 664 for (size_t i = 0; i < results->size(); ++i) { |
| 661 delete (*results)[i]; | 665 delete (*results)[i]; |
| 662 } | 666 } |
| 663 results->clear(); | 667 results->clear(); |
| 664 } | 668 } |
| 665 | 669 |
| 666 TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) { | 670 TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) { |
| 667 std::vector<PasswordForm*> result; | 671 std::vector<PasswordForm*> result; |
| 668 | 672 |
| 669 // Verify the database is empty. | 673 // Verify the database is empty. |
| 670 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 674 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 671 EXPECT_EQ(0U, result.size()); | 675 EXPECT_EQ(0U, result.size()); |
| 672 | 676 |
| 673 base::Time now = base::Time::Now(); | 677 base::Time now = base::Time::Now(); |
| 674 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 678 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 675 | 679 |
| 676 // Create one with a 0 time. | 680 // Create one with a 0 time. |
| 677 EXPECT_TRUE( | 681 EXPECT_TRUE( |
| 678 AddTimestampedLogin(&db_, "http://1.com", "foo1", base::Time(), true)); | 682 AddTimestampedLogin(&db(), "http://1.com", "foo1", base::Time(), true)); |
| 679 // Create one for now and +/- 1 day. | 683 // Create one for now and +/- 1 day. |
| 680 EXPECT_TRUE( | 684 EXPECT_TRUE( |
| 681 AddTimestampedLogin(&db_, "http://2.com", "foo2", now - one_day, true)); | 685 AddTimestampedLogin(&db(), "http://2.com", "foo2", now - one_day, true)); |
| 682 EXPECT_TRUE(AddTimestampedLogin(&db_, "http://3.com", "foo3", now, true)); | 686 EXPECT_TRUE(AddTimestampedLogin(&db(), "http://3.com", "foo3", now, true)); |
| 683 EXPECT_TRUE( | 687 EXPECT_TRUE( |
| 684 AddTimestampedLogin(&db_, "http://4.com", "foo4", now + one_day, true)); | 688 AddTimestampedLogin(&db(), "http://4.com", "foo4", now + one_day, true)); |
| 685 | 689 |
| 686 // Verify inserts worked. | 690 // Verify inserts worked. |
| 687 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 691 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 688 EXPECT_EQ(4U, result.size()); | 692 EXPECT_EQ(4U, result.size()); |
| 689 ClearResults(&result); | 693 ClearResults(&result); |
| 690 | 694 |
| 691 // Get everything from today's date and on. | 695 // Get everything from today's date and on. |
| 692 EXPECT_TRUE(db_.GetLoginsCreatedBetween(now, base::Time(), &result)); | 696 EXPECT_TRUE(db().GetLoginsCreatedBetween(now, base::Time(), &result)); |
| 693 EXPECT_EQ(2U, result.size()); | 697 EXPECT_EQ(2U, result.size()); |
| 694 ClearResults(&result); | 698 ClearResults(&result); |
| 695 | 699 |
| 696 // Delete everything from today's date and on. | 700 // Delete everything from today's date and on. |
| 697 db_.RemoveLoginsCreatedBetween(now, base::Time()); | 701 db().RemoveLoginsCreatedBetween(now, base::Time()); |
| 698 | 702 |
| 699 // Should have deleted half of what we inserted. | 703 // Should have deleted half of what we inserted. |
| 700 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 704 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 701 EXPECT_EQ(2U, result.size()); | 705 EXPECT_EQ(2U, result.size()); |
| 702 ClearResults(&result); | 706 ClearResults(&result); |
| 703 | 707 |
| 704 // Delete with 0 date (should delete all). | 708 // Delete with 0 date (should delete all). |
| 705 db_.RemoveLoginsCreatedBetween(base::Time(), base::Time()); | 709 db().RemoveLoginsCreatedBetween(base::Time(), base::Time()); |
| 706 | 710 |
| 707 // Verify nothing is left. | 711 // Verify nothing is left. |
| 708 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 712 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 709 EXPECT_EQ(0U, result.size()); | 713 EXPECT_EQ(0U, result.size()); |
| 710 } | 714 } |
| 711 | 715 |
| 712 TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) { | 716 TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) { |
| 713 ScopedVector<autofill::PasswordForm> result; | 717 ScopedVector<autofill::PasswordForm> result; |
| 714 | 718 |
| 715 base::Time now = base::Time::Now(); | 719 base::Time now = base::Time::Now(); |
| 716 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 720 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 717 | 721 |
| 718 // Create one with a 0 time. | 722 // Create one with a 0 time. |
| 719 EXPECT_TRUE( | 723 EXPECT_TRUE( |
| 720 AddTimestampedLogin(&db_, "http://1.com", "foo1", base::Time(), false)); | 724 AddTimestampedLogin(&db(), "http://1.com", "foo1", base::Time(), false)); |
| 721 // Create one for now and +/- 1 day. | 725 // Create one for now and +/- 1 day. |
| 722 EXPECT_TRUE( | 726 EXPECT_TRUE( |
| 723 AddTimestampedLogin(&db_, "http://2.com", "foo2", now - one_day, false)); | 727 AddTimestampedLogin(&db(), "http://2.com", "foo2", now - one_day, false)); |
| 724 EXPECT_TRUE(AddTimestampedLogin(&db_, "http://3.com", "foo3", now, false)); | 728 EXPECT_TRUE(AddTimestampedLogin(&db(), "http://3.com", "foo3", now, false)); |
| 725 EXPECT_TRUE( | 729 EXPECT_TRUE( |
| 726 AddTimestampedLogin(&db_, "http://4.com", "foo4", now + one_day, false)); | 730 AddTimestampedLogin(&db(), "http://4.com", "foo4", now + one_day, false)); |
| 727 | 731 |
| 728 // Verify inserts worked. | 732 // Verify inserts worked. |
| 729 EXPECT_TRUE(db_.GetAutofillableLogins(&result.get())); | 733 EXPECT_TRUE(db().GetAutofillableLogins(&result.get())); |
| 730 EXPECT_EQ(4U, result.size()); | 734 EXPECT_EQ(4U, result.size()); |
| 731 result.clear(); | 735 result.clear(); |
| 732 | 736 |
| 733 // Get everything from today's date and on. | 737 // Get everything from today's date and on. |
| 734 EXPECT_TRUE(db_.GetLoginsSyncedBetween(now, base::Time(), &result.get())); | 738 EXPECT_TRUE(db().GetLoginsSyncedBetween(now, base::Time(), &result.get())); |
| 735 ASSERT_EQ(2U, result.size()); | 739 ASSERT_EQ(2U, result.size()); |
| 736 EXPECT_EQ("http://3.com", result[0]->signon_realm); | 740 EXPECT_EQ("http://3.com", result[0]->signon_realm); |
| 737 EXPECT_EQ("http://4.com", result[1]->signon_realm); | 741 EXPECT_EQ("http://4.com", result[1]->signon_realm); |
| 738 result.clear(); | 742 result.clear(); |
| 739 | 743 |
| 740 // Delete everything from today's date and on. | 744 // Delete everything from today's date and on. |
| 741 db_.RemoveLoginsSyncedBetween(now, base::Time()); | 745 db().RemoveLoginsSyncedBetween(now, base::Time()); |
| 742 | 746 |
| 743 // Should have deleted half of what we inserted. | 747 // Should have deleted half of what we inserted. |
| 744 EXPECT_TRUE(db_.GetAutofillableLogins(&result.get())); | 748 EXPECT_TRUE(db().GetAutofillableLogins(&result.get())); |
| 745 ASSERT_EQ(2U, result.size()); | 749 ASSERT_EQ(2U, result.size()); |
| 746 EXPECT_EQ("http://1.com", result[0]->signon_realm); | 750 EXPECT_EQ("http://1.com", result[0]->signon_realm); |
| 747 EXPECT_EQ("http://2.com", result[1]->signon_realm); | 751 EXPECT_EQ("http://2.com", result[1]->signon_realm); |
| 748 result.clear(); | 752 result.clear(); |
| 749 | 753 |
| 750 // Delete with 0 date (should delete all). | 754 // Delete with 0 date (should delete all). |
| 751 db_.RemoveLoginsSyncedBetween(base::Time(), now); | 755 db().RemoveLoginsSyncedBetween(base::Time(), now); |
| 752 | 756 |
| 753 // Verify nothing is left. | 757 // Verify nothing is left. |
| 754 EXPECT_TRUE(db_.GetAutofillableLogins(&result.get())); | 758 EXPECT_TRUE(db().GetAutofillableLogins(&result.get())); |
| 755 EXPECT_EQ(0U, result.size()); | 759 EXPECT_EQ(0U, result.size()); |
| 756 } | 760 } |
| 757 | 761 |
| 758 TEST_F(LoginDatabaseTest, BlacklistedLogins) { | 762 TEST_F(LoginDatabaseTest, BlacklistedLogins) { |
| 759 std::vector<PasswordForm*> result; | 763 std::vector<PasswordForm*> result; |
| 760 | 764 |
| 761 // Verify the database is empty. | 765 // Verify the database is empty. |
| 762 EXPECT_TRUE(db_.GetBlacklistLogins(&result)); | 766 EXPECT_TRUE(db().GetBlacklistLogins(&result)); |
| 763 ASSERT_EQ(0U, result.size()); | 767 ASSERT_EQ(0U, result.size()); |
| 764 | 768 |
| 765 // Save a form as blacklisted. | 769 // Save a form as blacklisted. |
| 766 PasswordForm form; | 770 PasswordForm form; |
| 767 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 771 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 768 form.action = GURL("http://accounts.google.com/Login"); | 772 form.action = GURL("http://accounts.google.com/Login"); |
| 769 form.username_element = ASCIIToUTF16("Email"); | 773 form.username_element = ASCIIToUTF16("Email"); |
| 770 form.password_element = ASCIIToUTF16("Passwd"); | 774 form.password_element = ASCIIToUTF16("Passwd"); |
| 771 form.submit_element = ASCIIToUTF16("signIn"); | 775 form.submit_element = ASCIIToUTF16("signIn"); |
| 772 form.signon_realm = "http://www.google.com/"; | 776 form.signon_realm = "http://www.google.com/"; |
| 773 form.ssl_valid = false; | 777 form.ssl_valid = false; |
| 774 form.preferred = true; | 778 form.preferred = true; |
| 775 form.blacklisted_by_user = true; | 779 form.blacklisted_by_user = true; |
| 776 form.scheme = PasswordForm::SCHEME_HTML; | 780 form.scheme = PasswordForm::SCHEME_HTML; |
| 777 form.date_synced = base::Time::Now(); | 781 form.date_synced = base::Time::Now(); |
| 778 form.display_name = ASCIIToUTF16("Mr. Smith"); | 782 form.display_name = ASCIIToUTF16("Mr. Smith"); |
| 779 form.avatar_url = GURL("https://accounts.google.com/Avatar"); | 783 form.avatar_url = GURL("https://accounts.google.com/Avatar"); |
| 780 form.federation_url = GURL("https://accounts.google.com/federation"); | 784 form.federation_url = GURL("https://accounts.google.com/federation"); |
| 781 form.is_zero_click = true; | 785 form.is_zero_click = true; |
| 782 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 786 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 783 | 787 |
| 784 // Get all non-blacklisted logins (should be none). | 788 // Get all non-blacklisted logins (should be none). |
| 785 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 789 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 786 ASSERT_EQ(0U, result.size()); | 790 ASSERT_EQ(0U, result.size()); |
| 787 | 791 |
| 788 // GetLogins should give the blacklisted result. | 792 // GetLogins should give the blacklisted result. |
| 789 EXPECT_TRUE(db_.GetLogins(form, &result)); | 793 EXPECT_TRUE(db().GetLogins(form, &result)); |
| 790 ASSERT_EQ(1U, result.size()); | 794 ASSERT_EQ(1U, result.size()); |
| 791 FormsAreEqual(form, *result[0]); | 795 FormsAreEqual(form, *result[0]); |
| 792 ClearResults(&result); | 796 ClearResults(&result); |
| 793 | 797 |
| 794 // So should GetAllBlacklistedLogins. | 798 // So should GetAllBlacklistedLogins. |
| 795 EXPECT_TRUE(db_.GetBlacklistLogins(&result)); | 799 EXPECT_TRUE(db().GetBlacklistLogins(&result)); |
| 796 ASSERT_EQ(1U, result.size()); | 800 ASSERT_EQ(1U, result.size()); |
| 797 FormsAreEqual(form, *result[0]); | 801 FormsAreEqual(form, *result[0]); |
| 798 ClearResults(&result); | 802 ClearResults(&result); |
| 799 } | 803 } |
| 800 | 804 |
| 801 TEST_F(LoginDatabaseTest, VectorSerialization) { | 805 TEST_F(LoginDatabaseTest, VectorSerialization) { |
| 802 // Empty vector. | 806 // Empty vector. |
| 803 std::vector<base::string16> vec; | 807 std::vector<base::string16> vec; |
| 804 Pickle temp = SerializeVector(vec); | 808 Pickle temp = SerializeVector(vec); |
| 805 std::vector<base::string16> output = DeserializeVector(temp); | 809 std::vector<base::string16> output = DeserializeVector(temp); |
| 806 EXPECT_THAT(output, Eq(vec)); | 810 EXPECT_THAT(output, Eq(vec)); |
| 807 | 811 |
| 808 // Normal data. | 812 // Normal data. |
| 809 vec.push_back(ASCIIToUTF16("first")); | 813 vec.push_back(ASCIIToUTF16("first")); |
| 810 vec.push_back(ASCIIToUTF16("second")); | 814 vec.push_back(ASCIIToUTF16("second")); |
| 811 vec.push_back(ASCIIToUTF16("third")); | 815 vec.push_back(ASCIIToUTF16("third")); |
| 812 | 816 |
| 813 temp = SerializeVector(vec); | 817 temp = SerializeVector(vec); |
| 814 output = DeserializeVector(temp); | 818 output = DeserializeVector(temp); |
| 815 EXPECT_THAT(output, Eq(vec)); | 819 EXPECT_THAT(output, Eq(vec)); |
| 816 } | 820 } |
| 817 | 821 |
| 818 TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) { | 822 TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) { |
| 819 std::vector<autofill::PasswordForm*> result; | 823 std::vector<autofill::PasswordForm*> result; |
| 820 // Verify the database is empty. | 824 // Verify the database is empty. |
| 821 EXPECT_TRUE(db_.GetAutofillableLogins(&result)); | 825 EXPECT_TRUE(db().GetAutofillableLogins(&result)); |
| 822 ASSERT_EQ(0U, result.size()); | 826 ASSERT_EQ(0U, result.size()); |
| 823 | 827 |
| 824 // Save an incomplete form. Note that it only has a few fields set, ex. it's | 828 // Save an incomplete form. Note that it only has a few fields set, ex. it's |
| 825 // missing 'action', 'username_element' and 'password_element'. Such forms | 829 // missing 'action', 'username_element' and 'password_element'. Such forms |
| 826 // are sometimes inserted during import from other browsers (which may not | 830 // are sometimes inserted during import from other browsers (which may not |
| 827 // store this info). | 831 // store this info). |
| 828 PasswordForm incomplete_form; | 832 PasswordForm incomplete_form; |
| 829 incomplete_form.origin = GURL("http://accounts.google.com/LoginAuth"); | 833 incomplete_form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 830 incomplete_form.signon_realm = "http://accounts.google.com/"; | 834 incomplete_form.signon_realm = "http://accounts.google.com/"; |
| 831 incomplete_form.username_value = ASCIIToUTF16("my_username"); | 835 incomplete_form.username_value = ASCIIToUTF16("my_username"); |
| 832 incomplete_form.password_value = ASCIIToUTF16("my_password"); | 836 incomplete_form.password_value = ASCIIToUTF16("my_password"); |
| 833 incomplete_form.ssl_valid = false; | 837 incomplete_form.ssl_valid = false; |
| 834 incomplete_form.preferred = true; | 838 incomplete_form.preferred = true; |
| 835 incomplete_form.blacklisted_by_user = false; | 839 incomplete_form.blacklisted_by_user = false; |
| 836 incomplete_form.scheme = PasswordForm::SCHEME_HTML; | 840 incomplete_form.scheme = PasswordForm::SCHEME_HTML; |
| 837 EXPECT_EQ(AddChangeForForm(incomplete_form), db_.AddLogin(incomplete_form)); | 841 EXPECT_EQ(AddChangeForForm(incomplete_form), db().AddLogin(incomplete_form)); |
| 838 | 842 |
| 839 // A form on some website. It should trigger a match with the stored one. | 843 // A form on some website. It should trigger a match with the stored one. |
| 840 PasswordForm encountered_form; | 844 PasswordForm encountered_form; |
| 841 encountered_form.origin = GURL("http://accounts.google.com/LoginAuth"); | 845 encountered_form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 842 encountered_form.signon_realm = "http://accounts.google.com/"; | 846 encountered_form.signon_realm = "http://accounts.google.com/"; |
| 843 encountered_form.action = GURL("http://accounts.google.com/Login"); | 847 encountered_form.action = GURL("http://accounts.google.com/Login"); |
| 844 encountered_form.username_element = ASCIIToUTF16("Email"); | 848 encountered_form.username_element = ASCIIToUTF16("Email"); |
| 845 encountered_form.password_element = ASCIIToUTF16("Passwd"); | 849 encountered_form.password_element = ASCIIToUTF16("Passwd"); |
| 846 encountered_form.submit_element = ASCIIToUTF16("signIn"); | 850 encountered_form.submit_element = ASCIIToUTF16("signIn"); |
| 847 | 851 |
| 848 // Get matches for encountered_form. | 852 // Get matches for encountered_form. |
| 849 EXPECT_TRUE(db_.GetLogins(encountered_form, &result)); | 853 EXPECT_TRUE(db().GetLogins(encountered_form, &result)); |
| 850 ASSERT_EQ(1U, result.size()); | 854 ASSERT_EQ(1U, result.size()); |
| 851 EXPECT_EQ(incomplete_form.origin, result[0]->origin); | 855 EXPECT_EQ(incomplete_form.origin, result[0]->origin); |
| 852 EXPECT_EQ(incomplete_form.signon_realm, result[0]->signon_realm); | 856 EXPECT_EQ(incomplete_form.signon_realm, result[0]->signon_realm); |
| 853 EXPECT_EQ(incomplete_form.username_value, result[0]->username_value); | 857 EXPECT_EQ(incomplete_form.username_value, result[0]->username_value); |
| 854 #if defined(OS_MACOSX) && !defined(OS_IOS) | 858 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 855 // On Mac, passwords are not stored in login database, instead they're in | 859 // On Mac, passwords are not stored in login database, instead they're in |
| 856 // the keychain. | 860 // the keychain. |
| 857 EXPECT_TRUE(result[0]->password_value.empty()); | 861 EXPECT_TRUE(result[0]->password_value.empty()); |
| 858 #else | 862 #else |
| 859 EXPECT_EQ(incomplete_form.password_value, result[0]->password_value); | 863 EXPECT_EQ(incomplete_form.password_value, result[0]->password_value); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 871 ClearResults(&result); | 875 ClearResults(&result); |
| 872 | 876 |
| 873 // Let's say this login form worked. Now update the stored credentials with | 877 // Let's say this login form worked. Now update the stored credentials with |
| 874 // 'action', 'username_element', 'password_element' and 'submit_element' from | 878 // 'action', 'username_element', 'password_element' and 'submit_element' from |
| 875 // the encountered form. | 879 // the encountered form. |
| 876 PasswordForm completed_form(incomplete_form); | 880 PasswordForm completed_form(incomplete_form); |
| 877 completed_form.action = encountered_form.action; | 881 completed_form.action = encountered_form.action; |
| 878 completed_form.username_element = encountered_form.username_element; | 882 completed_form.username_element = encountered_form.username_element; |
| 879 completed_form.password_element = encountered_form.password_element; | 883 completed_form.password_element = encountered_form.password_element; |
| 880 completed_form.submit_element = encountered_form.submit_element; | 884 completed_form.submit_element = encountered_form.submit_element; |
| 881 EXPECT_EQ(AddChangeForForm(completed_form), db_.AddLogin(completed_form)); | 885 EXPECT_EQ(AddChangeForForm(completed_form), db().AddLogin(completed_form)); |
| 882 EXPECT_TRUE(db_.RemoveLogin(incomplete_form)); | 886 EXPECT_TRUE(db().RemoveLogin(incomplete_form)); |
| 883 | 887 |
| 884 // Get matches for encountered_form again. | 888 // Get matches for encountered_form again. |
| 885 EXPECT_TRUE(db_.GetLogins(encountered_form, &result)); | 889 EXPECT_TRUE(db().GetLogins(encountered_form, &result)); |
| 886 ASSERT_EQ(1U, result.size()); | 890 ASSERT_EQ(1U, result.size()); |
| 887 | 891 |
| 888 // This time we should have all the info available. | 892 // This time we should have all the info available. |
| 889 PasswordForm expected_form(completed_form); | 893 PasswordForm expected_form(completed_form); |
| 890 #if defined(OS_MACOSX) && !defined(OS_IOS) | 894 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 891 expected_form.password_value.clear(); | 895 expected_form.password_value.clear(); |
| 892 #endif // OS_MACOSX && !OS_IOS | 896 #endif // OS_MACOSX && !OS_IOS |
| 893 EXPECT_EQ(expected_form, *result[0]); | 897 EXPECT_EQ(expected_form, *result[0]); |
| 894 ClearResults(&result); | 898 ClearResults(&result); |
| 895 } | 899 } |
| 896 | 900 |
| 897 TEST_F(LoginDatabaseTest, UpdateOverlappingCredentials) { | 901 TEST_F(LoginDatabaseTest, UpdateOverlappingCredentials) { |
| 898 // Save an incomplete form. Note that it only has a few fields set, ex. it's | 902 // Save an incomplete form. Note that it only has a few fields set, ex. it's |
| 899 // missing 'action', 'username_element' and 'password_element'. Such forms | 903 // missing 'action', 'username_element' and 'password_element'. Such forms |
| 900 // are sometimes inserted during import from other browsers (which may not | 904 // are sometimes inserted during import from other browsers (which may not |
| 901 // store this info). | 905 // store this info). |
| 902 PasswordForm incomplete_form; | 906 PasswordForm incomplete_form; |
| 903 incomplete_form.origin = GURL("http://accounts.google.com/LoginAuth"); | 907 incomplete_form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 904 incomplete_form.signon_realm = "http://accounts.google.com/"; | 908 incomplete_form.signon_realm = "http://accounts.google.com/"; |
| 905 incomplete_form.username_value = ASCIIToUTF16("my_username"); | 909 incomplete_form.username_value = ASCIIToUTF16("my_username"); |
| 906 incomplete_form.password_value = ASCIIToUTF16("my_password"); | 910 incomplete_form.password_value = ASCIIToUTF16("my_password"); |
| 907 incomplete_form.ssl_valid = false; | 911 incomplete_form.ssl_valid = false; |
| 908 incomplete_form.preferred = true; | 912 incomplete_form.preferred = true; |
| 909 incomplete_form.blacklisted_by_user = false; | 913 incomplete_form.blacklisted_by_user = false; |
| 910 incomplete_form.scheme = PasswordForm::SCHEME_HTML; | 914 incomplete_form.scheme = PasswordForm::SCHEME_HTML; |
| 911 EXPECT_EQ(AddChangeForForm(incomplete_form), db_.AddLogin(incomplete_form)); | 915 EXPECT_EQ(AddChangeForForm(incomplete_form), db().AddLogin(incomplete_form)); |
| 912 | 916 |
| 913 // Save a complete version of the previous form. Both forms could exist if | 917 // Save a complete version of the previous form. Both forms could exist if |
| 914 // the user created the complete version before importing the incomplete | 918 // the user created the complete version before importing the incomplete |
| 915 // version from a different browser. | 919 // version from a different browser. |
| 916 PasswordForm complete_form = incomplete_form; | 920 PasswordForm complete_form = incomplete_form; |
| 917 complete_form.action = GURL("http://accounts.google.com/Login"); | 921 complete_form.action = GURL("http://accounts.google.com/Login"); |
| 918 complete_form.username_element = ASCIIToUTF16("username_element"); | 922 complete_form.username_element = ASCIIToUTF16("username_element"); |
| 919 complete_form.password_element = ASCIIToUTF16("password_element"); | 923 complete_form.password_element = ASCIIToUTF16("password_element"); |
| 920 complete_form.submit_element = ASCIIToUTF16("submit"); | 924 complete_form.submit_element = ASCIIToUTF16("submit"); |
| 921 | 925 |
| 922 // An update fails because the primary key for |complete_form| is different. | 926 // An update fails because the primary key for |complete_form| is different. |
| 923 EXPECT_EQ(PasswordStoreChangeList(), db_.UpdateLogin(complete_form)); | 927 EXPECT_EQ(PasswordStoreChangeList(), db().UpdateLogin(complete_form)); |
| 924 EXPECT_EQ(AddChangeForForm(complete_form), db_.AddLogin(complete_form)); | 928 EXPECT_EQ(AddChangeForForm(complete_form), db().AddLogin(complete_form)); |
| 925 | 929 |
| 926 // Make sure both passwords exist. | 930 // Make sure both passwords exist. |
| 927 ScopedVector<autofill::PasswordForm> result; | 931 ScopedVector<autofill::PasswordForm> result; |
| 928 EXPECT_TRUE(db_.GetAutofillableLogins(&result.get())); | 932 EXPECT_TRUE(db().GetAutofillableLogins(&result.get())); |
| 929 ASSERT_EQ(2U, result.size()); | 933 ASSERT_EQ(2U, result.size()); |
| 930 result.clear(); | 934 result.clear(); |
| 931 | 935 |
| 932 // Simulate the user changing their password. | 936 // Simulate the user changing their password. |
| 933 complete_form.password_value = ASCIIToUTF16("new_password"); | 937 complete_form.password_value = ASCIIToUTF16("new_password"); |
| 934 complete_form.date_synced = base::Time::Now(); | 938 complete_form.date_synced = base::Time::Now(); |
| 935 EXPECT_EQ(UpdateChangeForForm(complete_form), db_.UpdateLogin(complete_form)); | 939 EXPECT_EQ(UpdateChangeForForm(complete_form), |
| 940 db().UpdateLogin(complete_form)); |
| 936 | 941 |
| 937 // Both still exist now. | 942 // Both still exist now. |
| 938 EXPECT_TRUE(db_.GetAutofillableLogins(&result.get())); | 943 EXPECT_TRUE(db().GetAutofillableLogins(&result.get())); |
| 939 ASSERT_EQ(2U, result.size()); | 944 ASSERT_EQ(2U, result.size()); |
| 940 | 945 |
| 941 #if defined(OS_MACOSX) && !defined(OS_IOS) | 946 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 942 // On Mac, passwords are not stored in login database, instead they're in | 947 // On Mac, passwords are not stored in login database, instead they're in |
| 943 // the keychain. | 948 // the keychain. |
| 944 complete_form.password_value.clear(); | 949 complete_form.password_value.clear(); |
| 945 incomplete_form.password_value.clear(); | 950 incomplete_form.password_value.clear(); |
| 946 #endif // OS_MACOSX && !OS_IOS | 951 #endif // OS_MACOSX && !OS_IOS |
| 947 if (result[0]->username_element.empty()) | 952 if (result[0]->username_element.empty()) |
| 948 std::swap(result[0], result[1]); | 953 std::swap(result[0], result[1]); |
| 949 EXPECT_EQ(complete_form, *result[0]); | 954 EXPECT_EQ(complete_form, *result[0]); |
| 950 EXPECT_EQ(incomplete_form, *result[1]); | 955 EXPECT_EQ(incomplete_form, *result[1]); |
| 951 } | 956 } |
| 952 | 957 |
| 953 TEST_F(LoginDatabaseTest, DoubleAdd) { | 958 TEST_F(LoginDatabaseTest, DoubleAdd) { |
| 954 PasswordForm form; | 959 PasswordForm form; |
| 955 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 960 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 956 form.signon_realm = "http://accounts.google.com/"; | 961 form.signon_realm = "http://accounts.google.com/"; |
| 957 form.username_value = ASCIIToUTF16("my_username"); | 962 form.username_value = ASCIIToUTF16("my_username"); |
| 958 form.password_value = ASCIIToUTF16("my_password"); | 963 form.password_value = ASCIIToUTF16("my_password"); |
| 959 form.ssl_valid = false; | 964 form.ssl_valid = false; |
| 960 form.preferred = true; | 965 form.preferred = true; |
| 961 form.blacklisted_by_user = false; | 966 form.blacklisted_by_user = false; |
| 962 form.scheme = PasswordForm::SCHEME_HTML; | 967 form.scheme = PasswordForm::SCHEME_HTML; |
| 963 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 968 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 964 | 969 |
| 965 // Add almost the same form again. | 970 // Add almost the same form again. |
| 966 form.times_used++; | 971 form.times_used++; |
| 967 PasswordStoreChangeList list; | 972 PasswordStoreChangeList list; |
| 968 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 973 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 969 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 974 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
| 970 EXPECT_EQ(list, db_.AddLogin(form)); | 975 EXPECT_EQ(list, db().AddLogin(form)); |
| 971 } | 976 } |
| 972 | 977 |
| 973 TEST_F(LoginDatabaseTest, AddWrongForm) { | 978 TEST_F(LoginDatabaseTest, AddWrongForm) { |
| 974 PasswordForm form; | 979 PasswordForm form; |
| 975 // |origin| shouldn't be empty. | 980 // |origin| shouldn't be empty. |
| 976 form.origin = GURL(); | 981 form.origin = GURL(); |
| 977 form.signon_realm = "http://accounts.google.com/"; | 982 form.signon_realm = "http://accounts.google.com/"; |
| 978 form.username_value = ASCIIToUTF16("my_username"); | 983 form.username_value = ASCIIToUTF16("my_username"); |
| 979 form.password_value = ASCIIToUTF16("my_password"); | 984 form.password_value = ASCIIToUTF16("my_password"); |
| 980 form.ssl_valid = false; | 985 form.ssl_valid = false; |
| 981 form.preferred = true; | 986 form.preferred = true; |
| 982 form.blacklisted_by_user = false; | 987 form.blacklisted_by_user = false; |
| 983 form.scheme = PasswordForm::SCHEME_HTML; | 988 form.scheme = PasswordForm::SCHEME_HTML; |
| 984 EXPECT_EQ(PasswordStoreChangeList(), db_.AddLogin(form)); | 989 EXPECT_EQ(PasswordStoreChangeList(), db().AddLogin(form)); |
| 985 | 990 |
| 986 // |signon_realm| shouldn't be empty. | 991 // |signon_realm| shouldn't be empty. |
| 987 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 992 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 988 form.signon_realm.clear(); | 993 form.signon_realm.clear(); |
| 989 EXPECT_EQ(PasswordStoreChangeList(), db_.AddLogin(form)); | 994 EXPECT_EQ(PasswordStoreChangeList(), db().AddLogin(form)); |
| 990 } | 995 } |
| 991 | 996 |
| 992 TEST_F(LoginDatabaseTest, UpdateLogin) { | 997 TEST_F(LoginDatabaseTest, UpdateLogin) { |
| 993 PasswordForm form; | 998 PasswordForm form; |
| 994 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 999 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 995 form.signon_realm = "http://accounts.google.com/"; | 1000 form.signon_realm = "http://accounts.google.com/"; |
| 996 form.username_value = ASCIIToUTF16("my_username"); | 1001 form.username_value = ASCIIToUTF16("my_username"); |
| 997 form.password_value = ASCIIToUTF16("my_password"); | 1002 form.password_value = ASCIIToUTF16("my_password"); |
| 998 form.ssl_valid = false; | 1003 form.ssl_valid = false; |
| 999 form.preferred = true; | 1004 form.preferred = true; |
| 1000 form.blacklisted_by_user = false; | 1005 form.blacklisted_by_user = false; |
| 1001 form.scheme = PasswordForm::SCHEME_HTML; | 1006 form.scheme = PasswordForm::SCHEME_HTML; |
| 1002 EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form)); | 1007 EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form)); |
| 1003 | 1008 |
| 1004 form.action = GURL("http://accounts.google.com/login"); | 1009 form.action = GURL("http://accounts.google.com/login"); |
| 1005 form.password_value = ASCIIToUTF16("my_new_password"); | 1010 form.password_value = ASCIIToUTF16("my_new_password"); |
| 1006 form.ssl_valid = true; | 1011 form.ssl_valid = true; |
| 1007 form.preferred = false; | 1012 form.preferred = false; |
| 1008 form.other_possible_usernames.push_back(ASCIIToUTF16("my_new_username")); | 1013 form.other_possible_usernames.push_back(ASCIIToUTF16("my_new_username")); |
| 1009 form.times_used = 20; | 1014 form.times_used = 20; |
| 1010 form.submit_element = ASCIIToUTF16("submit_element"); | 1015 form.submit_element = ASCIIToUTF16("submit_element"); |
| 1011 form.date_synced = base::Time::Now(); | 1016 form.date_synced = base::Time::Now(); |
| 1012 form.date_created = base::Time::Now() - base::TimeDelta::FromDays(1); | 1017 form.date_created = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 1013 form.blacklisted_by_user = true; | 1018 form.blacklisted_by_user = true; |
| 1014 form.scheme = PasswordForm::SCHEME_BASIC; | 1019 form.scheme = PasswordForm::SCHEME_BASIC; |
| 1015 form.type = PasswordForm::TYPE_GENERATED; | 1020 form.type = PasswordForm::TYPE_GENERATED; |
| 1016 form.display_name = ASCIIToUTF16("Mr. Smith"); | 1021 form.display_name = ASCIIToUTF16("Mr. Smith"); |
| 1017 form.avatar_url = GURL("https://accounts.google.com/Avatar"); | 1022 form.avatar_url = GURL("https://accounts.google.com/Avatar"); |
| 1018 form.federation_url = GURL("https://accounts.google.com/federation"); | 1023 form.federation_url = GURL("https://accounts.google.com/federation"); |
| 1019 form.is_zero_click = true; | 1024 form.is_zero_click = true; |
| 1020 EXPECT_EQ(UpdateChangeForForm(form), db_.UpdateLogin(form)); | 1025 EXPECT_EQ(UpdateChangeForForm(form), db().UpdateLogin(form)); |
| 1021 | 1026 |
| 1022 ScopedVector<autofill::PasswordForm> result; | 1027 ScopedVector<autofill::PasswordForm> result; |
| 1023 EXPECT_TRUE(db_.GetLogins(form, &result.get())); | 1028 EXPECT_TRUE(db().GetLogins(form, &result.get())); |
| 1024 ASSERT_EQ(1U, result.size()); | 1029 ASSERT_EQ(1U, result.size()); |
| 1025 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1030 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 1026 // On Mac, passwords are not stored in login database, instead they're in | 1031 // On Mac, passwords are not stored in login database, instead they're in |
| 1027 // the keychain. | 1032 // the keychain. |
| 1028 form.password_value.clear(); | 1033 form.password_value.clear(); |
| 1029 #endif // OS_MACOSX && !OS_IOS | 1034 #endif // OS_MACOSX && !OS_IOS |
| 1030 EXPECT_EQ(form, *result[0]); | 1035 EXPECT_EQ(form, *result[0]); |
| 1031 } | 1036 } |
| 1032 | 1037 |
| 1033 TEST_F(LoginDatabaseTest, ReportMetricsTest) { | 1038 TEST_F(LoginDatabaseTest, ReportMetricsTest) { |
| 1034 PasswordForm password_form; | 1039 PasswordForm password_form; |
| 1035 password_form.origin = GURL("http://example.com"); | 1040 password_form.origin = GURL("http://example.com"); |
| 1036 password_form.username_value = ASCIIToUTF16("test1@gmail.com"); | 1041 password_form.username_value = ASCIIToUTF16("test1@gmail.com"); |
| 1037 password_form.password_value = ASCIIToUTF16("test"); | 1042 password_form.password_value = ASCIIToUTF16("test"); |
| 1038 password_form.signon_realm = "http://example.com/"; | 1043 password_form.signon_realm = "http://example.com/"; |
| 1039 password_form.times_used = 0; | 1044 password_form.times_used = 0; |
| 1040 EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form)); | 1045 EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form)); |
| 1041 | 1046 |
| 1042 password_form.username_value = ASCIIToUTF16("test2@gmail.com"); | 1047 password_form.username_value = ASCIIToUTF16("test2@gmail.com"); |
| 1043 password_form.times_used = 1; | 1048 password_form.times_used = 1; |
| 1044 EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form)); | 1049 EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form)); |
| 1045 | 1050 |
| 1046 password_form.origin = GURL("http://second.example.com"); | 1051 password_form.origin = GURL("http://second.example.com"); |
| 1047 password_form.signon_realm = "http://second.example.com"; | 1052 password_form.signon_realm = "http://second.example.com"; |
| 1048 password_form.times_used = 3; | 1053 password_form.times_used = 3; |
| 1049 EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form)); | 1054 EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form)); |
| 1050 | 1055 |
| 1051 password_form.username_value = ASCIIToUTF16("test3@gmail.com"); | 1056 password_form.username_value = ASCIIToUTF16("test3@gmail.com"); |
| 1052 password_form.type = PasswordForm::TYPE_GENERATED; | 1057 password_form.type = PasswordForm::TYPE_GENERATED; |
| 1053 password_form.times_used = 2; | 1058 password_form.times_used = 2; |
| 1054 EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form)); | 1059 EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form)); |
| 1055 | 1060 |
| 1056 password_form.origin = GURL("http://third.example.com/"); | 1061 password_form.origin = GURL("http://third.example.com/"); |
| 1057 password_form.signon_realm = "http://third.example.com/"; | 1062 password_form.signon_realm = "http://third.example.com/"; |
| 1058 password_form.times_used = 4; | 1063 password_form.times_used = 4; |
| 1059 EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form)); | 1064 EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form)); |
| 1060 | 1065 |
| 1061 base::HistogramTester histogram_tester; | 1066 base::HistogramTester histogram_tester; |
| 1062 db_.ReportMetrics("", false); | 1067 db().ReportMetrics("", false); |
| 1063 | 1068 |
| 1064 histogram_tester.ExpectUniqueSample( | 1069 histogram_tester.ExpectUniqueSample( |
| 1065 "PasswordManager.TotalAccounts.UserCreated.WithoutCustomPassphrase", | 1070 "PasswordManager.TotalAccounts.UserCreated.WithoutCustomPassphrase", |
| 1066 3, | 1071 3, |
| 1067 1); | 1072 1); |
| 1068 histogram_tester.ExpectBucketCount( | 1073 histogram_tester.ExpectBucketCount( |
| 1069 "PasswordManager.AccountsPerSite.UserCreated.WithoutCustomPassphrase", | 1074 "PasswordManager.AccountsPerSite.UserCreated.WithoutCustomPassphrase", |
| 1070 1, | 1075 1, |
| 1071 1); | 1076 1); |
| 1072 histogram_tester.ExpectBucketCount( | 1077 histogram_tester.ExpectBucketCount( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 ASSERT_EQ(1402955745, date_created[0]); | 1203 ASSERT_EQ(1402955745, date_created[0]); |
| 1199 ASSERT_EQ(1402950000, date_created[1]); | 1204 ASSERT_EQ(1402950000, date_created[1]); |
| 1200 } else { | 1205 } else { |
| 1201 ASSERT_EQ(13047429345000000, date_created[0]); | 1206 ASSERT_EQ(13047429345000000, date_created[0]); |
| 1202 ASSERT_EQ(13047423600000000, date_created[1]); | 1207 ASSERT_EQ(13047423600000000, date_created[1]); |
| 1203 } | 1208 } |
| 1204 | 1209 |
| 1205 { | 1210 { |
| 1206 // Assert that the database was successfully opened and updated | 1211 // Assert that the database was successfully opened and updated |
| 1207 // to current version. | 1212 // to current version. |
| 1208 LoginDatabase db; | 1213 LoginDatabase db(database_path_); |
| 1209 ASSERT_TRUE(db.Init(database_path_)); | 1214 ASSERT_TRUE(db.Init()); |
| 1210 // Verifies that the final version can save all the appropriate fields. | 1215 // Verifies that the final version can save all the appropriate fields. |
| 1211 std::vector<PasswordForm*> result; | 1216 std::vector<PasswordForm*> result; |
| 1212 PasswordForm form; | 1217 PasswordForm form; |
| 1213 GenerateExamplePasswordForm(&form); | 1218 GenerateExamplePasswordForm(&form); |
| 1214 db.AddLogin(form); | 1219 db.AddLogin(form); |
| 1215 EXPECT_TRUE(db.GetLogins(form, &result)); | 1220 EXPECT_TRUE(db.GetLogins(form, &result)); |
| 1216 ASSERT_EQ(1U, result.size()); | 1221 ASSERT_EQ(1U, result.size()); |
| 1217 FormsAreEqual(form, *result[0]); | 1222 FormsAreEqual(form, *result[0]); |
| 1218 EXPECT_TRUE(db.RemoveLogin(form)); | 1223 EXPECT_TRUE(db.RemoveLogin(form)); |
| 1219 delete result[0]; | 1224 delete result[0]; |
| 1220 result.clear(); | 1225 result.clear(); |
| 1221 } | 1226 } |
| 1222 // New date, in microseconds since platform independent epoch. | 1227 // New date, in microseconds since platform independent epoch. |
| 1223 std::vector<int64_t> new_date_created(GetDateCreated()); | 1228 std::vector<int64_t> new_date_created(GetDateCreated()); |
| 1224 ASSERT_EQ(13047429345000000, new_date_created[0]); | 1229 ASSERT_EQ(13047429345000000, new_date_created[0]); |
| 1225 ASSERT_EQ(13047423600000000, new_date_created[1]); | 1230 ASSERT_EQ(13047423600000000, new_date_created[1]); |
| 1226 if (table_version <= 8) { | 1231 if (table_version <= 8) { |
| 1227 // Check that the two dates match up. | 1232 // Check that the two dates match up. |
| 1228 for (size_t i = 0; i < date_created.size(); ++i) { | 1233 for (size_t i = 0; i < date_created.size(); ++i) { |
| 1229 EXPECT_EQ(base::Time::FromInternalValue(new_date_created[i]), | 1234 EXPECT_EQ(base::Time::FromInternalValue(new_date_created[i]), |
| 1230 base::Time::FromTimeT(date_created[i])); | 1235 base::Time::FromTimeT(date_created[i])); |
| 1231 } | 1236 } |
| 1232 } | 1237 } |
| 1233 DestroyDatabase(); | 1238 DestroyDatabase(); |
| 1234 } | 1239 } |
| 1235 } | 1240 } |
| 1236 | 1241 |
| 1237 } // namespace password_manager | 1242 } // namespace password_manager |
| OLD | NEW |