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

Side by Side Diff: chrome/renderer/autofill/password_generation_agent_browsertest.cc

Issue 563313004: [Password Manager] Unfriend PasswordAutofillAgentTest from PasswordAutofillAgent (clean-up). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unfriend PasswordAutofillAgentTest and RequestAutocompleteRendererTest from AutofillAgent. Created 6 years, 3 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
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 <string.h> 5 #include <string.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/test/base/chrome_render_view_test.h" 9 #include "chrome/test/base/chrome_render_view_test.h"
10 #include "components/autofill/content/common/autofill_messages.h" 10 #include "components/autofill/content/common/autofill_messages.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 password_generation_->OnMessageReceived(msg); 193 password_generation_->OnMessageReceived(msg);
194 194
195 // Passwords start out the same. 195 // Passwords start out the same.
196 EXPECT_EQ(password, first_password_element.value()); 196 EXPECT_EQ(password, first_password_element.value());
197 EXPECT_EQ(password, second_password_element.value()); 197 EXPECT_EQ(password, second_password_element.value());
198 198
199 // After editing the first field they are still the same. 199 // After editing the first field they are still the same.
200 base::string16 edited_password = base::ASCIIToUTF16("edited_password"); 200 base::string16 edited_password = base::ASCIIToUTF16("edited_password");
201 first_password_element.setValue(edited_password); 201 first_password_element.setValue(edited_password);
202 // Cast to WebAutofillClient where textFieldDidChange() is public. 202 // Cast to WebAutofillClient where textFieldDidChange() is public.
203 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 203 AutofillAgent* autofill_agent = (AutofillAgent*)autofill_agent_;
vabr (Chromium) 2014/09/15 14:26:59 Don't use C-style cast, use one of C++ casts. (htt
Pritam Nikam 2014/09/16 07:54:19 Done. I've missed including header earlier.
204 first_password_element); 204 static_cast<blink::WebAutofillClient*>(autofill_agent)
205 ->textFieldDidChange(first_password_element);
205 // textFieldDidChange posts a task, so we need to wait until it's been 206 // textFieldDidChange posts a task, so we need to wait until it's been
206 // processed. 207 // processed.
207 base::MessageLoop::current()->RunUntilIdle(); 208 base::MessageLoop::current()->RunUntilIdle();
208 209
209 EXPECT_EQ(edited_password, first_password_element.value()); 210 EXPECT_EQ(edited_password, first_password_element.value());
210 EXPECT_EQ(edited_password, second_password_element.value()); 211 EXPECT_EQ(edited_password, second_password_element.value());
211 } 212 }
212 213
213 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) { 214 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) {
214 // Did not receive not blacklisted message. Don't show password generation 215 // Did not receive not blacklisted message. Don't show password generation
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 WebElement element = 266 WebElement element =
266 document.getElementById(WebString::fromUTF8("first_password")); 267 document.getElementById(WebString::fromUTF8("first_password"));
267 ASSERT_FALSE(element.isNull()); 268 ASSERT_FALSE(element.isNull());
268 WebInputElement first_password_element = element.to<WebInputElement>(); 269 WebInputElement first_password_element = element.to<WebInputElement>();
269 270
270 // Make a password just under maximum offer size. 271 // Make a password just under maximum offer size.
271 first_password_element.setValue( 272 first_password_element.setValue(
272 base::ASCIIToUTF16( 273 base::ASCIIToUTF16(
273 std::string(password_generation_->kMaximumOfferSize - 1, 'a'))); 274 std::string(password_generation_->kMaximumOfferSize - 1, 'a')));
274 // Cast to WebAutofillClient where textFieldDidChange() is public. 275 // Cast to WebAutofillClient where textFieldDidChange() is public.
275 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 276 AutofillAgent* autofill_agent = (AutofillAgent*)autofill_agent_;
276 first_password_element); 277 static_cast<blink::WebAutofillClient*>(autofill_agent)
278 ->textFieldDidChange(first_password_element);
277 // textFieldDidChange posts a task, so we need to wait until it's been 279 // textFieldDidChange posts a task, so we need to wait until it's been
278 // processed. 280 // processed.
279 base::MessageLoop::current()->RunUntilIdle(); 281 base::MessageLoop::current()->RunUntilIdle();
280 // There should now be a message to show the UI. 282 // There should now be a message to show the UI.
281 ASSERT_EQ(1u, password_generation_->messages().size()); 283 ASSERT_EQ(1u, password_generation_->messages().size());
282 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 284 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
283 password_generation_->messages()[0]->type()); 285 password_generation_->messages()[0]->type());
284 password_generation_->clear_messages(); 286 password_generation_->clear_messages();
285 287
286 // Simulate a user typing a password just over maximum offer size. 288 // Simulate a user typing a password just over maximum offer size.
287 first_password_element.setValue( 289 first_password_element.setValue(
288 base::ASCIIToUTF16( 290 base::ASCIIToUTF16(
289 std::string(password_generation_->kMaximumOfferSize + 1, 'a'))); 291 std::string(password_generation_->kMaximumOfferSize + 1, 'a')));
290 // Cast to WebAutofillClient where textFieldDidChange() is public. 292 // Cast to WebAutofillClient where textFieldDidChange() is public.
291 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 293 static_cast<blink::WebAutofillClient*>(autofill_agent)
292 first_password_element); 294 ->textFieldDidChange(first_password_element);
293 // textFieldDidChange posts a task, so we need to wait until it's been 295 // textFieldDidChange posts a task, so we need to wait until it's been
294 // processed. 296 // processed.
295 base::MessageLoop::current()->RunUntilIdle(); 297 base::MessageLoop::current()->RunUntilIdle();
296 // There should now be a message to hide the UI. 298 // There should now be a message to hide the UI.
297 ASSERT_EQ(1u, password_generation_->messages().size()); 299 ASSERT_EQ(1u, password_generation_->messages().size());
298 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID, 300 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID,
299 password_generation_->messages()[0]->type()); 301 password_generation_->messages()[0]->type());
300 password_generation_->clear_messages(); 302 password_generation_->clear_messages();
301 303
302 // Simulate the user deleting characters. The generation popup should be shown 304 // Simulate the user deleting characters. The generation popup should be shown
303 // again. 305 // again.
304 first_password_element.setValue( 306 first_password_element.setValue(
305 base::ASCIIToUTF16( 307 base::ASCIIToUTF16(
306 std::string(password_generation_->kMaximumOfferSize, 'a'))); 308 std::string(password_generation_->kMaximumOfferSize, 'a')));
307 // Cast to WebAutofillClient where textFieldDidChange() is public. 309 // Cast to WebAutofillClient where textFieldDidChange() is public.
308 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 310 static_cast<blink::WebAutofillClient*>(autofill_agent)
309 first_password_element); 311 ->textFieldDidChange(first_password_element);
310 // textFieldDidChange posts a task, so we need to wait until it's been 312 // textFieldDidChange posts a task, so we need to wait until it's been
311 // processed. 313 // processed.
312 base::MessageLoop::current()->RunUntilIdle(); 314 base::MessageLoop::current()->RunUntilIdle();
313 // There should now be a message to show the UI. 315 // There should now be a message to show the UI.
314 ASSERT_EQ(1u, password_generation_->messages().size()); 316 ASSERT_EQ(1u, password_generation_->messages().size());
315 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 317 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
316 password_generation_->messages()[0]->type()); 318 password_generation_->messages()[0]->type());
317 password_generation_->clear_messages(); 319 password_generation_->clear_messages();
318 320
319 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, 321 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
320 // so no messages are sent. 322 // so no messages are sent.
321 ExecuteJavaScript("document.getElementById('username').focus();"); 323 ExecuteJavaScript("document.getElementById('username').focus();");
322 EXPECT_EQ(0u, password_generation_->messages().size()); 324 EXPECT_EQ(0u, password_generation_->messages().size());
323 password_generation_->clear_messages(); 325 password_generation_->clear_messages();
324 326
325 // Focusing the password field will bring up the generation UI again. 327 // Focusing the password field will bring up the generation UI again.
326 ExecuteJavaScript("document.getElementById('first_password').focus();"); 328 ExecuteJavaScript("document.getElementById('first_password').focus();");
327 EXPECT_EQ(1u, password_generation_->messages().size()); 329 EXPECT_EQ(1u, password_generation_->messages().size());
328 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 330 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
329 password_generation_->messages()[0]->type()); 331 password_generation_->messages()[0]->type());
330 password_generation_->clear_messages(); 332 password_generation_->clear_messages();
331 } 333 }
332 334
333 } // namespace autofill 335 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698