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

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: 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 class PasswordStoreSyncer : public password_manager::PasswordStoreConsumer {
vabr (Chromium) 2016/07/21 13:19:54 nit: The "Syncer" in the name may confuse the read
vasilii 2016/07/21 13:48:33 Done.
21 public:
22 PasswordStoreSyncer() = default;
23
24 void OnGetPasswordStoreResults(
25 ScopedVector<autofill::PasswordForm> results) override {
26 run_loop_.Quit();
27 }
28
29 void Wait() {
30 run_loop_.Run();
31 }
32
33 private:
34 base::RunLoop run_loop_;
35
36 DISALLOW_COPY_AND_ASSIGN(PasswordStoreSyncer);
37 };
38
19 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { 39 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase {
20 public: 40 public:
21 CredentialManagerBrowserTest() = default; 41 CredentialManagerBrowserTest() = default;
22 42
23 bool IsShowingAccountChooser() { 43 bool IsShowingAccountChooser() {
24 return PasswordsModelDelegateFromWebContents(WebContents())->GetState() == 44 return PasswordsModelDelegateFromWebContents(WebContents())->GetState() ==
25 password_manager::ui::CREDENTIAL_REQUEST_STATE; 45 password_manager::ui::CREDENTIAL_REQUEST_STATE;
26 } 46 }
27 47
48 void SyncPasswordStore() {
vabr (Chromium) 2016/07/21 13:19:54 nit: What about WaitForStoreResults to avoid the c
vasilii 2016/07/21 13:48:33 Done.
49 scoped_refptr<password_manager::PasswordStore> password_store =
50 PasswordStoreFactory::GetForProfile(
51 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS);
52 PasswordStoreSyncer syncer;
53 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer);
54 syncer.Wait();
55 }
56
28 private: 57 private:
29 net::EmbeddedTestServer https_test_server_;
30 58
31 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest); 59 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest);
32 }; 60 };
33 61
34 // Tests. 62 // Tests.
35 63
36 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, 64 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
37 AccountChooserWithOldCredentialAndNavigation) { 65 AccountChooserWithOldCredentialAndNavigation) {
38 // Save credentials with 'skip_zero_click'. 66 // Save credentials with 'skip_zero_click'.
39 scoped_refptr<password_manager::TestPasswordStore> password_store = 67 scoped_refptr<password_manager::TestPasswordStore> password_store =
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 prompt_observer->Dismiss(); 178 prompt_observer->Dismiss();
151 179
152 NavigationObserver form_submit_observer(WebContents()); 180 NavigationObserver form_submit_observer(WebContents());
153 ASSERT_TRUE(content::ExecuteScript( 181 ASSERT_TRUE(content::ExecuteScript(
154 RenderViewHost(), 182 RenderViewHost(),
155 "document.getElementById('input_submit_button').click();")); 183 "document.getElementById('input_submit_button').click();"));
156 form_submit_observer.Wait(); 184 form_submit_observer.Wait();
157 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 185 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
158 } 186 }
159 187
160 // Disabled due to flakes; see https://crbug.com/629459. 188 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. 189 // Save credentials with 'skip_zero_click' false.
164 scoped_refptr<password_manager::TestPasswordStore> password_store = 190 scoped_refptr<password_manager::TestPasswordStore> password_store =
165 static_cast<password_manager::TestPasswordStore*>( 191 static_cast<password_manager::TestPasswordStore*>(
166 PasswordStoreFactory::GetForProfile( 192 PasswordStoreFactory::GetForProfile(
167 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 193 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
168 .get()); 194 .get());
169 autofill::PasswordForm signin_form; 195 autofill::PasswordForm signin_form;
170 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 196 signin_form.signon_realm = embedded_test_server()->base_url().spec();
171 signin_form.password_value = base::ASCIIToUTF16("12345"); 197 signin_form.password_value = base::ASCIIToUTF16("old_pass");
172 signin_form.username_value = base::ASCIIToUTF16("user"); 198 signin_form.username_value = base::ASCIIToUTF16("user");
173 signin_form.origin = embedded_test_server()->base_url(); 199 signin_form.origin = embedded_test_server()->base_url();
174 signin_form.skip_zero_click = true; 200 signin_form.skip_zero_click = true;
175 signin_form.preferred = true; 201 signin_form.preferred = true;
176 password_store->AddLogin(signin_form); 202 password_store->AddLogin(signin_form);
177 203
178 NavigateToFile("/password/password_form.html"); 204 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 205
184 // Call the API to update the form. 206 // Postpone a submit event for 1second. Even for the static html page Chrome
vabr (Chromium) 2016/07/21 13:19:54 typo: 1second -> 1 second
vasilii 2016/07/21 13:48:33 Done.
207 // continues to parse and recreate the PasswordFormManager instances after the
208 // page load. Calling the API before this would make the test flaky. Clicking
209 // on the button emulates server analysing the credential and then saving and
vabr (Chromium) 2016/07/21 13:19:54 nit: 2 spaces before "and" -> 1 space
vasilii 2016/07/21 13:48:33 Done.
210 // navigating to the landing page.
185 ASSERT_TRUE(content::ExecuteScript( 211 ASSERT_TRUE(content::ExecuteScript(
186 RenderViewHost(), 212 RenderViewHost(),
187 "var c = new PasswordCredential({ id: 'user', password: '12345' });" 213 "document.getElementById('input_submit_button').addEventListener('click',"
188 "navigator.credentials.store(c);")); 214 "function(event) {"
215 "setTimeout( function() {"
216 "var c = new PasswordCredential({ id: 'user', password: 'API' });"
217 "navigator.credentials.store(c);"
218 "document.getElementById('testform').submit();"
219 "}, 1000 );"
220 "event.preventDefault();"
221 "});"));
222 // Fill the new password and click the button to submit the page later. The
223 // API should suppress the autofill password manager and overwrite the
224 // password.
225 NavigationObserver form_submit_observer(WebContents());
226 ASSERT_TRUE(content::ExecuteScript(
227 RenderViewHost(),
228 "document.getElementById('username_field').value = 'user';"
229 "document.getElementById('password_field').value = 'autofill';"
230 "document.getElementById('input_submit_button').click();"));
231 form_submit_observer.Wait();
232
189 std::unique_ptr<BubbleObserver> prompt_observer( 233 std::unique_ptr<BubbleObserver> prompt_observer(
190 new BubbleObserver(WebContents())); 234 new BubbleObserver(WebContents()));
191 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 235 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
192 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 236 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
237 SyncPasswordStore();
193 signin_form.skip_zero_click = false; 238 signin_form.skip_zero_click = false;
194 signin_form.times_used = 1; 239 signin_form.times_used = 1;
240 signin_form.password_value = base::ASCIIToUTF16("API");
195 password_manager::TestPasswordStore::PasswordMap stored = 241 password_manager::TestPasswordStore::PasswordMap stored =
196 password_store->stored_passwords(); 242 password_store->stored_passwords();
197 ASSERT_EQ(1u, stored.size()); 243 ASSERT_EQ(1u, stored.size());
198 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); 244 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 } 245 }
213 246
214 } // namespace 247 } // 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