summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/events/touch/script-tests/touch-target.js
blob: de58606ee5b1c2c619277ff0985f24042af88f07 (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
var targetsDiv = document.createElement("div");
targetsDiv.id = "targetsDiv";

var div1 = document.createElement("div");
div1.id = "targetA";
div1.style.width = "100px";
div1.style.height = "100px";
div1.style.backgroundColor = "blue";

var div2 = document.createElement("div");
div2.id = "targetB";
div2.style.width = "100px";
div2.style.height = "100px";
div2.style.backgroundColor = "green";

document.body.insertBefore(targetsDiv, document.getElementById('console'));
targetsDiv.appendChild(div1);
targetsDiv.appendChild(document.createElement('br'));
targetsDiv.appendChild(div2);

function declareTouchStart()
{
    var touchStartCount = 0;
    return function touchStartHandler()
    {
        shouldBeEqualToString('event.type', 'touchstart');
        switch (touchStartCount) {
            case 0:
                shouldBeEqualToString('event.touches[0].target.id', div1.id);
                shouldBeEqualToString('event.touches[1].target.id', div2.id);
                break;
            case 1:
                shouldBeEqualToString('event.touches[0].target.id', div2.id);
                shouldBeEqualToString('event.touches[1].target.id', div1.id);
                break;
        }
        shouldBe('event.targetTouches.length', '1');

        touchStartCount++;
    }
}

var totalTouchMoveCount = 0;

function declareTouchMove(div_id)
{
    var touchMoveCount = 0;
    return function touchMoveHandler()
    {
        shouldBeEqualToString('event.type', 'touchmove');
        switch (touchMoveCount) {
            case 0:
            case 1:
                shouldBeEqualToString('event.touches[0].target.id', div1.id);
                shouldBeEqualToString('event.touches[1].target.id', div2.id);
                break;
            case 2:
                shouldBeEqualToString('event.touches[0].target.id', div2.id);
                shouldBeEqualToString('event.touches[1].target.id', div1.id);
                break;
        }
        shouldBe('event.targetTouches.length', '1');
        ++touchMoveCount;

        if (++totalTouchMoveCount == 6)
        {
            successfullyParsed = true;
            layoutTestController.notifyDone();
            isSuccessfullyParsed();
        }
    }
}

div1.addEventListener("touchstart", declareTouchStart(), false);
div1.addEventListener("touchmove", declareTouchMove(), false);

div2.addEventListener("touchstart", declareTouchStart(), false);
div2.addEventListener("touchmove", declareTouchMove(), false);

description("Tests that the target of touches match the element where the event originated, not where the touch is currently occurring.");

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

if (window.eventSender) {
    eventSender.clearTouchPoints();
    eventSender.addTouchPoint(50, 150);
    eventSender.addTouchPoint(50, 250);
    eventSender.touchStart();

    eventSender.updateTouchPoint(0, 50, 250);
    eventSender.updateTouchPoint(1, 50, 150);
    eventSender.touchMove();

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

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

    eventSender.addTouchPoint(50,150);
    eventSender.touchStart();

    eventSender.updateTouchPoint(0, 500, 500);
    eventSender.updateTouchPoint(1, 500, 500);
    eventSender.touchMove();
} else
    debug('This test requires DRT.');