summaryrefslogtreecommitdiffstats
path: root/dom/base/test/useractivation/test_useractivation_scrollbar.html
blob: 778d6d08982a840f18b512b5e21ac3c61175d32b (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE HTML>
<html>
<head>
<title>User activation test: consume transient flag</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<textarea style="height: 100px; resize: none">
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
&nbsp
</textarea>
<div id="target" style="height: 100px; width: 200px; overflow: scroll">
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
&nbsp<br>
</div>
<div style="height: 2000px; width: 500px; background-color: green;"></div>
<script>

// Open a new window to ensure scrollbar is always visible.
if (!opener) {
  add_task(async function init() {
    // Turn on the prefs that force overlay scrollbars to always be visible.
    await SpecialPowers.pushPrefEnv({
      set: [["layout.testing.overlay-scrollbars.always-visible", true]],
    });
  });

  async function testOnNewWindow(aPrefValue) {
    await SpecialPowers.pushPrefEnv({
      set: [["dom.user_activation.ignore_scrollbars", aPrefValue]],
    });

    let win = window.open(location);
    // wait for message
    await new Promise((aResolve) => {
      window.addEventListener("message", function listener(event) {
        if ("done" == event.data) {
          window.removeEventListener("message", listener);
          aResolve();
        }
      });
    });
    win.close();
  }

  add_task(async function test_pref_on() {
    await testOnNewWindow(true);
  });

  add_task(async function test_pref_off() {
    await testOnNewWindow(false);
  });
} else {
  SimpleTest.waitForFocus(async function() {
    function waitForEvent(aTarget, aEvent) {
      return new Promise((aResolve) => {
        aTarget.addEventListener(aEvent, function listener(event) {
          aResolve();
        }, { once: true });
      });
    }

    let ignoreScrollbars = SpecialPowers.getBoolPref("dom.user_activation.ignore_scrollbars");

    SpecialPowers.wrap(document).clearUserGestureActivation();
    let textarea = document.querySelector("textarea");
    var rect = textarea.getBoundingClientRect();

    // click scrollbar of textarea
    let promise = waitForEvent(textarea, "scroll");
    synthesizeMouse(textarea, rect.width - 5, rect.height / 2, {});
    await promise;

    opener.is(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
              !ignoreScrollbars, "check has-been-user-activated");
    opener.is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
              !ignoreScrollbars, "check has-valid-transient-user-activation");

    SpecialPowers.wrap(document).clearUserGestureActivation();
    let div = document.querySelector("div[id=target]");
    rect = div.getBoundingClientRect();

    // click scrollbar of div
    promise = waitForEvent(div, "scroll");
    synthesizeMouse(div, rect.width - 5, rect.height / 2, {});
    await promise;

    opener.is(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
              !ignoreScrollbars, "check has-been-user-activated");
    opener.is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
              !ignoreScrollbars, "check has-valid-transient-user-activation");

    SpecialPowers.wrap(document).clearUserGestureActivation();
    let body = document.querySelector("body");

    // click scrollbar of page
    promise = waitForEvent(document, "scroll");
    synthesizeMouse(body, innerWidth - 10, innerHeight / 2, {});
    await promise;

    opener.is(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
              !ignoreScrollbars, "check has-been-user-activated");
    opener.is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
              !ignoreScrollbars, "check has-valid-transient-user-activation");

    opener.postMessage("done", "*");
  }, window);
}

</script>
</body>