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 "base/test/scoped_feature_list.h" | 7 #include "base/test/scoped_feature_list.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 9 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); | 198 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); |
199 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); | 199 EXPECT_TRUE(NavigateIframeToURL(web_contents, "child0", frame_url)); |
200 | 200 |
201 // Focus the subframe and then its input field. The return value | 201 // Focus the subframe and then its input field. The return value |
202 // "input-focus" will be sent once the input field's focus event fires. | 202 // "input-focus" will be sent once the input field's focus event fires. |
203 content::RenderFrameHost* child = | 203 content::RenderFrameHost* child = |
204 ChildFrameAt(web_contents->GetMainFrame(), 0); | 204 ChildFrameAt(web_contents->GetMainFrame(), 0); |
205 std::string result; | 205 std::string result; |
206 std::string script = | 206 std::string script = |
207 "function onInput(e) {" | 207 "function onInput(e) {" |
208 " domAutomationController.setAutomationId(0);" | |
209 " domAutomationController.send(getInputFieldText());" | 208 " domAutomationController.send(getInputFieldText());" |
210 "}" | 209 "}" |
211 "inputField = document.getElementById('text-field');" | 210 "inputField = document.getElementById('text-field');" |
212 "inputField.addEventListener('input', onInput, false);"; | 211 "inputField.addEventListener('input', onInput, false);"; |
213 EXPECT_TRUE(ExecuteScript(child, script)); | 212 EXPECT_TRUE(ExecuteScript(child, script)); |
214 EXPECT_TRUE(ExecuteScriptAndExtractString( | 213 EXPECT_TRUE(ExecuteScriptAndExtractString( |
215 child, "window.focus(); focusInputField();", &result)); | 214 child, "window.focus(); focusInputField();", &result)); |
216 EXPECT_EQ("input-focus", result); | 215 EXPECT_EQ("input-focus", result); |
217 | 216 |
218 // The subframe should now be focused. | 217 // The subframe should now be focused. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // from focus events. | 269 // from focus events. |
271 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); | 270 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); |
272 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); | 271 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); |
273 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); | 272 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); |
274 | 273 |
275 // This script will insert two <input> fields in the document, one at the | 274 // This script will insert two <input> fields in the document, one at the |
276 // beginning and one at the end. For root frame, this means that we will | 275 // beginning and one at the end. For root frame, this means that we will |
277 // have an <input>, then two <iframe> elements, then another <input>. | 276 // have an <input>, then two <iframe> elements, then another <input>. |
278 std::string script = | 277 std::string script = |
279 "function onFocus(e) {" | 278 "function onFocus(e) {" |
280 " domAutomationController.setAutomationId(0);" | |
281 " domAutomationController.send(window.name + '-focused-' + e.target.id);" | 279 " domAutomationController.send(window.name + '-focused-' + e.target.id);" |
282 "}" | 280 "}" |
283 "var input1 = document.createElement('input');" | 281 "var input1 = document.createElement('input');" |
284 "input1.id = 'input1';" | 282 "input1.id = 'input1';" |
285 "var input2 = document.createElement('input');" | 283 "var input2 = document.createElement('input');" |
286 "input2.id = 'input2';" | 284 "input2.id = 'input2';" |
287 "document.body.insertBefore(input1, document.body.firstChild);" | 285 "document.body.insertBefore(input1, document.body.firstChild);" |
288 "document.body.appendChild(input2);" | 286 "document.body.appendChild(input2);" |
289 "input1.addEventListener('focus', onFocus, false);" | 287 "input1.addEventListener('focus', onFocus, false);" |
290 "input2.addEventListener('focus', onFocus, false);"; | 288 "input2.addEventListener('focus', onFocus, false);"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 // This script will insert two <input> fields in the document, one at the | 357 // This script will insert two <input> fields in the document, one at the |
360 // beginning and one at the end. For root frame, this means that we will | 358 // beginning and one at the end. For root frame, this means that we will |
361 // have an <input>, then two <iframe> elements, then another <input>. | 359 // have an <input>, then two <iframe> elements, then another <input>. |
362 // The script will send back the coordinates to click for each <input>, in the | 360 // The script will send back the coordinates to click for each <input>, in the |
363 // document's space. Additionally, the outer frame will return the top left | 361 // document's space. Additionally, the outer frame will return the top left |
364 // point of each <iframe> to transform the coordinates of the inner <input> | 362 // point of each <iframe> to transform the coordinates of the inner <input> |
365 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each | 363 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each |
366 // iframe: 55,18;55,67 | 364 // iframe: 55,18;55,67 |
367 std::string script = | 365 std::string script = |
368 "function onFocus(e) {" | 366 "function onFocus(e) {" |
369 " domAutomationController.setAutomationId(0);" | |
370 " console.log(window.name + '-focused-' + e.target.id);" | 367 " console.log(window.name + '-focused-' + e.target.id);" |
371 " domAutomationController.send(window.name + '-focused-' + e.target.id);" | 368 " domAutomationController.send(window.name + '-focused-' + e.target.id);" |
372 "}" | 369 "}" |
373 "" | 370 "" |
374 "function getElementCoords(element) {" | 371 "function getElementCoords(element) {" |
375 " var rect = element.getBoundingClientRect();" | 372 " var rect = element.getBoundingClientRect();" |
376 " return Math.floor(rect.left + 0.5 * rect.width) +','+" | 373 " return Math.floor(rect.left + 0.5 * rect.width) +','+" |
377 " Math.floor(rect.top + 0.5 * rect.height);" | 374 " Math.floor(rect.top + 0.5 * rect.height);" |
378 "}" | 375 "}" |
379 "function getIframeCoords(element) {" | 376 "function getIframeCoords(element) {" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 return has_style; | 578 return has_style; |
582 } | 579 } |
583 | 580 |
584 // Add a listener that will send back a message whenever the (prefixed) | 581 // Add a listener that will send back a message whenever the (prefixed) |
585 // fullscreenchange event fires. The message will be "fullscreenchange", | 582 // fullscreenchange event fires. The message will be "fullscreenchange", |
586 // followed by a space and the provided |id|. | 583 // followed by a space and the provided |id|. |
587 void AddFullscreenChangeListener(content::RenderFrameHost* frame, | 584 void AddFullscreenChangeListener(content::RenderFrameHost* frame, |
588 const std::string& id) { | 585 const std::string& id) { |
589 std::string script = base::StringPrintf( | 586 std::string script = base::StringPrintf( |
590 "document.addEventListener('webkitfullscreenchange', function() {" | 587 "document.addEventListener('webkitfullscreenchange', function() {" |
591 " domAutomationController.setAutomationId(0);" | |
592 " domAutomationController.send('fullscreenchange %s');});", | 588 " domAutomationController.send('fullscreenchange %s');});", |
593 id.c_str()); | 589 id.c_str()); |
594 EXPECT_TRUE(ExecuteScript(frame, script)); | 590 EXPECT_TRUE(ExecuteScript(frame, script)); |
595 } | 591 } |
596 | 592 |
597 // Helper to add a listener that will send back a "resize" message when the | 593 // Helper to add a listener that will send back a "resize" message when the |
598 // target |frame| is resized to |expected_size|. | 594 // target |frame| is resized to |expected_size|. |
599 void AddResizeListener(content::RenderFrameHost* frame, | 595 void AddResizeListener(content::RenderFrameHost* frame, |
600 const gfx::Size& expected_size) { | 596 const gfx::Size& expected_size) { |
601 std::string script = | 597 std::string script = |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 } | 1447 } |
1452 | 1448 |
1453 // To make sure we never clicked into the date picker, get current date value | 1449 // To make sure we never clicked into the date picker, get current date value |
1454 // and make sure it matches the cached value. | 1450 // and make sure it matches the cached value. |
1455 std::string date; | 1451 std::string date; |
1456 ASSERT_TRUE(ExecuteScriptAndExtractString( | 1452 ASSERT_TRUE(ExecuteScriptAndExtractString( |
1457 child_frame, "window.domAutomationController.send(input.value);", &date)); | 1453 child_frame, "window.domAutomationController.send(input.value);", &date)); |
1458 EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date | 1454 EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date |
1459 << "' but current date is '" << date << "'."; | 1455 << "' but current date is '" << date << "'."; |
1460 } | 1456 } |
OLD | NEW |