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 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 16 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 17 #include "chrome/browser/password_manager/password_manager_test_base.h" | 17 #include "chrome/browser/password_manager/password_manager_test_base.h" |
| 18 #include "chrome/browser/password_manager/password_store_factory.h" | 18 #include "chrome/browser/password_manager/password_store_factory.h" |
| 19 #include "chrome/browser/password_manager/test_password_store_service.h" | 19 #include "chrome/browser/password_manager/test_password_store_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/login/login_prompt.h" | 22 #include "chrome/browser/ui/login/login_prompt.h" |
| 23 #include "chrome/browser/ui/login/login_prompt_test_utils.h" | 23 #include "chrome/browser/ui/login/login_prompt_test_utils.h" |
| 24 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/test/base/test_switches.h" | 29 #include "chrome/test/base/test_switches.h" |
| 29 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 30 #include "components/autofill/content/common/autofill_messages.h" | 31 #include "components/autofill/content/common/autofill_messages.h" |
| 31 #include "components/autofill/core/browser/autofill_test_utils.h" | 32 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 32 #include "components/autofill/core/browser/test_autofill_client.h" | 33 #include "components/autofill/core/browser/test_autofill_client.h" |
| 33 #include "components/autofill/core/common/password_form.h" | 34 #include "components/autofill/core/common/password_form.h" |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1540 "window.domAutomationController.send(usernameRect.left);", | 1541 "window.domAutomationController.send(usernameRect.left);", |
| 1541 &left)); | 1542 &left)); |
| 1542 | 1543 |
| 1543 content::SimulateMouseClickAt( | 1544 content::SimulateMouseClickAt( |
| 1544 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(left + 1, | 1545 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(left + 1, |
| 1545 top + 1)); | 1546 top + 1)); |
| 1546 // Make sure the popup would be shown. | 1547 // Make sure the popup would be shown. |
| 1547 observing_autofill_client.Wait(); | 1548 observing_autofill_client.Wait(); |
| 1548 } | 1549 } |
| 1549 | 1550 |
| 1550 // Passwords from change password forms should only be offered for saving when | 1551 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1551 // it is certain that the username is correct. | 1552 ChangePwdMarkedWithUsername) { |
| 1552 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, ChangePwdCorrect) { | |
| 1553 NavigateToFile("/password/password_form.html"); | 1553 NavigateToFile("/password/password_form.html"); |
| 1554 | 1554 |
| 1555 NavigationObserver observer(WebContents()); | 1555 NavigationObserver observer(WebContents()); |
| 1556 scoped_ptr<PromptObserver> prompt_observer( | 1556 scoped_ptr<PromptObserver> prompt_observer( |
| 1557 PromptObserver::Create(WebContents())); | 1557 PromptObserver::Create(WebContents())); |
| 1558 std::string fill_and_submit = | 1558 std::string fill_and_submit = |
| 1559 "document.getElementById('mark_chg_username_field').value = 'temp';" | 1559 "document.getElementById('mark_chg_username_field').value = 'temp';" |
| 1560 "document.getElementById('mark_chg_password_field').value = 'random';" | 1560 "document.getElementById('mark_chg_password_field').value = 'random';" |
| 1561 "document.getElementById('mark_chg_new_password_1').value = 'random1';" | 1561 "document.getElementById('mark_chg_new_password_1').value = 'random1';" |
| 1562 "document.getElementById('mark_chg_new_password_2').value = 'random1';" | 1562 "document.getElementById('mark_chg_new_password_2').value = 'random1';" |
| 1563 "document.getElementById('mark_chg_submit_button').click()"; | 1563 "document.getElementById('mark_chg_submit_button').click()"; |
| 1564 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1564 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1565 observer.Wait(); | 1565 observer.Wait(); |
| 1566 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); | 1566 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 1567 } | 1567 } |
| 1568 | 1568 |
| 1569 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, ChangePwdIncorrect) { | 1569 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, ChangePwdWithUsername) { |
| 1570 NavigateToFile("/password/password_form.html"); | 1570 NavigateToFile("/password/password_form.html"); |
| 1571 | 1571 |
| 1572 NavigationObserver observer(WebContents()); | 1572 NavigationObserver observer(WebContents()); |
| 1573 scoped_ptr<PromptObserver> prompt_observer( | 1573 scoped_ptr<PromptObserver> prompt_observer( |
| 1574 PromptObserver::Create(WebContents())); | 1574 PromptObserver::Create(WebContents())); |
| 1575 std::string fill_and_submit = | 1575 std::string fill_and_submit = |
| 1576 "document.getElementById('chg_not_username_field').value = 'temp';" | 1576 "document.getElementById('chg_not_username_field').value = 'temp';" |
| 1577 "document.getElementById('chg_password_field').value = 'random';" | 1577 "document.getElementById('chg_password_field').value = 'random';" |
| 1578 "document.getElementById('chg_new_password_1').value = 'random1';" | 1578 "document.getElementById('chg_new_password_1').value = 'random1';" |
| 1579 "document.getElementById('chg_new_password_2').value = 'random1';" | 1579 "document.getElementById('chg_new_password_2').value = 'random1';" |
| 1580 "document.getElementById('chg_submit_button').click()"; | 1580 "document.getElementById('chg_submit_button').click()"; |
| 1581 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1581 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1582 observer.Wait(); | 1582 observer.Wait(); |
| 1583 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); | 1583 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 // As the two ChangePwd* tests above, only with submitting through | 1586 // As the two ChangePwd* tests above, only with submitting through |
| 1587 // history.pushState(). | 1587 // history.pushState(). |
| 1588 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 1588 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1589 ChangePwdPushStateCorrect) { | 1589 ChangePwdPushStateMarkedWithUsername) { |
| 1590 NavigateToFile("/password/password_push_state.html"); | 1590 NavigateToFile("/password/password_push_state.html"); |
| 1591 | 1591 |
| 1592 NavigationObserver observer(WebContents()); | 1592 NavigationObserver observer(WebContents()); |
| 1593 observer.set_quit_on_entry_committed(true); | 1593 observer.set_quit_on_entry_committed(true); |
| 1594 scoped_ptr<PromptObserver> prompt_observer( | 1594 scoped_ptr<PromptObserver> prompt_observer( |
| 1595 PromptObserver::Create(WebContents())); | 1595 PromptObserver::Create(WebContents())); |
| 1596 std::string fill_and_submit = | 1596 std::string fill_and_submit = |
| 1597 "document.getElementById('mark_chg_username_field').value = 'temp';" | 1597 "document.getElementById('mark_chg_username_field').value = 'temp';" |
| 1598 "document.getElementById('mark_chg_password_field').value = 'random';" | 1598 "document.getElementById('mark_chg_password_field').value = 'random';" |
| 1599 "document.getElementById('mark_chg_new_password_1').value = 'random1';" | 1599 "document.getElementById('mark_chg_new_password_1').value = 'random1';" |
| 1600 "document.getElementById('mark_chg_new_password_2').value = 'random1';" | 1600 "document.getElementById('mark_chg_new_password_2').value = 'random1';" |
| 1601 "document.getElementById('mark_chg_submit_button').click()"; | 1601 "document.getElementById('mark_chg_submit_button').click()"; |
| 1602 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1602 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1603 observer.Wait(); | 1603 observer.Wait(); |
| 1604 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); | 1604 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 1605 } | 1605 } |
| 1606 | 1606 |
| 1607 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 1607 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1608 ChangePwdPushStateIncorrect) { | 1608 ChangePwdPushStateWithUsername) { |
| 1609 NavigateToFile("/password/password_push_state.html"); | 1609 NavigateToFile("/password/password_push_state.html"); |
| 1610 | 1610 |
| 1611 NavigationObserver observer(WebContents()); | 1611 NavigationObserver observer(WebContents()); |
| 1612 observer.set_quit_on_entry_committed(true); | 1612 observer.set_quit_on_entry_committed(true); |
| 1613 scoped_ptr<PromptObserver> prompt_observer( | 1613 scoped_ptr<PromptObserver> prompt_observer( |
| 1614 PromptObserver::Create(WebContents())); | 1614 PromptObserver::Create(WebContents())); |
| 1615 std::string fill_and_submit = | 1615 std::string fill_and_submit = |
| 1616 "document.getElementById('chg_not_username_field').value = 'temp';" | 1616 "document.getElementById('chg_not_username_field').value = 'temp';" |
| 1617 "document.getElementById('chg_password_field').value = 'random';" | 1617 "document.getElementById('chg_password_field').value = 'random';" |
| 1618 "document.getElementById('chg_new_password_1').value = 'random1';" | 1618 "document.getElementById('chg_new_password_1').value = 'random1';" |
| 1619 "document.getElementById('chg_new_password_2').value = 'random1';" | 1619 "document.getElementById('chg_new_password_2').value = 'random1';" |
| 1620 "document.getElementById('chg_submit_button').click()"; | 1620 "document.getElementById('chg_submit_button').click()"; |
| 1621 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1621 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1622 observer.Wait(); | 1622 observer.Wait(); |
| 1623 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); | 1623 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptOnBack) { | 1626 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptOnBack) { |
| 1627 // Go to a successful landing page through submitting first, so that it is | 1627 // Go to a successful landing page through submitting first, so that it is |
| 1628 // reachable through going back, and the remembered page transition is form | 1628 // reachable through going back, and the remembered page transition is form |
| 1629 // submit. There is no need to submit non-empty strings. | 1629 // submit. There is no need to submit non-empty strings. |
| 1630 NavigateToFile("/password/password_form.html"); | 1630 NavigateToFile("/password/password_form.html"); |
| 1631 | 1631 |
| 1632 NavigationObserver dummy_submit_observer(WebContents()); | 1632 NavigationObserver dummy_submit_observer(WebContents()); |
| 1633 std::string just_submit = | 1633 std::string just_submit = |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2013 content::RenderProcessHostWatcher iframe_killed( | 2013 content::RenderProcessHostWatcher iframe_killed( |
| 2014 iframe->GetProcess(), | 2014 iframe->GetProcess(), |
| 2015 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 2015 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 2016 | 2016 |
| 2017 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 2017 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 2018 iframe->GetProcess()->GetChannel(), illegal_forms_parsed); | 2018 iframe->GetProcess()->GetChannel(), illegal_forms_parsed); |
| 2019 | 2019 |
| 2020 iframe_killed.Wait(); | 2020 iframe_killed.Wait(); |
| 2021 } | 2021 } |
| 2022 | 2022 |
| 2023 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
| 2024 ChangePwdNoAccountStored) { | |
| 2025 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()); | |
| 2026 NavigateToFile("/password/password_form.html"); | |
| 2027 | |
| 2028 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 2029 password_manager::switches::kEnablePasswordChangeSupport); | |
| 2030 | |
| 2031 // Fill a form and submit through a <input type="submit"> button. | |
| 2032 NavigationObserver observer(WebContents()); | |
| 2033 scoped_ptr<PromptObserver> prompt_observer( | |
|
vabr (Chromium)
2015/07/31 12:48:13
Looks unused.
dvadym
2015/08/03 15:44:07
Not it's used after adding checking of credentials
| |
| 2034 PromptObserver::Create(WebContents())); | |
| 2035 ManagePasswordsUIController* ui_controller = | |
| 2036 ManagePasswordsUIController::FromWebContents(WebContents()); | |
| 2037 | |
| 2038 std::string fill_and_submit = | |
| 2039 "document.getElementById('chg_password_wo_username_field').value = " | |
| 2040 "'old_pw';" | |
| 2041 "document.getElementById('chg_new_password_wo_username_1').value = " | |
| 2042 "'new_pw';" | |
| 2043 "document.getElementById('chg_new_password_wo_username_2').value = " | |
| 2044 "'new_pw';" | |
| 2045 "document.getElementById('chg_submit_wo_username_button').click()"; | |
| 2046 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
| 2047 observer.Wait(); | |
| 2048 // No credentials stored, so save bubble is shown. | |
| 2049 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | |
| 2050 ui_controller->state()); | |
| 2051 } | |
|
vabr (Chromium)
2015/07/31 12:48:13
Is there a way (here and in the other test) to che
dvadym
2015/08/03 15:44:07
Good point, I've added check for these tests
| |
| 2052 | |
| 2053 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
| 2054 ChangePwd1AccountStored) { | |
| 2055 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()); | |
| 2056 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 2057 password_manager::switches::kEnablePasswordChangeSupport); | |
| 2058 // At first let us save credentials to the PasswordManager. | |
| 2059 NavigateToFile("/password/password_form.html"); | |
| 2060 NavigationObserver observer1(WebContents()); | |
| 2061 scoped_ptr<PromptObserver> prompt_observer( | |
| 2062 PromptObserver::Create(WebContents())); | |
| 2063 ManagePasswordsUIController* ui_controller = | |
| 2064 ManagePasswordsUIController::FromWebContents(WebContents()); | |
| 2065 std::string fill_and_submit_signin = | |
| 2066 "document.getElementById('username_field').value = 'temp';" | |
| 2067 "document.getElementById('password_field').value = 'random';" | |
| 2068 "document.getElementById('input_submit_button').click()"; | |
| 2069 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit_signin)); | |
| 2070 observer1.Wait(); | |
| 2071 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | |
| 2072 ui_controller->state()); | |
| 2073 prompt_observer->Accept(); | |
| 2074 // Check that credentials are stored. | |
| 2075 password_manager::TestPasswordStore* password_store = | |
|
vabr (Chromium)
2015/07/31 12:48:13
Is it actually possible to just store the credenti
vabr (Chromium)
2015/07/31 12:48:13
Keeping the test password store in a naked pointer
dvadym
2015/08/03 15:44:07
Here we don't owe this TestPasswordStore, so it se
dvadym
2015/08/03 15:44:07
I've implemented such possibility and made direct
vabr (Chromium)
2015/08/04 08:59:07
For scoped_refptr (unlike scoped_ptr), there is no
dvadym
2015/08/04 14:34:46
Done.
| |
| 2076 static_cast<password_manager::TestPasswordStore*>( | |
| 2077 PasswordStoreFactory::GetForProfile( | |
| 2078 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
| 2079 .get()); | |
| 2080 // Spin the message loop to make sure the password store had a chance to save | |
| 2081 // the password. | |
| 2082 base::RunLoop run_loop; | |
| 2083 run_loop.RunUntilIdle(); | |
| 2084 EXPECT_FALSE(password_store->IsEmpty()); | |
| 2085 | |
| 2086 // Check that password update bubble is shown. | |
| 2087 NavigateToFile("/password/password_form.html"); | |
| 2088 NavigationObserver observer2(WebContents()); | |
| 2089 std::string fill_and_submit_change_password = | |
| 2090 "document.getElementById('chg_password_wo_username_field').value = " | |
| 2091 "'random';" | |
| 2092 "document.getElementById('chg_new_password_wo_username_1').value = " | |
| 2093 "'new_pw';" | |
| 2094 "document.getElementById('chg_new_password_wo_username_2').value = " | |
| 2095 "'new_pw';" | |
| 2096 "document.getElementById('chg_submit_wo_username_button').click()"; | |
| 2097 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), | |
| 2098 fill_and_submit_change_password)); | |
| 2099 observer2.Wait(); | |
| 2100 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, | |
| 2101 ui_controller->state()); | |
| 2102 } | |
| 2103 | |
| 2023 } // namespace password_manager | 2104 } // namespace password_manager |
| 2024 | 2105 |
| OLD | NEW |