Chromium Code Reviews| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 8 #include "chrome/test/base/in_process_browser_test.h" | 8 #include "chrome/test/base/in_process_browser_test.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 99 |
| 100 EXPECT_TRUE(ExecuteScript(child2, "window.focus();")); | 100 EXPECT_TRUE(ExecuteScript(child2, "window.focus();")); |
| 101 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 101 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); |
| 102 | 102 |
| 103 EXPECT_TRUE(document_has_focus(main_frame)); | 103 EXPECT_TRUE(document_has_focus(main_frame)); |
| 104 EXPECT_FALSE(document_has_focus(child1)); | 104 EXPECT_FALSE(document_has_focus(child1)); |
| 105 EXPECT_FALSE(document_has_focus(grandchild)); | 105 EXPECT_FALSE(document_has_focus(grandchild)); |
| 106 EXPECT_TRUE(document_has_focus(child2)); | 106 EXPECT_TRUE(document_has_focus(child2)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Ensure that a cross-process subframe can receive keyboard events when in | |
| 110 // focus. | |
| 111 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, | |
| 112 SubframeKeyboardEventRouting) { | |
| 113 GURL main_url(embedded_test_server()->GetURL( | |
| 114 "a.com", "/frame_tree/page_with_one_frame.html")); | |
| 115 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 116 content::WebContents* web_contents = | |
| 117 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 118 | |
| 119 GURL frame_url( | |
| 120 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); | |
| 121 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); | |
| 122 | |
| 123 // Focus the subframe and then its input field. The return value | |
| 124 // "input-focus" will be sent once the input field's focus event fires. | |
| 125 content::RenderFrameHost* child = | |
| 126 ChildFrameAt(web_contents->GetMainFrame(), 0); | |
| 127 std::string result; | |
| 128 EXPECT_TRUE(ExecuteScriptAndExtractString(child, | |
| 129 "window.focus(); focusInputField()", | |
|
nasko
2016/04/08 22:41:50
nit: Semi-colon after the call to focusInputField(
alexmos
2016/04/11 18:38:22
Done.
| |
| 130 &result)); | |
| 131 EXPECT_EQ(result, "input-focus"); | |
| 132 | |
| 133 // The subframe should now be focused. | |
| 134 EXPECT_EQ(child, web_contents->GetFocusedFrame()); | |
| 135 | |
| 136 // Generate a few keyboard events and route them to currently focused frame. | |
| 137 SimulateKeyPress(web_contents, ui::VKEY_F, false, false, false, false); | |
| 138 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); | |
| 139 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); | |
| 140 | |
| 141 // Verify that the input field in the subframe received the keystrokes. | |
| 142 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 143 child, | |
| 144 "window.domAutomationController.send(getInputFieldText());", &result)); | |
| 145 EXPECT_EQ("FOO", result); | |
| 146 } | |
| 147 | |
| OLD | NEW |