tor-browser

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

touch-touchevent-constructor.html (6267B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title>Touch and TouchEvent Constructor Tests</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="support/touch.js"></script>
      8 </head>
      9 <body>
     10 <div id="target0"></div>
     11 <script>
     12 test(function() {
     13    var testIdentifier = 0;
     14    var testTarget = document.getElementById('target0');
     15 
     16    assert_throws_js(TypeError, function() {new Touch();}, "Touch constructor with no argument");
     17    assert_throws_js(TypeError, function() {new Touch(null);}, "Touch constructor with null argument");
     18    assert_throws_js(TypeError, function() {new Touch(undefined);}, "Touch constructor with undefined argument");
     19    assert_throws_js(TypeError, function() {new Touch({});}, "Touch constructor with empty object");
     20    assert_throws_js(TypeError, function() {new Touch({
     21        identifier: testIdentifier
     22    });}, "Touch constructor with only identifier");
     23    assert_throws_js(TypeError, function() {new Touch({
     24        target: testTarget
     25    });}, "Touch constructor with only target");
     26 }, "Touch constructor with insufficient properties");
     27 
     28 test(function() {
     29    var testIdentifier = 0;
     30    var testTarget = document.getElementById('target0');
     31 
     32    assert_throws_js(TypeError, function() {new Touch({
     33        identifier: testIdentifier,
     34        target: null
     35    });}, "Touch constructor with null target");
     36    assert_throws_js(TypeError, function() {new Touch({
     37        identifier: testIdentifier,
     38        target: undefined
     39    });}, "Touch constructor with undefined target");
     40    assert_throws_js(TypeError, function() {new Touch({
     41        identifier: testIdentifier,
     42        target: location
     43    });}, "Touch constructor with Location target");
     44 }, "Touch constructor with non-EventTarget target");
     45 
     46 test(function() {
     47    var testIdentifier = 74;
     48    var testTarget = document.getElementById('target0');
     49    var approxEpsilon = 0.00001;
     50 
     51    var touch1 = new Touch({
     52        identifier: testIdentifier,
     53        target: testTarget,
     54    });
     55    check_Touch_object(touch1);
     56    assert_equals(touch1.target, testTarget, "touch.target is requested value");
     57    assert_equals(touch1.identifier, testIdentifier, "touch.identifier is requested value");
     58    assert_approx_equals(touch1.pageX, 0, approxEpsilon, "touch.pageX is default value");
     59    assert_approx_equals(touch1.pageY, 0, approxEpsilon, "touch.pageY is default value");
     60    assert_approx_equals(touch1.screenX, 0, approxEpsilon, "touch.screenX is default value");
     61    assert_approx_equals(touch1.screenY, 0, approxEpsilon, "touch.screenY is default value");
     62    assert_approx_equals(touch1.clientX, 0, approxEpsilon, "touch.clientX is default value.");
     63    assert_approx_equals(touch1.clientY, 0, approxEpsilon, "touch.clientY is default value.");
     64 }, "Touch constructor exists and creates a Touch object with minimum properties");
     65 
     66 test(function() {
     67    var testIdentifier = 42;
     68    var testTarget = document.getElementById('target0');
     69    var testPageX = 15;
     70    var testPageY = 20.2;
     71    var testScreenX = 35.34;
     72    var testScreenY = 40.56;
     73    var testClientX = 10.175;
     74    var testClientY = 5;
     75    var approxEpsilon = 0.00001;
     76 
     77    var touch1 = new Touch({
     78        identifier: testIdentifier,
     79        target: testTarget,
     80        pageX: testPageX,
     81        pageY: testPageY,
     82        screenX: testScreenX,
     83        screenY: testScreenY,
     84        clientX: testClientX,
     85        clientY: testClientY,
     86    });
     87    check_Touch_object(touch1);
     88    assert_equals(touch1.identifier, testIdentifier, "touch.identifier is requested value");
     89    assert_equals(touch1.target, testTarget, "touch.target is requested value");
     90    assert_approx_equals(touch1.pageX, testPageX, approxEpsilon, "touch.pageX is requested value");
     91    assert_approx_equals(touch1.pageY, testPageY, approxEpsilon, "touch.pageY is requested value");
     92    assert_approx_equals(touch1.screenX, testScreenX, approxEpsilon, "touch.screenX is requested value");
     93    assert_approx_equals(touch1.screenY, testScreenY, approxEpsilon, "touch.screenY is requested value");
     94    assert_approx_equals(touch1.clientX, testClientX, approxEpsilon, "touch.clientX is requested value.");
     95    assert_approx_equals(touch1.clientY, testClientY, approxEpsilon, "touch.clientY is requested value.");
     96 }, "Touch constructor exists and creates a Touch object with requested properties");
     97 
     98 
     99 test(function() {
    100    var testTarget = document.getElementById('target0');
    101 
    102    var touch1 = new Touch({
    103        identifier: 45,
    104        target: testTarget,
    105        pageX: 45,
    106        pageY: 50,
    107        screenX: 65,
    108        screenY: 60,
    109        clientX: 70,
    110        clientY: 75,
    111    });
    112    var touch2 = new Touch({
    113        identifier: 52,
    114        target: testTarget,
    115        pageX: 15,
    116        pageY: 20,
    117        screenX: 15,
    118        screenY: 20,
    119        clientX: 15,
    120        clientY: 20,
    121    });
    122 
    123    var touchEvent1 = new TouchEvent("ontouchstart", {
    124        touches: [touch1, touch2],
    125        targetTouches: [touch1],
    126        altKey: true,
    127        metaKey: false,
    128    });
    129 
    130    check_TouchEvent(touchEvent1);
    131    assert_equals(touchEvent1.type, "ontouchstart", "touchEvent.type is requested value");
    132    assert_equals(touchEvent1.touches.length, 2, "touchEvent.touches.length is requested value");
    133    assert_equals(touchEvent1.touches[0], touch1, "touchEvent.touches[0] is requested value");
    134    assert_equals(touchEvent1.touches[1], touch2, "touchEvent.touches[1] is requested value");
    135    assert_equals(touchEvent1.targetTouches.length, 1, "touchEvent.targetTouches.length is requested value");
    136    assert_equals(touchEvent1.targetTouches[0], touch1, "touchEvent.targetTouches[0] is requested value");
    137    assert_equals(touchEvent1.changedTouches.length, 0, "touchEvent.changedTouches.length is requested value");
    138    assert_equals(touchEvent1.altKey, true, "touchEvent.altKey is requested value");
    139    assert_equals(touchEvent1.metaKey, false, "touchEvent.metaKey is requested value");
    140    assert_equals(touchEvent1.ctrlKey, false, "touchEvent.ctrlKey is requested value");
    141    assert_equals(touchEvent1.shiftKey, false, "touchEvent.shiftKey is requested value.");
    142 }, "TouchEvent constructor exists and creates a TouchEvent object with requested properties");
    143 </script>
    144 </body>
    145 </html>