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

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: 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 kInvalidUsernameName = "no-username";
15 const char* const kPasswordName = "password";
16
17 const char* const kAliceUsername = "alice";
18 const char* const kAlicePassword = "password";
19
20 const char* const kValue = "password";
21
22 } // namespace
23
24 class PasswordAutofillManagerTest : public testing::Test {
25 protected:
26 PasswordAutofillManagerTest() : password_autofill_manager_(NULL) {}
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_.AddPasswordFormMapping(username_field_,
43 fill_data_);
44 }
45
46 PasswordAutofillManager* password_autofill_manager() {
47 return &password_autofill_manager_;
48 }
49
50 const webkit::forms::FormField& username_field() { return username_field_; }
51
52 private:
53 webkit::forms::PasswordFormFillData fill_data_;
54 webkit::forms::FormField username_field_;
55
56 PasswordAutofillManager password_autofill_manager_;
57 };
58
59 TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) {
60 EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion(
61 username_field(), ASCIIToUTF16(kAliceUsername)));
62
63 webkit::forms::FormField invalid_username_field;
64 invalid_username_field.name = ASCIIToUTF16(kInvalidUsernameName);
65
66 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion(
67 invalid_username_field, ASCIIToUTF16(kAliceUsername)));
68
69 password_autofill_manager()->Reset();
70 EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion(
71 username_field(), ASCIIToUTF16(kAliceUsername)));
72 }
73
74 TEST_F(PasswordAutofillManagerTest, DidClearAutofillSelection) {
75 EXPECT_TRUE(password_autofill_manager()->DidClearAutofillSelection(
76 username_field()));
77
78 password_autofill_manager()->Reset();
79
80 EXPECT_FALSE(password_autofill_manager()->DidClearAutofillSelection(
81 username_field()));
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698