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

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

Issue 2169883002: Fix CredentialManagerBrowserTest.UpdateViaAPIAndAutofill flakiness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" 11 #include "chrome/browser/ui/passwords/passwords_model_delegate.h"
12 #include "components/password_manager/core/browser/password_bubble_experiment.h" 12 #include "components/password_manager/core/browser/password_bubble_experiment.h"
13 #include "components/password_manager/core/browser/password_store_consumer.h"
13 #include "components/password_manager/core/browser/test_password_store.h" 14 #include "components/password_manager/core/browser/test_password_store.h"
14 #include "content/public/test/browser_test.h" 15 #include "content/public/test/browser_test.h"
15 #include "content/public/test/browser_test_utils.h" 16 #include "content/public/test/browser_test_utils.h"
16 17
17 namespace { 18 namespace {
18 19
20 // A helper class that synchronously waits until the password store handles a
21 // GetLogins() request.
22 class PasswordStoreResultsObserver
23 : public password_manager::PasswordStoreConsumer {
24 public:
25 PasswordStoreResultsObserver() = default;
26
27 void OnGetPasswordStoreResults(
28 ScopedVector<autofill::PasswordForm> results) override {
29 run_loop_.Quit();
30 }
31
32 void Wait() {
33 run_loop_.Run();
34 }
35
36 private:
37 base::RunLoop run_loop_;
38
39 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver);
40 };
41
19 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { 42 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase {
20 public: 43 public:
21 CredentialManagerBrowserTest() = default; 44 CredentialManagerBrowserTest() = default;
22 45
23 bool IsShowingAccountChooser() { 46 bool IsShowingAccountChooser() {
24 return PasswordsModelDelegateFromWebContents(WebContents())->GetState() == 47 return PasswordsModelDelegateFromWebContents(WebContents())->GetState() ==
25 password_manager::ui::CREDENTIAL_REQUEST_STATE; 48 password_manager::ui::CREDENTIAL_REQUEST_STATE;
26 } 49 }
27 50
51 // Make sure that the password store processed all the previous calls which
52 // are executed on another thread.
53 void WaitForPasswordStore() {
54 scoped_refptr<password_manager::PasswordStore> password_store =
55 PasswordStoreFactory::GetForProfile(
56 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS);
57 PasswordStoreResultsObserver syncer;
58 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer);
59 syncer.Wait();
60 }
61
28 private: 62 private:
29 net::EmbeddedTestServer https_test_server_;
30 63
31 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest); 64 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest);
32 }; 65 };
33 66
34 // Tests. 67 // Tests.
35 68
36 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, 69 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
37 AccountChooserWithOldCredentialAndNavigation) { 70 AccountChooserWithOldCredentialAndNavigation) {
38 // Save credentials with 'skip_zero_click'. 71 // Save credentials with 'skip_zero_click'.
39 scoped_refptr<password_manager::TestPasswordStore> password_store = 72 scoped_refptr<password_manager::TestPasswordStore> password_store =
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 prompt_observer->Dismiss(); 183 prompt_observer->Dismiss();
151 184
152 NavigationObserver form_submit_observer(WebContents()); 185 NavigationObserver form_submit_observer(WebContents());
153 ASSERT_TRUE(content::ExecuteScript( 186 ASSERT_TRUE(content::ExecuteScript(
154 RenderViewHost(), 187 RenderViewHost(),
155 "document.getElementById('input_submit_button').click();")); 188 "document.getElementById('input_submit_button').click();"));
156 form_submit_observer.Wait(); 189 form_submit_observer.Wait();
157 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 190 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
158 } 191 }
159 192
160 // Disabled due to flakes; see https://crbug.com/629459. 193 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, UpdateViaAPIAndAutofill) {
161 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
162 DISABLED_UpdateViaAPIAndAutofill) {
163 // Save credentials with 'skip_zero_click' false. 194 // Save credentials with 'skip_zero_click' false.
164 scoped_refptr<password_manager::TestPasswordStore> password_store = 195 scoped_refptr<password_manager::TestPasswordStore> password_store =
165 static_cast<password_manager::TestPasswordStore*>( 196 static_cast<password_manager::TestPasswordStore*>(
166 PasswordStoreFactory::GetForProfile( 197 PasswordStoreFactory::GetForProfile(
167 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 198 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
168 .get()); 199 .get());
169 autofill::PasswordForm signin_form; 200 autofill::PasswordForm signin_form;
170 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 201 signin_form.signon_realm = embedded_test_server()->base_url().spec();
171 signin_form.password_value = base::ASCIIToUTF16("12345"); 202 signin_form.password_value = base::ASCIIToUTF16("old_pass");
172 signin_form.username_value = base::ASCIIToUTF16("user"); 203 signin_form.username_value = base::ASCIIToUTF16("user");
173 signin_form.origin = embedded_test_server()->base_url(); 204 signin_form.origin = embedded_test_server()->base_url();
174 signin_form.skip_zero_click = true; 205 signin_form.skip_zero_click = true;
175 signin_form.preferred = true; 206 signin_form.preferred = true;
176 password_store->AddLogin(signin_form); 207 password_store->AddLogin(signin_form);
177 208
178 NavigateToFile("/password/password_form.html"); 209 NavigateToFile("/password/password_form.html");
179 std::string fill_password =
180 "document.getElementById('username_field').value = 'user';"
181 "document.getElementById('password_field').value = '12345';";
182 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password));
183 210
184 // Call the API to update the form. 211 // Postpone a submit event for 1 second. Even for the static html page Chrome
212 // continues to parse and recreate the PasswordFormManager instances after the
213 // page load. Calling the API before this would make the test flaky. Clicking
214 // on the button emulates server analysing the credential and then saving and
215 // navigating to the landing page.
185 ASSERT_TRUE(content::ExecuteScript( 216 ASSERT_TRUE(content::ExecuteScript(
186 RenderViewHost(), 217 RenderViewHost(),
187 "var c = new PasswordCredential({ id: 'user', password: '12345' });" 218 "document.getElementById('input_submit_button').addEventListener('click',"
188 "navigator.credentials.store(c);")); 219 "function(event) {"
220 "setTimeout( function() {"
221 "var c = new PasswordCredential({ id: 'user', password: 'API' });"
222 "navigator.credentials.store(c);"
223 "document.getElementById('testform').submit();"
224 "}, 1000 );"
225 "event.preventDefault();"
226 "});"));
227 // Fill the new password and click the button to submit the page later. The
228 // API should suppress the autofill password manager and overwrite the
229 // password.
230 NavigationObserver form_submit_observer(WebContents());
231 ASSERT_TRUE(content::ExecuteScript(
232 RenderViewHost(),
233 "document.getElementById('username_field').value = 'user';"
234 "document.getElementById('password_field').value = 'autofill';"
235 "document.getElementById('input_submit_button').click();"));
236 form_submit_observer.Wait();
237
189 std::unique_ptr<BubbleObserver> prompt_observer( 238 std::unique_ptr<BubbleObserver> prompt_observer(
190 new BubbleObserver(WebContents())); 239 new BubbleObserver(WebContents()));
191 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 240 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
192 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 241 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
242 WaitForPasswordStore();
193 signin_form.skip_zero_click = false; 243 signin_form.skip_zero_click = false;
194 signin_form.times_used = 1; 244 signin_form.times_used = 1;
245 signin_form.password_value = base::ASCIIToUTF16("API");
195 password_manager::TestPasswordStore::PasswordMap stored = 246 password_manager::TestPasswordStore::PasswordMap stored =
196 password_store->stored_passwords(); 247 password_store->stored_passwords();
197 ASSERT_EQ(1u, stored.size()); 248 ASSERT_EQ(1u, stored.size());
198 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); 249 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]);
199
200 // Verify that the autofill password manager was suppressed and didn't touch
201 // the store. It would definitely update the '*_element' fields.
202 NavigationObserver form_submit_observer(WebContents());
203 ASSERT_TRUE(content::ExecuteScript(
204 RenderViewHost(),
205 "document.getElementById('input_submit_button').click();"));
206 form_submit_observer.Wait();
207 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
208 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
209 stored = password_store->stored_passwords();
210 ASSERT_EQ(1u, stored.size());
211 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]);
212 } 250 }
213 251
214 } // namespace 252 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698