tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

touch.js (4245B)


      1 // Check a Touch object's attributes for existence and correct type
      2 // TA: 1.1.2, 1.1.3
      3 function check_Touch_object(t) {
      4    assert_equals(Object.prototype.toString.call(t), "[object Touch]", "touch is of type Touch");
      5    [
      6        ["long", "identifier"],
      7        ["EventTarget", "target"],
      8        ["long", "screenX"],
      9        ["long", "screenY"],
     10        ["long", "clientX"],
     11        ["long", "clientY"],
     12        ["long", "pageX"],
     13        ["long", "pageY"],
     14        ["long", "radiusX"],
     15        ["long", "radiusY"],
     16        ["long", "rotationAngle"],
     17        ["long", "force"],
     18    ].forEach(function(attr) {
     19        var type = attr[0];
     20        var name = attr[1];
     21 
     22        // existence check
     23        assert_true(name in t, name + " attribute in Touch object");
     24 
     25        // type check
     26        switch (type) {
     27            case "long":
     28                assert_equals(typeof t[name], "number", name + " attribute of type long");
     29                break;
     30            case "EventTarget":
     31                // An event target is some type of Element
     32                assert_true(t[name] instanceof Element, "EventTarget must be an Element.");
     33                break;
     34            default:
     35                break;
     36        }
     37    });
     38 }
     39 
     40 // Check a TouchList object's attributes and methods for existence and proper type
     41 // Also make sure all of the members of the list are Touch objects
     42 // TA: 1.2.1, 1.2.2, 1.2.5, 1.2.6
     43 function check_TouchList_object(tl) {
     44    assert_equals(Object.prototype.toString.call(tl), "[object TouchList]", "touch list is of type TouchList");
     45    [
     46        ["unsigned long", "length"],
     47        ["function", "item"],
     48    ].forEach(function(attr) {
     49        var type = attr[0];
     50        var name = attr[1];
     51 
     52        // existence check
     53        assert_true(name in tl, name + " attribute in TouchList");
     54 
     55        // type check
     56        switch (type) {
     57            case "unsigned long":
     58                assert_equals(typeof tl[name], "number", name + " attribute of type long");
     59                break;
     60            case "function":
     61                assert_equals(typeof tl[name], "function", name + " attribute of type function");
     62                break;
     63            default:
     64                break;
     65        }
     66    });
     67    // Each member of tl should be a proper Touch object
     68    for (var i = 0; i < tl.length; i++) {
     69        check_Touch_object(tl.item(i));
     70    }
     71    // TouchList.item(x) should return null if x is >= TouchList.length
     72    var t = tl.item(tl.length);
     73    assert_equals(t, null, "TouchList.item returns null if the index is >= the length of the list");
     74 }
     75 
     76 // Check a TouchEvent event's attributes for existence and proper type
     77 // Also check that each of the event's TouchList objects are valid
     78 // TA: 1.{3,4,5}.1.1, 1.{3,4,5}.1.2
     79 function check_TouchEvent(ev) {
     80    assert_true(ev instanceof TouchEvent, ev.type + " event is a TouchEvent event");
     81    [
     82        ["TouchList", "touches"],
     83        ["TouchList", "targetTouches"],
     84        ["TouchList", "changedTouches"],
     85        ["boolean", "altKey"],
     86        ["boolean", "metaKey"],
     87        ["boolean", "ctrlKey"],
     88        ["boolean", "shiftKey"],
     89    ].forEach(function(attr) {
     90        var type = attr[0];
     91        var name = attr[1];
     92        // existence check
     93        assert_true(name in ev, name + " attribute in " + ev.type + " event");
     94        // type check
     95        switch (type) {
     96            case "boolean":
     97                assert_equals(typeof ev[name], "boolean", name + " attribute of type boolean");
     98                break;
     99            case "TouchList":
    100                assert_equals(Object.prototype.toString.call(ev[name]), "[object TouchList]", name + " attribute of type TouchList");
    101                break;
    102            default:
    103                break;
    104        }
    105    });
    106 }
    107 
    108 // This chromium-specific helper is a no-op to other user-agents. It can be used
    109 // to ensure that chromium's input-handling compositor thread is ready before
    110 // touch-related test logic proceeds.
    111 // TODO(crbug.com/41481669): This shouldn't be necessary if the test harness
    112 // deferred running the tests until after paint holding.
    113 async function waitTillReadyForTouchInput() {
    114  const animation =
    115    document.body.animate({ opacity: [ 0, 1 ] }, {duration: 1 });
    116  return animation.finished;
    117 }