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" |
| 11 #include "base/metrics/histogram_samples.h" | 11 #include "base/metrics/histogram_samples.h" |
| 12 #include "base/metrics/statistics_recorder.h" | 12 #include "base/metrics/statistics_recorder.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/test/histogram_tester.h" | |
| 18 #include "base/test/scoped_feature_list.h" | 19 #include "base/test/scoped_feature_list.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 22 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 22 #include "chrome/browser/password_manager/password_manager_test_base.h" | 23 #include "chrome/browser/password_manager/password_manager_test_base.h" |
| 23 #include "chrome/browser/password_manager/password_store_factory.h" | 24 #include "chrome/browser/password_manager/password_store_factory.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_navigator_params.h" | 27 #include "chrome/browser/ui/browser_navigator_params.h" |
| 27 #include "chrome/browser/ui/login/login_handler.h" | 28 #include "chrome/browser/ui/login/login_handler.h" |
| (...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1809 &left)); | 1810 &left)); |
| 1810 | 1811 |
| 1811 content::SimulateMouseClickAt( | 1812 content::SimulateMouseClickAt( |
| 1812 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(left + 1, | 1813 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(left + 1, |
| 1813 top + 1)); | 1814 top + 1)); |
| 1814 // Make sure the popup would be shown. | 1815 // Make sure the popup would be shown. |
| 1815 observing_autofill_client->Wait(); | 1816 observing_autofill_client->Wait(); |
| 1816 } | 1817 } |
| 1817 | 1818 |
| 1818 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 1819 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1820 ShowFormNotSecureOnUsernameField) { | |
| 1821 password_manager::ContentPasswordManagerDriverFactory* driver_factory = | |
| 1822 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( | |
| 1823 WebContents()); | |
| 1824 ObservingAutofillClient::CreateForWebContents(WebContents()); | |
| 1825 ObservingAutofillClient* observing_autofill_client = | |
| 1826 ObservingAutofillClient::FromWebContents(WebContents()); | |
| 1827 password_manager::ContentPasswordManagerDriver* driver = | |
| 1828 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); | |
| 1829 DCHECK(driver); | |
| 1830 driver->GetPasswordAutofillManager()->set_autofill_client( | |
| 1831 observing_autofill_client); | |
| 1832 | |
| 1833 // We need to serve from a non-localhost context for the form to be treated as | |
| 1834 // Not Secure. | |
| 1835 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 1836 NavigationObserver observer(WebContents()); | |
| 1837 ui_test_utils::NavigateToURL( | |
| 1838 browser(), embedded_test_server()->GetURL( | |
| 1839 "example.com", "/password/password_form.html")); | |
| 1840 observer.Wait(); | |
| 1841 | |
| 1842 ASSERT_TRUE(content::ExecuteScript( | |
| 1843 RenderViewHost(), | |
| 1844 "var inputRect = document.getElementById('username_field_no_name')" | |
| 1845 ".getBoundingClientRect();")); | |
| 1846 | |
| 1847 // Click on the username field to verify the warning is shown. | |
| 1848 int top; | |
| 1849 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 1850 RenderViewHost(), "window.domAutomationController.send(inputRect.top);", | |
| 1851 &top)); | |
| 1852 int left; | |
| 1853 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 1854 RenderViewHost(), "window.domAutomationController.send(inputRect.left);", | |
| 1855 &left)); | |
| 1856 | |
| 1857 const char kHistogram[] = | |
| 1858 "PasswordManager.ShowedFormNotSecureWarningOnCurrentNavigation"; | |
| 1859 base::HistogramTester histograms; | |
| 1860 | |
| 1861 content::SimulateMouseClickAt(WebContents(), 0, | |
| 1862 blink::WebMouseEvent::Button::Left, | |
| 1863 gfx::Point(left + 1, top + 1)); | |
| 1864 // Ensure the warning would be shown. | |
| 1865 observing_autofill_client->Wait(); | |
| 1866 // Ensure the histogram was updated. | |
| 1867 histograms.ExpectUniqueSample(kHistogram, true, 1); | |
| 1868 } | |
|
sebsg
2017/02/13 18:53:55
Can you add a test for when a user clicks on anoth
| |
| 1869 | |
| 1870 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
| 1819 ChangePwdFormBubbleShown) { | 1871 ChangePwdFormBubbleShown) { |
| 1820 NavigateToFile("/password/password_form.html"); | 1872 NavigateToFile("/password/password_form.html"); |
| 1821 | 1873 |
| 1822 NavigationObserver observer(WebContents()); | 1874 NavigationObserver observer(WebContents()); |
| 1823 std::unique_ptr<BubbleObserver> prompt_observer( | 1875 std::unique_ptr<BubbleObserver> prompt_observer( |
| 1824 new BubbleObserver(WebContents())); | 1876 new BubbleObserver(WebContents())); |
| 1825 std::string fill_and_submit = | 1877 std::string fill_and_submit = |
| 1826 "document.getElementById('chg_username_field').value = 'temp';" | 1878 "document.getElementById('chg_username_field').value = 'temp';" |
| 1827 "document.getElementById('chg_password_field').value = 'random';" | 1879 "document.getElementById('chg_password_field').value = 'random';" |
| 1828 "document.getElementById('chg_new_password_1').value = 'random1';" | 1880 "document.getElementById('chg_new_password_1').value = 'random1';" |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3209 // about all frames, not just the main one. The factories should receive | 3261 // about all frames, not just the main one. The factories should receive |
| 3210 // messages for non-main frames, in particular | 3262 // messages for non-main frames, in particular |
| 3211 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the | 3263 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the |
| 3212 // factories hear about such frames, this would crash. | 3264 // factories hear about such frames, this would crash. |
| 3213 tab_strip_model->AddWebContents(detached_web_contents.release(), -1, | 3265 tab_strip_model->AddWebContents(detached_web_contents.release(), -1, |
| 3214 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 3266 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 3215 TabStripModel::ADD_ACTIVE); | 3267 TabStripModel::ADD_ACTIVE); |
| 3216 } | 3268 } |
| 3217 | 3269 |
| 3218 } // namespace password_manager | 3270 } // namespace password_manager |
| OLD | NEW |