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" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 // Observer that waits for navigation to complete and for the password infobar | 40 // Observer that waits for navigation to complete and for the password infobar |
41 // to be shown. | 41 // to be shown. |
42 class NavigationObserver : public content::NotificationObserver, | 42 class NavigationObserver : public content::NotificationObserver, |
43 public content::WebContentsObserver { | 43 public content::WebContentsObserver { |
44 public: | 44 public: |
45 explicit NavigationObserver(content::WebContents* web_contents) | 45 explicit NavigationObserver(content::WebContents* web_contents) |
46 : content::WebContentsObserver(web_contents), | 46 : content::WebContentsObserver(web_contents), |
47 message_loop_runner_(new content::MessageLoopRunner), | 47 message_loop_runner_(new content::MessageLoopRunner), |
48 infobar_shown_(false), | 48 infobar_shown_(false), |
49 infobar_removed_(false), | |
50 auto_accept_infobar_(true), | |
49 infobar_service_(InfoBarService::FromWebContents(web_contents)) { | 51 infobar_service_(InfoBarService::FromWebContents(web_contents)) { |
50 registrar_.Add(this, | 52 registrar_.Add(this, |
51 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 53 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
52 content::Source<InfoBarService>(infobar_service_)); | 54 content::Source<InfoBarService>(infobar_service_)); |
55 registrar_.Add(this, | |
56 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | |
57 content::Source<InfoBarService>(infobar_service_)); | |
53 } | 58 } |
54 | 59 |
55 virtual ~NavigationObserver() {} | 60 virtual ~NavigationObserver() {} |
56 | 61 |
57 // Normally Wait() will not return until a main frame navigation occurs. | 62 // Normally Wait() will not return until a main frame navigation occurs. |
58 // If a path is set, Wait() will return after this path has been seen, | 63 // If a path is set, Wait() will return after this path has been seen, |
59 // regardless of the frame that navigated. Useful for multi-frame pages. | 64 // regardless of the frame that navigated. Useful for multi-frame pages. |
60 void SetPathToWaitFor(const std::string& path) { | 65 void SetPathToWaitFor(const std::string& path) { |
61 wait_for_path_ = path; | 66 wait_for_path_ = path; |
62 } | 67 } |
63 | 68 |
64 // content::NotificationObserver: | 69 // content::NotificationObserver: |
65 virtual void Observe(int type, | 70 virtual void Observe(int type, |
66 const content::NotificationSource& source, | 71 const content::NotificationSource& source, |
67 const content::NotificationDetails& details) OVERRIDE { | 72 const content::NotificationDetails& details) OVERRIDE { |
68 infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()-> | 73 switch (type) { |
69 Accept(); | 74 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: |
70 infobar_shown_ = true; | 75 if (auto_accept_infobar_) |
Ilya Sherman
2014/01/08 23:34:53
nit: This needs curlies.
vabr (Chromium)
2014/01/09 11:39:38
Done.
| |
76 infobar_service_->infobar_at(0) | |
77 ->delegate() | |
78 ->AsConfirmInfoBarDelegate() | |
79 ->Accept(); | |
80 infobar_shown_ = true; | |
81 break; | |
82 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: | |
83 infobar_removed_ = true; | |
84 break; | |
85 } | |
Ilya Sherman
2014/01/08 23:34:53
nit: Pretty sure you need to also have a default c
vabr (Chromium)
2014/01/09 11:39:38
Clang seemed to be fine with this, but I still add
| |
71 } | 86 } |
72 | 87 |
73 // content::WebContentsObserver: | 88 // content::WebContentsObserver: |
74 virtual void DidFinishLoad( | 89 virtual void DidFinishLoad( |
75 int64 frame_id, | 90 int64 frame_id, |
76 const GURL& validated_url, | 91 const GURL& validated_url, |
77 bool is_main_frame, | 92 bool is_main_frame, |
78 content::RenderViewHost* render_view_host) OVERRIDE { | 93 content::RenderViewHost* render_view_host) OVERRIDE { |
79 if (!wait_for_path_.empty()) { | 94 if (!wait_for_path_.empty()) { |
80 if (validated_url.path() == wait_for_path_) | 95 if (validated_url.path() == wait_for_path_) |
81 message_loop_runner_->Quit(); | 96 message_loop_runner_->Quit(); |
82 } else if (is_main_frame) { | 97 } else if (is_main_frame) { |
83 message_loop_runner_->Quit(); | 98 message_loop_runner_->Quit(); |
84 } | 99 } |
85 } | 100 } |
86 | 101 |
87 bool infobar_shown() const { return infobar_shown_; } | 102 bool infobar_shown() const { return infobar_shown_; } |
103 bool infobar_removed() const { return infobar_removed_; } | |
104 | |
105 void DisableAutoAcceptingInfobars() { auto_accept_infobar_ = false; } | |
Ilya Sherman
2014/01/08 23:34:53
nit: I'd name this "disable_foo", where "foo" is t
vabr (Chromium)
2014/01/09 11:39:38
Done.
| |
88 | 106 |
89 void Wait() { | 107 void Wait() { |
90 message_loop_runner_->Run(); | 108 message_loop_runner_->Run(); |
91 } | 109 } |
92 | 110 |
93 private: | 111 private: |
94 std::string wait_for_path_; | 112 std::string wait_for_path_; |
95 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 113 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
96 bool infobar_shown_; | 114 bool infobar_shown_; |
115 bool infobar_removed_; | |
116 bool auto_accept_infobar_; | |
Ilya Sherman
2014/01/08 23:34:53
nit: Please document this member var.
Ilya Sherman
2014/01/08 23:34:53
Optional nit: Perhaps a name like "should_automati
vabr (Chromium)
2014/01/09 11:39:38
Done.
vabr (Chromium)
2014/01/09 11:39:38
Done.
| |
97 content::NotificationRegistrar registrar_; | 117 content::NotificationRegistrar registrar_; |
98 InfoBarService* infobar_service_; | 118 InfoBarService* infobar_service_; |
99 | 119 |
100 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); | 120 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); |
101 }; | 121 }; |
102 | 122 |
103 } // namespace | 123 } // namespace |
104 | 124 |
105 | 125 |
106 // PasswordManagerBrowserTest ------------------------------------------------- | 126 // PasswordManagerBrowserTest ------------------------------------------------- |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 NavigationObserver observer(WebContents()); | 195 NavigationObserver observer(WebContents()); |
176 std::string fill_and_submit = | 196 std::string fill_and_submit = |
177 "document.getElementById('username_field').value = 'temp';" | 197 "document.getElementById('username_field').value = 'temp';" |
178 "document.getElementById('password_field').value = 'random';" | 198 "document.getElementById('password_field').value = 'random';" |
179 "document.getElementById('input_submit_button').click()"; | 199 "document.getElementById('input_submit_button').click()"; |
180 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 200 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
181 observer.Wait(); | 201 observer.Wait(); |
182 EXPECT_TRUE(observer.infobar_shown()); | 202 EXPECT_TRUE(observer.infobar_shown()); |
183 } | 203 } |
184 | 204 |
205 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, Redirects) { | |
206 NavigateToFile("/password/password_form.html"); | |
207 | |
208 // Fill a form and submit through a <input type="submit"> button. The form | |
209 // points to a redirection page. | |
210 NavigationObserver observer(WebContents()); | |
211 std::string fill_and_submit = | |
212 "document.getElementById('username_redirect').value = 'temp';" | |
213 "document.getElementById('password_redirect').value = 'random';" | |
214 "document.getElementById('submit_redirect').click()"; | |
215 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
216 observer.DisableAutoAcceptingInfobars(); | |
217 observer.Wait(); | |
218 EXPECT_TRUE(observer.infobar_shown()); | |
219 | |
220 // The redirection page now redirects via Javascript. We check that the | |
221 // infobar stays. | |
222 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), | |
223 "window.location.href = 'done.html';")); | |
224 observer.Wait(); | |
225 EXPECT_FALSE(observer.infobar_removed()); | |
226 } | |
227 | |
185 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 228 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
186 PromptForSubmitUsingJavaScript) { | 229 PromptForSubmitUsingJavaScript) { |
187 NavigateToFile("/password/password_form.html"); | 230 NavigateToFile("/password/password_form.html"); |
188 | 231 |
189 // Fill a form and submit using <button> that calls submit() on the form. | 232 // Fill a form and submit using <button> that calls submit() on the form. |
190 // This should work regardless of the type of element, as long as submit() is | 233 // This should work regardless of the type of element, as long as submit() is |
191 // called. | 234 // called. |
192 NavigationObserver observer(WebContents()); | 235 NavigationObserver observer(WebContents()); |
193 std::string fill_and_submit = | 236 std::string fill_and_submit = |
194 "document.getElementById('username_field').value = 'temp';" | 237 "document.getElementById('username_field').value = 'temp';" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 "document.getElementById('username_field').value = 'temp';" | 512 "document.getElementById('username_field').value = 'temp';" |
470 "document.getElementById('password_field').value = 'random';" | 513 "document.getElementById('password_field').value = 'random';" |
471 "document.getElementById('input_submit_button').click();" | 514 "document.getElementById('input_submit_button').click();" |
472 "window.location.href = 'done.html';"; | 515 "window.location.href = 'done.html';"; |
473 | 516 |
474 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), save_and_remove)); | 517 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), save_and_remove)); |
475 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); | 518 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
476 observer.Wait(); | 519 observer.Wait(); |
477 // The only thing we check here is that there is no use-after-free reported. | 520 // The only thing we check here is that there is no use-after-free reported. |
478 } | 521 } |
OLD | NEW |