OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/common/password_form_fill_data.h" | 5 #include "components/autofill/core/common/password_form_fill_data.h" |
6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 using base::ASCIIToUTF16; | 13 using base::ASCIIToUTF16; |
13 | 14 |
14 namespace autofill { | 15 namespace autofill { |
15 | 16 |
16 // Tests that the when there is a single preferred match, and no extra | 17 // Tests that the when there is a single preferred match, and no extra |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 preferred_match.password_element = ASCIIToUTF16("password"); | 103 preferred_match.password_element = ASCIIToUTF16("password"); |
103 preferred_match.password_value = ASCIIToUTF16("test"); | 104 preferred_match.password_value = ASCIIToUTF16("test"); |
104 preferred_match.submit_element = ASCIIToUTF16(""); | 105 preferred_match.submit_element = ASCIIToUTF16(""); |
105 preferred_match.signon_realm = "https://mobile.foo.com/"; | 106 preferred_match.signon_realm = "https://mobile.foo.com/"; |
106 preferred_match.original_signon_realm = "https://foo.com/"; | 107 preferred_match.original_signon_realm = "https://foo.com/"; |
107 preferred_match.ssl_valid = true; | 108 preferred_match.ssl_valid = true; |
108 preferred_match.preferred = true; | 109 preferred_match.preferred = true; |
109 preferred_match.scheme = PasswordForm::SCHEME_HTML; | 110 preferred_match.scheme = PasswordForm::SCHEME_HTML; |
110 | 111 |
111 // Create a match that matches exactly, so |original_signon_realm| is not set. | 112 // Create a match that matches exactly, so |original_signon_realm| is not set. |
112 PasswordForm exact_match; | 113 scoped_ptr<PasswordForm> scoped_exact_match(new PasswordForm); |
| 114 PasswordForm& exact_match = *scoped_exact_match; |
113 exact_match.origin = GURL("https://foo.com/"); | 115 exact_match.origin = GURL("https://foo.com/"); |
114 exact_match.action = GURL("https://foo.com/login"); | 116 exact_match.action = GURL("https://foo.com/login"); |
115 exact_match.username_element = ASCIIToUTF16("username"); | 117 exact_match.username_element = ASCIIToUTF16("username"); |
116 exact_match.username_value = ASCIIToUTF16("test1@gmail.com"); | 118 exact_match.username_value = ASCIIToUTF16("test1@gmail.com"); |
117 exact_match.password_element = ASCIIToUTF16("password"); | 119 exact_match.password_element = ASCIIToUTF16("password"); |
118 exact_match.password_value = ASCIIToUTF16("test"); | 120 exact_match.password_value = ASCIIToUTF16("test"); |
119 exact_match.submit_element = ASCIIToUTF16(""); | 121 exact_match.submit_element = ASCIIToUTF16(""); |
120 exact_match.signon_realm = "https://foo.com/"; | 122 exact_match.signon_realm = "https://foo.com/"; |
121 exact_match.ssl_valid = true; | 123 exact_match.ssl_valid = true; |
122 exact_match.preferred = false; | 124 exact_match.preferred = false; |
123 exact_match.scheme = PasswordForm::SCHEME_HTML; | 125 exact_match.scheme = PasswordForm::SCHEME_HTML; |
124 | 126 |
125 // Create a match that was matched using public suffix, so | 127 // Create a match that was matched using public suffix, so |
126 // |original_signon_realm| is set to where the result came from. | 128 // |original_signon_realm| is set to where the result came from. |
127 PasswordForm public_suffix_match; | 129 scoped_ptr<PasswordForm> scoped_public_suffix_match(new PasswordForm); |
| 130 PasswordForm& public_suffix_match = *scoped_public_suffix_match; |
128 public_suffix_match.origin = GURL("https://foo.com/"); | 131 public_suffix_match.origin = GURL("https://foo.com/"); |
129 public_suffix_match.action = GURL("https://foo.com/login"); | 132 public_suffix_match.action = GURL("https://foo.com/login"); |
130 public_suffix_match.username_element = ASCIIToUTF16("username"); | 133 public_suffix_match.username_element = ASCIIToUTF16("username"); |
131 public_suffix_match.username_value = ASCIIToUTF16("test2@gmail.com"); | 134 public_suffix_match.username_value = ASCIIToUTF16("test2@gmail.com"); |
132 public_suffix_match.password_element = ASCIIToUTF16("password"); | 135 public_suffix_match.password_element = ASCIIToUTF16("password"); |
133 public_suffix_match.password_value = ASCIIToUTF16("test"); | 136 public_suffix_match.password_value = ASCIIToUTF16("test"); |
134 public_suffix_match.submit_element = ASCIIToUTF16(""); | 137 public_suffix_match.submit_element = ASCIIToUTF16(""); |
135 public_suffix_match.original_signon_realm = "https://subdomain.foo.com/"; | 138 public_suffix_match.original_signon_realm = "https://subdomain.foo.com/"; |
136 public_suffix_match.signon_realm = "https://foo.com/"; | 139 public_suffix_match.signon_realm = "https://foo.com/"; |
137 public_suffix_match.ssl_valid = true; | 140 public_suffix_match.ssl_valid = true; |
138 public_suffix_match.preferred = false; | 141 public_suffix_match.preferred = false; |
139 public_suffix_match.scheme = PasswordForm::SCHEME_HTML; | 142 public_suffix_match.scheme = PasswordForm::SCHEME_HTML; |
140 | 143 |
141 // Add one exact match and one public suffix match. | 144 // Add one exact match and one public suffix match. |
142 PasswordFormMap matches; | 145 PasswordFormMap matches; |
143 matches[exact_match.username_value] = &exact_match; | 146 matches.insert(exact_match.username_value, scoped_exact_match.Pass()); |
144 matches[public_suffix_match.username_value] = &public_suffix_match; | 147 matches.insert(public_suffix_match.username_value, |
| 148 scoped_public_suffix_match.Pass()); |
145 | 149 |
146 PasswordFormFillData result; | 150 PasswordFormFillData result; |
147 InitPasswordFormFillData(form_on_page, | 151 InitPasswordFormFillData(form_on_page, |
148 matches, | 152 matches, |
149 &preferred_match, | 153 &preferred_match, |
150 true, | 154 true, |
151 false, | 155 false, |
152 &result); | 156 &result); |
153 EXPECT_TRUE(result.wait_for_username); | 157 EXPECT_TRUE(result.wait_for_username); |
154 // The preferred realm should match the original signon realm from the | 158 // The preferred realm should match the original signon realm from the |
155 // preferred match so the user can see where the result came from. | 159 // preferred match so the user can see where the result came from. |
156 EXPECT_EQ(result.preferred_realm, | 160 EXPECT_EQ(result.preferred_realm, |
157 preferred_match.original_signon_realm); | 161 preferred_match.original_signon_realm); |
158 | 162 |
159 // The realm of the exact match should be empty. | 163 // The realm of the exact match should be empty. |
160 PasswordFormFillData::LoginCollection::const_iterator iter = | 164 PasswordFormFillData::LoginCollection::const_iterator iter = |
161 result.additional_logins.find(exact_match.username_value); | 165 result.additional_logins.find(exact_match.username_value); |
162 EXPECT_EQ(iter->second.realm, ""); | 166 EXPECT_EQ(iter->second.realm, ""); |
163 | 167 |
164 // The realm of the public suffix match should be set to the original signon | 168 // The realm of the public suffix match should be set to the original signon |
165 // realm so the user can see where the result came from. | 169 // realm so the user can see where the result came from. |
166 iter = result.additional_logins.find(public_suffix_match.username_value); | 170 iter = result.additional_logins.find(public_suffix_match.username_value); |
167 EXPECT_EQ(iter->second.realm, public_suffix_match.original_signon_realm); | 171 EXPECT_EQ(iter->second.realm, public_suffix_match.original_signon_realm); |
168 } | 172 } |
169 | 173 |
170 } // namespace autofill | 174 } // namespace autofill |
OLD | NEW |