Chromium Code Reviews| 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 }, null, null); | |
| 421 } | |
| 422 | |
| 423 function testKeyboardFocusRunNextStep(expected) { | |
| 424 g_webview.contentWindow.postMessage( | |
| 425 JSON.stringify(['request-getInputValue']), '*'); | |
| 426 | |
| 427 window.addEventListener('message', function(e) { | |
| 428 var data = JSON.parse(e.data); | |
| 429 LOG('send window.message, data: ' + data); | |
| 430 if (data[0] == 'response-inputValue') { | |
| 431 if(data[1] == expected) { | |
|
alexmos
2016/06/24 01:38:49
nit: space after if
avallee
2016/07/25 19:02:05
Done.
| |
| 432 chrome.test.sendMessage('TEST_STEP_PASSED'); | |
| 433 } else { | |
| 434 chrome.test.sendMessage('TEST_STEP_FAILED'); | |
| 435 } | |
| 436 } | |
| 437 }); | |
| 438 } | |
| 439 | |
| 392 // This test verifies IME related stuff for guest. | 440 // This test verifies IME related stuff for guest. |
| 393 // | 441 // |
| 394 // Briefly: | 442 // Briefly: |
| 395 // 1) We load a guest, the guest gets initial focus and sends message | 443 // 1) We load a guest, the guest gets initial focus and sends message |
| 396 // back to the embedder. | 444 // back to the embedder. |
| 397 // 2) In InputMethodTestHelper's step 1, we receive some text via cpp, the | 445 // 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. | 446 // 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 | 447 // 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. | 448 // to InputTest456, this is done from cpp via committing an IME composition. |
| 401 // 4) In InputMethodTestHelper's step 3, we have a composition (InputTest789) | 449 // 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; | 639 webview.src = embedder.guestURL; |
| 592 } | 640 } |
| 593 | 641 |
| 594 embedder.test.testList = { | 642 embedder.test.testList = { |
| 595 'testAdvanceFocus': testAdvanceFocus, | 643 'testAdvanceFocus': testAdvanceFocus, |
| 596 'testBlurEvent': testBlurEvent, | 644 'testBlurEvent': testBlurEvent, |
| 597 'testFocusBeforeNavigation': testFocusBeforeNavigation, | 645 'testFocusBeforeNavigation': testFocusBeforeNavigation, |
| 598 'testFocusEvent': testFocusEvent, | 646 'testFocusEvent': testFocusEvent, |
| 599 'testFocusTracksEmbedder': testFocusTracksEmbedder, | 647 'testFocusTracksEmbedder': testFocusTracksEmbedder, |
| 600 'testInputMethod': testInputMethod, | 648 'testInputMethod': testInputMethod, |
| 649 'testKeyboardFocus': testKeyboardFocus, | |
| 601 'testFocusRestored': testFocusRestored | 650 'testFocusRestored': testFocusRestored |
| 602 }; | 651 }; |
| 603 | 652 |
| 604 onload = function() { | 653 onload = function() { |
| 605 chrome.test.getConfig(function(config) { | 654 chrome.test.getConfig(function(config) { |
| 606 chrome.test.sendMessage('Launched'); | 655 chrome.test.sendMessage('Launched'); |
| 607 }); | 656 }); |
| 608 }; | 657 }; |
| OLD | NEW |