1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/tests/test_native_key_bindings_mac.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,327 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 + <head> 1.7 + <meta charset='utf-8'/> 1.8 + <title>Native Key Bindings for Cocoa Test</title> 1.9 + <!-- Any copyright is dedicated to the Public Domain. 1.10 + http://creativecommons.org/publicdomain/zero/1.0/ --> 1.11 + <script type="text/javascript" 1.12 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <script type="text/javascript" 1.14 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.15 + <script type="text/javascript" 1.16 + src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script> 1.17 + </head> 1.18 + <body> 1.19 + <div id="editable" contenteditable> 1.20 + <p>Stretching attack nullam stuck in a tree zzz, suspendisse cras nec 1.21 + suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the 1.22 + curtains biting I don't like that food tristique biting sleep on your 1.23 + keyboard non. Lay down in your way cras nec tempus chase the red dot cras 1.24 + nec, pharetra pharetra eat the grass leap run orci turpis attack. 1.25 + Consectetur sleep in the sink eat I don't like that food, knock over the 1.26 + lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed 1.27 + everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. Nullam 1.28 + pellentesque rip the couch iaculis rhoncus nibh, give me fish orci turpis 1.29 + purr sleep on your face quis nunc bibendum.</p> 1.30 + 1.31 + <p>Neque jump on the table bat iaculis, adipiscing sleep on your keyboard 1.32 + jump vel justo shed everywhere suspendisse lick. Zzz enim faucibus 1.33 + hairball faucibus, pharetra sunbathe biting bat leap rip the couch attack. 1.34 + Tortor nibh in viverra quis hairball nam, vulputate adipiscing sleep on 1.35 + your keyboard purr knock over the lamp orci turpis. Vestibulum I don't 1.36 + like that food et chase the red dot, adipiscing neque bibendum rutrum 1.37 + accumsan quis rhoncus claw. Leap accumsan vehicula enim biting sleep on 1.38 + your face, pharetra nam accumsan egestas kittens sunbathe. Pharetra chase 1.39 + the red dot sniff non eat the grass, vulputate fluffy fur aliquam puking 1.40 + judging you.</p> 1.41 + 1.42 + <p>Claw purr sollicitudin sollicitudin lay down in your way consectetur, 1.43 + pellentesque vehicula zzz orci turpis consectetur. I don't like that food 1.44 + rhoncus pellentesque sniff attack, rhoncus tortor attack your ankles 1.45 + iaculis scratched hiss vel. Tortor zzz tortor nullam rip the couch rutrum, 1.46 + bat enim ut leap hairball iaculis. Bibendum sunbathe elit suspendisse 1.47 + nibh, puking adipiscing sleep on your face sleep on your face zzz catnip. 1.48 + Judging you rutrum bat sunbathe sleep on your face, jump on the table leap 1.49 + tincidunt a faucibus sleep in the sink. Stuck in a tree tristique zzz hiss 1.50 + in viverra nullam, quis tortor pharetra attack.</p> 1.51 + </div> 1.52 + 1.53 + <textarea id="textarea" cols="80"> 1.54 + Stretching attack nullam stuck in a tree zzz, suspendisse cras nec 1.55 + suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the 1.56 + curtains biting I don't like that food tristique biting sleep on your 1.57 + keyboard non. Lay down in your way cras nec tempus chase the red dot cras 1.58 + nec, pharetra pharetra eat the grass leap run orci turpis attack. 1.59 + Consectetur sleep in the sink eat I don't like that food, knock over the 1.60 + lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed 1.61 + everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. Nullam 1.62 + pellentesque rip the couch iaculis rhoncus nibh, give me fish orci turpis 1.63 + purr sleep on your face quis nunc bibendum. 1.64 + 1.65 + Neque jump on the table bat iaculis, adipiscing sleep on your keyboard 1.66 + jump vel justo shed everywhere suspendisse lick. Zzz enim faucibus 1.67 + hairball faucibus, pharetra sunbathe biting bat leap rip the couch attack. 1.68 + Tortor nibh in viverra quis hairball nam, vulputate adipiscing sleep on 1.69 + your keyboard purr knock over the lamp orci turpis. Vestibulum I don't 1.70 + like that food et chase the red dot, adipiscing neque bibendum rutrum 1.71 + accumsan quis rhoncus claw. Leap accumsan vehicula enim biting sleep on 1.72 + your face, pharetra nam accumsan egestas kittens sunbathe. Pharetra chase 1.73 + the red dot sniff non eat the grass, vulputate fluffy fur aliquam puking 1.74 + judging you. 1.75 + 1.76 + Claw purr sollicitudin sollicitudin lay down in your way consectetur, 1.77 + pellentesque vehicula zzz orci turpis consectetur. I don't like that food 1.78 + rhoncus pellentesque sniff attack, rhoncus tortor attack your ankles 1.79 + iaculis scratched hiss vel. Tortor zzz tortor nullam rip the couch rutrum, 1.80 + bat enim ut leap hairball iaculis. Bibendum sunbathe elit suspendisse 1.81 + nibh, puking adipiscing sleep on your face sleep on your face zzz catnip. 1.82 + Judging you rutrum bat sunbathe sleep on your face, jump on the table leap 1.83 + tincidunt a faucibus sleep in the sink. Stuck in a tree tristique zzz hiss 1.84 + in viverra nullam, quis tortor pharetra attack. 1.85 + </textarea> 1.86 + 1.87 + <input id="input" type="text" 1.88 + value="Stretching attack nullam stuck in a tree zzz, suspendisse cras nec 1.89 + suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the 1.90 + curtains biting I don't like that food tristique biting sleep on your 1.91 + keyboard non. Lay down in your way cras nec tempus chase the red dot cras 1.92 + nec, pharetra pharetra eat the grass leap run orci turpis attack. 1.93 + Consectetur sleep in the sink eat I don't like that food, knock over the 1.94 + lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed 1.95 + everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. 1.96 + Nullam pellentesque rip the couch iaculis rhoncus nibh, give me fish orci 1.97 + turpis purr sleep on your face quis nunc bibendum."> 1.98 + 1.99 + <script type="text/javascript;version=1.8"> 1.100 + SimpleTest.waitForExplicitFinish(); 1.101 + 1.102 + let synthesizedKeys = []; 1.103 + let expectations = []; 1.104 + 1.105 + // Move to beginning of line 1.106 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_LeftArrow, 1.107 + {ctrlKey: true}, "\uf702", "\uf702"]); 1.108 + expectations.push({ 1.109 + editable: [0, 0], 1.110 + textarea: [0, 0], 1.111 + input: [0, 0] 1.112 + }); 1.113 + 1.114 + // Move to end of line 1.115 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow, 1.116 + {ctrlKey: true}, "\uf703", "\uf703"]); 1.117 + expectations.push({ 1.118 + editable: [73, 73], 1.119 + textarea: [72, 72], 1.120 + input: [732, 732] 1.121 + }); 1.122 + 1.123 + // Move down 1.124 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_N, 1.125 + {ctrlKey: true}, "\u000e", "n"]); 1.126 + expectations.push({ 1.127 + editable: [140, 140], 1.128 + textarea: [145, 145], 1.129 + input: [732, 732] 1.130 + }); 1.131 + 1.132 + // Move to beginning of line 1.133 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_LeftArrow, 1.134 + {ctrlKey: true}, "\uf702", "\uf702"]); 1.135 + expectations.push({ 1.136 + editable: [73, 73], 1.137 + textarea: [73, 73], 1.138 + input: [0, 0] 1.139 + }); 1.140 + 1.141 + // Move word right and modify selection 1.142 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow, 1.143 + {altKey: true, shiftKey: true}, "\uf703", "\uf703"]); 1.144 + expectations.push({ 1.145 + editable: [73, 84], 1.146 + textarea: [73, 90], 1.147 + input: [0, 10] 1.148 + }); 1.149 + 1.150 + // Move word right 1.151 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow, 1.152 + {altKey: true}, "\uf703", "\uf703"]); 1.153 + expectations.push({ 1.154 + editable: [84, 84], 1.155 + textarea: [90, 90], 1.156 + input: [10, 10] 1.157 + }); 1.158 + 1.159 + // Move word right 1.160 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow, 1.161 + {altKey: true}, "\uf703", "\uf703"]); 1.162 + expectations.push({ 1.163 + editable: [89, 89], 1.164 + textarea: [95, 95], 1.165 + input: [17, 17] 1.166 + }); 1.167 + 1.168 + // Move down and modify selection 1.169 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_DownArrow, 1.170 + {shiftKey: true}, "\uf701", "\uf701"]); 1.171 + expectations.push({ 1.172 + editable: [89, 171], 1.173 + textarea: [95, 175], 1.174 + input: [17, 732] 1.175 + }); 1.176 + 1.177 + // Move backward and modify selection 1.178 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B, 1.179 + {ctrlKey: true, shiftKey: true}, "\u0002", "B"]); 1.180 + expectations.push({ 1.181 + editable: [89, 170], 1.182 + textarea: [95, 174], 1.183 + input: [17, 731] 1.184 + }); 1.185 + 1.186 + // Delete forward 1.187 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_D, 1.188 + {ctrlKey: true}, "\u0004", "d"]); 1.189 + expectations.push({ 1.190 + editable: [89, 89], 1.191 + textarea: [95, 95], 1.192 + input: [17, 17] 1.193 + }); 1.194 + 1.195 + // Delete backward 1.196 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_H, 1.197 + {ctrlKey: true}, "\u0008", "h"]); 1.198 + expectations.push({ 1.199 + editable: [88, 88], 1.200 + textarea: [94, 94], 1.201 + input: [16, 16] 1.202 + }); 1.203 + 1.204 + // Move backward 1.205 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B, 1.206 + {ctrlKey: true}, "\u0002", "b"]); 1.207 + expectations.push({ 1.208 + editable: [87, 87], 1.209 + textarea: [93, 93], 1.210 + input: [15, 15] 1.211 + }); 1.212 + 1.213 + // Move to beginning of paragraph (line for now) 1.214 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, 1.215 + {ctrlKey: true}, "\u0001", "a"]); 1.216 + expectations.push({ 1.217 + editable: [73, 73], 1.218 + textarea: [73, 73], 1.219 + input: [0, 0] 1.220 + }); 1.221 + 1.222 + // Move forward 1.223 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_F, 1.224 + {ctrlKey: true}, "\u0006", "f"]); 1.225 + expectations.push({ 1.226 + editable: [74, 74], 1.227 + textarea: [74, 74], 1.228 + input: [1, 1] 1.229 + }); 1.230 + 1.231 + // Move word right 1.232 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow, 1.233 + {altKey: true}, "\uf703", "\uf703"]); 1.234 + expectations.push({ 1.235 + editable: [84, 84], 1.236 + textarea: [90, 90], 1.237 + input: [10, 10] 1.238 + }); 1.239 + 1.240 + // Move word right 1.241 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow, 1.242 + {altKey: true}, "\uf703", "\uf703"]); 1.243 + expectations.push({ 1.244 + editable: [88, 88], 1.245 + textarea: [94, 94], 1.246 + input: [17, 17] 1.247 + }); 1.248 + 1.249 + // Delete to end of paragraph (line for now) 1.250 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_K, 1.251 + {ctrlKey: true}, "\u000b", "k"]); 1.252 + expectations.push({ 1.253 + editable: [88, 88], 1.254 + textarea: [94, 94], 1.255 + input: [17, 17] 1.256 + }); 1.257 + 1.258 + // Move backward and modify selection 1.259 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B, 1.260 + {ctrlKey: true, shiftKey: true}, "\u0002", "B"]); 1.261 + expectations.push({ 1.262 + editable: [88, 87], 1.263 + textarea: [93, 94], 1.264 + input: [16, 17] 1.265 + }); 1.266 + 1.267 + // Move to end of paragraph (line for now) 1.268 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_E, 1.269 + {ctrlKey: true}, "\u0005", "e"]); 1.270 + expectations.push({ 1.271 + editable: [144, 144], 1.272 + textarea: [94, 94], 1.273 + input: [17, 17] 1.274 + }); 1.275 + 1.276 + // Move up 1.277 + synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_P, 1.278 + {ctrlKey: true}, "\u0010", "p"]); 1.279 + expectations.push({ 1.280 + editable: [73, 73], 1.281 + textarea: [21, 21], 1.282 + input: [0, 0] 1.283 + }); 1.284 + 1.285 + function checkWindowSelection(aElement, aSelection) 1.286 + { 1.287 + let selection = window.getSelection(); 1.288 + 1.289 + is(selection.anchorOffset, aSelection[aElement.id][0], 1.290 + aElement.id + ": Incorrect anchor offset"); 1.291 + is(selection.focusOffset, aSelection[aElement.id][1], 1.292 + aElement.id + ": Incorrect focus offset"); 1.293 + } 1.294 + 1.295 + function checkElementSelection(aElement, aSelection) 1.296 + { 1.297 + is(aElement.selectionStart, aSelection[aElement.id][0], 1.298 + aElement.id + ": Incorrect selection start"); 1.299 + is(aElement.selectionEnd, aSelection[aElement.id][1], 1.300 + aElement.id + ": Incorrect selection end"); 1.301 + } 1.302 + 1.303 + function testRun(aElement, aSelectionCheck) 1.304 + { 1.305 + if (document.activeElement) { 1.306 + document.activeElement.blur(); 1.307 + } 1.308 + 1.309 + aElement.focus(); 1.310 + 1.311 + for (let i = 0; i < synthesizedKeys.length; i++) { 1.312 + synthesizeNativeKey.apply(null, synthesizedKeys[i]); 1.313 + aSelectionCheck.call(null, aElement, expectations[i]); 1.314 + } 1.315 + } 1.316 + 1.317 + function doTest() 1.318 + { 1.319 + testRun(document.getElementById("editable"), checkWindowSelection); 1.320 + testRun(document.getElementById("textarea"), checkElementSelection); 1.321 + testRun(document.getElementById("input"), checkElementSelection); 1.322 + 1.323 + SimpleTest.finish(); 1.324 + } 1.325 + 1.326 + SimpleTest.waitForFocus(doTest); 1.327 + </script> 1.328 + </body> 1.329 +</html> 1.330 +