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

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

Issue 1271053002: [PasswordManager] Fix Flaky BrowserTest related to dynamically created (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 PromptObserver::Create(WebContents())); 224 PromptObserver::Create(WebContents()));
225 std::string fill_and_submit = 225 std::string fill_and_submit =
226 "document.getElementById('username_field').value = 'temp';" 226 "document.getElementById('username_field').value = 'temp';"
227 "document.getElementById('password_field').value = 'random';" 227 "document.getElementById('password_field').value = 'random';"
228 "document.getElementById('submit_button').click()"; 228 "document.getElementById('submit_button').click()";
229 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 229 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
230 observer.Wait(); 230 observer.Wait();
231 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); 231 EXPECT_TRUE(prompt_observer->IsShowingPrompt());
232 } 232 }
233 233
234 // Flaky: crbug.com/301547, observed on win and mac. Probably happens on all 234 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForDynamicForm) {
235 // platforms.
236 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
237 DISABLED_PromptForDynamicForm) {
238 NavigateToFile("/password/dynamic_password_form.html"); 235 NavigateToFile("/password/dynamic_password_form.html");
239 236
237 // Create password form.
vabr (Chromium) 2015/08/05 08:37:35 nit: This comment is not necessary, you named the
xunlu 2015/08/05 18:37:12 Done.
238 std::string create_form =
239 "document.getElementById('create_form_button').click();";
240 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), create_form));
241
242 // Make sure PasswordStore::GetLogins() returned before submitting the form.
vabr (Chromium) 2015/08/05 08:37:35 This comment can be misunderstood. The observer sa
xunlu 2015/08/05 18:37:12 Your version is much more clear, thanks! Done
243 password_manager::TestPasswordStore* password_store =
vabr (Chromium) 2015/08/05 08:37:35 (1) You do not need TestPasswordStore interface, j
xunlu 2015/08/05 18:37:12 Done.
244 static_cast<password_manager::TestPasswordStore*>(
245 PasswordStoreFactory::GetForProfile(
246 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
247 PasswordStoreObserver store_observer(password_store);
248 store_observer.Wait();
249
240 // Fill the dynamic password form and submit. 250 // Fill the dynamic password form and submit.
241 NavigationObserver observer(WebContents()); 251 NavigationObserver observer(WebContents());
242 scoped_ptr<PromptObserver> prompt_observer( 252 scoped_ptr<PromptObserver> prompt_observer(
243 PromptObserver::Create(WebContents())); 253 PromptObserver::Create(WebContents()));
244 std::string fill_and_submit = 254 std::string fill_and_submit =
245 "document.getElementById('create_form_button').click();"
246 "window.setTimeout(function() {" 255 "window.setTimeout(function() {"
247 " document.dynamic_form.username.value = 'tempro';" 256 " document.dynamic_form.username.value = 'tempro';"
248 " document.dynamic_form.password.value = 'random';" 257 " document.dynamic_form.password.value = 'random';"
249 " document.dynamic_form.submit();" 258 " document.dynamic_form.submit();"
250 "}, 0)"; 259 "}, 0)";
251 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 260 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
252 observer.Wait(); 261 observer.Wait();
253 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); 262 EXPECT_TRUE(prompt_observer->IsShowingPrompt());
254 } 263 }
255 264
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 // needed for autofilling fields. 1395 // needed for autofilling fields.
1387 content::SimulateMouseClickAt( 1396 content::SimulateMouseClickAt(
1388 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); 1397 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
1389 1398
1390 // Wait until that interaction causes the password value to be revealed. 1399 // Wait until that interaction causes the password value to be revealed.
1391 WaitForElementValue("password", "mypassword"); 1400 WaitForElementValue("password", "mypassword");
1392 } 1401 }
1393 1402
1394 // Test that if a form gets autofilled, then it gets autofilled on re-creation 1403 // Test that if a form gets autofilled, then it gets autofilled on re-creation
1395 // as well. 1404 // as well.
1396 // TODO(vabr): This is flaky everywhere. http://crbug.com/442704
1397 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1405 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1398 DISABLED_ReCreatedFormsGetFilled) { 1406 ReCreatedFormsGetFilled) {
1399 NavigateToFile("/password/dynamic_password_form.html"); 1407 NavigateToFile("/password/dynamic_password_form.html");
1400 1408
1409 // Create password form.
1410 std::string create_form =
1411 "document.getElementById('create_form_button').click();";
1412 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), create_form));
1413
1414 // Make sure PasswordStore::GetLogins() returned before submitting form.
1415 password_manager::TestPasswordStore* password_store =
1416 static_cast<password_manager::TestPasswordStore*>(
1417 PasswordStoreFactory::GetForProfile(
1418 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
1419 PasswordStoreObserver store_observer(password_store);
1420 store_observer.Wait();
1421
1401 // Fill in the credentials, and make sure they are saved. 1422 // Fill in the credentials, and make sure they are saved.
1402 NavigationObserver form_submit_observer(WebContents()); 1423 NavigationObserver form_submit_observer(WebContents());
1403 scoped_ptr<PromptObserver> prompt_observer( 1424 scoped_ptr<PromptObserver> prompt_observer(
1404 PromptObserver::Create(WebContents())); 1425 PromptObserver::Create(WebContents()));
1405 std::string create_fill_and_submit = 1426 std::string fill_and_submit =
1406 "document.getElementById('create_form_button').click();"
1407 "window.setTimeout(function() {" 1427 "window.setTimeout(function() {"
1408 " var form = document.getElementById('dynamic_form_id');" 1428 " var form = document.getElementById('dynamic_form_id');"
1409 " form.username.value = 'temp';" 1429 " form.username.value = 'temp';"
1410 " form.password.value = 'random';" 1430 " form.password.value = 'random';"
1411 " form.submit();" 1431 " form.submit();"
1412 "}, 0)"; 1432 "}, 0)";
1413 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), create_fill_and_submit)); 1433 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1414 form_submit_observer.Wait(); 1434 form_submit_observer.Wait();
1415 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); 1435 EXPECT_TRUE(prompt_observer->IsShowingPrompt());
1416 prompt_observer->Accept(); 1436 prompt_observer->Accept();
1417 1437
1418 // Reload the original page to have the saved credentials autofilled. 1438 // Reload the original page to have the saved credentials autofilled.
1419 NavigationObserver reload_observer(WebContents()); 1439 NavigationObserver reload_observer(WebContents());
1420 NavigateToFile("/password/dynamic_password_form.html"); 1440 NavigateToFile("/password/dynamic_password_form.html");
1421 reload_observer.Wait(); 1441 reload_observer.Wait();
1422 std::string create_form =
1423 "document.getElementById('create_form_button').click();";
1424 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), create_form)); 1442 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), create_form));
1425 // Wait until the username is filled, to make sure autofill kicked in. 1443 // Wait until the username is filled, to make sure autofill kicked in.
1426 WaitForElementValue("username_id", "temp"); 1444 WaitForElementValue("username_id", "temp");
1427 1445
1428 // Now the form gets deleted and created again. It should get autofilled 1446 // Now the form gets deleted and created again. It should get autofilled
1429 // again. 1447 // again.
1430 std::string delete_form = 1448 std::string delete_form =
1431 "var form = document.getElementById('dynamic_form_id');" 1449 "var form = document.getElementById('dynamic_form_id');"
1432 "form.parentNode.removeChild(form);"; 1450 "form.parentNode.removeChild(form);";
1433 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), delete_form)); 1451 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), delete_form));
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 top + 1)); 1972 top + 1));
1955 // Verify password has been autofilled 1973 // Verify password has been autofilled
1956 WaitForElementValue("iframe", "password_field", "pa55w0rd"); 1974 WaitForElementValue("iframe", "password_field", "pa55w0rd");
1957 1975
1958 // Verify username has been autofilled 1976 // Verify username has been autofilled
1959 CheckElementValue("iframe", "username_field", "temp"); 1977 CheckElementValue("iframe", "username_field", "temp");
1960 1978
1961 } 1979 }
1962 1980
1963 } // namespace password_manager 1981 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698