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/channel_info.h" | 26 #include "chrome/common/channel_info.h" |
26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override { | 110 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override { |
110 message_loop_runner_->Quit(); | 111 message_loop_runner_->Quit(); |
111 } | 112 } |
112 | 113 |
113 private: | 114 private: |
114 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 115 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
115 | 116 |
116 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); | 117 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); |
117 }; | 118 }; |
118 | 119 |
| 120 // For simplicity we assume that password store contains only 1 credentials. |
| 121 void CheckThatCredentialsStored( |
| 122 password_manager::TestPasswordStore* password_store, |
| 123 const base::string16& username, |
| 124 const base::string16& password) { |
| 125 auto& passwords_map = password_store->stored_passwords(); |
| 126 ASSERT_EQ(1u, passwords_map.size()); |
| 127 auto& passwords_vector = passwords_map.begin()->second; |
| 128 ASSERT_EQ(1u, passwords_vector.size()); |
| 129 const autofill::PasswordForm& form = passwords_vector[0]; |
| 130 EXPECT_EQ(username, form.username_value); |
| 131 EXPECT_EQ(password, form.password_value); |
| 132 } |
| 133 |
119 } // namespace | 134 } // namespace |
120 | 135 |
121 namespace password_manager { | 136 namespace password_manager { |
122 | 137 |
123 // Actual tests --------------------------------------------------------------- | 138 // Actual tests --------------------------------------------------------------- |
124 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { | 139 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { |
125 NavigateToFile("/password/password_form.html"); | 140 NavigateToFile("/password/password_form.html"); |
126 | 141 |
127 // Fill a form and submit through a <input type="submit"> button. Nothing | 142 // Fill a form and submit through a <input type="submit"> button. Nothing |
128 // special. | 143 // special. |
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 content::RenderProcessHostWatcher iframe_killed( | 2028 content::RenderProcessHostWatcher iframe_killed( |
2014 iframe->GetProcess(), | 2029 iframe->GetProcess(), |
2015 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 2030 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
2016 | 2031 |
2017 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 2032 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
2018 iframe->GetProcess()->GetChannel(), illegal_forms_parsed); | 2033 iframe->GetProcess()->GetChannel(), illegal_forms_parsed); |
2019 | 2034 |
2020 iframe_killed.Wait(); | 2035 iframe_killed.Wait(); |
2021 } | 2036 } |
2022 | 2037 |
| 2038 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 2039 ChangePwdNoAccountStored) { |
| 2040 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()); |
| 2041 NavigateToFile("/password/password_form.html"); |
| 2042 |
| 2043 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2044 password_manager::switches::kEnablePasswordChangeSupport); |
| 2045 |
| 2046 // Fill a form and submit through a <input type="submit"> button. |
| 2047 NavigationObserver observer(WebContents()); |
| 2048 scoped_ptr<PromptObserver> prompt_observer( |
| 2049 PromptObserver::Create(WebContents())); |
| 2050 |
| 2051 std::string fill_and_submit = |
| 2052 "document.getElementById('chg_password_wo_username_field').value = " |
| 2053 "'old_pw';" |
| 2054 "document.getElementById('chg_new_password_wo_username_1').value = " |
| 2055 "'new_pw';" |
| 2056 "document.getElementById('chg_new_password_wo_username_2').value = " |
| 2057 "'new_pw';" |
| 2058 "document.getElementById('chg_submit_wo_username_button').click()"; |
| 2059 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 2060 observer.Wait(); |
| 2061 // No credentials stored before, so save bubble is shown. |
| 2062 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 2063 prompt_observer->Accept(); |
| 2064 // Check that credentials are stored. |
| 2065 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 2066 static_cast<password_manager::TestPasswordStore*>( |
| 2067 PasswordStoreFactory::GetForProfile( |
| 2068 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) |
| 2069 .get()); |
| 2070 // Spin the message loop to make sure the password store had a chance to save |
| 2071 // the password. |
| 2072 base::RunLoop run_loop; |
| 2073 run_loop.RunUntilIdle(); |
| 2074 EXPECT_FALSE(password_store->IsEmpty()); |
| 2075 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16(""), |
| 2076 base::ASCIIToUTF16("new_pw")); |
| 2077 } |
| 2078 |
| 2079 // TODO(dvadym): Turn on this test when Change password UI will be implemented |
| 2080 // for Mac. http://crbug.com/359315 |
| 2081 #ifndef OS_MACOSX |
| 2082 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 2083 ChangePwd1AccountStored) { |
| 2084 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()); |
| 2085 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2086 password_manager::switches::kEnablePasswordChangeSupport); |
| 2087 // At first let us save credentials to the PasswordManager. |
| 2088 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 2089 static_cast<password_manager::TestPasswordStore*>( |
| 2090 PasswordStoreFactory::GetForProfile( |
| 2091 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) |
| 2092 .get()); |
| 2093 autofill::PasswordForm signin_form; |
| 2094 signin_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2095 signin_form.password_value = base::ASCIIToUTF16("pw"); |
| 2096 signin_form.username_value = base::ASCIIToUTF16("temp"); |
| 2097 password_store->AddLogin(signin_form); |
| 2098 |
| 2099 // Check that password update bubble is shown. |
| 2100 NavigateToFile("/password/password_form.html"); |
| 2101 NavigationObserver observer(WebContents()); |
| 2102 scoped_ptr<PromptObserver> prompt_observer( |
| 2103 PromptObserver::Create(WebContents())); |
| 2104 std::string fill_and_submit_change_password = |
| 2105 "document.getElementById('chg_password_wo_username_field').value = " |
| 2106 "'random';" |
| 2107 "document.getElementById('chg_new_password_wo_username_1').value = " |
| 2108 "'new_pw';" |
| 2109 "document.getElementById('chg_new_password_wo_username_2').value = " |
| 2110 "'new_pw';" |
| 2111 "document.getElementById('chg_submit_wo_username_button').click()"; |
| 2112 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
| 2113 fill_and_submit_change_password)); |
| 2114 observer.Wait(); |
| 2115 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); |
| 2116 |
| 2117 const autofill::PasswordForm& stored_form = |
| 2118 password_store->stored_passwords().begin()->second[0]; |
| 2119 prompt_observer->AcceptUpdatePrompt(stored_form); |
| 2120 // Spin the message loop to make sure the password store had a chance to |
| 2121 // update the password. |
| 2122 base::RunLoop run_loop; |
| 2123 run_loop.RunUntilIdle(); |
| 2124 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), |
| 2125 base::ASCIIToUTF16("new_pw")); |
| 2126 } |
| 2127 #endif |
| 2128 |
2023 } // namespace password_manager | 2129 } // namespace password_manager |
2024 | |
OLD | NEW |