Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/autofill/password_autofill_manager_unittest.cc

Issue 9600038: Add Password Autofill Manager to New Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove frame id Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
27 virtual void SetUp() OVERRIDE {
28 // Add a preferred login and an additional login to the FillData.
29 string16 username1 = ASCIIToUTF16(kAliceUsername);
30 string16 password1 = ASCIIToUTF16(kAlicePassword);
31
32 username_field_.name = ASCIIToUTF16(kUsernameName);
33 username_field_.value = username1;
34 fill_data_.basic_data.fields.push_back(username_field_);
35
36 webkit::forms::FormField password_field;
37 password_field.name = ASCIIToUTF16(kPasswordName);
38 password_field.value = password1;
39 fill_data_.basic_data.fields.push_back(password_field);
40
41 password_autofill_manager_.PasswordFormMapping(username_field_,
42 fill_data_);
43 }
44
45 PasswordAutofillManager* password_autofill_manager() {
46 return &password_autofill_manager_;
47 }
48
49 const webkit::forms::FormField& username_field() { return username_field_; }
50
51 private:
52 webkit::forms::PasswordFormFillData fill_data_;
53 webkit::forms::FormField username_field_;
54
55 PasswordAutofillManager password_autofill_manager_;
56 };
57
58 TEST_F(PasswordAutofillManagerTest, HandleKeyDown) {
59 EXPECT_TRUE(password_autofill_manager()->WouldHandleKeyDown(
60 username_field()));
61
62 password_autofill_manager()->FrameClosing();
63
64 EXPECT_FALSE(password_autofill_manager()->WouldHandleKeyDown(
65 username_field()));
66 }
67
68 TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) {
69 EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion(
70 username_field(), ASCIIToUTF16(kValue)));
71
72 webkit::forms::FormField invalid_username;
73 invalid_username.name = ASCIIToUTF16(kUsernameName);
74 invalid_username.value = ASCIIToUTF16("no_user");
75
76 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion(
77 invalid_username, ASCIIToUTF16(kValue)));
78
79 password_autofill_manager()->FrameClosing();
80
81 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion(
82 username_field(), ASCIIToUTF16(kValue)));
83 }
84
85 TEST_F(PasswordAutofillManagerTest, DidSelectAutofillSuggestion) {
86 EXPECT_TRUE(password_autofill_manager()->DidSelectAutofillSuggestion(
87 username_field()));
88
89 password_autofill_manager()->FrameClosing();
90
91 EXPECT_FALSE(password_autofill_manager()->DidSelectAutofillSuggestion(
92 username_field()));
93 }
94
95 TEST_F(PasswordAutofillManagerTest, DidClearAutofillSelection) {
96 EXPECT_TRUE(password_autofill_manager()->DidClearAutofillSelection(
97 username_field()));
98
99 password_autofill_manager()->FrameClosing();
100
101 EXPECT_FALSE(password_autofill_manager()->DidClearAutofillSelection(
102 username_field()));
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698