OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/compiler_specific.h" |
| 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/autofill/password_autofill_manager.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 // The name of the username/password element in the form. |
| 13 const char* const kUsernameName = "username"; |
| 14 const char* const kPasswordName = "password"; |
| 15 |
| 16 const char* const kAliceUsername = "alice"; |
| 17 const char* const kAlicePassword = "password"; |
| 18 |
| 19 const char* const kValue = "password"; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 class PasswordAutofillManagerTest : public testing::Test { |
| 24 protected: |
| 25 PasswordAutofillManagerTest() : password_autofill_manager_(NULL), |
| 26 frame_id_(0) {} |
| 27 |
| 28 virtual void SetUp() OVERRIDE { |
| 29 // Add a preferred login and an additional login to the FillData. |
| 30 string16 username1 = ASCIIToUTF16(kAliceUsername); |
| 31 string16 password1 = ASCIIToUTF16(kAlicePassword); |
| 32 |
| 33 username_field_.name = ASCIIToUTF16(kUsernameName); |
| 34 username_field_.value = username1; |
| 35 fill_data_.basic_data.fields.push_back(username_field_); |
| 36 |
| 37 webkit::forms::FormField password_field; |
| 38 password_field.name = ASCIIToUTF16(kPasswordName); |
| 39 password_field.value = password1; |
| 40 fill_data_.basic_data.fields.push_back(password_field); |
| 41 |
| 42 password_autofill_manager_.FillPasswordForm(username_field_, |
| 43 fill_data_, |
| 44 frame_id_); |
| 45 } |
| 46 |
| 47 void CloseFrame() { |
| 48 password_autofill_manager()->FrameClosing(0); |
| 49 } |
| 50 |
| 51 PasswordAutofillManager* password_autofill_manager() { |
| 52 return &password_autofill_manager_; |
| 53 } |
| 54 |
| 55 const webkit::forms::FormField& username_field() { return username_field_; } |
| 56 |
| 57 private: |
| 58 webkit::forms::PasswordFormFillData fill_data_; |
| 59 webkit::forms::FormField username_field_; |
| 60 |
| 61 PasswordAutofillManager password_autofill_manager_; |
| 62 |
| 63 const int frame_id_; |
| 64 }; |
| 65 |
| 66 TEST_F(PasswordAutofillManagerTest, HandleKeyDown) { |
| 67 EXPECT_TRUE(password_autofill_manager()->WouldHandleKeyDown( |
| 68 username_field())); |
| 69 |
| 70 CloseFrame(); |
| 71 |
| 72 EXPECT_FALSE(password_autofill_manager()->WouldHandleKeyDown( |
| 73 username_field())); |
| 74 } |
| 75 |
| 76 TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) { |
| 77 EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 78 username_field(), ASCIIToUTF16(kValue))); |
| 79 |
| 80 webkit::forms::FormField invalid_username; |
| 81 invalid_username.name = ASCIIToUTF16(kUsernameName); |
| 82 invalid_username.value = ASCIIToUTF16("no_user"); |
| 83 |
| 84 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 85 invalid_username, ASCIIToUTF16(kValue))); |
| 86 |
| 87 CloseFrame(); |
| 88 |
| 89 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
| 90 username_field(), ASCIIToUTF16(kValue))); |
| 91 } |
| 92 |
| 93 TEST_F(PasswordAutofillManagerTest, DidSelectAutofillSuggestion) { |
| 94 EXPECT_TRUE(password_autofill_manager()->DidSelectAutofillSuggestion( |
| 95 username_field())); |
| 96 |
| 97 CloseFrame(); |
| 98 |
| 99 EXPECT_FALSE(password_autofill_manager()->DidSelectAutofillSuggestion( |
| 100 username_field())); |
| 101 } |
| 102 |
| 103 TEST_F(PasswordAutofillManagerTest, DidClearAutofillSelection) { |
| 104 EXPECT_TRUE(password_autofill_manager()->DidClearAutofillSelection( |
| 105 username_field())); |
| 106 |
| 107 CloseFrame(); |
| 108 |
| 109 EXPECT_FALSE(password_autofill_manager()->DidClearAutofillSelection( |
| 110 username_field())); |
| 111 } |
OLD | NEW |