summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/pointerevents/pointerevent_click_is_a_pointerevent_multiple_clicks.html
blob: fe18302ae4b914effd584b4ab192aa90f4d2ea69 (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
<!DOCTYPE HTML>
<title>click is a PointerEvent</title>
<meta name="variant" content="?mouse">
<meta name="variant" content="?pen">
<meta name="variant" content="?touch">
<link rel="help" href="https://github.com/w3c/pointerevents/pull/317">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<input id="target" style="margin: 20px">

<script>
'use strict';
let target = document.getElementById("target");
let pointerId_one = 0;
let pointerType_one = "";
let pointerId_two = 0;
let pointerType_two = "";
let pointerId_three = 0;
let pointerType_three = "";
let inputSource = location.search.substring(1);
const phase_one = 1;
const phase_two = 2;
const phase_three = 3;
let pointerdown_phase = phase_one;
let click_phase = phase_one;

target.addEventListener("pointerdown", (e)=>{
  if(pointerdown_phase === phase_one){
    pointerdown_phase = phase_two;
    pointerId_one = e.pointerId;
    pointerType_one = e.pointerType;
  }else if(pointerdown_phase === phase_two){
    pointerdown_phase = phase_three;
    pointerId_two = e.pointerId;
    pointerType_two = e.pointerType;
  }else if(pointerdown_phase === phase_three){
    pointerId_three = e.pointerId;
    pointerType_three = e.pointerType;
  }
});

function test_pointer(e, pointerId, pointerType, click_phase){
  assert_equals(e.constructor, window.PointerEvent, "click should use a PointerEvent constructor in phase " + click_phase);
  assert_true(e instanceof PointerEvent, "click should be a PointerEvent in phase " + click_phase);
  assert_equals(e.pointerId, pointerId, "click's pointerId should match the pointerId of the pointer event that triggers it in phase " + click_phase);
  assert_equals(e.pointerType, pointerType, "click's pointerType should match the pointerType of the pointer event that triggers it in phase " + click_phase);
}

function testFunction(test){
  return test.step_func(e=>{
    if(click_phase === phase_one){
      test_pointer(e, pointerId_one, pointerType_one, click_phase);
      click_phase = phase_two;
    }else if(click_phase === phase_two){
      test_pointer(e, pointerId_two, pointerType_two, click_phase);
      click_phase = phase_three;
    }else if(click_phase === phase_three)
      test_pointer(e, pointerId_three, pointerType_three, click_phase);
  });
}

function run_test(pointerType){
  promise_test((test) => new Promise((resolve, reject) => {
    const testPointer = pointerType + "TestPointer";
    let clickFunc = testFunction(test);
    test.add_cleanup(() => {
      target.removeEventListener("click", clickFunc);
      pointerId_one = 0;
      pointerType_one = "";
      pointerId_two = 0;
      pointerType_two = "";
      pointerId_three = 0;
      pointerType_three = "";
      pointerdown_phase = phase_one;
      click_phase = phase_one;
    });
    target.addEventListener("click", clickFunc);
    let eventWatcher = new EventWatcher(test, target, ["click"]);
    let actions = new test_driver.Actions();
    actions = actions
      .addPointer(testPointer, pointerType)
      .pointerMove(0,0, {origin:target, sourceName:testPointer})
      .pointerDown({sourceName:testPointer})
      .pointerUp({sourceName:testPointer})
      .pointerDown({sourceName:testPointer})
      .pointerUp({sourceName:testPointer})
      .pointerDown({sourceName:testPointer})
      .pointerUp({sourceName:testPointer});
    Promise.all([eventWatcher.wait_for(["click", "click", "click"]), actions.send()]).then(()=>resolve());
  }), "click using " + pointerType + " is a PointerEvent");
}

run_test(inputSource);
</script>