Index: chrome/browser/autofill/password_autofill_manager_unittest.cc |
diff --git a/chrome/browser/autofill/password_autofill_manager_unittest.cc b/chrome/browser/autofill/password_autofill_manager_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d8d20eeeb16df6c76aae0ae9134aae5df16ac1a3 |
--- /dev/null |
+++ b/chrome/browser/autofill/password_autofill_manager_unittest.cc |
@@ -0,0 +1,111 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/compiler_specific.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/browser/autofill/password_autofill_manager.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+// The name of the username/password element in the form. |
+const char* const kUsernameName = "username"; |
+const char* const kPasswordName = "password"; |
+ |
+const char* const kAliceUsername = "alice"; |
+const char* const kAlicePassword = "password"; |
+ |
+const char* const kValue = "password"; |
+ |
+} // namespace |
+ |
+class PasswordAutofillManagerTest : public testing::Test { |
+ protected: |
+ PasswordAutofillManagerTest() : password_autofill_manager_(NULL), |
+ frame_id_(0) {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ // Add a preferred login and an additional login to the FillData. |
+ string16 username1 = ASCIIToUTF16(kAliceUsername); |
+ string16 password1 = ASCIIToUTF16(kAlicePassword); |
+ |
+ username_field_.name = ASCIIToUTF16(kUsernameName); |
+ username_field_.value = username1; |
+ fill_data_.basic_data.fields.push_back(username_field_); |
+ |
+ webkit::forms::FormField password_field; |
+ password_field.name = ASCIIToUTF16(kPasswordName); |
+ password_field.value = password1; |
+ fill_data_.basic_data.fields.push_back(password_field); |
+ |
+ password_autofill_manager_.FillPasswordForm(username_field_, |
+ fill_data_, |
+ frame_id_); |
+ } |
+ |
+ void CloseFrame() { |
+ password_autofill_manager()->FrameClosing(0); |
+ } |
+ |
+ PasswordAutofillManager* password_autofill_manager() { |
+ return &password_autofill_manager_; |
+ } |
+ |
+ const webkit::forms::FormField& username_field() { return username_field_; } |
+ |
+ private: |
+ webkit::forms::PasswordFormFillData fill_data_; |
+ webkit::forms::FormField username_field_; |
+ |
+ PasswordAutofillManager password_autofill_manager_; |
+ |
+ const int frame_id_; |
Ilya Sherman
2012/03/08 23:22:14
nit: int -> long long?
csharp
2012/03/09 16:20:19
removed
|
+}; |
+ |
+TEST_F(PasswordAutofillManagerTest, HandleKeyDown) { |
+ EXPECT_TRUE(password_autofill_manager()->WouldHandleKeyDown( |
+ username_field())); |
+ |
+ CloseFrame(); |
+ |
+ EXPECT_FALSE(password_autofill_manager()->WouldHandleKeyDown( |
+ username_field())); |
+} |
+ |
+TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) { |
+ EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
+ username_field(), ASCIIToUTF16(kValue))); |
+ |
+ webkit::forms::FormField invalid_username; |
+ invalid_username.name = ASCIIToUTF16(kUsernameName); |
+ invalid_username.value = ASCIIToUTF16("no_user"); |
+ |
+ EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
+ invalid_username, ASCIIToUTF16(kValue))); |
+ |
+ CloseFrame(); |
+ |
+ EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion( |
+ username_field(), ASCIIToUTF16(kValue))); |
+} |
+ |
+TEST_F(PasswordAutofillManagerTest, DidSelectAutofillSuggestion) { |
+ EXPECT_TRUE(password_autofill_manager()->DidSelectAutofillSuggestion( |
+ username_field())); |
+ |
+ CloseFrame(); |
+ |
+ EXPECT_FALSE(password_autofill_manager()->DidSelectAutofillSuggestion( |
+ username_field())); |
+} |
+ |
+TEST_F(PasswordAutofillManagerTest, DidClearAutofillSelection) { |
+ EXPECT_TRUE(password_autofill_manager()->DidClearAutofillSelection( |
+ username_field())); |
+ |
+ CloseFrame(); |
+ |
+ EXPECT_FALSE(password_autofill_manager()->DidClearAutofillSelection( |
+ username_field())); |
+} |