OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/utf_string_conversions.h" | |
6 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
8 #include "chrome/browser/password_manager/password_manager_test_base.h" | |
9 #include "chrome/browser/password_manager/password_store_factory.h" | |
7 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" | 11 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" |
9 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
13 #include "components/autofill/core/browser/autofill_test_utils.h" | 16 #include "components/autofill/core/browser/autofill_test_utils.h" |
14 #include "components/autofill/core/common/autofill_switches.h" | 17 #include "components/autofill/core/common/autofill_switches.h" |
15 #include "components/password_manager/core/browser/password_generation_manager.h " | 18 #include "components/password_manager/core/browser/password_generation_manager.h " |
19 #include "components/password_manager/core/browser/test_password_store.h" | |
16 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
18 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
19 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/events/keycodes/keyboard_codes.h" | 25 #include "ui/events/keycodes/keyboard_codes.h" |
22 | 26 |
23 namespace { | 27 namespace { |
24 | 28 |
25 class TestPopupObserver : public autofill::PasswordGenerationPopupObserver { | 29 class TestPopupObserver : public autofill::PasswordGenerationPopupObserver { |
(...skipping 13 matching lines...) Expand all Loading... | |
39 bool popup_showing() { return popup_showing_; } | 43 bool popup_showing() { return popup_showing_; } |
40 bool password_visible() { return password_visible_; } | 44 bool password_visible() { return password_visible_; } |
41 | 45 |
42 private: | 46 private: |
43 bool popup_showing_; | 47 bool popup_showing_; |
44 bool password_visible_; | 48 bool password_visible_; |
45 }; | 49 }; |
46 | 50 |
47 } // namespace | 51 } // namespace |
48 | 52 |
49 class PasswordGenerationInteractiveTest : public InProcessBrowserTest { | 53 class PasswordGenerationInteractiveTest : |
54 public PasswordManagerBrowserTestBase { | |
50 public: | 55 public: |
51 void SetUpCommandLine(base::CommandLine* command_line) override { | 56 void SetUpCommandLine(base::CommandLine* command_line) override { |
52 // Make sure the feature is enabled. | 57 // Make sure the feature is enabled. |
53 command_line->AppendSwitch(autofill::switches::kEnablePasswordGeneration); | 58 command_line->AppendSwitch(autofill::switches::kEnablePasswordGeneration); |
54 | 59 |
55 // Don't require ping from autofill or blacklist checking. | 60 // Don't require ping from autofill or blacklist checking. |
56 command_line->AppendSwitch( | 61 command_line->AppendSwitch( |
57 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); | 62 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); |
58 } | 63 } |
59 | 64 |
60 void SetUpOnMainThread() override { | 65 void SetUpOnMainThread() override { |
66 PasswordManagerBrowserTestBase::SetUpOnMainThread(); | |
67 | |
61 // Disable Autofill requesting access to AddressBook data. This will cause | 68 // Disable Autofill requesting access to AddressBook data. This will cause |
62 // the tests to hang on Mac. | 69 // the tests to hang on Mac. |
63 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs()); | 70 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs()); |
64 | 71 |
65 // Set observer for popup. | 72 // Set observer for popup. |
66 ChromePasswordManagerClient* client = | 73 ChromePasswordManagerClient* client = |
67 ChromePasswordManagerClient::FromWebContents(GetWebContents()); | 74 ChromePasswordManagerClient::FromWebContents(WebContents()); |
68 client->SetTestObserver(&observer_); | 75 client->SetTestObserver(&observer_); |
69 | 76 |
70 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 77 NavigateToFile("/password/signup_form.html"); |
71 GURL url = embedded_test_server()->GetURL("/password/signup_form.html"); | |
72 ui_test_utils::NavigateToURL(browser(), url); | |
73 } | 78 } |
74 | 79 |
75 void TearDownOnMainThread() override { | 80 void TearDownOnMainThread() override { |
81 PasswordManagerBrowserTestBase::TearDownOnMainThread(); | |
82 | |
76 // Clean up UI. | 83 // Clean up UI. |
77 ChromePasswordManagerClient* client = | 84 ChromePasswordManagerClient* client = |
78 ChromePasswordManagerClient::FromWebContents(GetWebContents()); | 85 ChromePasswordManagerClient::FromWebContents(WebContents()); |
79 client->HidePasswordGenerationPopup(); | 86 client->HidePasswordGenerationPopup(); |
80 } | 87 } |
81 | 88 |
82 content::WebContents* GetWebContents() { | |
83 return browser()->tab_strip_model()->GetActiveWebContents(); | |
84 } | |
85 | |
86 content::RenderViewHost* GetRenderViewHost() { | |
87 return GetWebContents()->GetRenderViewHost(); | |
88 } | |
89 | |
90 std::string GetFieldValue(const std::string& field_id) { | 89 std::string GetFieldValue(const std::string& field_id) { |
91 std::string value; | 90 std::string value; |
92 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 91 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
93 GetRenderViewHost(), | 92 RenderViewHost(), |
94 "window.domAutomationController.send(" | 93 "window.domAutomationController.send(" |
95 " document.getElementById('" + field_id + "').value);", | 94 " document.getElementById('" + field_id + "').value);", |
96 &value)); | 95 &value)); |
97 return value; | 96 return value; |
98 } | 97 } |
99 | 98 |
100 std::string GetFocusedElement() { | 99 std::string GetFocusedElement() { |
101 std::string focused_element; | 100 std::string focused_element; |
102 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 101 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
103 GetRenderViewHost(), | 102 RenderViewHost(), |
104 "window.domAutomationController.send(" | 103 "window.domAutomationController.send(" |
105 " document.activeElement.id)", | 104 " document.activeElement.id)", |
106 &focused_element)); | 105 &focused_element)); |
107 return focused_element; | 106 return focused_element; |
108 } | 107 } |
109 | 108 |
110 void FocusPasswordField() { | 109 void FocusPasswordField() { |
111 ASSERT_TRUE(content::ExecuteScript( | 110 ASSERT_TRUE(content::ExecuteScript( |
112 GetRenderViewHost(), | 111 RenderViewHost(), |
113 "document.getElementById('password_field').focus()")); | 112 "document.getElementById('password_field').focus()")); |
114 } | 113 } |
115 | 114 |
116 void SendKeyToPopup(ui::KeyboardCode key) { | 115 void SendKeyToPopup(ui::KeyboardCode key) { |
117 content::NativeWebKeyboardEvent event; | 116 content::NativeWebKeyboardEvent event; |
118 event.windowsKeyCode = key; | 117 event.windowsKeyCode = key; |
119 event.type = blink::WebKeyboardEvent::RawKeyDown; | 118 event.type = blink::WebKeyboardEvent::RawKeyDown; |
120 GetRenderViewHost()->ForwardKeyboardEvent(event); | 119 RenderViewHost()->ForwardKeyboardEvent(event); |
121 } | 120 } |
122 | 121 |
123 bool GenerationPopupShowing() { | 122 bool GenerationPopupShowing() { |
124 return observer_.popup_showing() && observer_.password_visible(); | 123 return observer_.popup_showing() && observer_.password_visible(); |
125 } | 124 } |
126 | 125 |
127 bool EditingPopupShowing() { | 126 bool EditingPopupShowing() { |
128 return observer_.popup_showing() && !observer_.password_visible(); | 127 return observer_.popup_showing() && !observer_.password_visible(); |
129 } | 128 } |
130 | 129 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 // Popup is dismissed. | 162 // Popup is dismissed. |
164 EXPECT_FALSE(GenerationPopupShowing()); | 163 EXPECT_FALSE(GenerationPopupShowing()); |
165 } | 164 } |
166 | 165 |
167 // Disabled due to flakiness due to resizes, see http://crbug.com/407998. | 166 // Disabled due to flakiness due to resizes, see http://crbug.com/407998. |
168 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, | 167 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, |
169 DISABLED_PopupShownAndDismissedByScrolling) { | 168 DISABLED_PopupShownAndDismissedByScrolling) { |
170 FocusPasswordField(); | 169 FocusPasswordField(); |
171 EXPECT_TRUE(GenerationPopupShowing()); | 170 EXPECT_TRUE(GenerationPopupShowing()); |
172 | 171 |
173 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), | 172 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
174 "window.scrollTo(100, 0);")); | 173 "window.scrollTo(100, 0);")); |
175 | 174 |
176 EXPECT_FALSE(GenerationPopupShowing()); | 175 EXPECT_FALSE(GenerationPopupShowing()); |
177 } | 176 } |
178 | 177 |
179 // Disabled due to flakiness due to resizes, see http://crbug.com/407998. | 178 // Disabled due to flakiness due to resizes, see http://crbug.com/407998. |
180 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, | 179 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, |
181 DISABLED_GenerationTriggeredInIFrame) { | 180 DISABLED_GenerationTriggeredInIFrame) { |
182 GURL url = embedded_test_server()->GetURL( | 181 NavigateToFile("/password/framed_signup_form.html"); |
183 "/password/framed_signup_form.html"); | |
184 ui_test_utils::NavigateToURL(browser(), url); | |
185 | 182 |
186 std::string focus_script = | 183 std::string focus_script = |
187 "var frame = document.getElementById('signup_iframe');" | 184 "var frame = document.getElementById('signup_iframe');" |
188 "var frame_doc = frame.contentDocument;" | 185 "var frame_doc = frame.contentDocument;" |
189 "frame_doc.getElementById('password_field').focus();"; | 186 "frame_doc.getElementById('password_field').focus();"; |
190 | 187 |
191 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), focus_script)); | 188 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), focus_script)); |
192 EXPECT_TRUE(GenerationPopupShowing()); | 189 EXPECT_TRUE(GenerationPopupShowing()); |
193 } | 190 } |
191 | |
192 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, | |
193 DISABLED_AutoSavingGeneratedPassword) { | |
vabr (Chromium)
2015/07/13 14:57:00
nit: Could you please add a bugtracker URL associa
Garrett Casto
2015/07/13 17:20:13
Done.
| |
194 password_manager::TestPasswordStore* password_store = | |
195 static_cast<password_manager::TestPasswordStore*>( | |
196 PasswordStoreFactory::GetForProfile( | |
197 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); | |
198 | |
199 FocusPasswordField(); | |
200 EXPECT_TRUE(GenerationPopupShowing()); | |
201 SendKeyToPopup(ui::VKEY_DOWN); | |
202 SendKeyToPopup(ui::VKEY_RETURN); | |
203 | |
204 // Change the action so that it looks like the submission failed. | |
vabr (Chromium)
2015/07/13 14:57:00
I'm confused -- where is the script below changing
Garrett Casto
2015/07/13 17:20:13
I have no idea what I was thinking when I wrote th
| |
205 NavigationObserver observer(WebContents()); | |
206 std::string submit_script = | |
207 "document.getElementById('username_field').value = 'something';" | |
208 "document.getElementById('input_submit_button').click()"; | |
209 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_script)); | |
210 observer.Wait(); | |
211 | |
212 // Spin the message loop to make sure the password store had a chance to save | |
213 // the password. | |
214 base::RunLoop run_loop; | |
215 run_loop.RunUntilIdle(); | |
216 EXPECT_FALSE(password_store->IsEmpty()); | |
217 | |
218 // Make sure the username is correct. | |
219 password_manager::TestPasswordStore::PasswordMap stored_passwords = | |
220 password_store->stored_passwords(); | |
221 EXPECT_EQ(1u, stored_passwords.size()); | |
222 EXPECT_EQ(1u, stored_passwords.begin()->second.size()); | |
223 EXPECT_EQ(base::UTF8ToUTF16("something"), | |
224 (stored_passwords.begin()->second)[0].username_value); | |
225 } | |
OLD | NEW |