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

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

Issue 1184913002: [Password Manager] Suppress UI when password generation is active (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UMA Created 5 years, 6 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/renderer/autofill/password_generation_test_utils.h" 7 #include "chrome/renderer/autofill/password_generation_test_utils.h"
8 #include "chrome/test/base/chrome_render_view_test.h" 8 #include "chrome/test/base/chrome_render_view_test.h"
9 #include "components/autofill/content/common/autofill_messages.h" 9 #include "components/autofill/content/common/autofill_messages.h"
10 #include "components/autofill/content/renderer/autofill_agent.h" 10 #include "components/autofill/content/renderer/autofill_agent.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const char kNonVisibleFormHTML[] = 83 const char kNonVisibleFormHTML[] =
84 "<head> <style> form {display: none;} </style> </head>" 84 "<head> <style> form {display: none;} </style> </head>"
85 "<body>" 85 "<body>"
86 " <form>" 86 " <form>"
87 " <div>" 87 " <div>"
88 " <input type='password' id='password'/>" 88 " <input type='password' id='password'/>"
89 " </div>" 89 " </div>"
90 " </form>" 90 " </form>"
91 "</body>"; 91 "</body>";
92 92
93 const char kSignupFormHTML[] =
94 "<FORM name='LoginTestForm' action='http://www.bidule.com'>"
95 " <INPUT type='text' id='random_info'/>"
96 " <INPUT type='password' id='new_password'/>"
97 " <INPUT type='password' id='confirm_password'/>"
98 " <INPUT type='submit' value='Login'/>"
99 "</FORM>";
100
93 const char kEmptyWebpage[] = 101 const char kEmptyWebpage[] =
94 "<html>" 102 "<html>"
95 " <head>" 103 " <head>"
96 " </head>" 104 " </head>"
97 " <body>" 105 " <body>"
98 " </body>" 106 " </body>"
99 "</html>"; 107 "</html>";
100 108
101 const char kRedirectionWebpage[] = 109 const char kRedirectionWebpage[] =
102 "<html>" 110 "<html>"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 key.realm = "google.com"; 257 key.realm = "google.com";
250 fill_data_.other_possible_usernames[key].push_back(alternate_username3_); 258 fill_data_.other_possible_usernames[key].push_back(alternate_username3_);
251 259
252 // We need to set the origin so it matches the frame URL and the action so 260 // We need to set the origin so it matches the frame URL and the action so
253 // it matches the form action, otherwise we won't autocomplete. 261 // it matches the form action, otherwise we won't autocomplete.
254 UpdateOriginForHTML(kFormHTML); 262 UpdateOriginForHTML(kFormHTML);
255 fill_data_.action = GURL("http://www.bidule.com"); 263 fill_data_.action = GURL("http://www.bidule.com");
256 264
257 LoadHTML(kFormHTML); 265 LoadHTML(kFormHTML);
258 266
267 // Necessary for SimulateElementClick() to work correctly.
268 GetWebWidget()->resize(blink::WebSize(500, 500));
269 GetWebWidget()->setFocus(true);
270
259 // Now retrieve the input elements so the test can access them. 271 // Now retrieve the input elements so the test can access them.
260 UpdateUsernameAndPasswordElements(); 272 UpdateUsernameAndPasswordElements();
261 } 273 }
262 274
263 void TearDown() override { 275 void TearDown() override {
264 username_element_.reset(); 276 username_element_.reset();
265 password_element_.reset(); 277 password_element_.reset();
266 ChromeRenderViewTest::TearDown(); 278 ChromeRenderViewTest::TearDown();
267 } 279 }
268 280
(...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 password_generation_->OnMessageReceived(msg); 1868 password_generation_->OnMessageReceived(msg);
1857 1869
1858 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1870 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1859 ->WillSendSubmitEvent(username_element_.form()); 1871 ->WillSendSubmitEvent(username_element_.form());
1860 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1872 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1861 ->WillSubmitForm(username_element_.form()); 1873 ->WillSubmitForm(username_element_.form());
1862 1874
1863 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); 1875 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", "");
1864 } 1876 }
1865 1877
1878 // If password generation is enabled for a field, password autofill should not
1879 // show UI.
1880 TEST_F(PasswordAutofillAgentTest, PasswordGenerationSupersedesAutofill) {
1881 LoadHTML(kSignupFormHTML);
1882
1883 // Update password_element_;
1884 WebDocument document = GetMainFrame()->document();
1885 WebElement element =
1886 document.getElementById(WebString::fromUTF8("new_password"));
1887 ASSERT_FALSE(element.isNull());
1888 password_element_ = element.to<blink::WebInputElement>();
1889
1890 // Update fill_data_ for the new form and simulate filling. Pretend as if
1891 // the password manager didn't detect a username field so it will try to
1892 // show UI when the password field is focused.
1893 fill_data_.wait_for_username = true;
1894 fill_data_.username_field = FormFieldData();
1895 fill_data_.password_field.name = base::ASCIIToUTF16("new_password");
1896 UpdateOriginForHTML(kSignupFormHTML);
1897 SimulateOnFillPasswordForm(fill_data_);
1898
1899 // Simulate generation triggering.
1900 SetNotBlacklistedMessage(password_generation_,
1901 kSignupFormHTML);
1902 SetAccountCreationFormsDetectedMessage(password_generation_,
1903 GetMainFrame()->document(),
1904 0);
1905
1906 // Simulate the field being clicked to start typing. This should trigger
1907 // generation but not password autofill.
1908 SetFocused(password_element_);
1909 SimulateElementClick("new_password");
1910 EXPECT_EQ(nullptr,
1911 render_thread_->sink().GetFirstMessageMatching(
1912 AutofillHostMsg_ShowPasswordSuggestions::ID));
1913 ExpectPasswordGenerationAvailable(password_generation_, true);
1914 }
1915
1866 } // namespace autofill 1916 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698