widget/tests/test_native_key_bindings_mac.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3   <head>
     4     <meta charset='utf-8'/>
     5     <title>Native Key Bindings for Cocoa Test</title>
     6     <!-- Any copyright is dedicated to the Public Domain.
     7          http://creativecommons.org/publicdomain/zero/1.0/ -->
     8     <script type="text/javascript"
     9             src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    10     <script type="text/javascript"
    11             src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    12     <script type="text/javascript"
    13             src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
    14   </head>
    15   <body>
    16     <div id="editable" contenteditable>
    17       <p>Stretching attack nullam stuck in a tree zzz, suspendisse cras nec
    18       suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the
    19       curtains biting I don't like that food tristique biting sleep on your
    20       keyboard non. Lay down in your way cras nec tempus chase the red dot cras
    21       nec, pharetra pharetra eat the grass leap run orci turpis attack.
    22       Consectetur sleep in the sink eat I don't like that food, knock over the
    23       lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed
    24       everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. Nullam
    25       pellentesque rip the couch iaculis rhoncus nibh, give me fish orci turpis
    26       purr sleep on your face quis nunc bibendum.</p>
    28       <p>Neque jump on the table bat iaculis, adipiscing sleep on your keyboard
    29       jump vel justo shed everywhere suspendisse lick. Zzz enim faucibus
    30       hairball faucibus, pharetra sunbathe biting bat leap rip the couch attack.
    31       Tortor nibh in viverra quis hairball nam, vulputate adipiscing sleep on
    32       your keyboard purr knock over the lamp orci turpis. Vestibulum I don't
    33       like that food et chase the red dot, adipiscing neque bibendum rutrum
    34       accumsan quis rhoncus claw. Leap accumsan vehicula enim biting sleep on
    35       your face, pharetra nam accumsan egestas kittens sunbathe. Pharetra chase
    36       the red dot sniff non eat the grass, vulputate fluffy fur aliquam puking
    37       judging you.</p>
    39       <p>Claw purr sollicitudin sollicitudin lay down in your way consectetur,
    40       pellentesque vehicula zzz orci turpis consectetur. I don't like that food
    41       rhoncus pellentesque sniff attack, rhoncus tortor attack your ankles
    42       iaculis scratched hiss vel. Tortor zzz tortor nullam rip the couch rutrum,
    43       bat enim ut leap hairball iaculis. Bibendum sunbathe elit suspendisse
    44       nibh, puking adipiscing sleep on your face sleep on your face zzz catnip.
    45       Judging you rutrum bat sunbathe sleep on your face, jump on the table leap
    46       tincidunt a faucibus sleep in the sink. Stuck in a tree tristique zzz hiss
    47       in viverra nullam, quis tortor pharetra attack.</p>
    48     </div>
    50     <textarea id="textarea" cols="80">
    51       Stretching attack nullam stuck in a tree zzz, suspendisse cras nec
    52       suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the
    53       curtains biting I don't like that food tristique biting sleep on your
    54       keyboard non. Lay down in your way cras nec tempus chase the red dot cras
    55       nec, pharetra pharetra eat the grass leap run orci turpis attack.
    56       Consectetur sleep in the sink eat I don't like that food, knock over the
    57       lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed
    58       everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. Nullam
    59       pellentesque rip the couch iaculis rhoncus nibh, give me fish orci turpis
    60       purr sleep on your face quis nunc bibendum.
    62       Neque jump on the table bat iaculis, adipiscing sleep on your keyboard
    63       jump vel justo shed everywhere suspendisse lick. Zzz enim faucibus
    64       hairball faucibus, pharetra sunbathe biting bat leap rip the couch attack.
    65       Tortor nibh in viverra quis hairball nam, vulputate adipiscing sleep on
    66       your keyboard purr knock over the lamp orci turpis. Vestibulum I don't
    67       like that food et chase the red dot, adipiscing neque bibendum rutrum
    68       accumsan quis rhoncus claw. Leap accumsan vehicula enim biting sleep on
    69       your face, pharetra nam accumsan egestas kittens sunbathe. Pharetra chase
    70       the red dot sniff non eat the grass, vulputate fluffy fur aliquam puking
    71       judging you.
    73       Claw purr sollicitudin sollicitudin lay down in your way consectetur,
    74       pellentesque vehicula zzz orci turpis consectetur. I don't like that food
    75       rhoncus pellentesque sniff attack, rhoncus tortor attack your ankles
    76       iaculis scratched hiss vel. Tortor zzz tortor nullam rip the couch rutrum,
    77       bat enim ut leap hairball iaculis. Bibendum sunbathe elit suspendisse
    78       nibh, puking adipiscing sleep on your face sleep on your face zzz catnip.
    79       Judging you rutrum bat sunbathe sleep on your face, jump on the table leap
    80       tincidunt a faucibus sleep in the sink. Stuck in a tree tristique zzz hiss
    81       in viverra nullam, quis tortor pharetra attack.
    82     </textarea>
    84     <input id="input" type="text"
    85       value="Stretching attack nullam stuck in a tree zzz, suspendisse cras nec
    86       suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the
    87       curtains biting I don't like that food tristique biting sleep on your
    88       keyboard non. Lay down in your way cras nec tempus chase the red dot cras
    89       nec, pharetra pharetra eat the grass leap run orci turpis attack.
    90       Consectetur sleep in the sink eat I don't like that food, knock over the
    91       lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed
    92       everywhere kittens rhoncus, attack your ankles zzz iaculis kittens.
    93       Nullam pellentesque rip the couch iaculis rhoncus nibh, give me fish orci
    94       turpis purr sleep on your face quis nunc bibendum.">
    96     <script type="text/javascript;version=1.8">
    97       SimpleTest.waitForExplicitFinish();
    99       let synthesizedKeys = [];
   100       let expectations = [];
   102       // Move to beginning of line
   103       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_LeftArrow,
   104                             {ctrlKey: true}, "\uf702", "\uf702"]);
   105       expectations.push({
   106         editable: [0, 0],
   107         textarea: [0, 0],
   108         input:    [0, 0]
   109       });
   111       // Move to end of line
   112       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
   113                             {ctrlKey: true}, "\uf703", "\uf703"]);
   114       expectations.push({
   115         editable: [73, 73],
   116         textarea: [72, 72],
   117         input:    [732, 732]
   118       });
   120       // Move down
   121       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_N,
   122                             {ctrlKey: true}, "\u000e", "n"]);
   123       expectations.push({
   124         editable: [140, 140],
   125         textarea: [145, 145],
   126         input:    [732, 732]
   127       });
   129       // Move to beginning of line
   130       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_LeftArrow,
   131                             {ctrlKey: true}, "\uf702", "\uf702"]);
   132       expectations.push({
   133         editable: [73, 73],
   134         textarea: [73, 73],
   135         input:    [0, 0]
   136       });
   138       // Move word right and modify selection
   139       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
   140                             {altKey: true, shiftKey: true}, "\uf703", "\uf703"]);
   141       expectations.push({
   142         editable: [73, 84],
   143         textarea: [73, 90],
   144         input:    [0, 10]
   145       });
   147       // Move word right
   148       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
   149                             {altKey: true}, "\uf703", "\uf703"]);
   150       expectations.push({
   151         editable: [84, 84],
   152         textarea: [90, 90],
   153         input:    [10, 10]
   154       });
   156       // Move word right
   157       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
   158                             {altKey: true}, "\uf703", "\uf703"]);
   159       expectations.push({
   160         editable: [89, 89],
   161         textarea: [95, 95],
   162         input:    [17, 17]
   163       });
   165       // Move down and modify selection
   166       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_DownArrow,
   167                             {shiftKey: true}, "\uf701", "\uf701"]);
   168       expectations.push({
   169         editable: [89, 171],
   170         textarea: [95, 175],
   171         input:    [17, 732]
   172       });
   174       // Move backward and modify selection
   175       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B,
   176                             {ctrlKey: true, shiftKey: true}, "\u0002", "B"]);
   177       expectations.push({
   178         editable: [89, 170],
   179         textarea: [95, 174],
   180         input:    [17, 731]
   181       });
   183       // Delete forward
   184       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_D,
   185                             {ctrlKey: true}, "\u0004", "d"]);
   186       expectations.push({
   187         editable: [89, 89],
   188         textarea: [95, 95],
   189         input:    [17, 17]
   190       });
   192       // Delete backward
   193       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_H,
   194                             {ctrlKey: true}, "\u0008", "h"]);
   195       expectations.push({
   196         editable: [88, 88],
   197         textarea: [94, 94],
   198         input:    [16, 16]
   199       });
   201       // Move backward
   202       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B,
   203                             {ctrlKey: true}, "\u0002", "b"]);
   204       expectations.push({
   205         editable: [87, 87],
   206         textarea: [93, 93],
   207         input:    [15, 15]
   208       });
   210       // Move to beginning of paragraph (line for now)
   211       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A,
   212                             {ctrlKey: true}, "\u0001", "a"]);
   213       expectations.push({
   214         editable: [73, 73],
   215         textarea: [73, 73],
   216         input:    [0, 0]
   217       });
   219       // Move forward
   220       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_F,
   221                             {ctrlKey: true}, "\u0006", "f"]);
   222       expectations.push({
   223         editable: [74, 74],
   224         textarea: [74, 74],
   225         input:    [1, 1]
   226       });
   228       // Move word right
   229       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
   230                             {altKey: true}, "\uf703", "\uf703"]);
   231       expectations.push({
   232         editable: [84, 84],
   233         textarea: [90, 90],
   234         input:    [10, 10]
   235       });
   237       // Move word right
   238       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
   239                             {altKey: true}, "\uf703", "\uf703"]);
   240       expectations.push({
   241         editable: [88, 88],
   242         textarea: [94, 94],
   243         input:    [17, 17]
   244       });
   246       // Delete to end of paragraph (line for now)
   247       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_K,
   248                             {ctrlKey: true}, "\u000b", "k"]);
   249       expectations.push({
   250         editable: [88, 88],
   251         textarea: [94, 94],
   252         input:    [17, 17]
   253       });
   255       // Move backward and modify selection
   256       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B,
   257                             {ctrlKey: true, shiftKey: true}, "\u0002", "B"]);
   258       expectations.push({
   259         editable: [88, 87],
   260         textarea: [93, 94],
   261         input:    [16, 17]
   262       });
   264       // Move to end of paragraph (line for now)
   265       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_E,
   266                             {ctrlKey: true}, "\u0005", "e"]);
   267       expectations.push({
   268         editable: [144, 144],
   269         textarea: [94, 94],
   270         input:    [17, 17]
   271       });
   273       // Move up
   274       synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_P,
   275                             {ctrlKey: true}, "\u0010", "p"]);
   276       expectations.push({
   277         editable: [73, 73],
   278         textarea: [21, 21],
   279         input:    [0, 0]
   280       });
   282       function checkWindowSelection(aElement, aSelection)
   283       {
   284         let selection = window.getSelection();
   286         is(selection.anchorOffset, aSelection[aElement.id][0],
   287            aElement.id + ": Incorrect anchor offset");
   288         is(selection.focusOffset, aSelection[aElement.id][1],
   289            aElement.id + ": Incorrect focus offset");
   290       }
   292       function checkElementSelection(aElement, aSelection)
   293       {
   294         is(aElement.selectionStart, aSelection[aElement.id][0],
   295            aElement.id + ": Incorrect selection start");
   296         is(aElement.selectionEnd, aSelection[aElement.id][1],
   297            aElement.id + ": Incorrect selection end");
   298       }
   300       function testRun(aElement, aSelectionCheck)
   301       {
   302         if (document.activeElement) {
   303           document.activeElement.blur();
   304         }
   306         aElement.focus();
   308         for (let i = 0; i < synthesizedKeys.length; i++) {
   309           synthesizeNativeKey.apply(null, synthesizedKeys[i]);
   310           aSelectionCheck.call(null, aElement, expectations[i]);
   311         }
   312       }
   314       function doTest()
   315       {
   316         testRun(document.getElementById("editable"), checkWindowSelection);
   317         testRun(document.getElementById("textarea"), checkElementSelection);
   318         testRun(document.getElementById("input"), checkElementSelection);
   320         SimpleTest.finish();
   321       }
   323       SimpleTest.waitForFocus(doTest);
   324     </script>
   325   </body>
   326 </html>

mercurial