OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 "components/autofill/common/password_form_fill_data.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "content/public/common/password_form.h" | |
9 #include "testing/gmock/include/gmock/gmock.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 using content::PasswordForm; | |
13 using content::PasswordFormMap; | |
14 | |
15 namespace autofill { | |
16 | |
17 TEST(TestSinglePreferredMatch) { | |
18 // Tests that the when there is a single preferred match, and no extra | |
19 // matches, the PasswordFormFillData is filled in correctly. | |
Ilya Sherman
2013/06/19 23:41:14
Optional nit: I've generally seen such comments go
nyquist
2013/06/21 21:01:27
Done.
| |
20 | |
21 // Create the current form on the page. | |
22 PasswordForm form_on_page; | |
23 form_on_page.origin = GURL("https://foo.com/"); | |
24 form_on_page.action = GURL("https://foo.com/login"); | |
25 form_on_page.username_element = ASCIIToUTF16("username"); | |
26 form_on_page.username_value = ASCIIToUTF16("test@gmail.com"); | |
27 form_on_page.password_element = ASCIIToUTF16("password"); | |
28 form_on_page.password_value = ASCIIToUTF16("test"); | |
29 form_on_page.submit_element = ASCIIToUTF16(""); | |
30 form_on_page.signon_realm = "https://foo.com/"; | |
31 form_on_page.ssl_valid = true; | |
32 form_on_page.preferred = false; | |
33 form_on_page.scheme = PasswordForm::SCHEME_HTML; | |
34 | |
35 // Create an exact match in the database. | |
36 PasswordForm preferred_match; | |
37 preferred_match.origin = GURL("https://foo.com/"); | |
38 preferred_match.action = GURL("https://foo.com/login"); | |
39 preferred_match.username_element = ASCIIToUTF16("username"); | |
40 preferred_match.username_value = ASCIIToUTF16("test@gmail.com"); | |
41 preferred_match.password_element = ASCIIToUTF16("password"); | |
42 preferred_match.password_value = ASCIIToUTF16("test"); | |
43 preferred_match.submit_element = ASCIIToUTF16(""); | |
44 preferred_match.signon_realm = "https://foo.com/"; | |
45 preferred_match.ssl_valid = true; | |
46 preferred_match.preferred = true; | |
47 preferred_match.scheme = PasswordForm::SCHEME_HTML; | |
48 | |
49 PasswordFormMap matches; | |
50 | |
51 PasswordFormFillData result; | |
52 InitPasswordFormFillData(form_on_page, | |
53 matches, | |
54 &preferred_match, | |
55 true, | |
56 false, | |
57 &result); | |
58 | |
59 // |wait_for_username| should reflect the |wait_for_username_before_autofill| | |
60 // argument of InitPasswordFormFillData which in this case is true. | |
61 EXPECT_TRUE(result.wait_for_username); | |
62 // The preferred realm should match the signon realm from the preferred match. | |
63 EXPECT_EQ(result.preferred_realm, preferred_match.signon_realm); | |
64 | |
65 PasswordFormFillData result2; | |
66 InitPasswordFormFillData(form_on_page, | |
67 matches, | |
68 &preferred_match, | |
69 false, | |
70 false, | |
71 &result2); | |
72 | |
73 // |wait_for_username| should reflect the |wait_for_username_before_autofill| | |
74 // argument of InitPasswordFormFillData which in this case is false. | |
75 EXPECT_TRUE(result2.wait_for_username); | |
76 } | |
77 | |
78 TEST(TestPublicSuffixDomainMatching) { | |
79 // Tests that the InitPasswordFormFillData behaves correctly when there is a | |
80 // preferred match that was found using public suffix matching, an additional | |
81 // result that also used public suffix matching, and a third result that was | |
82 // found without using public suffix matching. | |
83 | |
84 // Create the current form on the page. | |
85 PasswordForm form_on_page; | |
86 form_on_page.origin = GURL("https://foo.com/"); | |
87 form_on_page.action = GURL("https://foo.com/login"); | |
88 form_on_page.username_element = ASCIIToUTF16("username"); | |
89 form_on_page.username_value = ASCIIToUTF16("test@gmail.com"); | |
90 form_on_page.password_element = ASCIIToUTF16("password"); | |
91 form_on_page.password_value = ASCIIToUTF16("test"); | |
92 form_on_page.submit_element = ASCIIToUTF16(""); | |
93 form_on_page.signon_realm = "https://foo.com/"; | |
94 form_on_page.ssl_valid = true; | |
95 form_on_page.preferred = false; | |
96 form_on_page.scheme = PasswordForm::SCHEME_HTML; | |
97 | |
98 // Create a match from the database that matches using public suffix. | |
99 PasswordForm preferred_match; | |
100 preferred_match.origin = GURL("https://mobile.foo.com/"); | |
101 preferred_match.action = GURL("https://mobile.foo.com/login"); | |
102 preferred_match.username_element = ASCIIToUTF16("username"); | |
103 preferred_match.username_value = ASCIIToUTF16("test@gmail.com"); | |
104 preferred_match.password_element = ASCIIToUTF16("password"); | |
105 preferred_match.password_value = ASCIIToUTF16("test"); | |
106 preferred_match.submit_element = ASCIIToUTF16(""); | |
107 preferred_match.signon_realm = "https://mobile.foo.com/"; | |
108 preferred_match.original_signon_realm = "https://foo.com/"; | |
109 preferred_match.ssl_valid = true; | |
110 preferred_match.preferred = true; | |
111 preferred_match.scheme = PasswordForm::SCHEME_HTML; | |
112 | |
113 // Create a match that matches exactly, so |original_signon_realm| is not set. | |
114 PasswordForm exact_match; | |
115 exact_match.origin = GURL("https://foo.com/"); | |
116 exact_match.action = GURL("https://foo.com/login"); | |
117 exact_match.username_element = ASCIIToUTF16("username"); | |
118 exact_match.username_value = ASCIIToUTF16("test1@gmail.com"); | |
119 exact_match.password_element = ASCIIToUTF16("password"); | |
120 exact_match.password_value = ASCIIToUTF16("test"); | |
121 exact_match.submit_element = ASCIIToUTF16(""); | |
122 exact_match.signon_realm = "https://foo.com/"; | |
123 exact_match.ssl_valid = true; | |
124 exact_match.preferred = false; | |
125 exact_match.scheme = PasswordForm::SCHEME_HTML; | |
126 | |
127 // Create a match that was matched using public suffix, so | |
128 // |original_signon_realm| is set to where the result came from. | |
129 PasswordForm public_suffix_match; | |
130 public_suffix_match.origin = GURL("https://foo.com/"); | |
131 public_suffix_match.action = GURL("https://foo.com/login"); | |
132 public_suffix_match.username_element = ASCIIToUTF16("username"); | |
133 public_suffix_match.username_value = ASCIIToUTF16("test2@gmail.com"); | |
134 public_suffix_match.password_element = ASCIIToUTF16("password"); | |
135 public_suffix_match.password_value = ASCIIToUTF16("test"); | |
136 public_suffix_match.submit_element = ASCIIToUTF16(""); | |
137 public_suffix_match.signon_realm = "https://foo.com/"; | |
138 public_suffix_match.ssl_valid = true; | |
139 public_suffix_match.preferred = false; | |
140 public_suffix_match.scheme = PasswordForm::SCHEME_HTML; | |
141 | |
142 // Add one exact match and one public suffix match. | |
143 PasswordFormMap matches; | |
144 matches[exact_match.username_value] = &exact_match; | |
145 matches[public_suffix_match.username_value] = &public_suffix_match; | |
146 | |
147 PasswordFormFillData result; | |
148 InitPasswordFormFillData(form_on_page, | |
149 matches, | |
150 &preferred_match, | |
151 true, | |
152 false, | |
153 &result); | |
154 EXPECT_TRUE(result.wait_for_username); | |
155 // The preferred realm should match the original signon realm from the | |
156 // preferred match so the user can see where the result came from. | |
157 EXPECT_EQ(result.preferred_realm, | |
158 preferred_match.original_signon_realm); | |
159 | |
160 // The realm of the exact match should be the same as the realm from the | |
161 // match. | |
162 PasswordFormFillData::LoginCollection::const_iterator iter = | |
163 result.additional_logins.find(exact_match.username_value); | |
164 EXPECT_EQ(iter->second.realm, exact_match.signon_realm); | |
165 | |
166 // The realm of the public suffix match should be set to the original signon | |
167 // realm so the user can see where the result came from. | |
168 iter = result.additional_logins.find(public_suffix_match.username_value); | |
169 EXPECT_EQ(iter->second.realm, public_suffix_match.signon_realm); | |
170 } | |
171 | |
172 } // namespace autofill | |
OLD | NEW |