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

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

Issue 2913193002: Enable PasswordManagerBrowserTestBase.UsernameChanged (Closed)
Patch Set: Created 3 years, 6 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 | chrome/browser/password_manager/password_manager_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/run_loop.h"
6 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/password_manager/password_manager_test_base.h" 6 #include "chrome/browser/password_manager/password_manager_test_base.h"
8 #include "chrome/browser/password_manager/password_store_factory.h" 7 #include "chrome/browser/password_manager/password_store_factory.h"
9 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "components/password_manager/core/browser/test_password_store.h" 10 #include "components/password_manager/core/browser/test_password_store.h"
11 #include "content/public/test/browser_test_utils.h" 11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/test_utils.h" 12 #include "content/public/test/test_utils.h"
13 #include "ui/events/keycodes/keyboard_codes.h" 13 #include "ui/events/keycodes/keyboard_codes.h"
14 14
15 namespace { 15 namespace {
16 16
17 void SimulateUserTypingInField(content::RenderViewHost* render_view_host, 17 void SimulateUserTypingInField(content::RenderViewHost* render_view_host,
18 content::WebContents* web_contents, 18 content::WebContents* web_contents,
19 const std::string& field_id) { 19 const std::string& field_id) {
(...skipping 14 matching lines...) Expand all
34 false); 34 false);
35 content::SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('Y'), 35 content::SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('Y'),
36 ui::DomCode::US_Y, ui::VKEY_Y, false, false, false, 36 ui::DomCode::US_Y, ui::VKEY_Y, false, false, false,
37 false); 37 false);
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 namespace password_manager { 42 namespace password_manager {
43 43
44 // TODO(crbug.com/616627): Flaky on Mac, CrOS and Linux. 44 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, UsernameChanged) {
45 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(OS_LINUX) 45 // At first let us save a credential to the password store.
46 #define MAYBE_UsernameChanged DISABLED_UsernameChanged
47 #else
48 #define MAYBE_UsernameChanged UsernameChanged
49 #endif
50 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, MAYBE_UsernameChanged) {
51 scoped_refptr<password_manager::TestPasswordStore> password_store = 46 scoped_refptr<password_manager::TestPasswordStore> password_store =
52 static_cast<password_manager::TestPasswordStore*>( 47 static_cast<password_manager::TestPasswordStore*>(
53 PasswordStoreFactory::GetForProfile( 48 PasswordStoreFactory::GetForProfile(
54 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); 49 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
50 autofill::PasswordForm signin_form;
51 signin_form.signon_realm = embedded_test_server()->base_url().spec();
52 signin_form.origin = embedded_test_server()->base_url();
53 signin_form.username_value = base::ASCIIToUTF16("temp");
54 signin_form.password_value = base::ASCIIToUTF16("random");
55 password_store->AddLogin(signin_form);
55 56
57 // Load the page to have the saved credentials autofilled.
56 NavigateToFile("/password/signup_form.html"); 58 NavigateToFile("/password/signup_form.html");
57 59
58 NavigationObserver observer(WebContents());
59 std::unique_ptr<BubbleObserver> prompt_observer(
60 new BubbleObserver(WebContents()));
61 std::string fill_and_submit =
62 "document.getElementById('username_field').value = 'temp';"
63 "document.getElementById('password_field').value = 'random';"
64 "document.getElementById('input_submit_button').click()";
65 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
66 observer.Wait();
67 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt());
68 prompt_observer->AcceptSavePrompt();
69
70 // Spin the message loop to make sure the password store had a chance to save
71 // the password.
72 base::RunLoop run_loop;
73 run_loop.RunUntilIdle();
74 EXPECT_FALSE(password_store->IsEmpty());
75
76 // Reload the original page to have the saved credentials autofilled.
77 NavigationObserver reload_observer(WebContents());
78 NavigateToFile("/password/signup_form.html");
79 reload_observer.Wait();
80
81 // Let the user interact with the page, so that DOM gets modification events, 60 // Let the user interact with the page, so that DOM gets modification events,
82 // needed for autofilling fields. 61 // needed for autofilling fields.
83 content::SimulateMouseClickAt( 62 content::SimulateMouseClickAt(
84 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1)); 63 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1));
85 64
86 WaitForElementValue("username_field", "temp"); 65 WaitForElementValue("username_field", "temp");
87 WaitForElementValue("password_field", "random"); 66 WaitForElementValue("password_field", "random");
88 67
89 // Change username and submit. This should add the characters "ORARY" to the 68 // Change username and submit. This should add the characters "ORARY" to the
90 // already autofilled username. 69 // already autofilled username.
91 SimulateUserTypingInField(RenderViewHost(), WebContents(), "username_field"); 70 SimulateUserTypingInField(RenderViewHost(), WebContents(), "username_field");
92 // TODO(gcasto): Not sure why this click is required. 71
93 content::SimulateMouseClickAt( 72 // Move the focus out of the inputs before waiting because WaitForElementValue
94 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1)); 73 // uses "onchange" event. The event is triggered only when the control looses
74 // focus.
75 chrome::FocusLocationBar(browser());
95 WaitForElementValue("username_field", "tempORARY"); 76 WaitForElementValue("username_field", "tempORARY");
96 77
97 NavigationObserver second_observer(WebContents()); 78 NavigationObserver navigation_observer(WebContents());
98 std::unique_ptr<BubbleObserver> second_prompt_observer( 79 BubbleObserver prompt_observer(WebContents());
99 new BubbleObserver(WebContents()));
100 std::string submit = 80 std::string submit =
101 "document.getElementById('input_submit_button').click();"; 81 "document.getElementById('input_submit_button').click();";
102 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); 82 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit));
103 second_observer.Wait(); 83 navigation_observer.Wait();
104 EXPECT_TRUE(second_prompt_observer->IsShowingSavePrompt()); 84 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt());
105 second_prompt_observer->AcceptSavePrompt(); 85 prompt_observer.AcceptSavePrompt();
106 86
107 // Spin the message loop to make sure the password store had a chance to save 87 // Spin the message loop to make sure the password store had a chance to save
108 // the password. 88 // the password.
109 base::RunLoop third_run_loop; 89 WaitForPasswordStore();
110 third_run_loop.RunUntilIdle();
111 EXPECT_FALSE(password_store->IsEmpty()); 90 EXPECT_FALSE(password_store->IsEmpty());
112 91
113 // Verify that there are two saved password, the old password and the new 92 // Verify that there are two saved password, the old password and the new
114 // password. 93 // password.
115 password_manager::TestPasswordStore::PasswordMap stored_passwords = 94 password_manager::TestPasswordStore::PasswordMap stored_passwords =
116 password_store->stored_passwords(); 95 password_store->stored_passwords();
117 EXPECT_EQ(1u, stored_passwords.size()); 96 EXPECT_EQ(1u, stored_passwords.size());
118 EXPECT_EQ(2u, stored_passwords.begin()->second.size()); 97 EXPECT_EQ(2u, stored_passwords.begin()->second.size());
119 EXPECT_EQ(base::UTF8ToUTF16("temp"), 98 EXPECT_EQ(base::UTF8ToUTF16("temp"),
120 (stored_passwords.begin()->second)[0].username_value); 99 (stored_passwords.begin()->second)[0].username_value);
121 EXPECT_EQ(base::UTF8ToUTF16("tempORARY"), 100 EXPECT_EQ(base::UTF8ToUTF16("tempORARY"),
122 (stored_passwords.begin()->second)[1].username_value); 101 (stored_passwords.begin()->second)[1].username_value);
123 } 102 }
124 103
125 } // namespace password_manager 104 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_manager_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698