Changeset 209892 in webkit


Ignore:
Timestamp:
Dec 15, 2016 5:14:40 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add coordinate space to event streams and streamline tests
https://bugs.webkit.org/show_bug.cgi?id=165119

Patch by Megan Gardner <Megan Gardner> on 2016-12-15
Reviewed by Simon Fraser.

Tools:

Update event streams to allow for both content and global coordinate space.
Update example script to more accurately show all the available options.

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
  • WebKitTestRunner/ios/HIDEventGenerator.h:
  • WebKitTestRunner/ios/HIDEventGenerator.mm:
  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::convertCoordinates):
(WTR::UIScriptController::sendEventStream):

LayoutTests:

Streamline tests. Make them more readable and only use one function for drags.
Update for new content coordinate space.

  • fast/events/touch/ios/long-press-then-drag-down-to-change-selected-text.html:
  • fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r209889 r209892  
     12016-12-15  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add coordinate space to event streams and streamline tests
     4        https://bugs.webkit.org/show_bug.cgi?id=165119
     5
     6        Reviewed by Simon Fraser.
     7
     8        Streamline tests. Make them more readable and only use one function for drags.
     9        Update for new content coordinate space.
     10
     11        * fast/events/touch/ios/long-press-then-drag-down-to-change-selected-text.html:
     12        * fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text.html:
     13
    1142016-12-15  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-down-to-change-selected-text.html

    r208934 r209892  
    1818            })();`
    1919        }
    20    
    21         function getDragDownOneScript()
     20
     21        function getDragScript(startX, startY, endX, endY)
    2222        {
    2323            return `
     
    2828                interpolate : "linear",
    2929                timestep: 0.1,
     30                coordinateSpace : "global",
    3031                startEvent : {
    3132                    inputType : "hand",
     
    3637                        phase : "began",
    3738                        id : 1,
    38                         x : 72,
    39                         y : 140,
     39                        x : ${startX},
     40                        y : ${startY},
    4041                        pressure : 0
    4142                        }
     
    5051                        phase : "moved",
    5152                        id : 1,
    52                         x : 72,
    53                         y : 150,
     53                        x : ${endX},
     54                        y : ${endY},
    5455                        pressure : 0
    5556                        }
     
    6162                uiController.uiScriptComplete();
    6263            })();`
    63         }
    64    
    65         function getDragDownTwoScript()
    66         {
    67             return `
    68             (function() {
    69              var eventStream = {
    70              events : [
    71                  {
    72                  interpolate : "linear",
    73                  timestep: 0.1,
    74                  startEvent : {
    75                      inputType : "hand",
    76                      timeOffset : 0,
    77                      touches : [
    78                          {
    79                          inputType : "finger",
    80                          phase : "began",
    81                          id : 1,
    82                          x : 72,
    83                          y : 150,
    84                          pressure : 0
    85                          }
    86                      ]
    87                  },
    88                  endEvent : {
    89                      inputType : "hand",
    90                      timeOffset : 0.5,
    91                      touches : [
    92                          {
    93                          inputType : "finger",
    94                          phase : "moved",
    95                          id : 1,
    96                          x : 72,
    97                          y : 170,
    98                          pressure : 0
    99                          }
    100                      ]
    101                  }
    102              }]};
    103              
    104              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    105                  uiController.uiScriptComplete();
    106              })();`
    107         }
    108         function getDragUpOneScript()
    109         {
    110             return `
    111             (function() {
    112              var eventStream = {
    113              events : [
    114                  {
    115                  interpolate : "linear",
    116                  timestep: 0.1,
    117                  startEvent : {
    118                      inputType : "hand",
    119                      timeOffset : 0,
    120                      touches : [
    121                          {
    122                          inputType : "finger",
    123                          phase : "began",
    124                          id : 1,
    125                          x : 72,
    126                          y : 170,
    127                          pressure : 0
    128                          }
    129                      ]
    130                  },
    131                  endEvent : {
    132                      inputType : "hand",
    133                      timeOffset : 0.5,
    134                      touches : [
    135                          {
    136                          inputType : "finger",
    137                          phase : "moved",
    138                          id : 1,
    139                          x : 72,
    140                          y : 150,
    141                          pressure : 0
    142                          }
    143                      ]
    144                  }
    145              }]};
    146              
    147              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    148                  uiController.uiScriptComplete();
    149              })();`
    150         }
    151         function getDragUpTwoScript()
    152         {
    153             return `
    154             (function() {
    155              var eventStream = {
    156              events : [
    157                  {
    158                  interpolate : "linear",
    159                  timestep: 0.1,
    160                  startEvent : {
    161                      inputType : "hand",
    162                      timeOffset : 0,
    163                      touches : [
    164                          {
    165                          inputType : "finger",
    166                          phase : "began",
    167                          id : 1,
    168                          x : 72,
    169                          y : 150,
    170                          pressure : 0
    171                          }
    172                      ]
    173                  },
    174                  endEvent : {
    175                      inputType : "hand",
    176                      timeOffset : 0.5,
    177                      touches : [
    178                          {
    179                          inputType : "finger",
    180                          phase : "moved",
    181                          id : 1,
    182                          x : 72,
    183                          y : 135,
    184                          pressure : 0
    185                          }
    186                      ]
    187                  }
    188              }]};
    189              
    190              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    191                  uiController.uiScriptComplete();
    192              })();`
    193         }
    194         function getDragUpPastScript()
    195         {
    196             return `
    197             (function() {
    198              var eventStream = {
    199              events : [
    200                  {
    201                  interpolate : "linear",
    202                  timestep: 0.1,
    203                  startEvent : {
    204                      inputType : "hand",
    205                      timeOffset : 0,
    206                      touches : [
    207                          {
    208                          inputType : "finger",
    209                          phase : "began",
    210                          id : 1,
    211                          x : 72,
    212                          y : 140,
    213                          pressure : 0
    214                          }
    215                      ]
    216                  },
    217                  endEvent : {
    218                      inputType : "hand",
    219                      timeOffset : 0.5,
    220                      touches : [
    221                          {
    222                          inputType : "finger",
    223                          phase : "moved",
    224                          id : 1,
    225                          x : 72,
    226                          y : 100,
    227                          pressure : 0
    228                          }
    229                      ]
    230                  }
    231              }]};
    232              
    233              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    234                  uiController.uiScriptComplete();
    235              })();`
    23664        }
    23765
     
    25280                    output += '<br>';
    25381
    254                     testRunner.runUIScript(getDragDownOneScript(), function(result) {
     82                    testRunner.runUIScript(getDragScript(72, 120, 72, 140), function(result) {
    25583                        if (document.getSelection().toString() == "Ut enim ad minim veniam, q")
    25684                            output += 'PASS: Correct Selection';
     
    25987                        output += '<br>';
    26088                                         
    261                         testRunner.runUIScript(getDragDownTwoScript(), function(result) {
     89                        testRunner.runUIScript(getDragScript(72, 140, 72, 160), function(result) {
    26290                            if (document.getSelection().toString() == "Ut enim ad minim veniam, quis nostrud exercitati")
    26391                                output += 'PASS: Correct Selection';
     
    26694                            output += '<br>';
    26795
    268                             testRunner.runUIScript(getDragUpOneScript(), function(result) {
     96                            testRunner.runUIScript(getDragScript(72, 160, 72, 140), function(result) {
    26997                                if (document.getSelection().toString() == "Ut enim ad minim veniam, q")
    27098                                    output += 'PASS: Correct Selection';
     
    273101                                output += '<br>';
    274102
    275                                 testRunner.runUIScript(getDragUpTwoScript(), function(result) {
     103                                testRunner.runUIScript(getDragScript(72, 140, 72, 115), function(result) {
    276104                                    if (document.getSelection().toString() == "Ut")
    277105                                        output += 'PASS: Correct Selection';
     
    280108                                    output += '<br>';
    281109                           
    282                                     testRunner.runUIScript(getDragUpPastScript(), function(result) {
     110                                    testRunner.runUIScript(getDragScript(72, 115, 72, 80), function(result) {
    283111                                        if (document.getSelection().toString() == "U")
    284112                                            output += 'PASS: Correct Selection';
  • trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text.html

    r208934 r209892  
    1919        }
    2020   
    21         function getDragUpOneScript()
     21        function getDragScript(startX, startY, endX, endY)
    2222        {
    2323            return `
     
    2828                interpolate : "linear",
    2929                timestep: 0.1,
     30                coordinateSpace : "content",
    3031                startEvent : {
    3132                    inputType : "hand",
     
    3637                        phase : "began",
    3738                        id : 1,
    38                         x : 56,
    39                         y : 109,
     39                        x : ${startX},
     40                        y : ${startY},
    4041                        pressure : 0
    4142                        }
     
    5051                        phase : "moved",
    5152                        id : 1,
    52                         x : 56,
    53                         y : 103,
     53                        x : ${endX},
     54                        y : ${endY},
    5455                        pressure : 0
    5556                        }
     
    6364        }
    6465   
    65         function getDragUpTwoScript()
    66         {
    67             return `
    68             (function() {
    69              var eventStream = {
    70              events : [
    71                  {
    72                  interpolate : "linear",
    73                  timestep: 0.1,
    74                  startEvent : {
    75                      inputType : "hand",
    76                      timeOffset : 0,
    77                      touches : [
    78                          {
    79                          inputType : "finger",
    80                          phase : "began",
    81                          id : 1,
    82                          x : 56,
    83                          y : 103,
    84                          pressure : 0
    85                          }
    86                      ]
    87                  },
    88                  endEvent : {
    89                      inputType : "hand",
    90                      timeOffset : 0.5,
    91                      touches : [
    92                          {
    93                          inputType : "finger",
    94                          phase : "moved",
    95                          id : 1,
    96                          x : 56,
    97                          y : 84,
    98                          pressure : 0
    99                          }
    100                      ]
    101                  }
    102              }]};
    103              
    104              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    105                  uiController.uiScriptComplete();
    106              })();`
    107         }
    108         function getDragDownOneScript()
    109         {
    110             return `
    111             (function() {
    112              var eventStream = {
    113              events : [
    114                  {
    115                  interpolate : "linear",
    116                  timestep: 0.1,
    117                  startEvent : {
    118                      inputType : "hand",
    119                      timeOffset : 0,
    120                      touches : [
    121                          {
    122                          inputType : "finger",
    123                          phase : "began",
    124                          id : 1,
    125                          x : 56,
    126                          y : 84,
    127                          pressure : 0
    128                          }
    129                      ]
    130                  },
    131                  endEvent : {
    132                      inputType : "hand",
    133                      timeOffset : 0.5,
    134                      touches : [
    135                          {
    136                          inputType : "finger",
    137                          phase : "moved",
    138                          id : 1,
    139                          x : 56,
    140                          y : 103,
    141                          pressure : 0
    142                          }
    143                      ]
    144                  }
    145              }]};
    146              
    147              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    148                  uiController.uiScriptComplete();
    149              })();`
    150         }
    151         function getDragDownTwoScript()
    152         {
    153             return `
    154             (function() {
    155              var eventStream = {
    156              events : [
    157                  {
    158                  interpolate : "linear",
    159                  timestep: 0.1,
    160                  startEvent : {
    161                      inputType : "hand",
    162                      timeOffset : 0,
    163                      touches : [
    164                          {
    165                          inputType : "finger",
    166                          phase : "began",
    167                          id : 1,
    168                          x : 56,
    169                          y : 103,
    170                          pressure : 0
    171                          }
    172                      ]
    173                  },
    174                  endEvent : {
    175                      inputType : "hand",
    176                      timeOffset : 0.5,
    177                      touches : [
    178                          {
    179                          inputType : "finger",
    180                          phase : "moved",
    181                          id : 1,
    182                          x : 56,
    183                          y : 112,
    184                          pressure : 0
    185                          }
    186                      ]
    187                  }
    188              }]};
    189              
    190              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    191                  uiController.uiScriptComplete();
    192              })();`
    193         }
    194         function getDragDownPastScript()
    195         {
    196             return `
    197             (function() {
    198              var eventStream = {
    199              events : [
    200                  {
    201                  interpolate : "linear",
    202                  timestep: 0.1,
    203                  startEvent : {
    204                      inputType : "hand",
    205                      timeOffset : 0,
    206                      touches : [
    207                          {
    208                          inputType : "finger",
    209                          phase : "began",
    210                          id : 1,
    211                          x : 56,
    212                          y : 112,
    213                          pressure : 0
    214                          }
    215                      ]
    216                  },
    217                  endEvent : {
    218                      inputType : "hand",
    219                      timeOffset : 0.5,
    220                      touches : [
    221                          {
    222                          inputType : "finger",
    223                          phase : "moved",
    224                          id : 1,
    225                          x : 56,
    226                          y : 140,
    227                          pressure : 0
    228                          }
    229                      ]
    230                  }
    231              }]};
    232              
    233              uiController.sendEventStream(JSON.stringify(eventStream), function() {});
    234                  uiController.uiScriptComplete();
    235              })();`
    236         }
    237 
    23866        function runTest()
    23967        {
     
    25280                    output += '<br>';
    25381
    254                     testRunner.runUIScript(getDragUpOneScript(), function(result) {
     82                    testRunner.runUIScript(getDragScript(56, 89, 56, 74), function(result) {
    25583                        if (document.getSelection().toString() == "e et dolore magna aliqua. Ut")
    25684                            output += 'PASS: Correct Selection';
     
    25987                        output += '<br>';
    26088                                         
    261                         testRunner.runUIScript(getDragUpTwoScript(), function(result) {
     89                        testRunner.runUIScript(getDragScript(56, 74, 56, 55), function(result) {
    26290                            if (document.getSelection().toString() == "mod tempor incididunt ut labore et dolore magna aliqua. Ut")
    26391                                output += 'PASS: Correct Selection';
     
    26694                            output += '<br>';
    26795
    268                             testRunner.runUIScript(getDragDownOneScript(), function(result) {
     96                            testRunner.runUIScript(getDragScript(56, 55, 56, 74), function(result) {
    26997                                if (document.getSelection().toString() == "e et dolore magna aliqua. Ut")
    27098                                    output += 'PASS: Correct Selection';
     
    273101                                output += '<br>';
    274102
    275                                 testRunner.runUIScript(getDragDownTwoScript(), function(result) {
     103                                testRunner.runUIScript(getDragScript(56, 74, 56, 92), function(result) {
    276104                                    if (document.getSelection().toString() == "Ut")
    277105                                        output += 'PASS: Correct Selection';
     
    280108                                    output += '<br>';
    281109                           
    282                                     testRunner.runUIScript(getDragDownPastScript(), function(result) {
     110                                    testRunner.runUIScript(getDragScript(56, 92, 56, 120), function(result) {
    283111                                        if (document.getSelection().toString() == "t")
    284112                                            output += 'PASS: Correct Selection';
     
    288116                                        output += result;
    289117                                        document.getElementById('target').innerHTML = output;
    290                                         //testRunner.notifyDone();
     118                                        testRunner.notifyDone();
    291119                                    });
    292120                                });
  • trunk/Tools/ChangeLog

    r209859 r209892  
     12016-12-15  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add coordinate space to event streams and streamline tests
     4        https://bugs.webkit.org/show_bug.cgi?id=165119
     5
     6        Reviewed by Simon Fraser.
     7
     8        Update event streams to allow for both content and global coordinate space.
     9        Update example script to more accurately show all the available options.
     10
     11        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     12        * WebKitTestRunner/ios/HIDEventGenerator.h:
     13        * WebKitTestRunner/ios/HIDEventGenerator.mm:
     14        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     15        (WTR::convertCoordinates):
     16        (WTR::UIScriptController::sendEventStream):
     17
    1182016-12-15  Claudio Saavedra  <csaavedra@igalia.com>
    219
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r208926 r209892  
    6060    //              "inputType" : "hand",
    6161    //              "timeOffset" : 0,
     62    //              "coordinateSpace" : "content",
    6263    //              "touches" : [
    6364    //                  {
     
    7071    //              ]
    7172    //          },
     73    //          // This is a basic force press
    7274    //          {
    7375    //              "interpolate" : "linear",
    7476    //              "timestep" : 0.025,
     77    //              "coordinateSpace" : "global",
    7578    //              "startEvent" : {
    7679    //                  "inputType" : "hand",
     
    9598    //                          "phase" : "stationary",
    9699    //                          "id" : 1,
     100    //                          "x" : 100,
     101    //                          "y" : 120,
     102    //                          "pressure" : 500
     103    //                      }
     104    //                  ]
     105    //              }
     106    //          },
     107    //          //This is a basic drag
     108    //          {
     109    //              "interpolate" : "linear",
     110    //              "timestep" : 0.025,
     111    //              "coordinateSpace" : "content",
     112    //              "startEvent" : {
     113    //                  "inputType" : "hand",
     114    //                  "timeOffset" : 3.025,
     115    //                  "touches" : [
     116    //                      {
     117    //                          "inputType" : "finger",
     118    //                          "phase" : "moved",
     119    //                          "id" : 1,
     120    //                          "x" : 100,
     121    //                          "y" : 120,
     122    //                          "pressure" : 0
     123    //                      }
     124    //                  ]
     125    //              },
     126    //              "endEvent" : {
     127    //                  "inputType" : "hand",
     128    //                  "timeOffset" : 4.0,
     129    //                  "touches" : [
     130    //                      {
     131    //                          "inputType" : "finger",
     132    //                          "phase" : "moved",
     133    //                          "id" : 1,
    97134    //                          "x" : 20,
    98135    //                          "y" : 40,
    99     //                          "pressure" : 500
     136    //                          "pressure" : 0
    100137    //                      }
    101138    //                  ]
    102139    //              }
    103140    //          },
     141    //          //ending lift
    104142    //          {
    105143    //              "inputType" : "hand",
    106     //              "timeOffset" : 0.002, // seconds relative to the first event
     144    //              "timeOffset" : 4.025, // seconds relative to the first event
     145    //              "coordinateSpace" : "content",
    107146    //              "touches" : [
    108147    //                  {
     
    110149    //                      "phase" : "ended",
    111150    //                      "id" : 1,
    112     //                      "x" : 100,
    113     //                      "y" : 120
     151    //                      "x" : 20,
     152    //                      "y" : 40
    114153    //                  }
    115154    //              ]
  • trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.h

    r206798 r209892  
    3232extern NSString* const HIDEventInputType;
    3333extern NSString* const HIDEventTimeOffsetKey;
     34extern NSString* const HIDEventTouchesKey;
    3435extern NSString* const HIDEventPhaseKey;
     36extern NSString* const HIDEventInterpolateKey;
     37extern NSString* const HIDEventTimestepKey;
     38extern NSString* const HIDEventCoordinateSpaceKey;
     39extern NSString* const HIDEventStartEventKey;
     40extern NSString* const HIDEventEndEventKey;
    3541extern NSString* const HIDEventTouchIDKey;
    3642extern NSString* const HIDEventPressureKey;
     
    4046extern NSString* const HIDEventMajorRadiusKey;
    4147extern NSString* const HIDEventMinorRadiusKey;
    42 extern NSString* const HIDEventTouchesKey;
    4348
    4449// Values for HIDEventInputType.
     
    4651extern NSString* const HIDEventInputTypeFinger;
    4752extern NSString* const HIDEventInputTypeStylus;
     53
     54// Values for HIDEventCoordinateSpaceKey.
     55extern NSString* const HIDEventCoordinateSpaceTypeGlobal;
     56extern NSString* const HIDEventCoordinateSpaceTypeContent;
     57
     58extern NSString* const HIDEventInterpolationTypeLinear;
     59extern NSString* const HIDEventInterpolationTypeSimpleCurve;
    4860
    4961// Values for HIDEventPhaseKey.
  • trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm

    r207153 r209892  
    4545NSString* const HIDEventInterpolateKey = @"interpolate";
    4646NSString* const HIDEventTimestepKey = @"timestep";
     47NSString* const HIDEventCoordinateSpaceKey = @"coordinateSpace";
    4748NSString* const HIDEventStartEventKey = @"startEvent";
    4849NSString* const HIDEventEndEventKey = @"endEvent";
     
    5859NSString* const HIDEventInputTypeFinger = @"finger";
    5960NSString* const HIDEventInputTypeStylus = @"stylus";
     61
     62NSString* const HIDEventCoordinateSpaceTypeGlobal = @"global";
     63NSString* const HIDEventCoordinateSpaceTypeContent = @"content";
    6064
    6165NSString* const HIDEventInterpolationTypeLinear = @"linear";
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r208985 r209892  
    204204    }];
    205205}
     206   
     207void convertCoordinates(NSMutableDictionary *event)
     208{
     209    if (event[HIDEventTouchesKey]) {
     210        for (NSMutableDictionary *touch in event[HIDEventTouchesKey]) {
     211            auto location = globalToContentCoordinates(TestController::singleton().mainWebView()->platformView(), (long)[touch[HIDEventXKey] doubleValue], (long)[touch[HIDEventYKey]doubleValue]);
     212            touch[HIDEventXKey] = @(location.x);
     213            touch[HIDEventYKey] = @(location.y);
     214        }
     215    }
     216}
    206217
    207218void UIScriptController::sendEventStream(JSStringRef eventsJSON, JSValueRef callback)
     
    210221
    211222    String jsonString = eventsJSON->string();
    212     auto eventInfo = dynamic_objc_cast<NSDictionary>([NSJSONSerialization JSONObjectWithData:[(NSString *)jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]);
     223    auto eventInfo = dynamic_objc_cast<NSDictionary>([NSJSONSerialization JSONObjectWithData:[(NSString *)jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil]);
     224   
     225    for (NSMutableDictionary *event in eventInfo[TopLevelEventInfoKey]) {
     226        if (![event[HIDEventCoordinateSpaceKey] isEqualToString:HIDEventCoordinateSpaceTypeContent])
     227            continue;
     228       
     229        if (event[HIDEventStartEventKey])
     230            convertCoordinates(event[HIDEventStartEventKey]);
     231       
     232        if (event[HIDEventEndEventKey])
     233            convertCoordinates(event[HIDEventEndEventKey]);
     234       
     235        if (event[HIDEventTouchesKey])
     236            convertCoordinates(event);
     237    }
     238   
    213239    if (!eventInfo || ![eventInfo isKindOfClass:[NSDictionary class]]) {
    214240        WTFLogAlways("JSON is not convertible to a dictionary");
Note: See TracChangeset for help on using the changeset viewer.