| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "content/public/test/browser_test_utils.h" | 46 #include "content/public/test/browser_test_utils.h" |
| 47 #include "content/public/test/test_renderer_host.h" | 47 #include "content/public/test/test_renderer_host.h" |
| 48 #include "content/public/test/test_utils.h" | 48 #include "content/public/test/test_utils.h" |
| 49 #include "net/base/net_errors.h" | 49 #include "net/base/net_errors.h" |
| 50 #include "net/test/embedded_test_server/embedded_test_server.h" | 50 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 51 #include "net/url_request/test_url_fetcher_factory.h" | 51 #include "net/url_request/test_url_fetcher_factory.h" |
| 52 #include "net/url_request/url_request_status.h" | 52 #include "net/url_request/url_request_status.h" |
| 53 #include "testing/gmock/include/gmock/gmock.h" | 53 #include "testing/gmock/include/gmock/gmock.h" |
| 54 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
| 55 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 55 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 56 #include "ui/events/base_event_utils.h" |
| 56 #include "ui/events/keycodes/keyboard_code_conversion.h" | 57 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 57 #include "ui/events/keycodes/keyboard_codes.h" | 58 #include "ui/events/keycodes/keyboard_codes.h" |
| 58 | 59 |
| 59 using base::ASCIIToUTF16; | 60 using base::ASCIIToUTF16; |
| 60 | 61 |
| 61 namespace autofill { | 62 namespace autofill { |
| 62 | 63 |
| 63 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,"; | 64 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,"; |
| 64 static const char kTestFormString[] = | 65 static const char kTestFormString[] = |
| 65 "<form action=\"http://www.example.com/\" method=\"POST\">" | 66 "<form action=\"http://www.example.com/\" method=\"POST\">" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 void SendKeyToPopupAndWait(ui::DomKey key) { | 460 void SendKeyToPopupAndWait(ui::DomKey key) { |
| 460 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key); | 461 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key); |
| 461 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code); | 462 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code); |
| 462 SendKeyToPopupAndWait(key, code, key_code); | 463 SendKeyToPopupAndWait(key, code, key_code); |
| 463 } | 464 } |
| 464 | 465 |
| 465 void SendKeyToPopupAndWait(ui::DomKey key, | 466 void SendKeyToPopupAndWait(ui::DomKey key, |
| 466 ui::DomCode code, | 467 ui::DomCode code, |
| 467 ui::KeyboardCode key_code) { | 468 ui::KeyboardCode key_code) { |
| 468 // Route popup-targeted key presses via the render view host. | 469 // Route popup-targeted key presses via the render view host. |
| 469 content::NativeWebKeyboardEvent event; | 470 content::NativeWebKeyboardEvent event(blink::WebKeyboardEvent::RawKeyDown, |
| 471 blink::WebInputEvent::NoModifiers, |
| 472 ui::EventTimeForNow()); |
| 470 event.windowsKeyCode = key_code; | 473 event.windowsKeyCode = key_code; |
| 471 event.domCode = static_cast<int>(code); | 474 event.domCode = static_cast<int>(code); |
| 472 event.domKey = key; | 475 event.domKey = key; |
| 473 event.type = blink::WebKeyboardEvent::RawKeyDown; | |
| 474 test_delegate_.Reset(); | 476 test_delegate_.Reset(); |
| 475 // Install the key press event sink to ensure that any events that are not | 477 // Install the key press event sink to ensure that any events that are not |
| 476 // handled by the installed callbacks do not end up crashing the test. | 478 // handled by the installed callbacks do not end up crashing the test. |
| 477 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback( | 479 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback( |
| 478 key_press_event_sink_); | 480 key_press_event_sink_); |
| 479 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); | 481 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); |
| 480 test_delegate_.Wait(); | 482 test_delegate_.Wait(); |
| 481 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback( | 483 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback( |
| 482 key_press_event_sink_); | 484 key_press_event_sink_); |
| 483 } | 485 } |
| 484 | 486 |
| 485 void SendKeyToDataListPopup(ui::DomKey key) { | 487 void SendKeyToDataListPopup(ui::DomKey key) { |
| 486 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key); | 488 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key); |
| 487 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code); | 489 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code); |
| 488 SendKeyToDataListPopup(key, code, key_code); | 490 SendKeyToDataListPopup(key, code, key_code); |
| 489 } | 491 } |
| 490 | 492 |
| 491 // Datalist does not support autofill preview. There is no need to start | 493 // Datalist does not support autofill preview. There is no need to start |
| 492 // message loop for Datalist. | 494 // message loop for Datalist. |
| 493 void SendKeyToDataListPopup(ui::DomKey key, | 495 void SendKeyToDataListPopup(ui::DomKey key, |
| 494 ui::DomCode code, | 496 ui::DomCode code, |
| 495 ui::KeyboardCode key_code) { | 497 ui::KeyboardCode key_code) { |
| 496 // Route popup-targeted key presses via the render view host. | 498 // Route popup-targeted key presses via the render view host. |
| 497 content::NativeWebKeyboardEvent event; | 499 content::NativeWebKeyboardEvent event(blink::WebKeyboardEvent::RawKeyDown, |
| 500 blink::WebInputEvent::NoModifiers, |
| 501 ui::EventTimeForNow()); |
| 498 event.windowsKeyCode = key_code; | 502 event.windowsKeyCode = key_code; |
| 499 event.domCode = static_cast<int>(code); | 503 event.domCode = static_cast<int>(code); |
| 500 event.domKey = key; | 504 event.domKey = key; |
| 501 event.type = blink::WebKeyboardEvent::RawKeyDown; | |
| 502 // Install the key press event sink to ensure that any events that are not | 505 // Install the key press event sink to ensure that any events that are not |
| 503 // handled by the installed callbacks do not end up crashing the test. | 506 // handled by the installed callbacks do not end up crashing the test. |
| 504 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback( | 507 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback( |
| 505 key_press_event_sink_); | 508 key_press_event_sink_); |
| 506 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); | 509 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); |
| 507 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback( | 510 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback( |
| 508 key_press_event_sink_); | 511 key_press_event_sink_); |
| 509 } | 512 } |
| 510 | 513 |
| 511 void TryBasicFormFill() { | 514 void TryBasicFormFill() { |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), | 1730 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), |
| 1728 GURL(std::string(kDataURIPrefix) + kTestPasswordFormString))); | 1731 GURL(std::string(kDataURIPrefix) + kTestPasswordFormString))); |
| 1729 ASSERT_TRUE(content::ExecuteScript( | 1732 ASSERT_TRUE(content::ExecuteScript( |
| 1730 GetRenderViewHost(), | 1733 GetRenderViewHost(), |
| 1731 "document.getElementById('user').value = 'user';")); | 1734 "document.getElementById('user').value = 'user';")); |
| 1732 FocusFieldByName("password"); | 1735 FocusFieldByName("password"); |
| 1733 PasteStringAndWait("foobar"); | 1736 PasteStringAndWait("foobar"); |
| 1734 } | 1737 } |
| 1735 | 1738 |
| 1736 } // namespace autofill | 1739 } // namespace autofill |
| OLD | NEW |