OLD | NEW |
---|---|
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/strings/stringprintf.h" | |
10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
13 #include "chrome/browser/password_manager/test_password_store_service.h" | 14 #include "chrome/browser/password_manager/test_password_store_service.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/test_switches.h" | 19 #include "chrome/test/base/test_switches.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 167 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
167 | 168 |
168 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | 169 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( |
169 password_manager::switches::kEnableAutomaticPasswordSaving)); | 170 password_manager::switches::kEnableAutomaticPasswordSaving)); |
170 NavigationObserver observer(WebContents()); | 171 NavigationObserver observer(WebContents()); |
171 GURL url = embedded_test_server()->GetURL(path); | 172 GURL url = embedded_test_server()->GetURL(path); |
172 ui_test_utils::NavigateToURL(browser(), url); | 173 ui_test_utils::NavigateToURL(browser(), url); |
173 observer.Wait(); | 174 observer.Wait(); |
174 } | 175 } |
175 | 176 |
176 // Executes |script| and uses the EXPECT macros to check the return value | 177 // Waits until the "value" atribute of the HTML element with |element_id| is |
bartfab (slow)
2014/06/05 16:45:54
Nit: s/atribute/attribute/
vabr (Chromium)
2014/06/05 17:58:13
Done.
| |
177 // against |expected_return_value|. | 178 // equal to |expected_value|. |
178 void CheckScriptReturnValue(std::string& script, bool expected_return_value); | 179 void WaitForElementValue(const std::string& element_id, |
180 const std::string& expected_value); | |
179 | 181 |
180 private: | 182 private: |
181 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); | 183 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); |
182 }; | 184 }; |
183 | 185 |
184 void PasswordManagerBrowserTest::CheckScriptReturnValue( | 186 void PasswordManagerBrowserTest::WaitForElementValue( |
185 std::string& script, | 187 const std::string& element_id, |
186 bool expected_return_value) { | 188 const std::string& expected_value) { |
187 const std::string wrapped_script = | 189 enum ReturnCodes { // Possible results of the JavaScript code. |
188 std::string("window.domAutomationController.send(") + script + ");"; | 190 RETURN_CODE_OK, |
189 bool return_value = !expected_return_value; | 191 RETURN_CODE_NO_ELEMENT, |
190 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 192 RETURN_CODE_WRONG_VALUE, |
191 RenderViewHost(), wrapped_script, &return_value)); | 193 RETURN_CODE_INVALID }; |
192 EXPECT_EQ(expected_return_value, return_value) << "script = " << script; | 194 const std::string value_check_function = base::StringPrintf( |
195 "function valueCheck() {" | |
196 " var element = document.getElementById('%s');" | |
197 " return element && element.value == '%s';" | |
198 "}", | |
199 element_id.c_str(), | |
200 expected_value.c_str()); | |
201 const std::string script = | |
202 value_check_function + | |
203 base::StringPrintf( | |
204 "if (valueCheck()) {" | |
205 " window.domAutomationController.send(%d);" | |
206 "} else {" | |
207 " var element = document.getElementById('%s');" | |
208 " if (!element)" | |
209 " window.domAutomationController.send(%d);" | |
210 " element.onchange = function() {" | |
211 " if (valueCheck())" | |
212 " window.domAutomationController.send(%d);" | |
213 " else" | |
214 " window.domAutomationController.send(%d);" | |
215 " };" | |
216 "}", | |
217 RETURN_CODE_OK, | |
218 element_id.c_str(), | |
219 RETURN_CODE_NO_ELEMENT, | |
220 RETURN_CODE_OK, | |
221 RETURN_CODE_WRONG_VALUE); | |
222 int return_value = RETURN_CODE_INVALID; | |
223 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
224 RenderViewHost(), script, &return_value)); | |
225 EXPECT_EQ(RETURN_CODE_OK, return_value) | |
226 << "element_id = " << element_id | |
227 << ", expected_value = " << expected_value; | |
193 } | 228 } |
194 | 229 |
195 // Actual tests --------------------------------------------------------------- | 230 // Actual tests --------------------------------------------------------------- |
196 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 231 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
197 PromptForNormalSubmit) { | 232 PromptForNormalSubmit) { |
198 NavigateToFile("/password/password_form.html"); | 233 NavigateToFile("/password/password_form.html"); |
199 | 234 |
200 // Fill a form and submit through a <input type="submit"> button. Nothing | 235 // Fill a form and submit through a <input type="submit"> button. Nothing |
201 // special. | 236 // special. |
202 NavigationObserver observer(WebContents()); | 237 NavigationObserver observer(WebContents()); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 "document.getElementById('password_field').value = 'random';" | 621 "document.getElementById('password_field').value = 'random';" |
587 "document.getElementById('input_submit_button').click();" | 622 "document.getElementById('input_submit_button').click();" |
588 "window.location.href = 'done.html';"; | 623 "window.location.href = 'done.html';"; |
589 | 624 |
590 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), save_and_remove)); | 625 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), save_and_remove)); |
591 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); | 626 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
592 observer.Wait(); | 627 observer.Wait(); |
593 // The only thing we check here is that there is no use-after-free reported. | 628 // The only thing we check here is that there is no use-after-free reported. |
594 } | 629 } |
595 | 630 |
596 // Disabled on Windows due to flakiness: http://crbug.com/346297 | 631 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PasswordValueAccessible) { |
597 #if defined(OS_WIN) | |
598 #define MAYBE_PasswordValueAccessible DISABLED_PasswordValueAccessible | |
599 #else | |
600 #define MAYBE_PasswordValueAccessible PasswordValueAccessible | |
601 #endif | |
602 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | |
603 MAYBE_PasswordValueAccessible) { | |
604 NavigateToFile("/password/form_and_link.html"); | 632 NavigateToFile("/password/form_and_link.html"); |
605 | 633 |
606 // Click on a link to open a new tab, then switch back to the first one. | 634 // Click on a link to open a new tab, then switch back to the first one. |
607 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 635 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
608 std::string click = | 636 std::string click = |
609 "document.getElementById('testlink').click();"; | 637 "document.getElementById('testlink').click();"; |
610 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click)); | 638 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click)); |
611 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 639 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
612 browser()->tab_strip_model()->ActivateTabAt(0, false); | 640 browser()->tab_strip_model()->ActivateTabAt(0, false); |
613 | 641 |
614 // Fill in the credentials, and make sure they are saved. | 642 // Fill in the credentials, and make sure they are saved. |
615 NavigationObserver form_submit_observer(WebContents()); | 643 NavigationObserver form_submit_observer(WebContents()); |
616 std::string fill_and_submit = | 644 std::string fill_and_submit = |
617 "document.getElementById('username_field').value = 'temp';" | 645 "document.getElementById('username_field').value = 'temp';" |
618 "document.getElementById('password_field').value = 'random';" | 646 "document.getElementById('password_field').value = 'random';" |
619 "document.getElementById('input_submit_button').click();"; | 647 "document.getElementById('input_submit_button').click();"; |
620 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 648 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
621 form_submit_observer.Wait(); | 649 form_submit_observer.Wait(); |
622 EXPECT_TRUE(form_submit_observer.infobar_shown()); | 650 EXPECT_TRUE(form_submit_observer.infobar_shown()); |
623 | 651 |
624 // Reload the original page to have the saved credentials autofilled. | 652 // Reload the original page to have the saved credentials autofilled. |
625 NavigationObserver reload_observer(WebContents()); | 653 NavigationObserver reload_observer(WebContents()); |
626 NavigateToFile("/password/form_and_link.html"); | 654 NavigateToFile("/password/form_and_link.html"); |
627 reload_observer.Wait(); | 655 reload_observer.Wait(); |
628 | 656 |
629 // Check that while the username is immediately available, the password value | 657 // Check that while the username is immediately available, the password value |
630 // needs a user interaction to show up. | 658 // needs a user interaction to show up. |
631 std::string check_username = | 659 WaitForElementValue("username_field", "temp"); |
632 "document.getElementById('username_field').value == 'temp'"; | 660 WaitForElementValue("password_field", ""); |
633 std::string check_password = | 661 content::SimulateMouseClickAt( |
634 "document.getElementById('password_field').value == 'random'"; | 662 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1,1)); |
635 CheckScriptReturnValue(check_username, true); | 663 WaitForElementValue("password_field", "random"); |
636 CheckScriptReturnValue(check_password, false); | 664 WaitForElementValue("username_field", "temp"); |
bartfab (slow)
2014/06/05 16:45:54
Nit: That's a bit hacky. Since you expect the user
vabr (Chromium)
2014/06/05 17:58:12
Following an off-line clarification, I tried to ma
| |
637 content::SimulateMouseClick( | |
638 WebContents(), 0, blink::WebMouseEvent::ButtonLeft); | |
639 CheckScriptReturnValue(check_username, true); | |
640 CheckScriptReturnValue(check_password, true); | |
641 } | 665 } |
642 | 666 |
643 // The following test is limited to Aura, because | 667 // The following test is limited to Aura, because |
644 // RenderWidgetHostViewGuest::ProcessAckedTouchEvent is, and | 668 // RenderWidgetHostViewGuest::ProcessAckedTouchEvent is, and |
645 // ProcessAckedTouchEvent is what triggers the translation of touch events to | 669 // ProcessAckedTouchEvent is what triggers the translation of touch events to |
646 // gesture events. | 670 // gesture events. |
647 #if defined(USE_AURA) | 671 #if defined(USE_AURA) |
648 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 672 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
649 PasswordValueAccessibleOnSubmit) { | 673 PasswordValueAccessibleOnSubmit) { |
650 NavigateToFile("/password/form_and_link.html"); | 674 NavigateToFile("/password/form_and_link.html"); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); | 771 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); |
748 | 772 |
749 NavigationObserver observer(WebContents()); | 773 NavigationObserver observer(WebContents()); |
750 GURL url = embedded_test_server()->GetURL("/password/password_form.html"); | 774 GURL url = embedded_test_server()->GetURL("/password/password_form.html"); |
751 chrome::NavigateParams params(browser(), url, | 775 chrome::NavigateParams params(browser(), url, |
752 content::PAGE_TRANSITION_RELOAD); | 776 content::PAGE_TRANSITION_RELOAD); |
753 ui_test_utils::NavigateToURL(¶ms); | 777 ui_test_utils::NavigateToURL(¶ms); |
754 observer.Wait(); | 778 observer.Wait(); |
755 EXPECT_FALSE(observer.infobar_shown()); | 779 EXPECT_FALSE(observer.infobar_shown()); |
756 } | 780 } |
OLD | NEW |