summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/events/touch/script-tests/basic-single-touch-events.js
blob: 756f49ea6f29412cde504945bbad35c2d58d1686 (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
var div = document.createElement("div");
div.id = "touchtarget";
div.style.width = "100px";
div.style.height = "100px";
div.style.backgroundColor = "blue";

var lastEvent = null;
var touchEventsReceived = 0;
var EXPECTED_TOUCH_EVENTS_TOTAL = 5;

function touchEventCallback() {
    if (window.eventSender) {
        lastEvent = event;
        verifyTouch(touchEventsReceived++);
    } else {
        debug(event.type);
    }

    if (window.layoutTestController && touchEventsReceived == EXPECTED_TOUCH_EVENTS_TOTAL) {
        // If we've got here, we can safely say we were successfully parsed :) We need to
        // call the isSucccessfullyParsed function to output the correct TEST COMPLETE
        // footer message.
        successfullyParsed = true;
        isSuccessfullyParsed();
        layoutTestController.notifyDone();
    }
}

div.addEventListener("touchstart", touchEventCallback, false);
div.addEventListener("touchmove", touchEventCallback, false);
div.addEventListener("touchend", touchEventCallback, false);
document.body.insertBefore(div, document.body.firstChild);

function verifyTouchEvent(type, totalTouchCount, changedTouchCount, targetTouchCount)
{
    shouldBeEqualToString("lastEvent.type", type);
    shouldBe("lastEvent.touches.length", totalTouchCount.toString());
    shouldBe("lastEvent.changedTouches.length", changedTouchCount.toString());
    shouldBe("lastEvent.targetTouches.length", targetTouchCount.toString());
    shouldBe("lastEvent.pageX", "0");
    shouldBe("lastEvent.pageY", "0");
}

function verifyTouchPoint(list, point, x, y, id)
{
    shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString());
    shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString());
    shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString());
    shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString());
    shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString());
}

function verifyTouch(which) {
    switch (which) {
        case 0:
           verifyTouchEvent("touchstart", 1, 1, 1);
           shouldBe("lastEvent.shiftKey", "false");
           shouldBeEqualToString("lastEvent.touches[0].target.id", "touchtarget");
           verifyTouchPoint("touches", 0, 10, 10, 0);
           verifyTouchPoint("changedTouches", 0, 10, 10, 0);
           verifyTouchPoint("targetTouches", 0, 10, 10, 0);
        break;
        case 1:
           verifyTouchEvent("touchmove", 1, 1, 1);
           verifyTouchPoint("touches", 0, 50, 50, 0);
           shouldBe("lastEvent.shiftKey", "true");
           shouldBe("lastEvent.altKey", "true");
           shouldBe("lastEvent.ctrlKey", "false");
           shouldBe("lastEvent.metaKey", "false");
        break;
        case 2:
            verifyTouchEvent("touchend", 0, 1, 0);
            verifyTouchPoint("changedTouches", 0, 50, 50, 0);
            shouldBe("lastEvent.shiftKey", "false");
            shouldBe("lastEvent.altKey", "false");
        break;
        case 3:
            verifyTouchEvent("touchstart", 1, 1, 1);
            shouldBeEqualToString("lastEvent.targetTouches[0].target.tagName", "DIV");
        break;
        case 4:
            verifyTouchEvent("touchmove", 1, 1, 1);
            shouldBeEqualToString("lastEvent.touches[0].target.tagName", "DIV");
        break;

        default: testFailed("Wrong number of touch events! (" + which + ")");
    }
}

function singleTouchSequence()
{
    eventSender.addTouchPoint(10, 10);
    eventSender.touchStart();

    eventSender.updateTouchPoint(0, 50, 50);
    eventSender.setTouchModifier("shift", true);
    eventSender.setTouchModifier("alt", true);
    eventSender.touchMove();

    eventSender.setTouchModifier("shift", false);
    eventSender.setTouchModifier("alt", false);

    eventSender.releaseTouchPoint(0);
    eventSender.touchEnd();
}

function touchTargets()
{
    eventSender.addTouchPoint(20, 20);
    eventSender.touchStart();

    eventSender.updateTouchPoint(0, 1000, 1000);
    eventSender.touchMove();
}

if (window.layoutTestController)
    layoutTestController.waitUntilDone();

if (window.eventSender) {
    description("This tests basic single touch event support.");

    lastEvent = null;
    eventSender.clearTouchPoints();
    singleTouchSequence();

    lastEvent = null;
    eventSender.clearTouchPoints();
    touchTargets();

} else {
    debug("This test requires DumpRenderTree.  Tap on the blue rect to log.")
}