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 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | |
167 password_manager::switches::kEnableAutomaticPasswordSaving)); | |
165 NavigationObserver observer(WebContents()); | 168 NavigationObserver observer(WebContents()); |
166 GURL url = embedded_test_server()->GetURL(path); | 169 GURL url = embedded_test_server()->GetURL(path); |
167 ui_test_utils::NavigateToURL(browser(), url); | 170 ui_test_utils::NavigateToURL(browser(), url); |
168 observer.Wait(); | 171 observer.Wait(); |
169 } | 172 } |
170 | 173 |
171 // Executes |script| and uses the EXPECT macros to check the return value | 174 // Executes |script| and uses the EXPECT macros to check the return value |
172 // against |expected_return_value|. | 175 // against |expected_return_value|. |
173 void CheckScriptReturnValue(std::string& script, bool expected_return_value); | 176 void CheckScriptReturnValue(std::string& script, bool expected_return_value); |
174 | 177 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 DontPromptForPasswordFormWithDefaultValue) { | 643 DontPromptForPasswordFormWithDefaultValue) { |
641 NavigateToFile("/password/password_form_with_default_value.html"); | 644 NavigateToFile("/password/password_form_with_default_value.html"); |
642 | 645 |
643 // Don't prompt if we navigate away even if there is a password value since | 646 // Don't prompt if we navigate away even if there is a password value since |
644 // it's not coming from the user. | 647 // it's not coming from the user. |
645 NavigationObserver observer(WebContents()); | 648 NavigationObserver observer(WebContents()); |
646 NavigateToFile("/password/done.html"); | 649 NavigateToFile("/password/done.html"); |
647 observer.Wait(); | 650 observer.Wait(); |
648 EXPECT_FALSE(observer.infobar_shown()); | 651 EXPECT_FALSE(observer.infobar_shown()); |
649 } | 652 } |
653 | |
654 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | |
655 PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) { | |
656 NavigateToFile("/password/password_form.html"); | |
657 | |
658 // Fill a form and submit through a <input type="submit"> button. | |
659 NavigationObserver observer(WebContents()); | |
660 std::string fill_and_submit = | |
661 "document.getElementById('username_field').value = 'temp';" | |
662 "document.getElementById('password_field').value = 'random';" | |
663 "document.getElementById('input_submit_button').click()"; | |
664 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
665 observer.Wait(); | |
666 EXPECT_TRUE(observer.infobar_shown()); | |
667 } | |
668 | |
669 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | |
670 DontPromptWhenEnableAutomaticPasswordSavingSwitchIsSet) { | |
671 password_manager::TestPasswordStore* password_store = | |
672 static_cast<password_manager::TestPasswordStore*> | |
673 (PasswordStoreFactory::GetForProfile(browser()->profile(), | |
vabr (Chromium)
2014/04/29 13:58:46
nit: Please format this correctly (even better, ru
rchtara
2014/04/29 14:25:03
Done.
| |
674 Profile::IMPLICIT_ACCESS).get()); | |
675 | |
676 EXPECT_EQ(password_store->stored_passwords().size(), 0U); | |
677 | |
678 NavigateToFile("/password/password_form.html"); | |
679 | |
680 // Enable the enable-automatic-password-saving switch | |
681 CommandLine::ForCurrentProcess()->AppendSwitch( | |
682 password_manager::switches::kEnableAutomaticPasswordSaving); | |
683 | |
684 // Fill a form and submit through a <input type="submit"> button. | |
685 NavigationObserver observer(WebContents()); | |
686 std::string fill_and_submit = | |
687 "document.getElementById('username_field').value = 'temp';" | |
688 "document.getElementById('password_field').value = 'random';" | |
689 "document.getElementById('input_submit_button').click()"; | |
690 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
691 observer.Wait(); | |
692 EXPECT_FALSE(observer.infobar_shown()); | |
693 EXPECT_EQ(password_store->stored_passwords().size(), 1U); | |
694 } | |
OLD | NEW |