| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="textinput_helper.js"></script> | |
| 4 <script> | |
| 5 var expectations = new Array(); | |
| 6 var result = true; | |
| 7 | |
| 8 /** | |
| 9 * Expectations are of the form: | |
| 10 * [ { keyCode: 39, shiftKey: true, ctrlKey: false, altKey: true}, ... ] | |
| 11 */ | |
| 12 function initKeyDownExpectations(expect) { | |
| 13 expectations = expect; | |
| 14 result = true; | |
| 15 } | |
| 16 | |
| 17 function didTestSucceed() { | |
| 18 if (!result) { | |
| 19 window.domAutomationController.send(false); | |
| 20 } else if (expectations.length != 0) { | |
| 21 console.error('There are un-satisfied expectations.'); | |
| 22 window.domAutomationController.send(false); | |
| 23 } else { | |
| 24 window.domAutomationController.send(true); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 window.onload = function() { | |
| 29 document.getElementById('text_id').onkeydown = function(e) { | |
| 30 if (expectations.length == 0) { | |
| 31 console.error('Expectations have been exhausted.'); | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 if (e.keyCode != expectations[0].keyCode) { | |
| 36 result = false; | |
| 37 console.error('keyCode does not match.' + | |
| 38 ' Expected:' + expectations[0].keyCode + | |
| 39 ' Actual: ' + e.keyCode); | |
| 40 } | |
| 41 if (e.shiftKey != expectations[0].shiftKey) { | |
| 42 result = false; | |
| 43 console.error('shiftKey does not match.' + | |
| 44 ' Expected:' + expectations[0].shiftKey + | |
| 45 ' Actual: ' + e.shiftKey); | |
| 46 } | |
| 47 | |
| 48 if (e.ctrlKey != expectations[0].ctrlKey) { | |
| 49 result = false; | |
| 50 console.error('ctrlKey does not match.' + | |
| 51 ' Expected:' + expectations[0].ctrlKey + | |
| 52 ' Actual: ' + e.ctrlKey); | |
| 53 } | |
| 54 | |
| 55 if (e.altKey != expectations[0].altKey) { | |
| 56 result = false; | |
| 57 console.error('altKey does not match.' + | |
| 58 ' Expected:' + expectations[0].altKey + | |
| 59 ' Actual: ' + e.altKey); | |
| 60 } | |
| 61 | |
| 62 expectations.shift(); | |
| 63 }; | |
| 64 } | |
| 65 </script> | |
| 66 </head> | |
| 67 <body> | |
| 68 <input type="text" id="text_id"> | |
| 69 </body> | |
| 70 </html> | |
| OLD | NEW |