| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/interactive_test_utils.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 19 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 20 #include "content/public/test/text_input_test_utils.h" | 21 #include "content/public/test/text_input_test_utils.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 22 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "ui/base/ime/composition_underline.h" | 24 #include "ui/base/ime/composition_underline.h" |
| 25 #include "ui/base/ime/text_edit_commands.h" |
| 24 #include "ui/base/ime/text_input_client.h" | 26 #include "ui/base/ime/text_input_client.h" |
| 25 #include "ui/base/ime/text_input_mode.h" | 27 #include "ui/base/ime/text_input_mode.h" |
| 26 #include "ui/base/ime/text_input_type.h" | 28 #include "ui/base/ime/text_input_type.h" |
| 27 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 28 | 30 |
| 31 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 32 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
| 33 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
| 34 #endif |
| 35 |
| 29 // TODO(ekaramad): The following tests should be active on all platforms. After | 36 // TODO(ekaramad): The following tests should be active on all platforms. After |
| 30 // fixing https://crbug.com/578168, this test file should be built for android | 37 // fixing https://crbug.com/578168, this test file should be built for android |
| 31 // as well and most of the following tests should be enabled for all platforms | 38 // as well and most of the following tests should be enabled for all platforms |
| 32 //(https://crbug.com/602723). | 39 //(https://crbug.com/602723). |
| 33 | 40 |
| 34 /////////////////////////////////////////////////////////////////////////////// | 41 /////////////////////////////////////////////////////////////////////////////// |
| 35 // TextInputManager and IME Tests | 42 // TextInputManager and IME Tests |
| 36 // | 43 // |
| 37 // The following tests verify the correctness of TextInputState tracking on the | 44 // The following tests verify the correctness of TextInputState tracking on the |
| 38 // browser side. They also make sure the IME logic works correctly. The baseline | 45 // browser side. They also make sure the IME logic works correctly. The baseline |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 | 859 |
| 853 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 860 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 854 sender.SetShowImeIfNeeded(true); | 861 sender.SetShowImeIfNeeded(true); |
| 855 EXPECT_TRUE(send_and_check_show_ime()); | 862 EXPECT_TRUE(send_and_check_show_ime()); |
| 856 | 863 |
| 857 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 864 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 858 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 865 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 859 EXPECT_FALSE(send_and_check_show_ime()); | 866 EXPECT_FALSE(send_and_check_show_ime()); |
| 860 } | 867 } |
| 861 #endif // USE_AURA | 868 #endif // USE_AURA |
| 869 |
| 870 // Ensure that a cross-process subframe can utilize keyboard edit commands. |
| 871 // See https://crbug.com/640706. This test is Linux-specific, as it relies on |
| 872 // overriding TextEditKeyBindingsDelegateAuraLinux, which only exists on Linux. |
| 873 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 874 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 875 SubframeKeyboardEditCommands) { |
| 876 GURL main_url(embedded_test_server()->GetURL( |
| 877 "a.com", "/frame_tree/page_with_one_frame.html")); |
| 878 ui_test_utils::NavigateToURL(browser(), main_url); |
| 879 content::WebContents* web_contents = active_contents(); |
| 880 |
| 881 GURL frame_url( |
| 882 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); |
| 883 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); |
| 884 |
| 885 // Focus the subframe and then its input field. The return value |
| 886 // "input-focus" will be sent once the input field's focus event fires. |
| 887 content::RenderFrameHost* child = |
| 888 ChildFrameAt(web_contents->GetMainFrame(), 0); |
| 889 std::string result; |
| 890 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 891 child, "window.focus(); focusInputField();", &result)); |
| 892 EXPECT_EQ("input-focus", result); |
| 893 EXPECT_EQ(child, web_contents->GetFocusedFrame()); |
| 894 |
| 895 // Generate a couple of keystrokes, which will be routed to the subframe. |
| 896 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('1'), |
| 897 ui::DomCode::DIGIT1, ui::VKEY_1, false, false, false, false); |
| 898 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('2'), |
| 899 ui::DomCode::DIGIT2, ui::VKEY_2, false, false, false, false); |
| 900 |
| 901 // Verify that the input field in the subframe received the keystrokes. |
| 902 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 903 child, "window.domAutomationController.send(getInputFieldText());", |
| 904 &result)); |
| 905 EXPECT_EQ("12", result); |
| 906 |
| 907 // Define and install a test delegate that translates any keystroke to a |
| 908 // command to delete all text from current cursor position to the beginning |
| 909 // of the line. |
| 910 class TextDeleteDelegate : public ui::TextEditKeyBindingsDelegateAuraLinux { |
| 911 public: |
| 912 TextDeleteDelegate() {} |
| 913 ~TextDeleteDelegate() override {} |
| 914 |
| 915 bool MatchEvent( |
| 916 const ui::Event& event, |
| 917 std::vector<ui::TextEditCommandAuraLinux>* commands) override { |
| 918 if (commands) { |
| 919 commands->emplace_back(ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE, |
| 920 ""); |
| 921 } |
| 922 return true; |
| 923 } |
| 924 |
| 925 private: |
| 926 DISALLOW_COPY_AND_ASSIGN(TextDeleteDelegate); |
| 927 }; |
| 928 |
| 929 TextDeleteDelegate delegate; |
| 930 ui::TextEditKeyBindingsDelegateAuraLinux* old_delegate = |
| 931 ui::GetTextEditKeyBindingsDelegate(); |
| 932 ui::SetTextEditKeyBindingsDelegate(&delegate); |
| 933 |
| 934 // Press ctrl-alt-shift-D. The test's delegate will pretend that this |
| 935 // corresponds to the command to delete everyting to the beginning of the |
| 936 // line. Note the use of SendKeyPressSync instead of SimulateKeyPress, as |
| 937 // the latter doesn't go through |
| 938 // RenderWidgetHostViewAura::ForwardKeyboardEvent, which contains the edit |
| 939 // commands logic that's tested here. |
| 940 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_D, |
| 941 true, true, true, false)); |
| 942 ui::SetTextEditKeyBindingsDelegate(old_delegate); |
| 943 |
| 944 // Verify that the input field in the subframe is erased. |
| 945 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 946 child, "window.domAutomationController.send(getInputFieldText());", |
| 947 &result)); |
| 948 EXPECT_EQ("", result); |
| 949 } |
| 950 #endif |
| OLD | NEW |