| 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/autofill/password_autofill_manager.h" | 7 #include "chrome/browser/autofill/password_autofill_manager.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() OVERRIDE { |
| 29 // Add a preferred login and an additional login to the FillData. | 29 // Add a preferred login and an additional login to the FillData. |
| 30 string16 username1 = ASCIIToUTF16(kAliceUsername); | 30 string16 username1 = ASCIIToUTF16(kAliceUsername); |
| 31 string16 password1 = ASCIIToUTF16(kAlicePassword); | 31 string16 password1 = ASCIIToUTF16(kAlicePassword); |
| 32 | 32 |
| 33 username_field_.name = ASCIIToUTF16(kUsernameName); | 33 username_field_.name = ASCIIToUTF16(kUsernameName); |
| 34 username_field_.value = username1; | 34 username_field_.value = username1; |
| 35 fill_data_.basic_data.fields.push_back(username_field_); | 35 fill_data_.basic_data.fields.push_back(username_field_); |
| 36 | 36 |
| 37 webkit::forms::FormField password_field; | 37 FormFieldData password_field; |
| 38 password_field.name = ASCIIToUTF16(kPasswordName); | 38 password_field.name = ASCIIToUTF16(kPasswordName); |
| 39 password_field.value = password1; | 39 password_field.value = password1; |
| 40 fill_data_.basic_data.fields.push_back(password_field); | 40 fill_data_.basic_data.fields.push_back(password_field); |
| 41 | 41 |
| 42 password_autofill_manager_.AddPasswordFormMapping(username_field_, | 42 password_autofill_manager_.AddPasswordFormMapping(username_field_, |
| 43 fill_data_); | 43 fill_data_); |
| 44 } | 44 } |
| 45 | 45 |
| 46 PasswordAutofillManager* password_autofill_manager() { | 46 PasswordAutofillManager* password_autofill_manager() { |
| 47 return &password_autofill_manager_; | 47 return &password_autofill_manager_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 const webkit::forms::FormField& username_field() { return username_field_; } | 50 const FormFieldData& username_field() { return username_field_; } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 webkit::forms::PasswordFormFillData fill_data_; | 53 PasswordFormFillData fill_data_; |
| 54 webkit::forms::FormField username_field_; | 54 FormFieldData username_field_; |
| 55 | 55 |
| 56 PasswordAutofillManager password_autofill_manager_; | 56 PasswordAutofillManager password_autofill_manager_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) { | 59 TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) { |
| 60 EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion( | 60 EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 61 username_field(), ASCIIToUTF16(kAliceUsername))); | 61 username_field(), ASCIIToUTF16(kAliceUsername))); |
| 62 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( | 62 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 63 username_field(), ASCIIToUTF16(kInvalidUsername))); | 63 username_field(), ASCIIToUTF16(kInvalidUsername))); |
| 64 | 64 |
| 65 webkit::forms::FormField invalid_username_field; | 65 FormFieldData invalid_username_field; |
| 66 invalid_username_field.name = ASCIIToUTF16(kInvalidUsername); | 66 invalid_username_field.name = ASCIIToUTF16(kInvalidUsername); |
| 67 | 67 |
| 68 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( | 68 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 69 invalid_username_field, ASCIIToUTF16(kAliceUsername))); | 69 invalid_username_field, ASCIIToUTF16(kAliceUsername))); |
| 70 | 70 |
| 71 password_autofill_manager()->Reset(); | 71 password_autofill_manager()->Reset(); |
| 72 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( | 72 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 73 username_field(), ASCIIToUTF16(kAliceUsername))); | 73 username_field(), ASCIIToUTF16(kAliceUsername))); |
| 74 } | 74 } |
| OLD | NEW |