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/chrome_content_browser_client.h" | 9 #include "chrome/browser/chrome_content_browser_client.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1108 |
1109 GURL frame_url( | 1109 GURL frame_url( |
1110 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); | 1110 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); |
1111 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); | 1111 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); |
1112 | 1112 |
1113 // Focus the subframe and then its input field. The return value | 1113 // Focus the subframe and then its input field. The return value |
1114 // "input-focus" will be sent once the input field's focus event fires. | 1114 // "input-focus" will be sent once the input field's focus event fires. |
1115 content::RenderFrameHost* child = | 1115 content::RenderFrameHost* child = |
1116 ChildFrameAt(web_contents->GetMainFrame(), 0); | 1116 ChildFrameAt(web_contents->GetMainFrame(), 0); |
1117 std::string result; | 1117 std::string result; |
| 1118 std::string script = |
| 1119 "function onInput(e) {" |
| 1120 " domAutomationController.setAutomationId(0);" |
| 1121 " domAutomationController.send(getInputFieldText());" |
| 1122 "}" |
| 1123 "inputField = document.getElementById('text-field');" |
| 1124 "inputField.addEventListener('input', onInput, false);"; |
| 1125 EXPECT_TRUE(ExecuteScript(child, script)); |
1118 EXPECT_TRUE(ExecuteScriptAndExtractString( | 1126 EXPECT_TRUE(ExecuteScriptAndExtractString( |
1119 child, "window.focus(); focusInputField();", &result)); | 1127 child, "window.focus(); focusInputField();", &result)); |
1120 EXPECT_EQ("input-focus", result); | 1128 EXPECT_EQ("input-focus", result); |
1121 EXPECT_EQ(child, web_contents->GetFocusedFrame()); | 1129 EXPECT_EQ(child, web_contents->GetFocusedFrame()); |
1122 | 1130 |
1123 // Generate a couple of keystrokes, which will be routed to the subframe. | 1131 // Generate a couple of keystrokes, which will be routed to the subframe. |
| 1132 content::DOMMessageQueue msg_queue; |
| 1133 std::string reply; |
1124 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('1'), | 1134 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('1'), |
1125 ui::DomCode::DIGIT1, ui::VKEY_1, false, false, false, false); | 1135 ui::DomCode::DIGIT1, ui::VKEY_1, false, false, false, false); |
| 1136 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
1126 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('2'), | 1137 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('2'), |
1127 ui::DomCode::DIGIT2, ui::VKEY_2, false, false, false, false); | 1138 ui::DomCode::DIGIT2, ui::VKEY_2, false, false, false, false); |
| 1139 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
1128 | 1140 |
1129 // Verify that the input field in the subframe received the keystrokes. | 1141 // Verify that the input field in the subframe received the keystrokes. |
1130 EXPECT_TRUE(ExecuteScriptAndExtractString( | 1142 EXPECT_TRUE(ExecuteScriptAndExtractString( |
1131 child, "window.domAutomationController.send(getInputFieldText());", | 1143 child, "window.domAutomationController.send(getInputFieldText());", |
1132 &result)); | 1144 &result)); |
1133 EXPECT_EQ("12", result); | 1145 EXPECT_EQ("12", result); |
1134 | 1146 |
1135 // Define and install a test delegate that translates any keystroke to a | 1147 // Define and install a test delegate that translates any keystroke to a |
1136 // command to delete all text from current cursor position to the beginning | 1148 // command to delete all text from current cursor position to the beginning |
1137 // of the line. | 1149 // of the line. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 | 1359 |
1348 // Closing this WebContents while we still hold on to our TestBrowserClient. | 1360 // Closing this WebContents while we still hold on to our TestBrowserClient. |
1349 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( | 1361 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( |
1350 1, TabStripModel::CLOSE_USER_GESTURE)); | 1362 1, TabStripModel::CLOSE_USER_GESTURE)); |
1351 | 1363 |
1352 // For the cleanup of the original WebContents in tab index 0. | 1364 // For the cleanup of the original WebContents in tab index 0. |
1353 content::SetBrowserClientForTesting(old_browser_client); | 1365 content::SetBrowserClientForTesting(old_browser_client); |
1354 } | 1366 } |
1355 #endif // defined(MAC_OSX) | 1367 #endif // defined(MAC_OSX) |
1356 #endif // !defined(OS_ANDROID) | 1368 #endif // !defined(OS_ANDROID) |
OLD | NEW |