| 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 19 matching lines...) Expand all Loading... |
| 30 break; | 30 break; |
| 31 case 'testInputMethodRunNextStep': | 31 case 'testInputMethodRunNextStep': |
| 32 testInputMethodRunNextStep(opt_step); | 32 testInputMethodRunNextStep(opt_step); |
| 33 break; | 33 break; |
| 34 case 'testFocusRestoredRunNextStep': | 34 case 'testFocusRestoredRunNextStep': |
| 35 testFocusRestoredRunNextStep(opt_step); | 35 testFocusRestoredRunNextStep(opt_step); |
| 36 break; | 36 break; |
| 37 case 'testKeyboardFocusRunNextStep': | 37 case 'testKeyboardFocusRunNextStep': |
| 38 testKeyboardFocusRunNextStep(opt_step); | 38 testKeyboardFocusRunNextStep(opt_step); |
| 39 break; | 39 break; |
| 40 case 'monitorGuestEvent': |
| 41 monitorGuestEvent(opt_step); |
| 42 case 'waitGuestEvent': |
| 43 waitGuestEvent(opt_step); |
| 40 default: | 44 default: |
| 41 embedder.test.fail(); | 45 embedder.test.fail(); |
| 42 } | 46 } |
| 43 }; | 47 }; |
| 44 // window.* exported functions end. | 48 // window.* exported functions end. |
| 45 | 49 |
| 46 var LOG = function(msg) { | 50 var LOG = function(msg) { |
| 47 window.console.log(msg); | 51 window.console.log(msg); |
| 48 }; | 52 }; |
| 49 | 53 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // This test verifies that keyboard input is correctly routed into the guest. | 400 // This test verifies that keyboard input is correctly routed into the guest. |
| 397 // | 401 // |
| 398 // 1) Load the guest and attach an <input> to the guest dom. Count the number of | 402 // 1) Load the guest and attach an <input> to the guest dom. Count the number of |
| 399 // input events sent to that element. | 403 // input events sent to that element. |
| 400 // 2) C++ simulates a mouse over and click of the <input> element and waits for | 404 // 2) C++ simulates a mouse over and click of the <input> element and waits for |
| 401 // the browser to see the guest main frame as focused. | 405 // the browser to see the guest main frame as focused. |
| 402 // 3) Injects the key sequence: a, Shift+b, c. | 406 // 3) Injects the key sequence: a, Shift+b, c. |
| 403 // 4) In the second step, the test waits for the input events to be processed | 407 // 4) In the second step, the test waits for the input events to be processed |
| 404 // and then expects the vaue of the <input> to be what the test sent, notably: | 408 // and then expects the vaue of the <input> to be what the test sent, notably: |
| 405 // aBc. | 409 // aBc. |
| 406 function testKeyboardFocus() { | 410 function testKeyboardFocusImpl(input_length) { |
| 407 embedder.testFocus_(function(webview) { | 411 embedder.testFocus_(function(webview) { |
| 408 var created = function(e) { | 412 var created = function(e) { |
| 409 var data = JSON.parse(e.data); | 413 var data = JSON.parse(e.data); |
| 410 if (data[0] === 'response-createdInput') { | 414 if (data[0] === 'response-createdInput') { |
| 411 chrome.test.sendMessage('TEST_PASSED'); | 415 chrome.test.sendMessage('TEST_PASSED'); |
| 412 window.removeEventListener('message', created); | 416 window.removeEventListener('message', created); |
| 413 } | 417 } |
| 414 }; | 418 }; |
| 415 window.addEventListener('message', created); | 419 window.addEventListener('message', created); |
| 416 | 420 |
| 417 g_webview = webview; | 421 g_webview = webview; |
| 418 var msg = ['request-createInput', 3]; | 422 var msg = ['request-createInput', input_length]; |
| 419 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 423 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 420 }, 'response-elementClicked', function() { | 424 }, 'response-elementClicked', function() { |
| 421 chrome.test.sendMessage('TEST_STEP_PASSED'); | 425 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 422 }); | 426 }); |
| 423 | 427 |
| 424 } | 428 } |
| 425 | 429 |
| 426 function testKeyboardFocusRunNextStep(expected) { | 430 function testKeyboardFocusRunNextStep(expected) { |
| 427 g_webview.contentWindow.postMessage( | |
| 428 JSON.stringify(['request-getInputValue']), '*'); | |
| 429 | |
| 430 window.addEventListener('message', function(e) { | 431 window.addEventListener('message', function(e) { |
| 431 var data = JSON.parse(e.data); | 432 var data = JSON.parse(e.data); |
| 432 LOG('send window.message, data: ' + data); | 433 LOG('send window.message, data: ' + data); |
| 433 if (data[0] == 'response-inputValue') { | 434 if (data[0] == 'response-inputValue') { |
| 434 if (data[1] == expected) { | 435 if (data[1] == expected) { |
| 435 chrome.test.sendMessage('TEST_STEP_PASSED'); | 436 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 436 } else { | 437 } else { |
| 437 chrome.test.sendMessage('TEST_STEP_FAILED'); | 438 chrome.test.sendMessage('TEST_STEP_FAILED'); |
| 438 } | 439 } |
| 439 } | 440 } |
| 440 }); | 441 }); |
| 442 |
| 443 g_webview.contentWindow.postMessage( |
| 444 JSON.stringify(['request-getInputValue']), '*'); |
| 445 } |
| 446 |
| 447 function testKeyboardFocusSimple() { |
| 448 testKeyboardFocusImpl(3); |
| 449 } |
| 450 |
| 451 function testKeyboardFocusWindowFocusCycle() { |
| 452 testKeyboardFocusImpl(6); |
| 441 } | 453 } |
| 442 | 454 |
| 443 // This test verifies IME related stuff for guest. | 455 // This test verifies IME related stuff for guest. |
| 444 // | 456 // |
| 445 // Briefly: | 457 // Briefly: |
| 446 // 1) We load a guest, the guest gets initial focus and sends message | 458 // 1) We load a guest, the guest gets initial focus and sends message |
| 447 // back to the embedder. | 459 // back to the embedder. |
| 448 // 2) In InputMethodTestHelper's step 1, we receive some text via cpp, the | 460 // 2) In InputMethodTestHelper's step 1, we receive some text via cpp, the |
| 449 // text is InputTest123, we verify we've seen the change in the guest. | 461 // text is InputTest123, we verify we've seen the change in the guest. |
| 450 // 3) In InputMethodTestHelper's step 2, we expect the text to be changed | 462 // 3) In InputMethodTestHelper's step 2, we expect the text to be changed |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 embedder.test.fail(); | 647 embedder.test.fail(); |
| 636 return; | 648 return; |
| 637 } | 649 } |
| 638 webview.contentWindow.postMessage(JSON.stringify(['connect']), '*'); | 650 webview.contentWindow.postMessage(JSON.stringify(['connect']), '*'); |
| 639 }); | 651 }); |
| 640 }); | 652 }); |
| 641 | 653 |
| 642 webview.src = embedder.guestURL; | 654 webview.src = embedder.guestURL; |
| 643 } | 655 } |
| 644 | 656 |
| 657 function monitorGuestEvent(type) { |
| 658 g_webview.contentWindow.postMessage( |
| 659 JSON.stringify(['request-monitorEvent', type]), '*'); |
| 660 } |
| 661 |
| 662 function waitGuestEvent(type) { |
| 663 var listener = function(e) { |
| 664 var data = JSON.parse(e.data); |
| 665 if (data[0] == 'response-waitEvent') { |
| 666 window.removeEventListener('message', listener); |
| 667 if (data[1] == type) { |
| 668 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 669 } else { |
| 670 chrome.test.sendMessage('TEST_STEP_FAILED'); |
| 671 } |
| 672 } |
| 673 } |
| 674 window.addEventListener('message', listener); |
| 675 |
| 676 g_webview.contentWindow.postMessage( |
| 677 JSON.stringify(['request-waitEvent', type]), '*'); |
| 678 } |
| 679 |
| 645 embedder.test.testList = { | 680 embedder.test.testList = { |
| 646 'testAdvanceFocus': testAdvanceFocus, | 681 'testAdvanceFocus': testAdvanceFocus, |
| 647 'testBlurEvent': testBlurEvent, | 682 'testBlurEvent': testBlurEvent, |
| 648 'testFocusBeforeNavigation': testFocusBeforeNavigation, | 683 'testFocusBeforeNavigation': testFocusBeforeNavigation, |
| 649 'testFocusEvent': testFocusEvent, | 684 'testFocusEvent': testFocusEvent, |
| 650 'testFocusTracksEmbedder': testFocusTracksEmbedder, | 685 'testFocusTracksEmbedder': testFocusTracksEmbedder, |
| 651 'testInputMethod': testInputMethod, | 686 'testInputMethod': testInputMethod, |
| 652 'testKeyboardFocus': testKeyboardFocus, | 687 'testKeyboardFocusSimple': testKeyboardFocusSimple, |
| 688 'testKeyboardFocusWindowFocusCycle': testKeyboardFocusWindowFocusCycle, |
| 653 'testFocusRestored': testFocusRestored | 689 'testFocusRestored': testFocusRestored |
| 654 }; | 690 }; |
| 655 | 691 |
| 656 onload = function() { | 692 onload = function() { |
| 657 chrome.test.getConfig(function(config) { | 693 chrome.test.getConfig(function(config) { |
| 658 chrome.test.sendMessage('Launched'); | 694 chrome.test.sendMessage('Launched'); |
| 659 }); | 695 }); |
| 660 }; | 696 }; |
| OLD | NEW |