Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 1151373006: Update Confirmation UI for saved password change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tiny test fix Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override { 109 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override {
109 message_loop_runner_->Quit(); 110 message_loop_runner_->Quit();
110 } 111 }
111 112
112 private: 113 private:
113 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 114 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
114 115
115 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); 116 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient);
116 }; 117 };
117 118
119 // For simplicity we assume that password store contains only 1 credentials.
120 void CheckThatCredentialsStored(
121 password_manager::TestPasswordStore* password_store,
122 const base::string16& username,
123 const base::string16& password) {
124 auto& passwords_map = password_store->stored_passwords();
125 ASSERT_EQ(1u, passwords_map.size());
126 auto& passwords_vector = passwords_map.begin()->second;
127 ASSERT_EQ(1u, passwords_vector.size());
128 const autofill::PasswordForm& form = passwords_vector[0];
129 ASSERT_EQ(username, form.username_value);
vabr (Chromium) 2015/08/04 08:59:07 EXPECT rather than ASSERT? Unlike the above 2 asse
dvadym 2015/08/04 14:34:46 Done.
130 ASSERT_EQ(password, form.password_value);
131 }
132
118 } // namespace 133 } // namespace
119 134
120 namespace password_manager { 135 namespace password_manager {
121 136
122 // Actual tests --------------------------------------------------------------- 137 // Actual tests ---------------------------------------------------------------
123 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { 138 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) {
124 NavigateToFile("/password/password_form.html"); 139 NavigateToFile("/password/password_form.html");
125 140
126 // Fill a form and submit through a <input type="submit"> button. Nothing 141 // Fill a form and submit through a <input type="submit"> button. Nothing
127 // special. 142 // special.
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->IsShowingUpdatePrompt());
2063 prompt_observer->Accept();
2064 // Check that credentials are stored.
2065 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, base::ASCIIToUTF16(""),
2076 base::ASCIIToUTF16("new_pw"));
2077 }
2078
2079 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2080 ChangePwd1AccountStored) {
2081 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled());
2082 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2083 password_manager::switches::kEnablePasswordChangeSupport);
2084 // At first let us save credentials to the PasswordManager.
2085 password_manager::TestPasswordStore* password_store =
2086 static_cast<password_manager::TestPasswordStore*>(
2087 PasswordStoreFactory::GetForProfile(
2088 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
2089 .get());
2090 autofill::PasswordForm signin_form;
2091 signin_form.signon_realm = embedded_test_server()->base_url().spec();
2092 signin_form.password_value = base::ASCIIToUTF16("pw");
2093 signin_form.username_value = base::ASCIIToUTF16("temp");
2094 password_store->AddCredentials(signin_form);
2095
2096 // Check that password update bubble is shown.
2097 NavigateToFile("/password/password_form.html");
2098 NavigationObserver observer(WebContents());
2099 scoped_ptr<PromptObserver> prompt_observer(
2100 PromptObserver::Create(WebContents()));
2101 std::string fill_and_submit_change_password =
2102 "document.getElementById('chg_password_wo_username_field').value = "
2103 "'random';"
2104 "document.getElementById('chg_new_password_wo_username_1').value = "
2105 "'new_pw';"
2106 "document.getElementById('chg_new_password_wo_username_2').value = "
2107 "'new_pw';"
2108 "document.getElementById('chg_submit_wo_username_button').click()";
2109 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
2110 fill_and_submit_change_password));
2111 observer.Wait();
2112 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt());
2113
2114 const autofill::PasswordForm& stored_form =
2115 password_store->stored_passwords().begin()->second[0];
2116 prompt_observer->AcceptUpdatePrompt(stored_form);
2117 // Spin the message loop to make sure the password store had a chance to
2118 // update the password.
2119 base::RunLoop run_loop;
2120 run_loop.RunUntilIdle();
2121 CheckThatCredentialsStored(password_store, base::ASCIIToUTF16("temp"),
2122 base::ASCIIToUTF16("new_pw"));
2123 }
2124
2023 } // namespace password_manager 2125 } // namespace password_manager
2024
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698