| 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 "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/password_manager/password_store_factory.h" | 10 #include "chrome/browser/password_manager/password_store_factory.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 message_loop_runner_(new content::MessageLoopRunner), | 34 message_loop_runner_(new content::MessageLoopRunner), |
| 35 info_bar_shown_(false), | 35 info_bar_shown_(false), |
| 36 infobar_service_(InfoBarService::FromWebContents(web_contents)) { | 36 infobar_service_(InfoBarService::FromWebContents(web_contents)) { |
| 37 registrar_.Add(this, | 37 registrar_.Add(this, |
| 38 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 38 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 39 content::Source<InfoBarService>(infobar_service_)); | 39 content::Source<InfoBarService>(infobar_service_)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual ~NavigationObserver() {} | 42 virtual ~NavigationObserver() {} |
| 43 | 43 |
| 44 void Wait() { | |
| 45 message_loop_runner_->Run(); | |
| 46 } | |
| 47 | |
| 48 bool InfoBarWasShown() { | |
| 49 return info_bar_shown_; | |
| 50 } | |
| 51 | |
| 52 // content::NotificationObserver: | 44 // content::NotificationObserver: |
| 53 virtual void Observe(int type, | 45 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE { | 47 const content::NotificationDetails& details) OVERRIDE { |
| 56 // Accept in the infobar. | 48 // Accept in the infobar. |
| 57 InfoBarDelegate* infobar = infobar_service_->infobar_at(0); | 49 InfoBarDelegate* infobar = infobar_service_->infobar_at(0); |
| 58 ConfirmInfoBarDelegate* confirm_infobar = | 50 ConfirmInfoBarDelegate* confirm_infobar = |
| 59 infobar->AsConfirmInfoBarDelegate(); | 51 infobar->AsConfirmInfoBarDelegate(); |
| 60 confirm_infobar->Accept(); | 52 confirm_infobar->Accept(); |
| 61 info_bar_shown_ = true; | 53 info_bar_shown_ = true; |
| 62 } | 54 } |
| 63 | 55 |
| 64 // content::WebContentsObserver | 56 // content::WebContentsObserver: |
| 65 virtual void DidFinishLoad( | 57 virtual void DidFinishLoad( |
| 66 int64 frame_id, | 58 int64 frame_id, |
| 67 const GURL& validated_url, | 59 const GURL& validated_url, |
| 68 bool is_main_frame, | 60 bool is_main_frame, |
| 69 content::RenderViewHost* render_view_host) OVERRIDE { | 61 content::RenderViewHost* render_view_host) OVERRIDE { |
| 70 message_loop_runner_->Quit(); | 62 message_loop_runner_->Quit(); |
| 71 } | 63 } |
| 72 | 64 |
| 65 bool infobar_shown() { return info_bar_shown_; } |
| 66 |
| 67 void Wait() { |
| 68 message_loop_runner_->Run(); |
| 69 } |
| 70 |
| 73 private: | 71 private: |
| 74 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 72 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 75 bool info_bar_shown_; | 73 bool info_bar_shown_; |
| 76 content::NotificationRegistrar registrar_; | 74 content::NotificationRegistrar registrar_; |
| 77 InfoBarService* infobar_service_; | 75 InfoBarService* infobar_service_; |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 } // namespace | 78 } // namespace |
| 81 | 79 |
| 82 class PasswordManagerBrowserTest : public InProcessBrowserTest { | 80 class PasswordManagerBrowserTest : public InProcessBrowserTest { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 111 // in its onsubmit handler but instead logs in/navigates via XHR. | 109 // in its onsubmit handler but instead logs in/navigates via XHR. |
| 112 // Note that calling 'submit()' on a form with javascript doesn't call | 110 // Note that calling 'submit()' on a form with javascript doesn't call |
| 113 // the onsubmit handler, so we click the submit button instead. | 111 // the onsubmit handler, so we click the submit button instead. |
| 114 NavigationObserver observer(WebContents()); | 112 NavigationObserver observer(WebContents()); |
| 115 std::string fill_and_submit = | 113 std::string fill_and_submit = |
| 116 "document.getElementById('username_field').value = 'temp';" | 114 "document.getElementById('username_field').value = 'temp';" |
| 117 "document.getElementById('password_field').value = 'random';" | 115 "document.getElementById('password_field').value = 'random';" |
| 118 "document.getElementById('submit_button').click()"; | 116 "document.getElementById('submit_button').click()"; |
| 119 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 117 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 120 observer.Wait(); | 118 observer.Wait(); |
| 121 EXPECT_TRUE(observer.InfoBarWasShown()); | 119 EXPECT_TRUE(observer.infobar_shown()); |
| 122 } | 120 } |
| 123 | 121 |
| 124 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForOtherXHR) { | 122 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForOtherXHR) { |
| 125 ASSERT_TRUE(test_server()->Start()); | 123 ASSERT_TRUE(test_server()->Start()); |
| 126 | 124 |
| 127 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html"); | 125 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html"); |
| 128 ui_test_utils::NavigateToURL(browser(), url); | 126 ui_test_utils::NavigateToURL(browser(), url); |
| 129 | 127 |
| 130 // Verify that if random XHR navigation occurs, we don't try and save the | 128 // Verify that if random XHR navigation occurs, we don't try and save the |
| 131 // password. | 129 // password. |
| 132 // | 130 // |
| 133 // We may want to change this functionality in the future to account for | 131 // We may want to change this functionality in the future to account for |
| 134 // cases where the element that users click on isn't a submit button. | 132 // cases where the element that users click on isn't a submit button. |
| 135 NavigationObserver observer(WebContents()); | 133 NavigationObserver observer(WebContents()); |
| 136 std::string fill_and_navigate = | 134 std::string fill_and_navigate = |
| 137 "document.getElementById('username_field').value = 'temp';" | 135 "document.getElementById('username_field').value = 'temp';" |
| 138 "document.getElementById('password_field').value = 'random';" | 136 "document.getElementById('password_field').value = 'random';" |
| 139 "send_xhr()"; | 137 "send_xhr()"; |
| 140 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); | 138 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); |
| 141 observer.Wait(); | 139 observer.Wait(); |
| 142 EXPECT_FALSE(observer.InfoBarWasShown()); | 140 EXPECT_FALSE(observer.infobar_shown()); |
| 143 } | 141 } |
| OLD | NEW |