Home | History | Annotate | Download | only in script-tests
      1 var targetsDiv = document.createElement("div");
      2 targetsDiv.id = "targetsDiv";
      3 
      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";
      9 
     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";
     15 
     16 document.body.insertBefore(targetsDiv, document.getElementById('console'));
     17 targetsDiv.appendChild(div1);
     18 targetsDiv.appendChild(document.createElement('br'));
     19 targetsDiv.appendChild(div2);
     20 
     21 function declareTouchStart()
     22 {
     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');
     38 
     39         touchStartCount++;
     40     }
     41 }
     42 
     43 var totalTouchMoveCount = 0;
     44 
     45 function declareTouchMove(div_id)
     46 {
     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;
     64 
     65         if (++totalTouchMoveCount == 6)
     66         {
     67             successfullyParsed = true;
     68             layoutTestController.notifyDone();
     69             isSuccessfullyParsed();
     70         }
     71     }
     72 }
     73 
     74 div1.addEventListener("touchstart", declareTouchStart(), false);
     75 div1.addEventListener("touchmove", declareTouchMove(), false);
     76 
     77 div2.addEventListener("touchstart", declareTouchStart(), false);
     78 div2.addEventListener("touchmove", declareTouchMove(), false);
     79 
     80 description("Tests that the target of touches match the element where the event originated, not where the touch is currently occurring.");
     81 
     82 if (window.layoutTestController) {
     83     layoutTestController.waitUntilDone();
     84 }
     85 
     86 if (window.eventSender) {
     87     eventSender.clearTouchPoints();
     88     eventSender.addTouchPoint(50, 150);
     89     eventSender.addTouchPoint(50, 250);
     90     eventSender.touchStart();
     91 
     92     eventSender.updateTouchPoint(0, 50, 250);
     93     eventSender.updateTouchPoint(1, 50, 150);
     94     eventSender.touchMove();
     95 
     96     eventSender.updateTouchPoint(0, 1000, 1000);
     97     eventSender.updateTouchPoint(1, 1000, 1000);
     98     eventSender.touchMove();
     99 
    100     eventSender.releaseTouchPoint(0);
    101     eventSender.touchEnd();
    102 
    103     eventSender.addTouchPoint(50,150);
    104     eventSender.touchStart();
    105 
    106     eventSender.updateTouchPoint(0, 500, 500);
    107     eventSender.updateTouchPoint(1, 500, 500);
    108     eventSender.touchMove();
    109 } else
    110     debug('This test requires DRT.');
    111 
    112