| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); | 137 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); |
| 138 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); | 138 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); |
| 139 | 139 |
| 140 // Verify that the input field in the subframe received the keystrokes. | 140 // Verify that the input field in the subframe received the keystrokes. |
| 141 EXPECT_TRUE(ExecuteScriptAndExtractString( | 141 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 142 child, | 142 child, |
| 143 "window.domAutomationController.send(getInputFieldText());", &result)); | 143 "window.domAutomationController.send(getInputFieldText());", &result)); |
| 144 EXPECT_EQ("FOO", result); | 144 EXPECT_EQ("FOO", result); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Ensure that sequential focus navigation (advancing focused elements with |
| 148 // <tab> and <shift-tab>) works across cross-process subframes. |
| 149 // The test sets up six inputs fields in a page with two cross-process |
| 150 // subframes: |
| 151 // child1 child2 |
| 152 // /------------\ /------------\. |
| 153 // | 2. <input> | | 4. <input> | |
| 154 // 1. <input> | 3. <input> | | 5. <input> | 6. <input> |
| 155 // \------------/ \------------/. |
| 156 // |
| 157 // The test then presses <tab> six times to cycle through focused elements 1-6. |
| 158 // The test then repeats this with <shift-tab> to cycle in reverse order. |
| 159 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
| 160 SequentialFocusNavigation) { |
| 161 GURL main_url(embedded_test_server()->GetURL( |
| 162 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); |
| 163 ui_test_utils::NavigateToURL(browser(), main_url); |
| 164 |
| 165 content::WebContents* web_contents = |
| 166 browser()->tab_strip_model()->GetActiveWebContents(); |
| 167 |
| 168 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 169 content::RenderFrameHost* child1 = ChildFrameAt(main_frame, 0); |
| 170 ASSERT_NE(nullptr, child1); |
| 171 content::RenderFrameHost* child2 = ChildFrameAt(main_frame, 1); |
| 172 ASSERT_NE(nullptr, child2); |
| 173 |
| 174 // Assign a name to each frame. This will be sent along in test messages |
| 175 // from focus events. |
| 176 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); |
| 177 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); |
| 178 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); |
| 179 |
| 180 // This script will insert two <input> fields in the document, one at the |
| 181 // beginning and one at the end. For root frame, this means that we will |
| 182 // have an <input>, then two <iframe> elements, then another <input>. |
| 183 std::string script = |
| 184 "function onFocus(e) {" |
| 185 " domAutomationController.setAutomationId(0);" |
| 186 " domAutomationController.send(window.name + '-focused-' + e.target.id);" |
| 187 "}" |
| 188 "var input1 = document.createElement('input');" |
| 189 "input1.id = 'input1';" |
| 190 "var input2 = document.createElement('input');" |
| 191 "input2.id = 'input2';" |
| 192 "document.body.insertBefore(input1, document.body.firstChild);" |
| 193 "document.body.appendChild(input2);" |
| 194 "input1.addEventListener('focus', onFocus, false);" |
| 195 "input2.addEventListener('focus', onFocus, false);"; |
| 196 |
| 197 // Add two input fields to each of the three frames. |
| 198 EXPECT_TRUE(ExecuteScript(main_frame, script)); |
| 199 EXPECT_TRUE(ExecuteScript(child1, script)); |
| 200 EXPECT_TRUE(ExecuteScript(child2, script)); |
| 201 |
| 202 // Helper to simulate a tab press and wait for a focus message. |
| 203 auto press_tab_and_wait_for_message = [web_contents](bool reverse) { |
| 204 content::DOMMessageQueue msg_queue; |
| 205 std::string reply; |
| 206 SimulateKeyPress(web_contents, ui::VKEY_TAB, false, reverse /* shift */, |
| 207 false, false); |
| 208 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 209 return reply; |
| 210 }; |
| 211 |
| 212 // Press <tab> six times to focus each of the <input> elements in turn. |
| 213 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(false)); |
| 214 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 215 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(false)); |
| 216 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
| 217 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(false)); |
| 218 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); |
| 219 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); |
| 220 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(false)); |
| 221 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); |
| 222 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 223 |
| 224 // Now, press <shift-tab> to navigate focus in the reverse direction. |
| 225 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); |
| 226 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); |
| 227 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); |
| 228 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
| 229 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
| 230 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); |
| 231 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); |
| 232 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 233 } |
| 234 |
| OLD | NEW |