summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/touch-events/touch-touchevent-constructor.html
blob: e2d0950d5e27aa9905a9c2e1ca26242ed57fee53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE HTML>
<html>
<head>
<title>Touch and TouchEvent Constructor Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/touch.js"></script>
</head>
<body>
<div id="target0"></div>
<script>
test(function() {
    var testIdentifier = 0;
    var testTarget = document.getElementById('target0');

    assert_throws_js(TypeError, function() {new Touch();}, "Touch constructor with no argument");
    assert_throws_js(TypeError, function() {new Touch(null);}, "Touch constructor with null argument");
    assert_throws_js(TypeError, function() {new Touch(undefined);}, "Touch constructor with undefined argument");
    assert_throws_js(TypeError, function() {new Touch({});}, "Touch constructor with empty object");
    assert_throws_js(TypeError, function() {new Touch({
        identifier: testIdentifier
    });}, "Touch constructor with only identifier");
    assert_throws_js(TypeError, function() {new Touch({
        target: testTarget
    });}, "Touch constructor with only target");
}, "Touch constructor with insufficient properties");

test(function() {
    var testIdentifier = 0;
    var testTarget = document.getElementById('target0');

    assert_throws_js(TypeError, function() {new Touch({
        identifier: testIdentifier,
        target: null
    });}, "Touch constructor with null target");
    assert_throws_js(TypeError, function() {new Touch({
        identifier: testIdentifier,
        target: undefined
    });}, "Touch constructor with undefined target");
    assert_throws_js(TypeError, function() {new Touch({
        identifier: testIdentifier,
        target: location
    });}, "Touch constructor with Location target");
}, "Touch constructor with non-EventTarget target");

test(function() {
    var testIdentifier = 74;
    var testTarget = document.getElementById('target0');
    var approxEpsilon = 0.00001;

    var touch1 = new Touch({
        identifier: testIdentifier,
        target: testTarget,
    });
    check_Touch_object(touch1);
    assert_equals(touch1.target, testTarget, "touch.target is requested value");
    assert_equals(touch1.identifier, testIdentifier, "touch.identifier is requested value");
    assert_approx_equals(touch1.pageX, 0, approxEpsilon, "touch.pageX is default value");
    assert_approx_equals(touch1.pageY, 0, approxEpsilon, "touch.pageY is default value");
    assert_approx_equals(touch1.screenX, 0, approxEpsilon, "touch.screenX is default value");
    assert_approx_equals(touch1.screenY, 0, approxEpsilon, "touch.screenY is default value");
    assert_approx_equals(touch1.clientX, 0, approxEpsilon, "touch.clientX is default value.");
    assert_approx_equals(touch1.clientY, 0, approxEpsilon, "touch.clientY is default value.");
}, "Touch constructor exists and creates a Touch object with minimum properties");

test(function() {
    var testIdentifier = 42;
    var testTarget = document.getElementById('target0');
    var testPageX = 15;
    var testPageY = 20.2;
    var testScreenX = 35.34;
    var testScreenY = 40.56;
    var testClientX = 10.175;
    var testClientY = 5;
    var approxEpsilon = 0.00001;

    var touch1 = new Touch({
        identifier: testIdentifier,
        target: testTarget,
        pageX: testPageX,
        pageY: testPageY,
        screenX: testScreenX,
        screenY: testScreenY,
        clientX: testClientX,
        clientY: testClientY,
    });
    check_Touch_object(touch1);
    assert_equals(touch1.identifier, testIdentifier, "touch.identifier is requested value");
    assert_equals(touch1.target, testTarget, "touch.target is requested value");
    assert_approx_equals(touch1.pageX, testPageX, approxEpsilon, "touch.pageX is requested value");
    assert_approx_equals(touch1.pageY, testPageY, approxEpsilon, "touch.pageY is requested value");
    assert_approx_equals(touch1.screenX, testScreenX, approxEpsilon, "touch.screenX is requested value");
    assert_approx_equals(touch1.screenY, testScreenY, approxEpsilon, "touch.screenY is requested value");
    assert_approx_equals(touch1.clientX, testClientX, approxEpsilon, "touch.clientX is requested value.");
    assert_approx_equals(touch1.clientY, testClientY, approxEpsilon, "touch.clientY is requested value.");
}, "Touch constructor exists and creates a Touch object with requested properties");


test(function() {
    var testTarget = document.getElementById('target0');

    var touch1 = new Touch({
        identifier: 45,
        target: testTarget,
        pageX: 45,
        pageY: 50,
        screenX: 65,
        screenY: 60,
        clientX: 70,
        clientY: 75,
    });
    var touch2 = new Touch({
        identifier: 52,
        target: testTarget,
        pageX: 15,
        pageY: 20,
        screenX: 15,
        screenY: 20,
        clientX: 15,
        clientY: 20,
    });

    var touchEvent1 = new TouchEvent("ontouchstart", {
        touches: [touch1, touch2],
        targetTouches: [touch1],
        altKey: true,
        metaKey: false,
    });

    check_TouchEvent(touchEvent1);
    assert_equals(touchEvent1.type, "ontouchstart", "touchEvent.type is requested value");
    assert_equals(touchEvent1.touches.length, 2, "touchEvent.touches.length is requested value");
    assert_equals(touchEvent1.touches[0], touch1, "touchEvent.touches[0] is requested value");
    assert_equals(touchEvent1.touches[1], touch2, "touchEvent.touches[1] is requested value");
    assert_equals(touchEvent1.targetTouches.length, 1, "touchEvent.targetTouches.length is requested value");
    assert_equals(touchEvent1.targetTouches[0], touch1, "touchEvent.targetTouches[0] is requested value");
    assert_equals(touchEvent1.changedTouches.length, 0, "touchEvent.changedTouches.length is requested value");
    assert_equals(touchEvent1.altKey, true, "touchEvent.altKey is requested value");
    assert_equals(touchEvent1.metaKey, false, "touchEvent.metaKey is requested value");
    assert_equals(touchEvent1.ctrlKey, false, "touchEvent.ctrlKey is requested value");
    assert_equals(touchEvent1.shiftKey, false, "touchEvent.shiftKey is requested value.");
}, "TouchEvent constructor exists and creates a TouchEvent object with requested properties");
</script>
</body>
</html>