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 "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" | 9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 GURL frame_url( | 143 GURL frame_url( |
144 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); | 144 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); |
145 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); | 145 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); |
146 | 146 |
147 // Focus the subframe and then its input field. The return value | 147 // Focus the subframe and then its input field. The return value |
148 // "input-focus" will be sent once the input field's focus event fires. | 148 // "input-focus" will be sent once the input field's focus event fires. |
149 content::RenderFrameHost* child = | 149 content::RenderFrameHost* child = |
150 ChildFrameAt(web_contents->GetMainFrame(), 0); | 150 ChildFrameAt(web_contents->GetMainFrame(), 0); |
151 std::string result; | 151 std::string result; |
| 152 std::string script = |
| 153 "function onInput(e) {" |
| 154 " domAutomationController.setAutomationId(0);" |
| 155 " domAutomationController.send(getInputFieldText());" |
| 156 "}" |
| 157 "inputField = document.getElementById('text-field');" |
| 158 "inputField.addEventListener('input', onInput, false);"; |
| 159 EXPECT_TRUE(ExecuteScript(child, script)); |
152 EXPECT_TRUE(ExecuteScriptAndExtractString( | 160 EXPECT_TRUE(ExecuteScriptAndExtractString( |
153 child, "window.focus(); focusInputField();", &result)); | 161 child, "window.focus(); focusInputField();", &result)); |
154 EXPECT_EQ("input-focus", result); | 162 EXPECT_EQ("input-focus", result); |
155 | 163 |
156 // The subframe should now be focused. | 164 // The subframe should now be focused. |
157 EXPECT_EQ(child, web_contents->GetFocusedFrame()); | 165 EXPECT_EQ(child, web_contents->GetFocusedFrame()); |
158 | 166 |
159 // Generate a few keyboard events and route them to currently focused frame. | 167 // Generate a few keyboard events and route them to currently focused frame. |
| 168 // We wait for replies to be sent back from the page, since keystrokes may |
| 169 // take time to propagate to the renderer's main thread. |
| 170 content::DOMMessageQueue msg_queue; |
| 171 std::string reply; |
160 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('f'), | 172 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('f'), |
161 ui::DomCode::US_F, ui::VKEY_F, false, false, false, false); | 173 ui::DomCode::US_F, ui::VKEY_F, false, false, false, false); |
| 174 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 175 EXPECT_EQ("\"F\"", reply); |
| 176 |
162 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('O'), | 177 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('O'), |
163 ui::DomCode::US_O, ui::VKEY_O, false, false, false, false); | 178 ui::DomCode::US_O, ui::VKEY_O, false, false, false, false); |
| 179 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 180 EXPECT_EQ("\"FO\"", reply); |
| 181 |
164 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('O'), | 182 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('O'), |
165 ui::DomCode::US_O, ui::VKEY_O, false, false, false, false); | 183 ui::DomCode::US_O, ui::VKEY_O, false, false, false, false); |
166 | 184 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
167 // Verify that the input field in the subframe received the keystrokes. | 185 EXPECT_EQ("\"FOO\"", reply); |
168 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
169 child, | |
170 "window.domAutomationController.send(getInputFieldText());", &result)); | |
171 EXPECT_EQ("FOO", result); | |
172 } | 186 } |
173 | 187 |
174 // Ensure that sequential focus navigation (advancing focused elements with | 188 // Ensure that sequential focus navigation (advancing focused elements with |
175 // <tab> and <shift-tab>) works across cross-process subframes. | 189 // <tab> and <shift-tab>) works across cross-process subframes. |
176 // The test sets up six inputs fields in a page with two cross-process | 190 // The test sets up six inputs fields in a page with two cross-process |
177 // subframes: | 191 // subframes: |
178 // child1 child2 | 192 // child1 child2 |
179 // /------------\ /------------\. | 193 // /------------\ /------------\. |
180 // | 2. <input> | | 4. <input> | | 194 // | 2. <input> | | 4. <input> | |
181 // 1. <input> | 3. <input> | | 5. <input> | 6. <input> | 195 // 1. <input> | 3. <input> | | 5. <input> | 6. <input> |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 "document.pointerLockElement)", | 778 "document.pointerLockElement)", |
765 &mouse_locked)); | 779 &mouse_locked)); |
766 EXPECT_TRUE(mouse_locked); | 780 EXPECT_TRUE(mouse_locked); |
767 EXPECT_TRUE(main_frame->GetView()->IsMouseLocked()); | 781 EXPECT_TRUE(main_frame->GetView()->IsMouseLocked()); |
768 | 782 |
769 EXPECT_TRUE(ExecuteScript(main_frame, | 783 EXPECT_TRUE(ExecuteScript(main_frame, |
770 "document.querySelector('iframe').parentNode." | 784 "document.querySelector('iframe').parentNode." |
771 "removeChild(document.querySelector('iframe'))")); | 785 "removeChild(document.querySelector('iframe'))")); |
772 EXPECT_FALSE(main_frame->GetView()->IsMouseLocked()); | 786 EXPECT_FALSE(main_frame->GetView()->IsMouseLocked()); |
773 } | 787 } |
OLD | NEW |