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

Side by Side Diff: chrome/renderer/autofill/password_autofill_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: Incorporated review comments. 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/test/base/chrome_render_view_test.h" 7 #include "chrome/test/base/chrome_render_view_test.h"
8 #include "components/autofill/content/common/autofill_messages.h" 8 #include "components/autofill/content/common/autofill_messages.h"
9 #include "components/autofill/content/renderer/autofill_agent.h" 9 #include "components/autofill/content/renderer/autofill_agent.h"
10 #include "components/autofill/content/renderer/form_autofill_util.h" 10 #include "components/autofill/content/renderer/form_autofill_util.h"
11 #include "components/autofill/content/renderer/password_autofill_agent.h" 11 #include "components/autofill/content/renderer/password_autofill_agent.h"
12 #include "components/autofill/content/renderer/test_autofill_agent.h"
12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 13 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
13 #include "components/autofill/core/common/form_data.h" 14 #include "components/autofill/core/common/form_data.h"
14 #include "components/autofill/core/common/form_field_data.h" 15 #include "components/autofill/core/common/form_field_data.h"
15 #include "components/autofill/core/common/password_autofill_util.h" 16 #include "components/autofill/core/common/password_autofill_util.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/platform/WebVector.h" 19 #include "third_party/WebKit/public/platform/WebVector.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 20 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebElement.h" 21 #include "third_party/WebKit/public/web/WebElement.h"
21 #include "third_party/WebKit/public/web/WebFormElement.h" 22 #include "third_party/WebKit/public/web/WebFormElement.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 WebInputElement& input, 272 WebInputElement& input,
272 bool is_user_input) { 273 bool is_user_input) {
273 input.setValue(WebString::fromUTF8(new_value), is_user_input); 274 input.setValue(WebString::fromUTF8(new_value), is_user_input);
274 // The field must have focus or AutofillAgent will think the 275 // The field must have focus or AutofillAgent will think the
275 // change should be ignored. 276 // change should be ignored.
276 while (!input.focused()) 277 while (!input.focused())
277 input_frame->document().frame()->view()->advanceFocus(false); 278 input_frame->document().frame()->view()->advanceFocus(false);
278 if (move_caret_to_end) 279 if (move_caret_to_end)
279 input.setSelectionRange(new_value.length(), new_value.length()); 280 input.setSelectionRange(new_value.length(), new_value.length());
280 if (is_user_input) 281 if (is_user_input)
281 password_autofill_agent()->FirstUserGestureObserved(); 282 password_autofill_->FirstUserGestureObserved();
282 autofill_agent_->textFieldDidChange(input); 283 autofill_agent_->textFieldDidChange(input);
283 // Processing is delayed because of a Blink bug: 284 // Processing is delayed because of a Blink bug:
284 // https://bugs.webkit.org/show_bug.cgi?id=16976 285 // https://bugs.webkit.org/show_bug.cgi?id=16976
285 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. 286 // See PasswordAutofillAgent::TextDidChangeInTextField() for details.
286 287
287 // Autocomplete will trigger a style recalculation when we put up the next 288 // Autocomplete will trigger a style recalculation when we put up the next
288 // frame, but we don't want to wait that long. Instead, trigger a style 289 // frame, but we don't want to wait that long. Instead, trigger a style
289 // recalcuation manually after TextFieldDidChangeImpl runs. 290 // recalcuation manually after TextFieldDidChangeImpl runs.
290 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 291 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
291 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); 292 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this)));
292 293
293 base::MessageLoop::current()->RunUntilIdle(); 294 base::MessageLoop::current()->RunUntilIdle();
294 } 295 }
295 296
296 void SimulateSuggestionChoice(WebInputElement& username_input) { 297 void SimulateSuggestionChoice(WebInputElement& username_input) {
297 blink::WebString blink_username = 298 blink::WebString blink_username =
298 blink::WebString::fromUTF8(kAliceUsername); 299 blink::WebString::fromUTF8(kAliceUsername);
299 blink::WebString blink_password = 300 blink::WebString blink_password =
300 blink::WebString::fromUTF8(kAlicePassword); 301 blink::WebString::fromUTF8(kAlicePassword);
301 302
302 // This call is necessary to setup the autofill agent appropriate for the 303 // This call is necessary to setup the autofill agent appropriate for the
303 // user selection; simulates the menu actually popping up. 304 // user selection; simulates the menu actually popping up.
304 render_thread_->sink().ClearMessages(); 305 render_thread_->sink().ClearMessages();
305 autofill_agent_->FormControlElementClicked(username_input, false); 306 autofill_agent_->FormControlElementClicked(username_input, false);
Ilya Sherman 2014/09/19 17:34:18 Hmm, are you sure that this code is no longer need
Ilya Sherman 2014/09/19 19:08:59 Indeed, it looks like test fail without this code.
Pritam Nikam 2014/09/20 05:09:54 Done. Sorry! Looks like I missed executing ClickA
306 307
307 autofill_agent_->OnFillPasswordSuggestion(blink_username, blink_password); 308 autofill_agent_->OnFillPasswordSuggestion(blink_username, blink_password);
308 } 309 }
309 310
310 void LayoutMainFrame() { 311 void LayoutMainFrame() {
311 GetMainFrame()->view()->layout(); 312 GetMainFrame()->view()->layout();
312 } 313 }
313 314
314 void SimulateUsernameChange(const std::string& username, 315 void SimulateUsernameChange(const std::string& username,
315 bool move_caret_to_end, 316 bool move_caret_to_end,
(...skipping 22 matching lines...) Expand all
338 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing 339 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing
339 // is filled). 340 // is filled).
340 // 341 //
341 // These tests only make sense in the context of not ignoring 342 // These tests only make sense in the context of not ignoring
342 // autocomplete='off', so only test them if the disable autocomplete='off' 343 // autocomplete='off', so only test them if the disable autocomplete='off'
343 // flag is not enabled. 344 // flag is not enabled.
344 // TODO(jww): Remove this function and callers once autocomplete='off' is 345 // TODO(jww): Remove this function and callers once autocomplete='off' is
345 // permanently ignored. 346 // permanently ignored.
346 if (!ShouldIgnoreAutocompleteOffForPasswordFields()) { 347 if (!ShouldIgnoreAutocompleteOffForPasswordFields()) {
347 EXPECT_TRUE( 348 EXPECT_TRUE(
348 password_autofill_agent()->ShowSuggestions(username_element_, false)); 349 password_autofill_->ShowSuggestions(username_element_, false));
349 350
350 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 351 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
351 AutofillHostMsg_ShowPasswordSuggestions::ID)); 352 AutofillHostMsg_ShowPasswordSuggestions::ID));
352 } 353 }
353 } 354 }
354 355
355 void SimulateKeyDownEvent(const WebInputElement& element, 356 void SimulateKeyDownEvent(const WebInputElement& element,
356 ui::KeyboardCode key_code) { 357 ui::KeyboardCode key_code) {
357 blink::WebKeyboardEvent key_event; 358 blink::WebKeyboardEvent key_event;
358 key_event.windowsKeyCode = key_code; 359 key_event.windowsKeyCode = key_code;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 EXPECT_TRUE(it != usernames.end()); 451 EXPECT_TRUE(it != usernames.end());
451 if (it != usernames.end()) 452 if (it != usernames.end())
452 usernames.erase(it); 453 usernames.erase(it);
453 } 454 }
454 455
455 EXPECT_TRUE(usernames.empty()); 456 EXPECT_TRUE(usernames.empty());
456 457
457 render_thread_->sink().ClearMessages(); 458 render_thread_->sink().ClearMessages();
458 } 459 }
459 460
460 PasswordAutofillAgent* password_autofill_agent() {
461 return autofill_agent_->password_autofill_agent_;
462 }
463
464 void ExpectFormSubmittedWithPasswords(const std::string& password_value, 461 void ExpectFormSubmittedWithPasswords(const std::string& password_value,
465 const std::string& new_password_value) { 462 const std::string& new_password_value) {
466 const IPC::Message* message = 463 const IPC::Message* message =
467 render_thread_->sink().GetFirstMessageMatching( 464 render_thread_->sink().GetFirstMessageMatching(
468 AutofillHostMsg_PasswordFormSubmitted::ID); 465 AutofillHostMsg_PasswordFormSubmitted::ID);
469 ASSERT_TRUE(message); 466 ASSERT_TRUE(message);
470 Tuple1<autofill::PasswordForm> args; 467 Tuple1<autofill::PasswordForm> args;
471 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); 468 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args);
472 EXPECT_EQ(ASCIIToUTF16(password_value), args.a.password_value); 469 EXPECT_EQ(ASCIIToUTF16(password_value), args.a.password_value);
473 EXPECT_EQ(ASCIIToUTF16(new_password_value), args.a.new_password_value); 470 EXPECT_EQ(ASCIIToUTF16(new_password_value), args.a.new_password_value);
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 TEST_F(PasswordAutofillAgentTest, 1498 TEST_F(PasswordAutofillAgentTest,
1502 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { 1499 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) {
1503 SimulateInputChangeForElement( 1500 SimulateInputChangeForElement(
1504 "temp", true, GetMainFrame(), username_element_, true); 1501 "temp", true, GetMainFrame(), username_element_, true);
1505 SimulateInputChangeForElement( 1502 SimulateInputChangeForElement(
1506 "random", true, GetMainFrame(), password_element_, true); 1503 "random", true, GetMainFrame(), password_element_, true);
1507 1504
1508 // Simulate that the password value was cleared by the site's JavaScript 1505 // Simulate that the password value was cleared by the site's JavaScript
1509 // before submit. 1506 // before submit.
1510 password_element_.setValue(WebString()); 1507 password_element_.setValue(WebString());
1511 static_cast<content::RenderViewObserver*>(password_autofill_agent()) 1508 static_cast<content::RenderViewObserver*>(password_autofill_)
1512 ->WillSubmitForm(GetMainFrame(), username_element_.form()); 1509 ->WillSubmitForm(GetMainFrame(), username_element_.form());
1513 1510
1514 // Observe that the PasswordAutofillAgent still remembered the last non-empty 1511 // Observe that the PasswordAutofillAgent still remembered the last non-empty
1515 // password and sent that to the browser. 1512 // password and sent that to the browser.
1516 ExpectFormSubmittedWithPasswords("random", ""); 1513 ExpectFormSubmittedWithPasswords("random", "");
1517 } 1514 }
1518 1515
1519 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time 1516 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time
1520 // it's the user who clears the password. This test checks that in that case, 1517 // it's the user who clears the password. This test checks that in that case,
1521 // the last non-empty password is not remembered. 1518 // the last non-empty password is not remembered.
1522 TEST_F(PasswordAutofillAgentTest, 1519 TEST_F(PasswordAutofillAgentTest,
1523 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { 1520 RememberLastNonEmptyPasswordOnSubmit_UserCleared) {
1524 SimulateInputChangeForElement( 1521 SimulateInputChangeForElement(
1525 "temp", true, GetMainFrame(), username_element_, true); 1522 "temp", true, GetMainFrame(), username_element_, true);
1526 SimulateInputChangeForElement( 1523 SimulateInputChangeForElement(
1527 "random", true, GetMainFrame(), password_element_, true); 1524 "random", true, GetMainFrame(), password_element_, true);
1528 1525
1529 // Simulate that the user actually cleared the password again. 1526 // Simulate that the user actually cleared the password again.
1530 SimulateInputChangeForElement( 1527 SimulateInputChangeForElement(
1531 "", true, GetMainFrame(), password_element_, true); 1528 "", true, GetMainFrame(), password_element_, true);
1532 static_cast<content::RenderViewObserver*>(password_autofill_agent()) 1529 static_cast<content::RenderViewObserver*>(password_autofill_)
1533 ->WillSubmitForm(GetMainFrame(), username_element_.form()); 1530 ->WillSubmitForm(GetMainFrame(), username_element_.form());
1534 1531
1535 // Observe that the PasswordAutofillAgent respects the user having cleared the 1532 // Observe that the PasswordAutofillAgent respects the user having cleared the
1536 // password. 1533 // password.
1537 ExpectFormSubmittedWithPasswords("", ""); 1534 ExpectFormSubmittedWithPasswords("", "");
1538 } 1535 }
1539 1536
1540 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the 1537 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the
1541 // new password instead of the current password. 1538 // new password instead of the current password.
1542 TEST_F(PasswordAutofillAgentTest, 1539 TEST_F(PasswordAutofillAgentTest,
1543 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { 1540 RememberLastNonEmptyPasswordOnSubmit_NewPassword) {
1544 const char kNewPasswordFormHTML[] = 1541 const char kNewPasswordFormHTML[] =
1545 "<FORM name='LoginTestForm'>" 1542 "<FORM name='LoginTestForm'>"
1546 " <INPUT type='text' id='username' autocomplete='username'/>" 1543 " <INPUT type='text' id='username' autocomplete='username'/>"
1547 " <INPUT type='password' id='password' autocomplete='new-password'/>" 1544 " <INPUT type='password' id='password' autocomplete='new-password'/>"
1548 " <INPUT type='submit' value='Login'/>" 1545 " <INPUT type='submit' value='Login'/>"
1549 "</FORM>"; 1546 "</FORM>";
1550 LoadHTML(kNewPasswordFormHTML); 1547 LoadHTML(kNewPasswordFormHTML);
1551 UpdateUsernameAndPasswordElements(); 1548 UpdateUsernameAndPasswordElements();
1552 1549
1553 SimulateInputChangeForElement( 1550 SimulateInputChangeForElement(
1554 "temp", true, GetMainFrame(), username_element_, true); 1551 "temp", true, GetMainFrame(), username_element_, true);
1555 SimulateInputChangeForElement( 1552 SimulateInputChangeForElement(
1556 "random", true, GetMainFrame(), password_element_, true); 1553 "random", true, GetMainFrame(), password_element_, true);
1557 1554
1558 // Simulate that the password value was cleared by the site's JavaScript 1555 // Simulate that the password value was cleared by the site's JavaScript
1559 // before submit. 1556 // before submit.
1560 password_element_.setValue(WebString()); 1557 password_element_.setValue(WebString());
1561 static_cast<content::RenderViewObserver*>(password_autofill_agent()) 1558 static_cast<content::RenderViewObserver*>(password_autofill_)
1562 ->WillSubmitForm(GetMainFrame(), username_element_.form()); 1559 ->WillSubmitForm(GetMainFrame(), username_element_.form());
1563 1560
1564 // Observe that the PasswordAutofillAgent still remembered the last non-empty 1561 // Observe that the PasswordAutofillAgent still remembered the last non-empty
1565 // password and sent that to the browser. 1562 // password and sent that to the browser.
1566 ExpectFormSubmittedWithPasswords("", "random"); 1563 ExpectFormSubmittedWithPasswords("", "random");
1567 } 1564 }
1568 1565
1569 // The user first accepts a suggestion, but then overwrites the password. This 1566 // The user first accepts a suggestion, but then overwrites the password. This
1570 // test checks that the overwritten password is not reverted back if the user 1567 // test checks that the overwritten password is not reverted back if the user
1571 // triggers autofill through focusing (but not changing) the username again. 1568 // triggers autofill through focusing (but not changing) the username again.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 password_element_, 1615 password_element_,
1619 /*is_user_input=*/true); 1616 /*is_user_input=*/true);
1620 1617
1621 // Simulate the user typing a stored username. 1618 // Simulate the user typing a stored username.
1622 SimulateUsernameChange(kAliceUsername, true); 1619 SimulateUsernameChange(kAliceUsername, true);
1623 // The autofileld password should replace the typed one. 1620 // The autofileld password should replace the typed one.
1624 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1621 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1625 } 1622 }
1626 1623
1627 } // namespace autofill 1624 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698