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/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" |
20 #include "components/autofill/core/browser/autofill_test_utils.h" | 21 #include "components/autofill/core/browser/autofill_test_utils.h" |
21 #include "components/infobars/core/infobar.h" | 22 #include "components/infobars/core/infobar.h" |
22 #include "components/infobars/core/infobar_manager.h" | 23 #include "components/infobars/core/infobar_manager.h" |
23 #include "components/password_manager/core/browser/test_password_store.h" | 24 #include "components/password_manager/core/browser/test_password_store.h" |
| 25 #include "components/password_manager/core/common/password_manager_switches.h" |
24 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_observer.h" | 28 #include "content/public/browser/web_contents_observer.h" |
27 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
28 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "net/url_request/test_url_fetcher_factory.h" | 32 #include "net/url_request/test_url_fetcher_factory.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "third_party/WebKit/public/web/WebInputEvent.h" | 34 #include "third_party/WebKit/public/web/WebInputEvent.h" |
33 #include "ui/events/keycodes/keyboard_codes.h" | 35 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 157 |
156 // Wrapper around ui_test_utils::NavigateToURL that waits until | 158 // Wrapper around ui_test_utils::NavigateToURL that waits until |
157 // DidFinishLoad() fires. Normally this function returns after | 159 // DidFinishLoad() fires. Normally this function returns after |
158 // DidStopLoading(), which caused flakiness as the NavigationObserver | 160 // DidStopLoading(), which caused flakiness as the NavigationObserver |
159 // would sometimes see the DidFinishLoad event from a previous navigation and | 161 // would sometimes see the DidFinishLoad event from a previous navigation and |
160 // return immediately. | 162 // return immediately. |
161 void NavigateToFile(const std::string& path) { | 163 void NavigateToFile(const std::string& path) { |
162 if (!embedded_test_server()->Started()) | 164 if (!embedded_test_server()->Started()) |
163 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 165 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
164 | 166 |
| 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. |
| 660 NavigationObserver observer(WebContents()); |
| 661 std::string fill_and_submit = |
| 662 "document.getElementById('username_field').value = 'temp';" |
| 663 "document.getElementById('password_field').value = 'random';" |
| 664 "document.getElementById('input_submit_button').click()"; |
| 665 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 666 observer.Wait(); |
| 667 EXPECT_TRUE(observer.infobar_shown()); |
| 668 } |
| 669 |
| 670 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 671 DontPromptWhenEnableAutomaticPasswordSavingSwitchIsSet) { |
| 672 password_manager::TestPasswordStore* password_store = |
| 673 static_cast<password_manager::TestPasswordStore*>( |
| 674 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 675 Profile::IMPLICIT_ACCESS).get()); |
| 676 |
| 677 EXPECT_EQ(0U, password_store->stored_passwords().size()); |
| 678 |
| 679 NavigateToFile("/password/password_form.html"); |
| 680 |
| 681 // Enable the enable-automatic-password-saving switch |
| 682 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 683 password_manager::switches::kEnableAutomaticPasswordSaving); |
| 684 |
| 685 // Fill a form and submit through a <input type="submit"> button. |
| 686 NavigationObserver observer(WebContents()); |
| 687 std::string fill_and_submit = |
| 688 "document.getElementById('username_field').value = 'temp';" |
| 689 "document.getElementById('password_field').value = 'random';" |
| 690 "document.getElementById('input_submit_button').click()"; |
| 691 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 692 observer.Wait(); |
| 693 if (chrome::VersionInfo::GetChannel() == |
| 694 chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 695 EXPECT_FALSE(observer.infobar_shown()); |
| 696 EXPECT_EQ(1U, password_store->stored_passwords().size()); |
| 697 } else { |
| 698 EXPECT_TRUE(observer.infobar_shown()); |
| 699 EXPECT_EQ(0U, password_store->stored_passwords().size()); |
| 700 } |
| 701 } |
OLD | NEW |