OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/password_manager/password_form_manager.h" | 9 #include "chrome/browser/password_manager/password_form_manager.h" |
10 #include "chrome/browser/password_manager/password_manager.h" | 10 #include "chrome/browser/password_manager/password_manager.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 saved_match_ = observed_form_; | 29 saved_match_ = observed_form_; |
30 saved_match_.origin = GURL("http://www.google.com/a/ServiceLoginAuth"); | 30 saved_match_.origin = GURL("http://www.google.com/a/ServiceLoginAuth"); |
31 saved_match_.action = GURL("http://www.google.com/a/ServiceLogin"); | 31 saved_match_.action = GURL("http://www.google.com/a/ServiceLogin"); |
32 saved_match_.preferred = true; | 32 saved_match_.preferred = true; |
33 saved_match_.username_value = ASCIIToUTF16("test@gmail.com"); | 33 saved_match_.username_value = ASCIIToUTF16("test@gmail.com"); |
34 saved_match_.password_value = ASCIIToUTF16("test1"); | 34 saved_match_.password_value = ASCIIToUTF16("test1"); |
35 profile_ = new TestingProfile(); | 35 profile_ = new TestingProfile(); |
36 } | 36 } |
37 | 37 |
38 // Remove the username and regererate the profile. | |
Ilya Sherman
2012/04/19 00:27:37
nit: "regererate" -> "regenerate"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
39 // This function change the observed_form_ and saved_match_. | |
Ilya Sherman
2012/04/19 00:27:37
nit: "change" -> "changes"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
40 // This function should be called at the beginning of tests | |
41 // that there is no username. | |
Ilya Sherman
2012/04/19 00:27:37
nit: "that there is no username" -> "for which the
| |
42 void SetUpForNoUsernameTests() { | |
43 observed_form_.origin = GURL("http://www.google.com/b/LoginAuth"); | |
44 observed_form_.action = GURL("http://www.google.com/b/Login"); | |
45 observed_form_.username_element = ASCIIToUTF16(""); | |
46 observed_form_.password_element = ASCIIToUTF16("Passwd"); | |
47 observed_form_.submit_element = ASCIIToUTF16("signIn"); | |
48 observed_form_.signon_realm = "http://www.google.com"; | |
49 | |
50 saved_match_ = observed_form_; | |
51 saved_match_.origin = GURL("http://www.google.com/b/ServiceLoginAuth"); | |
52 saved_match_.action = GURL("http://www.google.com/b/ServiceLogin"); | |
53 saved_match_.preferred = true; | |
54 saved_match_.username_value = ASCIIToUTF16(""); | |
55 saved_match_.password_value = ASCIIToUTF16("test2"); | |
56 } | |
57 | |
38 virtual void TearDown() { | 58 virtual void TearDown() { |
39 delete profile_; | 59 delete profile_; |
40 } | 60 } |
41 | 61 |
42 PasswordForm* GetPendingCredentials(PasswordFormManager* p) { | 62 PasswordForm* GetPendingCredentials(PasswordFormManager* p) { |
43 return &p->pending_credentials_; | 63 return &p->pending_credentials_; |
44 } | 64 } |
45 | 65 |
46 void SimulateMatchingPhase(PasswordFormManager* p, bool find_match) { | 66 void SimulateMatchingPhase(PasswordFormManager* p, bool find_match) { |
47 // Roll up the state to mock out the matching phase. | 67 // Roll up the state to mock out the matching phase. |
48 p->state_ = PasswordFormManager::POST_MATCHING_PHASE; | 68 p->state_ = PasswordFormManager::POST_MATCHING_PHASE; |
49 if (!find_match) | 69 if (!find_match) |
50 return; | 70 return; |
51 | 71 |
52 PasswordForm* match = new PasswordForm(saved_match_); | 72 PasswordForm* match = new PasswordForm(saved_match_); |
53 // Heap-allocated form is owned by p. | 73 // Heap-allocated form is owned by p. |
54 p->best_matches_[match->username_value] = match; | 74 p->best_matches_[match->username_value] = match; |
55 p->preferred_match_ = match; | 75 p->preferred_match_ = match; |
56 } | 76 } |
57 | 77 |
58 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) { | 78 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) { |
59 return p->IgnoreResult(*form); | 79 return p->IgnoreResult(*form); |
60 } | 80 } |
61 | 81 |
82 void VerifyNewLogin(PasswordFormManager* manager) { | |
83 // Successful login. The PasswordManager would instruct PasswordFormManager | |
84 // to save, which should know this is a new login. | |
85 EXPECT_TRUE(manager->IsNewLogin()); | |
86 // Make sure the credentials that would be submitted on successful login | |
87 // are going to match the stored entry in the db. | |
88 EXPECT_EQ(observed_form()->origin.spec(), | |
89 GetPendingCredentials(manager)->origin.spec()); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please indent to the parenthesis after "EQ"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
90 EXPECT_EQ(observed_form()->signon_realm, | |
91 GetPendingCredentials(manager)->signon_realm); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please indent to the parenthesis after "EQ"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
92 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); | |
93 EXPECT_EQ(saved_match()->password_value, | |
94 GetPendingCredentials(manager)->password_value); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please indent to the parenthesis after "EQ"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
95 EXPECT_EQ(saved_match()->username_value, | |
96 GetPendingCredentials(manager)->username_value); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please indent to the parenthesis after "EQ"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
97 return; | |
Ilya Sherman
2012/04/19 00:27:37
nit: This return statement is redundant; please re
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
98 } | |
99 | |
100 void EmptyAction() { | |
Ilya Sherman
2012/04/19 00:27:37
nit: Perhaps "TestEmptyAction()"? Method names ty
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
101 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( | |
102 profile(), NULL, *observed_form(), false)); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please preserve the previous indentation, i.e
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
103 | |
104 saved_match()->action = GURL(); | |
105 SimulateMatchingPhase(manager.get(), true); | |
106 // User logs in with the autofilled username / password from saved_match. | |
107 PasswordForm login = *observed_form(); | |
108 login.username_value = saved_match()->username_value; | |
109 login.password_value = saved_match()->password_value; | |
110 manager->ProvisionallySave(login); | |
111 EXPECT_FALSE(manager->IsNewLogin()); | |
112 // We bless our saved PasswordForm entry with the action URL of the | |
113 // observed form. | |
114 EXPECT_EQ(observed_form()->action, | |
115 GetPendingCredentials(manager.get())->action); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please indent to the parenthesis after "EQ"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
116 } | |
117 | |
118 void ValidForms() { | |
Ilya Sherman
2012/04/19 00:27:37
nit: Perhaps "TestValidForms()"? Method names typ
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
119 // User submits credentials for the observed form. | |
120 PasswordForm credentials = *observed_form(); | |
121 credentials.scheme = PasswordForm::SCHEME_HTML; | |
122 credentials.username_value = saved_match()->username_value; | |
123 credentials.password_value = saved_match()->password_value; | |
124 | |
125 // Form with both username_element and password_element. | |
126 PasswordFormManager manager1(profile(), NULL, credentials, false); | |
127 SimulateMatchingPhase(&manager1, false); | |
128 EXPECT_TRUE(manager1.HasValidPasswordForm()); | |
129 | |
130 // Form without a username_element but with a password_element. | |
131 // It should be true, because we should save and autofill a password | |
132 // if there isn't any username. | |
133 credentials.username_element.clear(); | |
134 PasswordFormManager manager2(profile(), NULL, credentials, false); | |
135 SimulateMatchingPhase(&manager2, false); | |
136 EXPECT_TRUE(manager2.HasValidPasswordForm()); | |
137 | |
138 // Form without a password_element but with a username_element. | |
139 credentials.username_element = saved_match()->username_element; | |
140 credentials.password_element.clear(); | |
141 PasswordFormManager manager3(profile(), NULL, credentials, false); | |
142 SimulateMatchingPhase(&manager3, false); | |
143 EXPECT_FALSE(manager3.HasValidPasswordForm()); | |
144 | |
145 // Form with neither a password_element nor a username_element. | |
146 credentials.username_element.clear(); | |
147 credentials.password_element.clear(); | |
148 PasswordFormManager manager4(profile(), NULL, credentials, false); | |
149 SimulateMatchingPhase(&manager4, false); | |
150 EXPECT_FALSE(manager4.HasValidPasswordForm()); | |
151 } | |
152 | |
153 void ValidFormsBasic() { | |
Ilya Sherman
2012/04/19 00:27:37
nit: Perhaps "TestValidFormsBasic()"? Method name
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
154 // User submits credentials for the observed form. | |
155 PasswordForm credentials = *observed_form(); | |
156 credentials.scheme = PasswordForm::SCHEME_BASIC; | |
157 credentials.username_value = saved_match()->username_value; | |
158 credentials.password_value = saved_match()->password_value; | |
159 | |
160 // Form with both username_element and password_element. | |
161 PasswordFormManager manager1(profile(), NULL, credentials, false); | |
162 SimulateMatchingPhase(&manager1, false); | |
163 EXPECT_TRUE(manager1.HasValidPasswordForm()); | |
164 | |
165 // Form without a username_element but with a password_element. | |
166 credentials.username_element.clear(); | |
167 PasswordFormManager manager2(profile(), NULL, credentials, false); | |
168 SimulateMatchingPhase(&manager2, false); | |
169 EXPECT_TRUE(manager2.HasValidPasswordForm()); | |
170 | |
171 // Form without a password_element but with a username_element. | |
172 credentials.username_element = saved_match()->username_element; | |
173 credentials.password_element.clear(); | |
174 PasswordFormManager manager3(profile(), NULL, credentials, false); | |
175 SimulateMatchingPhase(&manager3, false); | |
176 EXPECT_TRUE(manager3.HasValidPasswordForm()); | |
177 | |
178 // Form with neither a password_element nor a username_element. | |
179 credentials.username_element.clear(); | |
180 credentials.password_element.clear(); | |
181 PasswordFormManager manager4(profile(), NULL, credentials, false); | |
182 SimulateMatchingPhase(&manager4, false); | |
183 EXPECT_TRUE(manager4.HasValidPasswordForm()); | |
184 } | |
185 | |
62 Profile* profile() { return profile_; } | 186 Profile* profile() { return profile_; } |
63 | 187 |
64 PasswordForm* observed_form() { return &observed_form_; } | 188 PasswordForm* observed_form() { return &observed_form_; } |
65 PasswordForm* saved_match() { return &saved_match_; } | 189 PasswordForm* saved_match() { return &saved_match_; } |
66 | 190 |
67 private: | 191 private: |
68 PasswordForm observed_form_; | 192 PasswordForm observed_form_; |
69 PasswordForm saved_match_; | 193 PasswordForm saved_match_; |
70 Profile* profile_; | 194 Profile* profile_; |
71 }; | 195 }; |
72 | 196 |
73 TEST_F(PasswordFormManagerTest, TestNewLogin) { | 197 TEST_F(PasswordFormManagerTest, TestNewLogin) { |
74 PasswordFormManager* manager = new PasswordFormManager( | 198 PasswordFormManager* manager = new PasswordFormManager( |
75 profile(), NULL, *observed_form(), false); | 199 profile(), NULL, *observed_form(), false); |
Ilya Sherman
2012/04/19 00:27:37
nit: Can this be allocated on the stack, rather th
Yumikiyo Osanai
2012/04/26 23:33:22
Oh! You are right.
I've fixed to allocate the inst
| |
76 SimulateMatchingPhase(manager, false); | 200 SimulateMatchingPhase(manager, false); |
77 // User submits credentials for the observed form. | 201 // User submits credentials for the observed form. |
78 PasswordForm credentials = *observed_form(); | 202 PasswordForm credentials = *observed_form(); |
79 credentials.username_value = saved_match()->username_value; | 203 credentials.username_value = saved_match()->username_value; |
80 credentials.password_value = saved_match()->password_value; | 204 credentials.password_value = saved_match()->password_value; |
81 credentials.preferred = true; | 205 credentials.preferred = true; |
82 manager->ProvisionallySave(credentials); | 206 manager->ProvisionallySave(credentials); |
83 | 207 VerifyNewLogin(manager); |
84 // Successful login. The PasswordManager would instruct PasswordFormManager | |
85 // to save, which should know this is a new login. | |
86 EXPECT_TRUE(manager->IsNewLogin()); | |
87 // Make sure the credentials that would be submitted on successful login | |
88 // are going to match the stored entry in the db. | |
89 EXPECT_EQ(observed_form()->origin.spec(), | |
90 GetPendingCredentials(manager)->origin.spec()); | |
91 EXPECT_EQ(observed_form()->signon_realm, | |
92 GetPendingCredentials(manager)->signon_realm); | |
93 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); | |
94 EXPECT_EQ(saved_match()->password_value, | |
95 GetPendingCredentials(manager)->password_value); | |
96 EXPECT_EQ(saved_match()->username_value, | |
97 GetPendingCredentials(manager)->username_value); | |
98 | 208 |
99 // Now, suppose the user re-visits the site and wants to save an additional | 209 // Now, suppose the user re-visits the site and wants to save an additional |
100 // login for the site with a new username. In this case, the matching phase | 210 // login for the site with a new username. In this case, the matching phase |
101 // will yield the previously saved login. | 211 // will yield the previously saved login. |
102 SimulateMatchingPhase(manager, true); | 212 SimulateMatchingPhase(manager, true); |
103 // Set up the new login. | 213 // Set up the new login. |
104 string16 new_user = ASCIIToUTF16("newuser"); | 214 string16 new_user = ASCIIToUTF16("newuser"); |
105 string16 new_pass = ASCIIToUTF16("newpass"); | 215 string16 new_pass = ASCIIToUTF16("newpass"); |
106 credentials.username_value = new_user; | 216 credentials.username_value = new_user; |
107 credentials.password_value = new_pass; | 217 credentials.password_value = new_pass; |
108 manager->ProvisionallySave(credentials); | 218 manager->ProvisionallySave(credentials); |
109 | 219 |
110 // Again, the PasswordFormManager should know this is still a new login. | 220 // Again, the PasswordFormManager should know this is still a new login. |
111 EXPECT_TRUE(manager->IsNewLogin()); | 221 EXPECT_TRUE(manager->IsNewLogin()); |
112 // And make sure everything squares up again. | 222 // And make sure everything squares up again. |
113 EXPECT_EQ(observed_form()->origin.spec(), | 223 EXPECT_EQ(observed_form()->origin.spec(), |
114 GetPendingCredentials(manager)->origin.spec()); | 224 GetPendingCredentials(manager)->origin.spec()); |
115 EXPECT_EQ(observed_form()->signon_realm, | 225 EXPECT_EQ(observed_form()->signon_realm, |
116 GetPendingCredentials(manager)->signon_realm); | 226 GetPendingCredentials(manager)->signon_realm); |
117 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); | 227 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); |
118 EXPECT_EQ(new_pass, | 228 EXPECT_EQ(new_pass, |
119 GetPendingCredentials(manager)->password_value); | 229 GetPendingCredentials(manager)->password_value); |
120 EXPECT_EQ(new_user, | 230 EXPECT_EQ(new_user, |
121 GetPendingCredentials(manager)->username_value); | 231 GetPendingCredentials(manager)->username_value); |
122 // Done. | 232 // Done. |
123 delete manager; | 233 delete manager; |
124 } | 234 } |
125 | 235 |
236 TEST_F(PasswordFormManagerTest, TestNewLoginAndUpdateWithoutUsername) { | |
237 SetUpForNoUsernameTests(); | |
238 PasswordFormManager* manager = new PasswordFormManager( | |
239 profile(), NULL, *observed_form(), false); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Can this be allocated on the stack, rather th
| |
240 SimulateMatchingPhase(manager, false); | |
241 | |
242 // User submits credentials for the observed form. | |
243 PasswordForm credentials = *observed_form(); | |
244 credentials.username_value = saved_match()->username_value; | |
245 credentials.password_value = saved_match()->password_value; | |
246 credentials.preferred = true; | |
247 manager->ProvisionallySave(credentials); | |
248 VerifyNewLogin(manager); | |
249 | |
250 // Now, suppose the user re-visits the site and wants to save an additional | |
251 // login for the site with a new password. In this case, the matching phase | |
252 // will yield the previously saved login. | |
253 SimulateMatchingPhase(manager, true); | |
254 | |
255 // Set up the update login. | |
256 string16 new_pass = ASCIIToUTF16("newpass2"); | |
257 credentials.password_value = new_pass; | |
258 manager->ProvisionallySave(credentials); | |
259 | |
260 // If there is no username, we supporse it's an update. | |
Ilya Sherman
2012/04/19 00:27:37
nit: "supporse" -> "assume"
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
261 EXPECT_FALSE(manager->IsNewLogin()); | |
262 | |
263 // And make sure everything squares up again. | |
264 EXPECT_EQ(GetPendingCredentials(manager)->origin.spec(), | |
265 saved_match()->origin.spec()); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please preserve the parameter order that was
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
266 EXPECT_EQ(GetPendingCredentials(manager)->signon_realm, | |
267 saved_match()->signon_realm); | |
Ilya Sherman
2012/04/19 00:27:37
nit: Please preserve the parameter order that was
Yumikiyo Osanai
2012/04/26 23:33:22
Done.
| |
268 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); | |
269 EXPECT_EQ(new_pass, | |
270 GetPendingCredentials(manager)->password_value); | |
271 | |
272 // Done. | |
273 delete manager; | |
274 } | |
275 | |
276 | |
126 TEST_F(PasswordFormManagerTest, TestUpdatePassword) { | 277 TEST_F(PasswordFormManagerTest, TestUpdatePassword) { |
127 // Create a PasswordFormManager with observed_form, as if we just | 278 // Create a PasswordFormManager with observed_form, as if we just |
128 // saw this form and need to find matching logins. | 279 // saw this form and need to find matching logins. |
129 PasswordFormManager* manager = new PasswordFormManager( | 280 PasswordFormManager* manager = new PasswordFormManager( |
130 profile(), NULL, *observed_form(), false); | 281 profile(), NULL, *observed_form(), false); |
131 SimulateMatchingPhase(manager, true); | 282 SimulateMatchingPhase(manager, true); |
132 | 283 |
133 // User submits credentials for the observed form using a username previously | 284 // User submits credentials for the observed form using a username previously |
134 // stored, but a new password. Note that the observed form may have different | 285 // stored, but a new password. Note that the observed form may have different |
135 // origin URL (as it does in this case) than the saved_match, but we want to | 286 // origin URL (as it does in this case) than the saved_match, but we want to |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // Different paths for action / origin are okay. | 324 // Different paths for action / origin are okay. |
174 saved_match()->action = GURL("http://www.google.com/b/Login"); | 325 saved_match()->action = GURL("http://www.google.com/b/Login"); |
175 saved_match()->origin = GURL("http://www.google.com/foo"); | 326 saved_match()->origin = GURL("http://www.google.com/foo"); |
176 EXPECT_FALSE(IgnoredResult(manager, saved_match())); | 327 EXPECT_FALSE(IgnoredResult(manager, saved_match())); |
177 | 328 |
178 // Done. | 329 // Done. |
179 delete manager; | 330 delete manager; |
180 } | 331 } |
181 | 332 |
182 TEST_F(PasswordFormManagerTest, TestEmptyAction) { | 333 TEST_F(PasswordFormManagerTest, TestEmptyAction) { |
183 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( | 334 EmptyAction(); |
184 profile(), NULL, *observed_form(), false)); | 335 } |
185 | 336 |
186 saved_match()->action = GURL(); | 337 TEST_F(PasswordFormManagerTest, TestEmptyActionWithoutUsername) { |
187 SimulateMatchingPhase(manager.get(), true); | 338 SetUpForNoUsernameTests(); |
188 // User logs in with the autofilled username / password from saved_match. | 339 EmptyAction(); |
189 PasswordForm login = *observed_form(); | |
190 login.username_value = saved_match()->username_value; | |
191 login.password_value = saved_match()->password_value; | |
192 manager->ProvisionallySave(login); | |
193 EXPECT_FALSE(manager->IsNewLogin()); | |
194 // We bless our saved PasswordForm entry with the action URL of the | |
195 // observed form. | |
196 EXPECT_EQ(observed_form()->action, | |
197 GetPendingCredentials(manager.get())->action); | |
198 } | 340 } |
199 | 341 |
200 TEST_F(PasswordFormManagerTest, TestValidForms) { | 342 TEST_F(PasswordFormManagerTest, TestValidForms) { |
201 // User submits credentials for the observed form. | 343 ValidForms(); |
202 PasswordForm credentials = *observed_form(); | 344 } |
203 credentials.scheme = PasswordForm::SCHEME_HTML; | |
204 credentials.username_value = saved_match()->username_value; | |
205 credentials.password_value = saved_match()->password_value; | |
206 | 345 |
207 // Form with both username_element and password_element. | 346 TEST_F(PasswordFormManagerTest, TestValidFormsWithNoUsername) { |
208 PasswordFormManager manager1(profile(), NULL, credentials, false); | 347 SetUpForNoUsernameTests(); |
209 SimulateMatchingPhase(&manager1, false); | 348 ValidForms(); |
210 EXPECT_TRUE(manager1.HasValidPasswordForm()); | |
211 | |
212 // Form without a username_element but with a password_element. | |
213 credentials.username_element.clear(); | |
214 PasswordFormManager manager2(profile(), NULL, credentials, false); | |
215 SimulateMatchingPhase(&manager2, false); | |
216 EXPECT_FALSE(manager2.HasValidPasswordForm()); | |
217 | |
218 // Form without a password_element but with a username_element. | |
219 credentials.username_element = saved_match()->username_element; | |
220 credentials.password_element.clear(); | |
221 PasswordFormManager manager3(profile(), NULL, credentials, false); | |
222 SimulateMatchingPhase(&manager3, false); | |
223 EXPECT_FALSE(manager3.HasValidPasswordForm()); | |
224 | |
225 // Form with neither a password_element nor a username_element. | |
226 credentials.username_element.clear(); | |
227 credentials.password_element.clear(); | |
228 PasswordFormManager manager4(profile(), NULL, credentials, false); | |
229 SimulateMatchingPhase(&manager4, false); | |
230 EXPECT_FALSE(manager4.HasValidPasswordForm()); | |
231 } | 349 } |
232 | 350 |
233 TEST_F(PasswordFormManagerTest, TestValidFormsBasic) { | 351 TEST_F(PasswordFormManagerTest, TestValidFormsBasic) { |
234 // User submits credentials for the observed form. | 352 ValidFormsBasic(); |
353 } | |
354 | |
355 TEST_F(PasswordFormManagerTest, TestValidFormsBasicWithoutUsername) { | |
356 SetUpForNoUsernameTests(); | |
357 ValidFormsBasic(); | |
358 } | |
359 | |
360 TEST_F(PasswordFormManagerTest, TestVisitOtherForm) { | |
361 // Create forms haven't username element. | |
362 SetUpForNoUsernameTests(); | |
363 | |
364 // Save the password for a form with no username element | |
365 // on http://www.google.com/b/LoginAuth | |
366 PasswordFormManager* manager = new PasswordFormManager( | |
367 profile(), NULL, *observed_form(), false); | |
Ilya Sherman
2012/04/19 00:27:37
nit: It looks like this will leak. Can it be allo
| |
368 SimulateMatchingPhase(manager, false); | |
235 PasswordForm credentials = *observed_form(); | 369 PasswordForm credentials = *observed_form(); |
236 credentials.scheme = PasswordForm::SCHEME_BASIC; | |
237 credentials.username_value = saved_match()->username_value; | 370 credentials.username_value = saved_match()->username_value; |
238 credentials.password_value = saved_match()->password_value; | 371 credentials.password_value = saved_match()->password_value; |
372 credentials.preferred = true; | |
373 manager->ProvisionallySave(credentials); | |
374 VerifyNewLogin(manager); | |
239 | 375 |
240 // Form with both username_element and password_element. | 376 // the user visits foo.com/a, which has a password form |
241 PasswordFormManager manager1(profile(), NULL, credentials, false); | 377 // *with* a username element. |
Ilya Sherman
2012/04/19 00:27:37
Should there be code below this comment?
Yumikiyo Osanai
2012/04/26 23:33:22
Oh, Thank you for pointing out it.
I forgot to del
| |
242 SimulateMatchingPhase(&manager1, false); | |
243 EXPECT_TRUE(manager1.HasValidPasswordForm()); | |
244 | 378 |
245 // Form without a username_element but with a password_element. | 379 // the user visits foo.com/a, which has a password form |
246 credentials.username_element.clear(); | 380 // *without* a username element. |
Ilya Sherman
2012/04/19 00:27:37
Should there be code below this comment?
Yumikiyo Osanai
2012/04/26 23:33:22
Oh, I'll remove this comment.
What I'd like to tes
| |
247 PasswordFormManager manager2(profile(), NULL, credentials, false); | |
248 SimulateMatchingPhase(&manager2, false); | |
249 EXPECT_TRUE(manager2.HasValidPasswordForm()); | |
250 | 381 |
251 // Form without a password_element but with a username_element. | |
252 credentials.username_element = saved_match()->username_element; | |
253 credentials.password_element.clear(); | |
254 PasswordFormManager manager3(profile(), NULL, credentials, false); | |
255 SimulateMatchingPhase(&manager3, false); | |
256 EXPECT_TRUE(manager3.HasValidPasswordForm()); | |
257 | |
258 // Form with neither a password_element nor a username_element. | |
259 credentials.username_element.clear(); | |
260 credentials.password_element.clear(); | |
261 PasswordFormManager manager4(profile(), NULL, credentials, false); | |
262 SimulateMatchingPhase(&manager4, false); | |
263 EXPECT_TRUE(manager4.HasValidPasswordForm()); | |
264 } | 382 } |
OLD | NEW |