Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/password_manager/password_manager_test_base.h" | 7 #include "chrome/browser/password_manager/password_manager_test_base.h" |
| 8 #include "chrome/browser/password_manager/password_store_factory.h" | 8 #include "chrome/browser/password_manager/password_store_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 // Enable 'auto signin' for the profile. | 137 // Enable 'auto signin' for the profile. |
| 138 password_bubble_experiment::RecordAutoSignInPromptFirstRunExperienceWasShown( | 138 password_bubble_experiment::RecordAutoSignInPromptFirstRunExperienceWasShown( |
| 139 browser()->profile()->GetPrefs()); | 139 browser()->profile()->GetPrefs()); |
| 140 | 140 |
| 141 NavigateToFile("/password/password_form.html"); | 141 NavigateToFile("/password/password_form.html"); |
| 142 std::string fill_password = | 142 std::string fill_password = |
| 143 "document.getElementById('username_field').value = 'trash';" | 143 "document.getElementById('username_field').value = 'trash';" |
| 144 "document.getElementById('password_field').value = 'trash';"; | 144 "document.getElementById('password_field').value = 'trash';"; |
| 145 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password)); | 145 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password)); |
| 146 | 146 |
| 147 // Call the API with a delay to trigger the notification to the client. The | 147 // Call the API to trigger the notification to the client. |
| 148 // delay ensures that parsing password forms won't happen again after the API | |
| 149 // call making the test flaky. | |
| 150 ASSERT_TRUE(content::ExecuteScript( | 148 ASSERT_TRUE(content::ExecuteScript( |
| 151 RenderViewHost(), | 149 RenderViewHost(), |
| 152 "setTimeout( function() {" | 150 "navigator.credentials.get({password: true})" |
| 153 "navigator.credentials.get({password: true})" | 151 ".then(cred => window.location = '/password/done.html');")); |
| 154 ".then(cred => window.location = '/password/done.html');" | |
| 155 "}, 1000)")); | |
| 156 | 152 |
| 157 NavigationObserver observer(WebContents()); | 153 NavigationObserver observer(WebContents()); |
| 158 observer.SetPathToWaitFor("/password/done.html"); | 154 observer.SetPathToWaitFor("/password/done.html"); |
| 159 observer.Wait(); | 155 observer.Wait(); |
| 160 | 156 |
| 161 std::unique_ptr<BubbleObserver> prompt_observer( | 157 std::unique_ptr<BubbleObserver> prompt_observer( |
| 162 new BubbleObserver(WebContents())); | 158 new BubbleObserver(WebContents())); |
| 163 // The autofill password manager shouldn't react to the successful login. | 159 // The autofill password manager shouldn't react to the successful login |
| 160 // because it was suppressed when the site fot the credential back. | |
|
kolos1
2016/08/04 09:18:34
fot->got?
vasilii
2016/08/04 09:31:21
Done.
| |
| 164 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 161 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); |
| 165 } | 162 } |
| 166 | 163 |
| 167 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) { | 164 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) { |
| 168 NavigateToFile("/password/password_form.html"); | 165 NavigateToFile("/password/password_form.html"); |
| 169 | 166 |
| 170 // Postpone a submit event for 1 second. Even for the static html page Chrome | |
| 171 // continues to parse and recreate the PasswordFormManager instances after the | |
| 172 // page load. Calling the API before this would make the test flaky. Clicking | |
| 173 // on the button emulates server analysing the credential and then saving and | |
| 174 // navigating to the landing page. | |
| 175 ASSERT_TRUE(content::ExecuteScript( | 167 ASSERT_TRUE(content::ExecuteScript( |
| 176 RenderViewHost(), | 168 RenderViewHost(), |
| 177 "document.getElementById('input_submit_button').addEventListener('click'," | 169 "document.getElementById('input_submit_button').addEventListener('click'," |
| 178 "function(event) {" | 170 "function(event) {" |
| 179 "setTimeout( function() {" | 171 "var c = new PasswordCredential({ id: 'user', password: 'API' });" |
| 180 "var c = new PasswordCredential({ id: 'user', password: 'API' });" | 172 "navigator.credentials.store(c);" |
| 181 "navigator.credentials.store(c);" | |
| 182 "document.getElementById('testform').submit();" | |
| 183 "}, 1000 );" | |
| 184 "event.preventDefault();" | |
| 185 "});")); | 173 "});")); |
| 186 // Fill the password and click the button to submit the page later. The API | 174 // Fill the password and click the button to submit the page. The API should |
| 187 // should suppress the autofill password manager. | 175 // suppress the autofill password manager. |
| 188 NavigationObserver form_submit_observer(WebContents()); | 176 NavigationObserver form_submit_observer(WebContents()); |
| 189 ASSERT_TRUE(content::ExecuteScript( | 177 ASSERT_TRUE(content::ExecuteScript( |
| 190 RenderViewHost(), | 178 RenderViewHost(), |
| 191 "document.getElementById('username_field').value = 'user';" | 179 "document.getElementById('username_field').value = 'user';" |
| 192 "document.getElementById('password_field').value = 'autofill';" | 180 "document.getElementById('password_field').value = 'autofill';" |
| 193 "document.getElementById('input_submit_button').click();")); | 181 "document.getElementById('input_submit_button').click();")); |
| 194 form_submit_observer.Wait(); | 182 form_submit_observer.Wait(); |
| 195 | 183 |
| 196 WaitForPasswordStore(); | 184 WaitForPasswordStore(); |
| 197 std::unique_ptr<BubbleObserver> prompt_observer( | 185 std::unique_ptr<BubbleObserver> prompt_observer( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 225 signin_form.signon_realm = embedded_test_server()->base_url().spec(); | 213 signin_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 226 signin_form.password_value = base::ASCIIToUTF16("old_pass"); | 214 signin_form.password_value = base::ASCIIToUTF16("old_pass"); |
| 227 signin_form.username_value = base::ASCIIToUTF16("user"); | 215 signin_form.username_value = base::ASCIIToUTF16("user"); |
| 228 signin_form.origin = embedded_test_server()->base_url(); | 216 signin_form.origin = embedded_test_server()->base_url(); |
| 229 signin_form.skip_zero_click = true; | 217 signin_form.skip_zero_click = true; |
| 230 signin_form.preferred = true; | 218 signin_form.preferred = true; |
| 231 password_store->AddLogin(signin_form); | 219 password_store->AddLogin(signin_form); |
| 232 | 220 |
| 233 NavigateToFile("/password/password_form.html"); | 221 NavigateToFile("/password/password_form.html"); |
| 234 | 222 |
| 235 // Postpone a submit event for 1 second. Even for the static html page Chrome | |
| 236 // continues to parse and recreate the PasswordFormManager instances after the | |
| 237 // page load. Calling the API before this would make the test flaky. Clicking | |
| 238 // on the button emulates server analysing the credential and then saving and | |
| 239 // navigating to the landing page. | |
| 240 ASSERT_TRUE(content::ExecuteScript( | 223 ASSERT_TRUE(content::ExecuteScript( |
| 241 RenderViewHost(), | 224 RenderViewHost(), |
| 242 "document.getElementById('input_submit_button').addEventListener('click'," | 225 "document.getElementById('input_submit_button').addEventListener('click'," |
| 243 "function(event) {" | 226 "function(event) {" |
| 244 "setTimeout( function() {" | 227 "var c = new PasswordCredential({ id: 'user', password: 'API' });" |
| 245 "var c = new PasswordCredential({ id: 'user', password: 'API' });" | 228 "navigator.credentials.store(c);" |
| 246 "navigator.credentials.store(c);" | |
| 247 "document.getElementById('testform').submit();" | |
| 248 "}, 1000 );" | |
| 249 "event.preventDefault();" | |
| 250 "});")); | 229 "});")); |
| 251 // Fill the new password and click the button to submit the page later. The | 230 // Fill the new password and click the button to submit the page later. The |
| 252 // API should suppress the autofill password manager and overwrite the | 231 // API should suppress the autofill password manager and overwrite the |
| 253 // password. | 232 // password. |
| 254 NavigationObserver form_submit_observer(WebContents()); | 233 NavigationObserver form_submit_observer(WebContents()); |
| 255 ASSERT_TRUE(content::ExecuteScript( | 234 ASSERT_TRUE(content::ExecuteScript( |
| 256 RenderViewHost(), | 235 RenderViewHost(), |
| 257 "document.getElementById('username_field').value = 'user';" | 236 "document.getElementById('username_field').value = 'user';" |
| 258 "document.getElementById('password_field').value = 'autofill';" | 237 "document.getElementById('password_field').value = 'autofill';" |
| 259 "document.getElementById('input_submit_button').click();")); | 238 "document.getElementById('input_submit_button').click();")); |
| 260 form_submit_observer.Wait(); | 239 form_submit_observer.Wait(); |
| 261 | 240 |
| 262 // Wait for the password store before checking the prompt because it pops up | 241 // Wait for the password store before checking the prompt because it pops up |
| 263 // after the store replies. | 242 // after the store replies. |
| 264 WaitForPasswordStore(); | 243 WaitForPasswordStore(); |
| 265 std::unique_ptr<BubbleObserver> prompt_observer( | 244 std::unique_ptr<BubbleObserver> prompt_observer( |
| 266 new BubbleObserver(WebContents())); | 245 new BubbleObserver(WebContents())); |
| 267 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 246 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); |
| 268 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); | 247 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); |
| 269 signin_form.skip_zero_click = false; | 248 signin_form.skip_zero_click = false; |
| 270 signin_form.times_used = 1; | 249 signin_form.times_used = 1; |
| 271 signin_form.password_value = base::ASCIIToUTF16("API"); | 250 signin_form.password_value = base::ASCIIToUTF16("API"); |
| 272 password_manager::TestPasswordStore::PasswordMap stored = | 251 password_manager::TestPasswordStore::PasswordMap stored = |
| 273 password_store->stored_passwords(); | 252 password_store->stored_passwords(); |
| 274 ASSERT_EQ(1u, stored.size()); | 253 ASSERT_EQ(1u, stored.size()); |
| 275 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 254 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
| 276 } | 255 } |
| 277 | 256 |
| 278 } // namespace | 257 } // namespace |
| OLD | NEW |