Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | 5 #include <string> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 315 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 316 observer.Wait(); | 316 observer.Wait(); |
| 317 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 317 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, Redirects) { | 320 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, Redirects) { |
| 321 NavigateToFile("/password/password_form.html"); | 321 NavigateToFile("/password/password_form.html"); |
| 322 | 322 |
| 323 // Fill a form and submit through a <input type="submit"> button. The form | 323 // Fill a form and submit through a <input type="submit"> button. The form |
| 324 // points to a redirection page. | 324 // points to a redirection page. |
| 325 NavigationObserver observer(WebContents()); | 325 NavigationObserver observer1(WebContents()); |
| 326 std::unique_ptr<BubbleObserver> prompt_observer( | |
| 327 new BubbleObserver(WebContents())); | |
| 328 std::string fill_and_submit = | 326 std::string fill_and_submit = |
| 329 "document.getElementById('username_redirect').value = 'temp';" | 327 "document.getElementById('username_redirect').value = 'temp';" |
| 330 "document.getElementById('password_redirect').value = 'random';" | 328 "document.getElementById('password_redirect').value = 'random';" |
| 331 "document.getElementById('submit_redirect').click()"; | 329 "document.getElementById('submit_redirect').click()"; |
| 332 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 330 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 333 observer.Wait(); | 331 observer1.Wait(); |
| 334 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); | 332 BubbleObserver prompt_observer(WebContents()); |
|
vabr (Chromium)
2017/03/21 18:46:52
optional nit: This could be as well called |bubble
vasilii
2017/03/22 09:28:58
Done.
| |
| 333 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt()); | |
| 335 | 334 |
| 336 // The redirection page now redirects via Javascript. We check that the | 335 // The redirection page now redirects via Javascript. We check that the |
| 337 // infobar stays. | 336 // bubble stays. |
| 337 NavigationObserver observer2(WebContents()); | |
| 338 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), | 338 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
| 339 "window.location.href = 'done.html';")); | 339 "window.location.href = 'done.html';")); |
| 340 observer.Wait(); | 340 observer2.Wait(); |
| 341 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); | 341 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 344 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 345 PromptForSubmitUsingJavaScript) { | 345 PromptForSubmitUsingJavaScript) { |
| 346 NavigateToFile("/password/password_form.html"); | 346 NavigateToFile("/password/password_form.html"); |
| 347 | 347 |
| 348 // Fill a form and submit using <button> that calls submit() on the form. | 348 // Fill a form and submit using <button> that calls submit() on the form. |
| 349 // This should work regardless of the type of element, as long as submit() is | 349 // This should work regardless of the type of element, as long as submit() is |
| 350 // called. | 350 // called. |
| 351 NavigationObserver observer(WebContents()); | 351 NavigationObserver observer(WebContents()); |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1278 | 1278 |
| 1279 LoginPromptBrowserTestObserver login_observer; | 1279 LoginPromptBrowserTestObserver login_observer; |
| 1280 // We need to register to all sources, because the navigation observer we are | 1280 // We need to register to all sources, because the navigation observer we are |
| 1281 // interested in is for a new tab to be opened, and thus does not exist yet. | 1281 // interested in is for a new tab to be opened, and thus does not exist yet. |
| 1282 login_observer.Register(content::NotificationService::AllSources()); | 1282 login_observer.Register(content::NotificationService::AllSources()); |
| 1283 | 1283 |
| 1284 scoped_refptr<password_manager::TestPasswordStore> password_store = | 1284 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 1285 static_cast<password_manager::TestPasswordStore*>( | 1285 static_cast<password_manager::TestPasswordStore*>( |
| 1286 PasswordStoreFactory::GetForProfile( | 1286 PasswordStoreFactory::GetForProfile( |
| 1287 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); | 1287 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); |
| 1288 EXPECT_TRUE(password_store->IsEmpty()); | 1288 ASSERT_TRUE(password_store->IsEmpty()); |
| 1289 | 1289 |
| 1290 // Navigate to a page requiring HTTP auth. Wait for the tab to get the correct | 1290 // Navigate to a page requiring HTTP auth. Wait for the tab to get the correct |
| 1291 // WebContents, but don't wait for navigation, which only finishes after | 1291 // WebContents, but don't wait for navigation, which only finishes after |
| 1292 // authentication. | 1292 // authentication. |
| 1293 ui_test_utils::NavigateToURLWithDisposition( | 1293 ui_test_utils::NavigateToURLWithDisposition( |
| 1294 browser(), http_test_server.GetURL("/basic_auth"), | 1294 browser(), http_test_server.GetURL("/basic_auth"), |
| 1295 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 1295 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 1296 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1296 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1297 | 1297 |
| 1298 content::NavigationController* nav_controller = | 1298 content::WebContents* tab = |
| 1299 &WebContents()->GetController(); | 1299 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1300 NavigationObserver nav_observer(WebContents()); | 1300 content::NavigationController* nav_controller = &tab->GetController(); |
| 1301 std::unique_ptr<BubbleObserver> prompt_observer( | 1301 NavigationObserver nav_observer(tab); |
| 1302 new BubbleObserver(WebContents())); | |
| 1303 WindowedAuthNeededObserver auth_needed_observer(nav_controller); | 1302 WindowedAuthNeededObserver auth_needed_observer(nav_controller); |
| 1304 auth_needed_observer.Wait(); | 1303 auth_needed_observer.Wait(); |
| 1305 | 1304 |
| 1306 WindowedAuthSuppliedObserver auth_supplied_observer(nav_controller); | 1305 WindowedAuthSuppliedObserver auth_supplied_observer(nav_controller); |
| 1307 // Offer valid credentials on the auth challenge. | 1306 // Offer valid credentials on the auth challenge. |
| 1308 ASSERT_EQ(1u, login_observer.handlers().size()); | 1307 ASSERT_EQ(1u, login_observer.handlers().size()); |
| 1309 LoginHandler* handler = *login_observer.handlers().begin(); | 1308 LoginHandler* handler = *login_observer.handlers().begin(); |
| 1310 ASSERT_TRUE(handler); | 1309 ASSERT_TRUE(handler); |
| 1311 // Any username/password will work. | 1310 // Any username/password will work. |
| 1312 handler->SetAuth(base::UTF8ToUTF16("user"), base::UTF8ToUTF16("pwd")); | 1311 handler->SetAuth(base::UTF8ToUTF16("user"), base::UTF8ToUTF16("pwd")); |
| 1313 auth_supplied_observer.Wait(); | 1312 auth_supplied_observer.Wait(); |
| 1314 | 1313 |
| 1315 // The password manager should be working correctly. | 1314 // The password manager should be working correctly. |
| 1316 nav_observer.Wait(); | 1315 nav_observer.Wait(); |
| 1317 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); | 1316 WaitForPasswordStore(); |
| 1318 prompt_observer->AcceptSavePrompt(); | 1317 BubbleObserver prompt_observer(tab); |
| 1318 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt()); | |
| 1319 prompt_observer.AcceptSavePrompt(); | |
| 1319 | 1320 |
| 1320 // Spin the message loop to make sure the password store had a chance to save | 1321 // Spin the message loop to make sure the password store had a chance to save |
| 1321 // the password. | 1322 // the password. |
| 1322 base::RunLoop run_loop; | 1323 WaitForPasswordStore(); |
| 1323 run_loop.RunUntilIdle(); | |
| 1324 EXPECT_FALSE(password_store->IsEmpty()); | 1324 EXPECT_FALSE(password_store->IsEmpty()); |
| 1325 } | 1325 } |
| 1326 | 1326 |
| 1327 // In some situations, multiple PasswordFormManager instances from | 1327 // In some situations, multiple PasswordFormManager instances from |
| 1328 // PasswordManager::pending_login_managers_ would match (via DoesManage) a form | 1328 // PasswordManager::pending_login_managers_ would match (via DoesManage) a form |
| 1329 // to be provisionally saved. One of them might be a complete match, the other | 1329 // to be provisionally saved. One of them might be a complete match, the other |
| 1330 // all-but-action match. Normally, the former should be preferred, but if the | 1330 // all-but-action match. Normally, the former should be preferred, but if the |
| 1331 // former has not finished matching, and the latter has, the latter should be | 1331 // former has not finished matching, and the latter has, the latter should be |
| 1332 // used (otherwise we'd give up even though we could have saved the password). | 1332 // used (otherwise we'd give up even though we could have saved the password). |
| 1333 // | 1333 // |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1770 "document.getElementById('pa_username_field').value = 'temp';" | 1770 "document.getElementById('pa_username_field').value = 'temp';" |
| 1771 "document.getElementById('pa_password_field').value = 'random';" | 1771 "document.getElementById('pa_password_field').value = 'random';" |
| 1772 "document.getElementById('pa_submit_button').click()"; | 1772 "document.getElementById('pa_submit_button').click()"; |
| 1773 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1773 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1774 observer.Wait(); | 1774 observer.Wait(); |
| 1775 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 1775 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 1778 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1779 InFrameNavigationDoesNotClearPopupState) { | 1779 InFrameNavigationDoesNotClearPopupState) { |
| 1780 scoped_refptr<password_manager::TestPasswordStore> password_store = | |
| 1781 static_cast<password_manager::TestPasswordStore*>( | |
| 1782 PasswordStoreFactory::GetForProfile( | |
| 1783 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
| 1784 .get()); | |
| 1785 autofill::PasswordForm signin_form; | |
| 1786 signin_form.signon_realm = embedded_test_server()->base_url().spec(); | |
| 1787 signin_form.username_value = base::ASCIIToUTF16("temp"); | |
| 1788 signin_form.password_value = base::ASCIIToUTF16("random123"); | |
| 1789 password_store->AddLogin(signin_form); | |
| 1790 | |
| 1791 NavigateToFile("/password/password_form.html"); | |
| 1792 | |
| 1780 // Mock out the AutofillClient so we know how long to wait. Unfortunately | 1793 // Mock out the AutofillClient so we know how long to wait. Unfortunately |
| 1781 // there isn't otherwise a good event to wait on to verify that the popup | 1794 // there isn't otherwise a good event to wait on to verify that the popup |
| 1782 // would have been shown. | 1795 // would have been shown. |
| 1783 password_manager::ContentPasswordManagerDriverFactory* driver_factory = | 1796 password_manager::ContentPasswordManagerDriverFactory* driver_factory = |
| 1784 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( | 1797 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( |
| 1785 WebContents()); | 1798 WebContents()); |
| 1786 ObservingAutofillClient::CreateForWebContents(WebContents()); | 1799 ObservingAutofillClient::CreateForWebContents(WebContents()); |
| 1787 ObservingAutofillClient* observing_autofill_client = | 1800 ObservingAutofillClient* observing_autofill_client = |
| 1788 ObservingAutofillClient::FromWebContents(WebContents()); | 1801 ObservingAutofillClient::FromWebContents(WebContents()); |
| 1789 password_manager::ContentPasswordManagerDriver* driver = | 1802 password_manager::ContentPasswordManagerDriver* driver = |
| 1790 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); | 1803 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); |
| 1791 DCHECK(driver); | 1804 DCHECK(driver); |
| 1792 driver->GetPasswordAutofillManager()->set_autofill_client( | 1805 driver->GetPasswordAutofillManager()->set_autofill_client( |
| 1793 observing_autofill_client); | 1806 observing_autofill_client); |
| 1794 | 1807 |
| 1795 NavigateToFile("/password/password_form.html"); | |
| 1796 | |
| 1797 NavigationObserver form_submit_observer(WebContents()); | |
| 1798 std::unique_ptr<BubbleObserver> prompt_observer( | |
| 1799 new BubbleObserver(WebContents())); | |
| 1800 std::string fill = | |
| 1801 "document.getElementById('username_field').value = 'temp';" | |
| 1802 "document.getElementById('password_field').value = 'random123';" | |
| 1803 "document.getElementById('input_submit_button').click();"; | |
| 1804 | |
| 1805 // Save credentials for the site. | |
| 1806 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); | |
| 1807 form_submit_observer.Wait(); | |
| 1808 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); | |
| 1809 prompt_observer->AcceptSavePrompt(); | |
| 1810 | |
| 1811 NavigateToFile("/password/password_form.html"); | |
| 1812 ASSERT_TRUE(content::ExecuteScript( | 1808 ASSERT_TRUE(content::ExecuteScript( |
| 1813 RenderViewHost(), | 1809 RenderViewHost(), |
| 1814 "var usernameRect = document.getElementById('username_field')" | 1810 "var usernameRect = document.getElementById('username_field')" |
| 1815 ".getBoundingClientRect();")); | 1811 ".getBoundingClientRect();")); |
| 1816 | 1812 |
| 1817 // Trigger in page navigation. | 1813 // Trigger in page navigation. |
| 1818 std::string in_page_navigate = "location.hash = '#blah';"; | 1814 std::string in_page_navigate = "location.hash = '#blah';"; |
| 1819 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), in_page_navigate)); | 1815 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), in_page_navigate)); |
| 1820 | 1816 |
| 1821 // Click on the username field to display the popup. | 1817 // Click on the username field to display the popup. |
| 1822 int top; | 1818 int top; |
| 1823 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 1819 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 1824 RenderViewHost(), | 1820 RenderViewHost(), |
| 1825 "window.domAutomationController.send(usernameRect.top);", | 1821 "window.domAutomationController.send(usernameRect.top);", |
| 1826 &top)); | 1822 &top)); |
| 1827 int left; | 1823 int left; |
| 1828 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 1824 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 1829 RenderViewHost(), | 1825 RenderViewHost(), |
| 1830 "window.domAutomationController.send(usernameRect.left);", | 1826 "window.domAutomationController.send(usernameRect.left);", |
| 1831 &left)); | 1827 &left)); |
| 1832 | 1828 |
| 1833 content::SimulateMouseClickAt( | 1829 content::SimulateMouseClickAt(WebContents(), 0, |
| 1834 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(left + 1, | 1830 blink::WebMouseEvent::Button::Left, |
| 1835 top + 1)); | 1831 gfx::Point(left + 1, top + 1)); |
| 1836 // Make sure the popup would be shown. | 1832 // Make sure the popup would be shown. |
| 1837 observing_autofill_client->Wait(); | 1833 observing_autofill_client->Wait(); |
| 1838 } | 1834 } |
| 1839 | 1835 |
| 1840 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 1836 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1841 ChangePwdFormBubbleShown) { | 1837 ChangePwdFormBubbleShown) { |
| 1842 NavigateToFile("/password/password_form.html"); | 1838 NavigateToFile("/password/password_form.html"); |
| 1843 | 1839 |
| 1844 NavigationObserver observer(WebContents()); | 1840 NavigationObserver observer(WebContents()); |
| 1845 std::unique_ptr<BubbleObserver> prompt_observer( | 1841 std::unique_ptr<BubbleObserver> prompt_observer( |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2908 browser(), GURL("chrome://password-manager-internals"), | 2904 browser(), GURL("chrome://password-manager-internals"), |
| 2909 WindowOpenDisposition::CURRENT_TAB, | 2905 WindowOpenDisposition::CURRENT_TAB, |
| 2910 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 2906 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 2911 content::WebContents* internals_web_contents = WebContents(); | 2907 content::WebContents* internals_web_contents = WebContents(); |
| 2912 | 2908 |
| 2913 // Open some page with a HTML form. | 2909 // Open some page with a HTML form. |
| 2914 ui_test_utils::NavigateToURLWithDisposition( | 2910 ui_test_utils::NavigateToURLWithDisposition( |
| 2915 browser(), embedded_test_server()->GetURL("/password/password_form.html"), | 2911 browser(), embedded_test_server()->GetURL("/password/password_form.html"), |
| 2916 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 2912 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 2917 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 2913 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 2918 content::WebContents* forms_web_contents = WebContents(); | 2914 content::WebContents* forms_web_contents = |
| 2915 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2919 | 2916 |
| 2920 // The renderer queries the availability of logging on start-up. However, it | 2917 // The renderer queries the availability of logging on start-up. However, it |
| 2921 // can take too long to propagate that message from the browser back to the | 2918 // can take too long to propagate that message from the browser back to the |
| 2922 // renderer. The renderer might have attempted logging in the meantime. | 2919 // renderer. The renderer might have attempted logging in the meantime. |
| 2923 // Therefore the page with the form is reloaded to increase the likelihood | 2920 // Therefore the page with the form is reloaded to increase the likelihood |
| 2924 // that the availability query was answered before the logging during page | 2921 // that the availability query was answered before the logging during page |
| 2925 // load. | 2922 // load. |
| 2926 NavigationObserver observer(forms_web_contents); | 2923 NavigationObserver observer(forms_web_contents); |
| 2927 forms_web_contents->ReloadFocusedFrame(false); | 2924 forms_web_contents->ReloadFocusedFrame(false); |
| 2928 observer.Wait(); | 2925 observer.Wait(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3236 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 3233 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 3237 TabStripModel::ADD_ACTIVE); | 3234 TabStripModel::ADD_ACTIVE); |
| 3238 } | 3235 } |
| 3239 | 3236 |
| 3240 // Verify the Form-Not-Secure warning is shown on a non-secure username field. | 3237 // Verify the Form-Not-Secure warning is shown on a non-secure username field. |
| 3241 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestWarning, | 3238 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestWarning, |
| 3242 ShowFormNotSecureOnUsernameField) { | 3239 ShowFormNotSecureOnUsernameField) { |
| 3243 ASSERT_TRUE( | 3240 ASSERT_TRUE( |
| 3244 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); | 3241 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); |
| 3245 | 3242 |
| 3243 // We need to serve from a non-localhost context for the form to be treated as | |
| 3244 // Not Secure. | |
| 3245 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 3246 NavigationObserver observer(WebContents()); | |
| 3247 ui_test_utils::NavigateToURL( | |
| 3248 browser(), embedded_test_server()->GetURL( | |
| 3249 "example.com", "/password/password_form.html")); | |
| 3250 observer.Wait(); | |
| 3251 | |
| 3252 // Mock the autofill client. | |
| 3246 password_manager::ContentPasswordManagerDriverFactory* driver_factory = | 3253 password_manager::ContentPasswordManagerDriverFactory* driver_factory = |
| 3247 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( | 3254 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( |
| 3248 WebContents()); | 3255 WebContents()); |
| 3249 ObservingAutofillClient::CreateForWebContents(WebContents()); | 3256 ObservingAutofillClient::CreateForWebContents(WebContents()); |
| 3250 ObservingAutofillClient* observing_autofill_client = | 3257 ObservingAutofillClient* observing_autofill_client = |
| 3251 ObservingAutofillClient::FromWebContents(WebContents()); | 3258 ObservingAutofillClient::FromWebContents(WebContents()); |
| 3252 password_manager::ContentPasswordManagerDriver* driver = | 3259 password_manager::ContentPasswordManagerDriver* driver = |
| 3253 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); | 3260 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); |
| 3254 DCHECK(driver); | 3261 DCHECK(driver); |
| 3255 driver->GetPasswordAutofillManager()->set_autofill_client( | 3262 driver->GetPasswordAutofillManager()->set_autofill_client( |
| 3256 observing_autofill_client); | 3263 observing_autofill_client); |
| 3257 | 3264 |
| 3258 // We need to serve from a non-localhost context for the form to be treated as | |
| 3259 // Not Secure. | |
| 3260 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 3261 NavigationObserver observer(WebContents()); | |
| 3262 ui_test_utils::NavigateToURL( | |
| 3263 browser(), embedded_test_server()->GetURL( | |
| 3264 "example.com", "/password/password_form.html")); | |
| 3265 observer.Wait(); | |
| 3266 | |
| 3267 ASSERT_TRUE(content::ExecuteScript( | 3265 ASSERT_TRUE(content::ExecuteScript( |
| 3268 RenderViewHost(), | 3266 RenderViewHost(), |
| 3269 "var inputRect = document.getElementById('username_field_no_name')" | 3267 "var inputRect = document.getElementById('username_field_no_name')" |
| 3270 ".getBoundingClientRect();")); | 3268 ".getBoundingClientRect();")); |
| 3271 | 3269 |
| 3272 // Click on the username field to verify the warning is shown. | 3270 // Click on the username field to verify the warning is shown. |
| 3273 int top; | 3271 int top; |
| 3274 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 3272 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 3275 RenderViewHost(), "window.domAutomationController.send(inputRect.top);", | 3273 RenderViewHost(), "window.domAutomationController.send(inputRect.top);", |
| 3276 &top)); | 3274 &top)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3291 // Ensure the histogram was updated. | 3289 // Ensure the histogram was updated. |
| 3292 histograms.ExpectUniqueSample(kHistogram, true, 1); | 3290 histograms.ExpectUniqueSample(kHistogram, true, 1); |
| 3293 } | 3291 } |
| 3294 | 3292 |
| 3295 // Verify the Form-Not-Secure warning is not shown on a non-credential field. | 3293 // Verify the Form-Not-Secure warning is not shown on a non-credential field. |
| 3296 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestWarning, | 3294 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestWarning, |
| 3297 DoNotShowFormNotSecureOnUnrelatedField) { | 3295 DoNotShowFormNotSecureOnUnrelatedField) { |
| 3298 ASSERT_TRUE( | 3296 ASSERT_TRUE( |
| 3299 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); | 3297 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); |
| 3300 | 3298 |
| 3299 // We need to serve from a non-localhost context for the form to be treated as | |
| 3300 // Not Secure. | |
| 3301 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 3302 NavigationObserver observer(WebContents()); | |
| 3303 ui_test_utils::NavigateToURL( | |
| 3304 browser(), embedded_test_server()->GetURL( | |
| 3305 "example.com", "/password/password_form.html")); | |
| 3306 observer.Wait(); | |
| 3307 | |
| 3308 // Mock the autofill client. | |
| 3301 password_manager::ContentPasswordManagerDriverFactory* driver_factory = | 3309 password_manager::ContentPasswordManagerDriverFactory* driver_factory = |
| 3302 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( | 3310 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( |
| 3303 WebContents()); | 3311 WebContents()); |
| 3304 ObservingAutofillClient::CreateForWebContents(WebContents()); | 3312 ObservingAutofillClient::CreateForWebContents(WebContents()); |
| 3305 ObservingAutofillClient* observing_autofill_client = | 3313 ObservingAutofillClient* observing_autofill_client = |
| 3306 ObservingAutofillClient::FromWebContents(WebContents()); | 3314 ObservingAutofillClient::FromWebContents(WebContents()); |
| 3307 password_manager::ContentPasswordManagerDriver* driver = | 3315 password_manager::ContentPasswordManagerDriver* driver = |
| 3308 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); | 3316 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); |
| 3309 DCHECK(driver); | 3317 DCHECK(driver); |
| 3310 driver->GetPasswordAutofillManager()->set_autofill_client( | 3318 driver->GetPasswordAutofillManager()->set_autofill_client( |
| 3311 observing_autofill_client); | 3319 observing_autofill_client); |
| 3312 | 3320 |
| 3313 // We need to serve from a non-localhost context for the form to be treated as | |
| 3314 // Not Secure. | |
| 3315 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 3316 NavigationObserver observer(WebContents()); | |
| 3317 ui_test_utils::NavigateToURL( | |
| 3318 browser(), embedded_test_server()->GetURL( | |
| 3319 "example.com", "/password/password_form.html")); | |
| 3320 observer.Wait(); | |
| 3321 | |
| 3322 ASSERT_TRUE(content::ExecuteScript( | 3321 ASSERT_TRUE(content::ExecuteScript( |
| 3323 RenderViewHost(), | 3322 RenderViewHost(), |
| 3324 "var inputRect = document.getElementById('ef_extra')" | 3323 "var inputRect = document.getElementById('ef_extra')" |
| 3325 ".getBoundingClientRect();")); | 3324 ".getBoundingClientRect();")); |
| 3326 | 3325 |
| 3327 // Click on the non-username text field. | 3326 // Click on the non-username text field. |
| 3328 int top; | 3327 int top; |
| 3329 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 3328 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 3330 RenderViewHost(), "window.domAutomationController.send(inputRect.top);", | 3329 RenderViewHost(), "window.domAutomationController.send(inputRect.top);", |
| 3331 &top)); | 3330 &top)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 3343 gfx::Point(left + 1, top + 1)); | 3342 gfx::Point(left + 1, top + 1)); |
| 3344 // Force a round-trip. | 3343 // Force a round-trip. |
| 3345 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), "var noop = 'noop';")); | 3344 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), "var noop = 'noop';")); |
| 3346 // Ensure the warning was not triggered. | 3345 // Ensure the warning was not triggered. |
| 3347 ASSERT_FALSE(observing_autofill_client->DidPopupAppear()); | 3346 ASSERT_FALSE(observing_autofill_client->DidPopupAppear()); |
| 3348 // Ensure the histogram remains empty. | 3347 // Ensure the histogram remains empty. |
| 3349 histograms.ExpectTotalCount(kHistogram, 0); | 3348 histograms.ExpectTotalCount(kHistogram, 0); |
| 3350 } | 3349 } |
| 3351 | 3350 |
| 3352 } // namespace password_manager | 3351 } // namespace password_manager |
| OLD | NEW |