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 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_contents_observer.h" | 28 #include "content/public/browser/web_contents_observer.h" |
29 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
30 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
31 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
32 #include "net/url_request/test_url_fetcher_factory.h" | 32 #include "net/url_request/test_url_fetcher_factory.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "third_party/WebKit/public/web/WebInputEvent.h" |
34 #include "ui/events/keycodes/keyboard_codes.h" | 35 #include "ui/events/keycodes/keyboard_codes.h" |
35 | 36 |
36 | 37 |
37 // NavigationObserver --------------------------------------------------------- | 38 // NavigationObserver --------------------------------------------------------- |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 // Observer that waits for navigation to complete and for the password infobar | 42 // Observer that waits for navigation to complete and for the password infobar |
42 // to be shown. | 43 // to be shown. |
43 class NavigationObserver : public content::NotificationObserver, | 44 class NavigationObserver : public content::NotificationObserver, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 void NavigateToFile(const std::string& path) { | 168 void NavigateToFile(const std::string& path) { |
168 if (!embedded_test_server()->Started()) | 169 if (!embedded_test_server()->Started()) |
169 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 170 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
170 | 171 |
171 NavigationObserver observer(WebContents()); | 172 NavigationObserver observer(WebContents()); |
172 GURL url = embedded_test_server()->GetURL(path); | 173 GURL url = embedded_test_server()->GetURL(path); |
173 ui_test_utils::NavigateToURL(browser(), url); | 174 ui_test_utils::NavigateToURL(browser(), url); |
174 observer.Wait(); | 175 observer.Wait(); |
175 } | 176 } |
176 | 177 |
| 178 // Simulate a user clicking somewhere in the page. |
| 179 void SimulateClick(); |
| 180 |
177 private: | 181 private: |
178 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); | 182 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); |
179 }; | 183 }; |
180 | 184 |
| 185 void PasswordManagerBrowserTest::SimulateClick() { |
| 186 blink::WebMouseEvent mouse_event; |
| 187 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 188 mouse_event.button = blink::WebMouseEvent::ButtonLeft; |
| 189 mouse_event.x = 1; |
| 190 mouse_event.y = 1; |
| 191 mouse_event.clickCount = 1; |
| 192 WebContents()->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 193 } |
| 194 |
181 // Actual tests --------------------------------------------------------------- | 195 // Actual tests --------------------------------------------------------------- |
182 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 196 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
183 PromptForNormalSubmit) { | 197 PromptForNormalSubmit) { |
184 NavigateToFile("/password/password_form.html"); | 198 NavigateToFile("/password/password_form.html"); |
185 | 199 |
186 // Fill a form and submit through a <input type="submit"> button. Nothing | 200 // Fill a form and submit through a <input type="submit"> button. Nothing |
187 // special. | 201 // special. |
188 NavigationObserver observer(WebContents()); | 202 NavigationObserver observer(WebContents()); |
189 std::string fill_and_submit = | 203 std::string fill_and_submit = |
190 "document.getElementById('username_field').value = 'temp';" | 204 "document.getElementById('username_field').value = 'temp';" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 452 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
439 | 453 |
440 first_observer.Wait(); | 454 first_observer.Wait(); |
441 ASSERT_TRUE(first_observer.infobar_shown()); | 455 ASSERT_TRUE(first_observer.infobar_shown()); |
442 | 456 |
443 // Now navigate to a login form that has similar HTML markup. | 457 // Now navigate to a login form that has similar HTML markup. |
444 NavigateToFile("/password/password_form.html"); | 458 NavigateToFile("/password/password_form.html"); |
445 | 459 |
446 // Simulate a user click to force an autofill of the form's DOM value, not | 460 // Simulate a user click to force an autofill of the form's DOM value, not |
447 // just the suggested value. | 461 // just the suggested value. |
448 std::string click = "document.getElementById('testform_no_name').click()"; | 462 SimulateClick(); |
449 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click)); | |
450 | 463 |
451 // The form should be filled with the previously submitted username. | 464 // The form should be filled with the previously submitted username. |
452 std::string get_username = | 465 std::string get_username = |
453 "window.domAutomationController.send(" | 466 "window.domAutomationController.send(" |
454 "document.getElementById('username_field').value);"; | 467 "document.getElementById('username_field').value);"; |
455 std::string actual_username; | 468 std::string actual_username; |
456 ASSERT_TRUE(content::ExecuteScriptAndExtractString(RenderViewHost(), | 469 ASSERT_TRUE(content::ExecuteScriptAndExtractString(RenderViewHost(), |
457 get_username, | 470 get_username, |
458 &actual_username)); | 471 &actual_username)); |
459 ASSERT_EQ("my_username", actual_username); | 472 ASSERT_EQ("my_username", actual_username); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 "document.getElementById('username_field').value = 'temp';" | 581 "document.getElementById('username_field').value = 'temp';" |
569 "document.getElementById('password_field').value = 'random';" | 582 "document.getElementById('password_field').value = 'random';" |
570 "document.getElementById('input_submit_button').click();" | 583 "document.getElementById('input_submit_button').click();" |
571 "window.location.href = 'done.html';"; | 584 "window.location.href = 'done.html';"; |
572 | 585 |
573 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), save_and_remove)); | 586 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), save_and_remove)); |
574 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); | 587 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
575 observer.Wait(); | 588 observer.Wait(); |
576 // The only thing we check here is that there is no use-after-free reported. | 589 // The only thing we check here is that there is no use-after-free reported. |
577 } | 590 } |
OLD | NEW |