OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 var g_webview = null; | 5 var g_webview = null; |
6 var embedder = {}; | 6 var embedder = {}; |
7 var seenFocusCount = 0; | 7 var seenFocusCount = 0; |
8 embedder.tests = {}; | 8 embedder.tests = {}; |
9 embedder.guestURL = | 9 embedder.guestURL = |
10 'data:text/html,<html><body>Guest<body></html>'; | 10 'data:text/html,<html><body>Guest<body></html>'; |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 if (!g_focusRestoredTestHelper) { | 543 if (!g_focusRestoredTestHelper) { |
544 g_focusRestoredTestHelper = new FocusRestoredTestHelper(); | 544 g_focusRestoredTestHelper = new FocusRestoredTestHelper(); |
545 } | 545 } |
546 g_focusRestoredTestHelper.runStep(step, function(stepPassed) { | 546 g_focusRestoredTestHelper.runStep(step, function(stepPassed) { |
547 LOG('runStep callback, stepPassed: ' + stepPassed); | 547 LOG('runStep callback, stepPassed: ' + stepPassed); |
548 chrome.test.sendMessage(stepPassed ? 'TEST_STEP_PASSED' | 548 chrome.test.sendMessage(stepPassed ? 'TEST_STEP_PASSED' |
549 : 'TEST_STEP_FAILED'); | 549 : 'TEST_STEP_FAILED'); |
550 }); | 550 }); |
551 } | 551 } |
552 | 552 |
| 553 // Ensures that the tab key can be used to navigate out of the webview. There is |
| 554 // a corner case where focus can be trapped in the webview if the next focusable |
| 555 // element in the embedder is focused when trying to tab or the previous element |
| 556 // when using shift-tab. |
| 557 // |
| 558 // Briefly: |
| 559 // 1) Start with the embedder input focused |
| 560 // 2) Click the guest input and wait for it to be focused |
| 561 // 3) Send a tab key event |
| 562 // 4) Wait for the embedder input to receive another input event. |
| 563 function testFocusTakeFocus() { |
| 564 var input = document.createElement('input'); |
| 565 var webview = embedder.setUpGuest_(); |
| 566 g_webview = webview; |
| 567 document.body.appendChild(input); |
| 568 |
| 569 var onChannelEstablished = function(webview) { |
| 570 input.focus(); |
| 571 |
| 572 var msg = ['request-coords']; |
| 573 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 574 }; |
| 575 |
| 576 var inputFocusedHandler = function(e) { |
| 577 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 578 } |
| 579 |
| 580 var guestFocusedHandler = function(e) { |
| 581 console.log('input focused in guest'); |
| 582 window.removeEventListener('message', guestFocusedHandler); |
| 583 input.addEventListener('focus', inputFocusedHandler); |
| 584 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 585 }; |
| 586 |
| 587 var coordHandler = function(response) { |
| 588 var rect = g_webview.getBoundingClientRect(); |
| 589 window.clickX = rect.left + response[1]; |
| 590 window.clickY = rect.top + response[2]; |
| 591 window.addEventListener('message', guestFocusedHandler); |
| 592 chrome.test.sendMessage('TEST_PASSED'); |
| 593 }; |
| 594 |
| 595 embedder.waitForResponseFromGuest_(webview, |
| 596 'inject_focus_take_focus.js', |
| 597 onChannelEstablished, |
| 598 'response-coords', |
| 599 coordHandler); |
| 600 } |
| 601 |
553 // Tests that if we focus/blur the embedder, it also gets reflected in the | 602 // Tests that if we focus/blur the embedder, it also gets reflected in the |
554 // guest. | 603 // guest. |
555 // | 604 // |
556 // This test has two steps: | 605 // This test has two steps: |
557 // 1) testFocusTracksEmbedder(), in this step we create a <webview> and | 606 // 1) testFocusTracksEmbedder(), in this step we create a <webview> and |
558 // focus it before navigating. After navigating it to a URL, we focus an input | 607 // focus it before navigating. After navigating it to a URL, we focus an input |
559 // element inside the <webview>, and wait for its 'focus' event to fire. | 608 // element inside the <webview>, and wait for its 'focus' event to fire. |
560 // 2) testFocusTracksEmbedderRunNextStep(), in this step, we have already called | 609 // 2) testFocusTracksEmbedderRunNextStep(), in this step, we have already called |
561 // Blur() on the embedder's RVH (see WebViewTest.Focus_FocusTracksEmbedder), | 610 // Blur() on the embedder's RVH (see WebViewTest.Focus_FocusTracksEmbedder), |
562 // we make sure we see a 'blur' event on the <webview>'s input element. | 611 // we make sure we see a 'blur' event on the <webview>'s input element. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 | 728 |
680 embedder.test.testList = { | 729 embedder.test.testList = { |
681 'testAdvanceFocus': testAdvanceFocus, | 730 'testAdvanceFocus': testAdvanceFocus, |
682 'testBlurEvent': testBlurEvent, | 731 'testBlurEvent': testBlurEvent, |
683 'testFocusBeforeNavigation': testFocusBeforeNavigation, | 732 'testFocusBeforeNavigation': testFocusBeforeNavigation, |
684 'testFocusEvent': testFocusEvent, | 733 'testFocusEvent': testFocusEvent, |
685 'testFocusTracksEmbedder': testFocusTracksEmbedder, | 734 'testFocusTracksEmbedder': testFocusTracksEmbedder, |
686 'testInputMethod': testInputMethod, | 735 'testInputMethod': testInputMethod, |
687 'testKeyboardFocusSimple': testKeyboardFocusSimple, | 736 'testKeyboardFocusSimple': testKeyboardFocusSimple, |
688 'testKeyboardFocusWindowFocusCycle': testKeyboardFocusWindowFocusCycle, | 737 'testKeyboardFocusWindowFocusCycle': testKeyboardFocusWindowFocusCycle, |
689 'testFocusRestored': testFocusRestored | 738 'testFocusRestored': testFocusRestored, |
| 739 'testFocusTakeFocus': testFocusTakeFocus |
690 }; | 740 }; |
691 | 741 |
692 onload = function() { | 742 onload = function() { |
693 chrome.test.getConfig(function(config) { | 743 chrome.test.getConfig(function(config) { |
694 chrome.test.sendMessage('Launched'); | 744 chrome.test.sendMessage('Launched'); |
695 }); | 745 }); |
696 }; | 746 }; |
OLD | NEW |