| 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 15 matching lines...) Expand all Loading... |
| 26 window.console.log('window.runCommand: ' + command); | 26 window.console.log('window.runCommand: ' + command); |
| 27 switch (command) { | 27 switch (command) { |
| 28 case 'testFocusTracksEmbedderRunNextStep': | 28 case 'testFocusTracksEmbedderRunNextStep': |
| 29 testFocusTracksEmbedderRunNextStep(); | 29 testFocusTracksEmbedderRunNextStep(); |
| 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; |
| 37 case 'testKeyboardFocusRunNextStep': |
| 38 testKeyboardFocusRunNextStep(opt_step); |
| 39 break; |
| 36 default: | 40 default: |
| 37 embedder.test.fail(); | 41 embedder.test.fail(); |
| 38 } | 42 } |
| 39 }; | 43 }; |
| 40 // window.* exported functions end. | 44 // window.* exported functions end. |
| 41 | 45 |
| 42 var LOG = function(msg) { | 46 var LOG = function(msg) { |
| 43 window.console.log(msg); | 47 window.console.log(msg); |
| 44 }; | 48 }; |
| 45 | 49 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 webview.blur(); | 386 webview.blur(); |
| 383 }, 'blurred', function() { | 387 }, 'blurred', function() { |
| 384 if (seenResponse) { | 388 if (seenResponse) { |
| 385 return; | 389 return; |
| 386 } | 390 } |
| 387 seenResponse = true; | 391 seenResponse = true; |
| 388 embedder.test.succeed(); | 392 embedder.test.succeed(); |
| 389 }); | 393 }); |
| 390 } | 394 } |
| 391 | 395 |
| 396 // This test verifies that keyboard input is correctly routed into the guest. |
| 397 // |
| 398 // 1) Load the guest and attach an <input> to the guest dom. Count the number of |
| 399 // input events sent to that element. |
| 400 // 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. |
| 402 // 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 |
| 404 // and then expects the vaue of the <input> to be what the test sent, notably: |
| 405 // aBc. |
| 406 function testKeyboardFocus() { |
| 407 embedder.testFocus_(function(webview) { |
| 408 var created = function(e) { |
| 409 var data = JSON.parse(e.data); |
| 410 if (data[0] === 'response-createdInput') { |
| 411 chrome.test.sendMessage('TEST_PASSED'); |
| 412 window.removeEventListener('message', created); |
| 413 } |
| 414 }; |
| 415 window.addEventListener('message', created); |
| 416 |
| 417 g_webview = webview; |
| 418 var msg = ['request-createInput', 3]; |
| 419 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 420 }, 'response-elementClicked', function() { |
| 421 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 422 }); |
| 423 |
| 424 } |
| 425 |
| 426 function testKeyboardFocusRunNextStep(expected) { |
| 427 g_webview.contentWindow.postMessage( |
| 428 JSON.stringify(['request-getInputValue']), '*'); |
| 429 |
| 430 window.addEventListener('message', function(e) { |
| 431 var data = JSON.parse(e.data); |
| 432 LOG('send window.message, data: ' + data); |
| 433 if (data[0] == 'response-inputValue') { |
| 434 if (data[1] == expected) { |
| 435 chrome.test.sendMessage('TEST_STEP_PASSED'); |
| 436 } else { |
| 437 chrome.test.sendMessage('TEST_STEP_FAILED'); |
| 438 } |
| 439 } |
| 440 }); |
| 441 } |
| 442 |
| 392 // This test verifies IME related stuff for guest. | 443 // This test verifies IME related stuff for guest. |
| 393 // | 444 // |
| 394 // Briefly: | 445 // Briefly: |
| 395 // 1) We load a guest, the guest gets initial focus and sends message | 446 // 1) We load a guest, the guest gets initial focus and sends message |
| 396 // back to the embedder. | 447 // back to the embedder. |
| 397 // 2) In InputMethodTestHelper's step 1, we receive some text via cpp, the | 448 // 2) In InputMethodTestHelper's step 1, we receive some text via cpp, the |
| 398 // text is InputTest123, we verify we've seen the change in the guest. | 449 // text is InputTest123, we verify we've seen the change in the guest. |
| 399 // 3) In InputMethodTestHelper's step 2, we expect the text to be changed | 450 // 3) In InputMethodTestHelper's step 2, we expect the text to be changed |
| 400 // to InputTest456, this is done from cpp via committing an IME composition. | 451 // to InputTest456, this is done from cpp via committing an IME composition. |
| 401 // 4) In InputMethodTestHelper's step 3, we have a composition (InputTest789) | 452 // 4) In InputMethodTestHelper's step 3, we have a composition (InputTest789) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 webview.src = embedder.guestURL; | 642 webview.src = embedder.guestURL; |
| 592 } | 643 } |
| 593 | 644 |
| 594 embedder.test.testList = { | 645 embedder.test.testList = { |
| 595 'testAdvanceFocus': testAdvanceFocus, | 646 'testAdvanceFocus': testAdvanceFocus, |
| 596 'testBlurEvent': testBlurEvent, | 647 'testBlurEvent': testBlurEvent, |
| 597 'testFocusBeforeNavigation': testFocusBeforeNavigation, | 648 'testFocusBeforeNavigation': testFocusBeforeNavigation, |
| 598 'testFocusEvent': testFocusEvent, | 649 'testFocusEvent': testFocusEvent, |
| 599 'testFocusTracksEmbedder': testFocusTracksEmbedder, | 650 'testFocusTracksEmbedder': testFocusTracksEmbedder, |
| 600 'testInputMethod': testInputMethod, | 651 'testInputMethod': testInputMethod, |
| 652 'testKeyboardFocus': testKeyboardFocus, |
| 601 'testFocusRestored': testFocusRestored | 653 'testFocusRestored': testFocusRestored |
| 602 }; | 654 }; |
| 603 | 655 |
| 604 onload = function() { | 656 onload = function() { |
| 605 chrome.test.getConfig(function(config) { | 657 chrome.test.getConfig(function(config) { |
| 606 chrome.test.sendMessage('Launched'); | 658 chrome.test.sendMessage('Launched'); |
| 607 }); | 659 }); |
| 608 }; | 660 }; |
| OLD | NEW |