Chromium Code Reviews| Index: chrome/browser/site_per_process_interactive_browsertest.cc |
| diff --git a/chrome/browser/site_per_process_interactive_browsertest.cc b/chrome/browser/site_per_process_interactive_browsertest.cc |
| index 3cbea83b464c7ce83f7556c0d9c6a1a3e553ca46..04a73e46e2c0caf59071ca8142958c06218d4e0f 100644 |
| --- a/chrome/browser/site_per_process_interactive_browsertest.cc |
| +++ b/chrome/browser/site_per_process_interactive_browsertest.cc |
| @@ -20,10 +20,16 @@ |
| #include "content/public/test/test_utils.h" |
| #include "net/dns/mock_host_resolver.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "ui/base/ime/text_edit_commands.h" |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| #include "url/gurl.h" |
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| +#include "ui/base/ime/linux/text_edit_command_auralinux.h" |
| +#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
| +#endif |
| + |
| class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { |
| public: |
| SitePerProcessInteractiveBrowserTest() {} |
| @@ -171,6 +177,89 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
| EXPECT_EQ("FOO", result); |
| } |
| +// Ensure that a cross-process subframe can utilize keyboard edit commands. |
| +// See https://crbug.com/640706. This test is Linux-specific, as it relies on |
| +// overriding TextEditKeyBindingsDelegateAuraLinux, which only exists on Linux. |
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| +IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
| + SubframeKeyboardEditCommands) { |
|
Charlie Reis
2016/09/07 20:41:42
I think this might belong more in site_per_process
alexmos
2016/09/08 21:00:07
Done. It was straightforward to move. :)
|
| + GURL main_url(embedded_test_server()->GetURL( |
| + "a.com", "/frame_tree/page_with_one_frame.html")); |
| + ui_test_utils::NavigateToURL(browser(), main_url); |
| + content::WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + |
| + GURL frame_url( |
| + embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); |
| + EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); |
| + |
| + // Focus the subframe and then its input field. The return value |
| + // "input-focus" will be sent once the input field's focus event fires. |
| + content::RenderFrameHost* child = |
| + ChildFrameAt(web_contents->GetMainFrame(), 0); |
| + std::string result; |
| + EXPECT_TRUE(ExecuteScriptAndExtractString( |
| + child, "window.focus(); focusInputField();", &result)); |
| + EXPECT_EQ("input-focus", result); |
| + EXPECT_EQ(child, web_contents->GetFocusedFrame()); |
| + |
| + // Generate a couple of keystrokes, which will be routed to the subframe. |
| + SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('1'), |
| + ui::DomCode::DIGIT1, ui::VKEY_1, false, false, false, false); |
| + SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('2'), |
| + ui::DomCode::DIGIT2, ui::VKEY_2, false, false, false, false); |
| + |
| + // Verify that the input field in the subframe received the keystrokes. |
| + EXPECT_TRUE(ExecuteScriptAndExtractString( |
| + child, "window.domAutomationController.send(getInputFieldText());", |
| + &result)); |
| + EXPECT_EQ("12", result); |
| + |
| + // Define and install a test delegate that translates any keystroke to a |
| + // command to delete all text from current cursor position to the beginning |
| + // of the line. |
| + class TextDeleteDelegate : public ui::TextEditKeyBindingsDelegateAuraLinux { |
| + public: |
| + TextDeleteDelegate() {} |
| + ~TextDeleteDelegate() override {} |
| + |
| + bool MatchEvent( |
| + const ui::Event& event, |
| + std::vector<ui::TextEditCommandAuraLinux>* commands) override { |
| + if (commands) { |
| + commands->emplace_back(ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE, |
| + ""); |
| + } |
| + return true; |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TextDeleteDelegate); |
| + }; |
| + |
| + TextDeleteDelegate delegate; |
| + ui::TextEditKeyBindingsDelegateAuraLinux* old_delegate = |
| + ui::GetTextEditKeyBindingsDelegate(); |
| + ui::SetTextEditKeyBindingsDelegate(&delegate); |
| + |
| + // Press ctrl-alt-shift-D. The test's delegate will pretend that this |
| + // corresponds to the command to delete everyting to the beginning of the |
| + // line. Note the use of SendKeyPressSync instead of SimulateKeyPress, as |
| + // the latter doesn't go through |
| + // RenderWidgetHostViewAura::ForwardKeyboardEvent, which contains the edit |
| + // commands logic that's's tested here. |
|
Charlie Reis
2016/09/07 20:41:42
nit: that's
alexmos
2016/09/08 21:00:07
Done.
|
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_D, |
| + true, true, true, false)); |
| + ui::SetTextEditKeyBindingsDelegate(old_delegate); |
| + |
| + // Verify that the input field in the subframe is erased. |
| + EXPECT_TRUE(ExecuteScriptAndExtractString( |
| + child, "window.domAutomationController.send(getInputFieldText());", |
| + &result)); |
| + EXPECT_EQ("", result); |
| +} |
| +#endif |
| + |
| // Ensure that sequential focus navigation (advancing focused elements with |
| // <tab> and <shift-tab>) works across cross-process subframes. |
| // The test sets up six inputs fields in a page with two cross-process |