Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "components/autofill/content/renderer/form_autofill_util.h" | 11 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 12 #include "components/autofill/content/renderer/password_autofill_agent.h" | 12 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 13 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 13 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
| 14 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 14 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
| 15 #include "components/autofill/core/common/autofill_constants.h" | 15 #include "components/autofill/core/common/autofill_constants.h" |
| 16 #include "components/autofill/core/common/autofill_switches.h" | 16 #include "components/autofill/core/common/autofill_switches.h" |
| 17 #include "components/autofill/core/common/form_data.h" | 17 #include "components/autofill/core/common/form_data.h" |
| 18 #include "components/autofill/core/common/form_field_data.h" | 18 #include "components/autofill/core/common/form_field_data.h" |
| 19 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 19 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
| 20 #include "content/public/renderer/render_frame.h" | 20 #include "content/public/renderer/render_frame.h" |
| 21 #include "content/public/renderer/render_view.h" | |
|
please use gerrit instead
2015/06/16 00:53:23
Is this include necessary?
Garrett Casto
2015/06/16 06:15:04
Leftover from debugging, removed.
| |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/WebKit/public/platform/WebString.h" | 23 #include "third_party/WebKit/public/platform/WebString.h" |
| 23 #include "third_party/WebKit/public/platform/WebVector.h" | 24 #include "third_party/WebKit/public/platform/WebVector.h" |
| 24 #include "third_party/WebKit/public/web/WebDocument.h" | 25 #include "third_party/WebKit/public/web/WebDocument.h" |
| 25 #include "third_party/WebKit/public/web/WebElement.h" | 26 #include "third_party/WebKit/public/web/WebElement.h" |
| 26 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 27 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 27 #include "third_party/WebKit/public/web/WebFormElement.h" | 28 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 28 #include "third_party/WebKit/public/web/WebInputElement.h" | 29 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 30 #include "third_party/WebKit/public/web/WebNode.h" | 31 #include "third_party/WebKit/public/web/WebNode.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 const char kNonVisibleFormHTML[] = | 84 const char kNonVisibleFormHTML[] = |
| 84 "<head> <style> form {display: none;} </style> </head>" | 85 "<head> <style> form {display: none;} </style> </head>" |
| 85 "<body>" | 86 "<body>" |
| 86 " <form>" | 87 " <form>" |
| 87 " <div>" | 88 " <div>" |
| 88 " <input type='password' id='password'/>" | 89 " <input type='password' id='password'/>" |
| 89 " </div>" | 90 " </div>" |
| 90 " </form>" | 91 " </form>" |
| 91 "</body>"; | 92 "</body>"; |
| 92 | 93 |
| 94 const char kChangePasswordFormHTML[] = | |
| 95 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" | |
| 96 " <INPUT type='password' id='old_password'/>" | |
| 97 " <INPUT type='password' id='new_password'/>" | |
| 98 " <INPUT type='password' id='confirm_password'/>" | |
| 99 " <INPUT type='submit' value='Login'/>" | |
| 100 "</FORM>"; | |
| 101 | |
| 93 const char kEmptyWebpage[] = | 102 const char kEmptyWebpage[] = |
| 94 "<html>" | 103 "<html>" |
| 95 " <head>" | 104 " <head>" |
| 96 " </head>" | 105 " </head>" |
| 97 " <body>" | 106 " <body>" |
| 98 " </body>" | 107 " </body>" |
| 99 "</html>"; | 108 "</html>"; |
| 100 | 109 |
| 101 const char kRedirectionWebpage[] = | 110 const char kRedirectionWebpage[] = |
| 102 "<html>" | 111 "<html>" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 key.realm = "google.com"; | 258 key.realm = "google.com"; |
| 250 fill_data_.other_possible_usernames[key].push_back(alternate_username3_); | 259 fill_data_.other_possible_usernames[key].push_back(alternate_username3_); |
| 251 | 260 |
| 252 // We need to set the origin so it matches the frame URL and the action so | 261 // 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. | 262 // it matches the form action, otherwise we won't autocomplete. |
| 254 UpdateOriginForHTML(kFormHTML); | 263 UpdateOriginForHTML(kFormHTML); |
| 255 fill_data_.action = GURL("http://www.bidule.com"); | 264 fill_data_.action = GURL("http://www.bidule.com"); |
| 256 | 265 |
| 257 LoadHTML(kFormHTML); | 266 LoadHTML(kFormHTML); |
| 258 | 267 |
| 268 // Necessary for SimulateElementClick() to work correctly. | |
| 269 GetWebWidget()->resize(blink::WebSize(500, 500)); | |
| 270 GetWebWidget()->setFocus(true); | |
| 271 | |
| 259 // Now retrieve the input elements so the test can access them. | 272 // Now retrieve the input elements so the test can access them. |
| 260 UpdateUsernameAndPasswordElements(); | 273 UpdateUsernameAndPasswordElements(); |
| 261 } | 274 } |
| 262 | 275 |
| 263 void TearDown() override { | 276 void TearDown() override { |
| 264 username_element_.reset(); | 277 username_element_.reset(); |
| 265 password_element_.reset(); | 278 password_element_.reset(); |
| 266 ChromeRenderViewTest::TearDown(); | 279 ChromeRenderViewTest::TearDown(); |
| 267 } | 280 } |
| 268 | 281 |
| (...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1856 password_generation_->OnMessageReceived(msg); | 1869 password_generation_->OnMessageReceived(msg); |
| 1857 | 1870 |
| 1858 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1871 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1859 ->WillSendSubmitEvent(username_element_.form()); | 1872 ->WillSendSubmitEvent(username_element_.form()); |
| 1860 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1873 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1861 ->WillSubmitForm(username_element_.form()); | 1874 ->WillSubmitForm(username_element_.form()); |
| 1862 | 1875 |
| 1863 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); | 1876 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); |
| 1864 } | 1877 } |
| 1865 | 1878 |
| 1879 // If password generation is enabled for a field, password autofill should not | |
| 1880 // show UI. | |
| 1881 TEST_F(PasswordAutofillAgentTest, PasswordGenerationSupersedesAutofill) { | |
| 1882 LoadHTML(kChangePasswordFormHTML); | |
| 1883 | |
| 1884 // Update password_element_; | |
| 1885 WebDocument document = GetMainFrame()->document(); | |
| 1886 WebElement element = | |
| 1887 document.getElementById(WebString::fromUTF8("old_password")); | |
| 1888 ASSERT_FALSE(element.isNull()); | |
| 1889 password_element_ = element.to<blink::WebInputElement>(); | |
| 1890 | |
| 1891 // Update fill_data_ for the new form and simulate filling. | |
| 1892 fill_data_.wait_for_username = true; | |
| 1893 fill_data_.username_field = FormFieldData(); | |
| 1894 fill_data_.password_field.name = base::ASCIIToUTF16("old_password"); | |
| 1895 UpdateOriginForHTML(kChangePasswordFormHTML); | |
| 1896 SimulateOnFillPasswordForm(fill_data_); | |
| 1897 | |
| 1898 // Simulate generation triggering. | |
| 1899 SetNotBlacklistedMessage(password_generation_, | |
| 1900 kChangePasswordFormHTML); | |
| 1901 SetAccountCreationFormsDetectedMessage(password_generation_, | |
| 1902 GetMainFrame()->document(), | |
| 1903 0); | |
| 1904 | |
| 1905 // Simulate the field being clicked to start typing. This should trigger | |
| 1906 // generation but not password autofill. | |
| 1907 SetFocused(password_element_); | |
| 1908 SimulateElementClick("old_password"); | |
|
please use gerrit instead
2015/06/16 00:53:23
Shouldn't password generation trigger on "new_pass
Garrett Casto
2015/06/16 06:15:04
In general yes. The test for this is slightly cont
| |
| 1909 const IPC::Message* message = | |
| 1910 render_thread_->sink().GetFirstMessageMatching( | |
| 1911 AutofillHostMsg_ShowPasswordSuggestions::ID); | |
| 1912 EXPECT_FALSE(message); | |
|
please use gerrit instead
2015/06/16 00:53:23
EXPECT_EQ(nullptr, render_thread_->sink().GetFirst
Garrett Casto
2015/06/16 06:15:04
Done.
| |
| 1913 ExpectPasswordGenerationAvailable(password_generation_, | |
| 1914 true); | |
|
Ilya Sherman
2015/06/16 02:24:09
nit: No need to wrap here. (Might want to run "gi
Garrett Casto
2015/06/16 06:15:04
Done.
| |
| 1915 } | |
| 1916 | |
| 1866 } // namespace autofill | 1917 } // namespace autofill |
| OLD | NEW |