Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / touch / script-tests / touch-target-limited.js
blob8d1ddf5dfbaaca775713765bdad65df714d275c3
1 var targetsDiv = document.createElement("div");
2 targetsDiv.id = "targetsDiv";
4 var div1 = document.createElement("div");
5 div1.id = "targetA";
6 div1.style.width = "100px";
7 div1.style.height = "100px";
8 div1.style.backgroundColor = "blue";
10 var div2 = document.createElement("div");
11 div2.id = "targetB";
12 div2.style.width = "100px";
13 div2.style.height = "100px";
14 div2.style.backgroundColor = "green";
16 document.body.insertBefore(targetsDiv, document.getElementById('console'));
17 targetsDiv.appendChild(div1);
18 targetsDiv.appendChild(document.createElement('br'));
19 targetsDiv.appendChild(div2);
21 function declareTouchStart()
23     var touchStartCount = 0;
24     return function touchStartHandler()
25     {
26         shouldBeEqualToString('event.type', 'touchstart');
27         switch (touchStartCount) {
28             case 0:
29                 shouldBeEqualToString('event.touches[0].target.id', div1.id);
30                 shouldBeEqualToString('event.touches[1].target.id', div2.id);
31                 break;
32             case 1:
33                 shouldBeEqualToString('event.touches[0].target.id', div2.id);
34                 shouldBeEqualToString('event.touches[1].target.id', div1.id);
35                 break;
36         }
37         shouldBe('event.targetTouches.length', '1');
39         touchStartCount++;
40     }
43 var totalTouchMoveCount = 0;
45 function declareTouchMove(div_id)
47     var touchMoveCount = 0;
48     return function touchMoveHandler()
49     {
50         shouldBeEqualToString('event.type', 'touchmove');
51         switch (touchMoveCount) {
52             case 0:
53             case 1:
54                 shouldBeEqualToString('event.touches[0].target.id', div1.id);
55                 shouldBeEqualToString('event.touches[1].target.id', div2.id);
56                 break;
57             case 2:
58                 shouldBeEqualToString('event.touches[0].target.id', div2.id);
59                 shouldBeEqualToString('event.touches[1].target.id', div1.id);
60                 break;
61         }
62         shouldBe('event.targetTouches.length', '1');
63         ++touchMoveCount;
65         if (++totalTouchMoveCount == 6)
66         {
67             testRunner.notifyDone();
68             isSuccessfullyParsed();
69         }
70     }
73 div1.addEventListener("touchstart", declareTouchStart(), false);
74 div1.addEventListener("touchmove", declareTouchMove(), false);
76 div2.addEventListener("touchstart", declareTouchStart(), false);
77 div2.addEventListener("touchmove", declareTouchMove(), false);
79 description("Tests that the target of touches match the element where the event originated, not where the touch is currently occurring. This is a limited version of test touch-target.html that avoids the situation where one touch point is released while another is maintained.");
81 if (window.testRunner) {
82     testRunner.waitUntilDone();
85 if (window.eventSender) {
86     eventSender.clearTouchPoints();
87     eventSender.addTouchPoint(50, 150);
88     eventSender.addTouchPoint(50, 250);
89     eventSender.touchStart();
91     eventSender.updateTouchPoint(0, 50, 250);
92     eventSender.updateTouchPoint(1, 50, 150);
93     eventSender.touchMove();
95     eventSender.updateTouchPoint(0, 1000, 1000);
96     eventSender.updateTouchPoint(1, 1000, 1000);
97     eventSender.touchMove();
99     eventSender.releaseTouchPoint(0);
100     eventSender.releaseTouchPoint(1);
101     eventSender.touchEnd();
103     eventSender.addTouchPoint(50, 250);
104     eventSender.addTouchPoint(50, 150);
105     eventSender.touchStart();
107     eventSender.updateTouchPoint(0, 500, 500);
108     eventSender.updateTouchPoint(1, 500, 500);
109     eventSender.touchMove();
110 } else
111     debug('This test requires DRT.');