Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 2641653002: Make ObservingAutofillClient a WebContentsUserData (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } else { 101 } else {
102 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( 102 std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
103 new net::test_server::BasicHttpResponse); 103 new net::test_server::BasicHttpResponse);
104 http_response->set_code(net::HTTP_UNAUTHORIZED); 104 http_response->set_code(net::HTTP_UNAUTHORIZED);
105 http_response->AddCustomHeader("WWW-Authenticate", 105 http_response->AddCustomHeader("WWW-Authenticate",
106 "Basic realm=\"test realm\""); 106 "Basic realm=\"test realm\"");
107 return std::move(http_response); 107 return std::move(http_response);
108 } 108 }
109 } 109 }
110 110
111 class ObservingAutofillClient : public autofill::TestAutofillClient { 111 class ObservingAutofillClient
112 : public autofill::TestAutofillClient,
113 public content::WebContentsUserData<ObservingAutofillClient> {
112 public: 114 public:
113 ObservingAutofillClient()
114 : message_loop_runner_(new content::MessageLoopRunner) {}
115 ~ObservingAutofillClient() override {} 115 ~ObservingAutofillClient() override {}
116 116
117 void Wait() { message_loop_runner_->Run(); } 117 void Wait() { message_loop_runner_->Run(); }
118 118
119 void ShowAutofillPopup( 119 void ShowAutofillPopup(
120 const gfx::RectF& element_bounds, 120 const gfx::RectF& element_bounds,
121 base::i18n::TextDirection text_direction, 121 base::i18n::TextDirection text_direction,
122 const std::vector<autofill::Suggestion>& suggestions, 122 const std::vector<autofill::Suggestion>& suggestions,
123 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override { 123 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override {
124 message_loop_runner_->Quit(); 124 message_loop_runner_->Quit();
125 } 125 }
126 126
127 private: 127 private:
128 explicit ObservingAutofillClient(content::WebContents* web_contents)
129 : message_loop_runner_(new content::MessageLoopRunner) {}
130 friend class content::WebContentsUserData<ObservingAutofillClient>;
131
128 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 132 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
129 133
130 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); 134 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient);
131 }; 135 };
132 136
133 // For simplicity we assume that password store contains only 1 credentials. 137 // For simplicity we assume that password store contains only 1 credentials.
134 void CheckThatCredentialsStored( 138 void CheckThatCredentialsStored(
135 password_manager::TestPasswordStore* password_store, 139 password_manager::TestPasswordStore* password_store,
136 const base::string16& username, 140 const base::string16& username,
137 const base::string16& password) { 141 const base::string16& password) {
(...skipping 19 matching lines...) Expand all
157 "document.getElementById('password_failed').value = 'random';" 161 "document.getElementById('password_failed').value = 'random';"
158 "document.getElementById('failed_form').submit()"; 162 "document.getElementById('failed_form').submit()";
159 163
160 ASSERT_TRUE(content::ExecuteScript(rvh, fill_and_submit)); 164 ASSERT_TRUE(content::ExecuteScript(rvh, fill_and_submit));
161 observer.Wait(); 165 observer.Wait();
162 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 166 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
163 } 167 }
164 168
165 } // namespace 169 } // namespace
166 170
171 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ObservingAutofillClient);
172
167 namespace password_manager { 173 namespace password_manager {
168 174
169 // Actual tests --------------------------------------------------------------- 175 // Actual tests ---------------------------------------------------------------
170 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { 176 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) {
171 NavigateToFile("/password/password_form.html"); 177 NavigateToFile("/password/password_form.html");
172 178
173 // Fill a form and submit through a <input type="submit"> button. Nothing 179 // Fill a form and submit through a <input type="submit"> button. Nothing
174 // special. 180 // special.
175 NavigationObserver observer(WebContents()); 181 NavigationObserver observer(WebContents());
176 std::unique_ptr<BubbleObserver> prompt_observer( 182 std::unique_ptr<BubbleObserver> prompt_observer(
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 } 1711 }
1706 1712
1707 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1713 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1708 InFrameNavigationDoesNotClearPopupState) { 1714 InFrameNavigationDoesNotClearPopupState) {
1709 // Mock out the AutofillClient so we know how long to wait. Unfortunately 1715 // Mock out the AutofillClient so we know how long to wait. Unfortunately
1710 // there isn't otherwise a good even to wait on to verify that the popup 1716 // there isn't otherwise a good even to wait on to verify that the popup
1711 // would have been shown. 1717 // would have been shown.
1712 password_manager::ContentPasswordManagerDriverFactory* driver_factory = 1718 password_manager::ContentPasswordManagerDriverFactory* driver_factory =
1713 password_manager::ContentPasswordManagerDriverFactory::FromWebContents( 1719 password_manager::ContentPasswordManagerDriverFactory::FromWebContents(
1714 WebContents()); 1720 WebContents());
1715 ObservingAutofillClient observing_autofill_client; 1721 ObservingAutofillClient::CreateForWebContents(WebContents());
1722 ObservingAutofillClient* observing_autofill_client =
1723 ObservingAutofillClient::FromWebContents(WebContents());
1716 password_manager::ContentPasswordManagerDriver* driver = 1724 password_manager::ContentPasswordManagerDriver* driver =
1717 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame()); 1725 driver_factory->GetDriverForFrame(RenderViewHost()->GetMainFrame());
1718 DCHECK(driver); 1726 DCHECK(driver);
1719 driver->GetPasswordAutofillManager()->set_autofill_client( 1727 driver->GetPasswordAutofillManager()->set_autofill_client(
1720 &observing_autofill_client); 1728 observing_autofill_client);
1721 1729
1722 NavigateToFile("/password/password_form.html"); 1730 NavigateToFile("/password/password_form.html");
1723 1731
1724 NavigationObserver form_submit_observer(WebContents()); 1732 NavigationObserver form_submit_observer(WebContents());
1725 std::unique_ptr<BubbleObserver> prompt_observer( 1733 std::unique_ptr<BubbleObserver> prompt_observer(
1726 new BubbleObserver(WebContents())); 1734 new BubbleObserver(WebContents()));
1727 std::string fill = 1735 std::string fill =
1728 "document.getElementById('username_field').value = 'temp';" 1736 "document.getElementById('username_field').value = 'temp';"
1729 "document.getElementById('password_field').value = 'random123';" 1737 "document.getElementById('password_field').value = 'random123';"
1730 "document.getElementById('input_submit_button').click();"; 1738 "document.getElementById('input_submit_button').click();";
(...skipping 23 matching lines...) Expand all
1754 int left; 1762 int left;
1755 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 1763 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
1756 RenderViewHost(), 1764 RenderViewHost(),
1757 "window.domAutomationController.send(usernameRect.left);", 1765 "window.domAutomationController.send(usernameRect.left);",
1758 &left)); 1766 &left));
1759 1767
1760 content::SimulateMouseClickAt( 1768 content::SimulateMouseClickAt(
1761 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(left + 1, 1769 WebContents(), 0, blink::WebMouseEvent::Button::Left, gfx::Point(left + 1,
1762 top + 1)); 1770 top + 1));
1763 // Make sure the popup would be shown. 1771 // Make sure the popup would be shown.
1764 observing_autofill_client.Wait(); 1772 observing_autofill_client->Wait();
1765 } 1773 }
1766 1774
1767 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1775 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1768 ChangePwdFormBubbleShown) { 1776 ChangePwdFormBubbleShown) {
1769 NavigateToFile("/password/password_form.html"); 1777 NavigateToFile("/password/password_form.html");
1770 1778
1771 NavigationObserver observer(WebContents()); 1779 NavigationObserver observer(WebContents());
1772 std::unique_ptr<BubbleObserver> prompt_observer( 1780 std::unique_ptr<BubbleObserver> prompt_observer(
1773 new BubbleObserver(WebContents())); 1781 new BubbleObserver(WebContents()));
1774 std::string fill_and_submit = 1782 std::string fill_and_submit =
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
3152 // about all frames, not just the main one. The factories should receive 3160 // about all frames, not just the main one. The factories should receive
3153 // messages for non-main frames, in particular 3161 // messages for non-main frames, in particular
3154 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the 3162 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the
3155 // factories hear about such frames, this would crash. 3163 // factories hear about such frames, this would crash.
3156 tab_strip_model->AddWebContents(detached_web_contents.release(), -1, 3164 tab_strip_model->AddWebContents(detached_web_contents.release(), -1,
3157 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 3165 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
3158 TabStripModel::ADD_ACTIVE); 3166 TabStripModel::ADD_ACTIVE);
3159 } 3167 }
3160 3168
3161 } // namespace password_manager 3169 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698