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 "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 11 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
14 #include "chrome/browser/password_manager/test_password_store_service.h" | 14 #include "chrome/browser/password_manager/test_password_store_service.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/test_switches.h" | 18 #include "chrome/test/base/test_switches.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "components/autofill/core/browser/autofill_test_utils.h" | 20 #include "components/autofill/core/browser/autofill_test_utils.h" |
21 #include "components/infobars/core/infobar.h" | 21 #include "components/infobars/core/infobar.h" |
22 #include "components/infobars/core/infobar_manager.h" | 22 #include "components/infobars/core/infobar_manager.h" |
23 #include "components/password_manager/core/browser/test_password_store.h" | 23 #include "components/password_manager/core/browser/test_password_store.h" |
24 #include "components/password_manager/core/common/password_manager_switches.h" | |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
27 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
28 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "net/url_request/test_url_fetcher_factory.h" | 31 #include "net/url_request/test_url_fetcher_factory.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "third_party/WebKit/public/web/WebInputEvent.h" | 33 #include "third_party/WebKit/public/web/WebInputEvent.h" |
33 #include "ui/events/keycodes/keyboard_codes.h" | 34 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 156 |
156 // Wrapper around ui_test_utils::NavigateToURL that waits until | 157 // Wrapper around ui_test_utils::NavigateToURL that waits until |
157 // DidFinishLoad() fires. Normally this function returns after | 158 // DidFinishLoad() fires. Normally this function returns after |
158 // DidStopLoading(), which caused flakiness as the NavigationObserver | 159 // DidStopLoading(), which caused flakiness as the NavigationObserver |
159 // would sometimes see the DidFinishLoad event from a previous navigation and | 160 // would sometimes see the DidFinishLoad event from a previous navigation and |
160 // return immediately. | 161 // return immediately. |
161 void NavigateToFile(const std::string& path) { | 162 void NavigateToFile(const std::string& path) { |
162 if (!embedded_test_server()->Started()) | 163 if (!embedded_test_server()->Started()) |
163 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 164 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
164 | 165 |
166 // Checkes that enable-automatic-password-saving is not enabled | |
vabr (Chromium)
2014/04/29 09:08:26
nit: This comment is not really necessary, please
rchtara
2014/04/29 12:20:08
Done.
| |
167 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | |
168 password_manager::switches::kEnableAutomaticPasswordSaving)); | |
165 NavigationObserver observer(WebContents()); | 169 NavigationObserver observer(WebContents()); |
166 GURL url = embedded_test_server()->GetURL(path); | 170 GURL url = embedded_test_server()->GetURL(path); |
167 ui_test_utils::NavigateToURL(browser(), url); | 171 ui_test_utils::NavigateToURL(browser(), url); |
168 observer.Wait(); | 172 observer.Wait(); |
169 } | 173 } |
170 | 174 |
171 // Executes |script| and uses the EXPECT macros to check the return value | 175 // Executes |script| and uses the EXPECT macros to check the return value |
172 // against |expected_return_value|. | 176 // against |expected_return_value|. |
173 void CheckScriptReturnValue(std::string& script, bool expected_return_value); | 177 void CheckScriptReturnValue(std::string& script, bool expected_return_value); |
174 | 178 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 DontPromptForPasswordFormWithDefaultValue) { | 644 DontPromptForPasswordFormWithDefaultValue) { |
641 NavigateToFile("/password/password_form_with_default_value.html"); | 645 NavigateToFile("/password/password_form_with_default_value.html"); |
642 | 646 |
643 // Don't prompt if we navigate away even if there is a password value since | 647 // Don't prompt if we navigate away even if there is a password value since |
644 // it's not coming from the user. | 648 // it's not coming from the user. |
645 NavigationObserver observer(WebContents()); | 649 NavigationObserver observer(WebContents()); |
646 NavigateToFile("/password/done.html"); | 650 NavigateToFile("/password/done.html"); |
647 observer.Wait(); | 651 observer.Wait(); |
648 EXPECT_FALSE(observer.infobar_shown()); | 652 EXPECT_FALSE(observer.infobar_shown()); |
649 } | 653 } |
654 | |
655 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | |
656 PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) { | |
657 NavigateToFile("/password/password_form.html"); | |
658 | |
659 // Fill a form and submit through a <input type="submit"> button. Nothing | |
vabr (Chromium)
2014/04/29 09:08:26
nit: "Nothing special" is just clutter, please rem
rchtara
2014/04/29 12:20:08
Done.
| |
660 // special. | |
661 NavigationObserver observer(WebContents()); | |
662 std::string fill_and_submit = | |
663 "document.getElementById('username_field').value = 'temp';" | |
664 "document.getElementById('password_field').value = 'random';" | |
665 "document.getElementById('input_submit_button').click()"; | |
666 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
667 observer.Wait(); | |
668 EXPECT_TRUE(observer.infobar_shown()); | |
669 } | |
670 | |
671 IN_PROC_BROWSER_TEST_F( | |
672 PasswordManagerBrowserTest, | |
673 DontPromptWhenEnableAutomaticPasswordSavingSwitchIsSet) { | |
674 NavigateToFile("/password/password_form.html"); | |
675 | |
676 // Enable the enable-automatic-password-saving switch | |
677 CommandLine::ForCurrentProcess()->AppendSwitch( | |
678 password_manager::switches::kEnableAutomaticPasswordSaving); | |
679 | |
680 // Fill a form and submit through a <input type="submit"> button. Nothing | |
681 // special. | |
682 NavigationObserver observer(WebContents()); | |
683 std::string fill_and_submit = | |
684 "document.getElementById('username_field').value = 'temp';" | |
685 "document.getElementById('password_field').value = 'random';" | |
686 "document.getElementById('input_submit_button').click()"; | |
687 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
688 observer.Wait(); | |
689 EXPECT_FALSE(observer.infobar_shown()); | |
vabr (Chromium)
2014/04/29 09:08:26
Please also check that the password indeed got sav
| |
690 } | |
OLD | NEW |