summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_bug1724759.html
blob: a012bb0fc0570cb5f2e37b8d2898bd141eba300a (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
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>Tests that :active state is cleared after a longpress event</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
 <script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="apz_test_utils.js"></script>
<script src="apz_test_native_event_utils.js"></script>
<style>
  #button {
    width: 100px;
    height: 100px;
  }
</style>
<button id="button">Button</button>
<script>
async function test() {
  const contextmenuPromise = promiseOneEvent(button, "contextmenu", e => {
    e.preventDefault();
    return true;
  });
  await synthesizeNativeTouch(button, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);

  // In JS there's no way to ensure `APZStateChange::eStartTouch` notification
  // has been processed. So we wait for `:active` state change here.
  await SimpleTest.promiseWaitForCondition(
    () => button.matches(":active"),
    "Waiting for :active state change");

  ok(button.matches(":active"), "should be active");

  await contextmenuPromise;

  await synthesizeNativeTouch(button, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);

  // Same as above. We need to wait for not `:active` state here.
  await SimpleTest.promiseWaitForCondition(
    () => !button.matches(":active"),
    "Waiting for :active state change");

  ok(!button.matches(":active"), "should not be active");
}

if (getPlatform() == "windows") {
  // On Windows every context menu on touch screens opens __after__ lifting the
  // finger.
  ok(true, "Test doesn't need to run on Windows");
  subtestDone();
} else {
  waitUntilApzStable()
  .then(test)
  .then(subtestDone, subtestFailed);
}
</script>
</html>