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
|
const PAGE = `
<!doctype html>
<select>
<option>ABC</option>
<option>DEFG</option>
</select>
`;
function promiseChangeHandlingUserInput(browser) {
return SpecialPowers.spawn(browser, [], async function () {
content.document.clearUserGestureActivation();
let element = content.document.querySelector("select");
let reply = {};
function getUserInputState() {
return {
isHandlingUserInput: content.window.windowUtils.isHandlingUserInput,
hasValidTransientUserGestureActivation:
content.document.hasValidTransientUserGestureActivation,
};
}
reply.before = getUserInputState();
await ContentTaskUtils.waitForEvent(element, "change", false, () => {
reply.during = getUserInputState();
return true;
});
await new Promise(r => content.window.setTimeout(r));
reply.after = getUserInputState();
return reply;
});
}
async function testHandlingUserInputOnChange(aTriggerFn) {
const url = "data:text/html," + encodeURI(PAGE);
return BrowserTestUtils.withNewTab(
{
gBrowser,
url,
},
async function (browser) {
let popup = await openSelectPopup("click");
let userInputOnChange = promiseChangeHandlingUserInput(browser);
await aTriggerFn(popup);
let userInput = await userInputOnChange;
ok(
!userInput.before.isHandlingUserInput,
"Shouldn't be handling user input before test"
);
ok(
!userInput.before.hasValidTransientUserGestureActivation,
"transient activation should be cleared before test"
);
ok(
userInput.during.hasValidTransientUserGestureActivation,
"should provide transient activation during event"
);
ok(
userInput.during.isHandlingUserInput,
"isHandlingUserInput should be true during event"
);
ok(
userInput.after.hasValidTransientUserGestureActivation,
"should provide transient activation after event"
);
ok(
!userInput.after.isHandlingUserInput,
"isHandlingUserInput should be false after event"
);
}
);
}
// This test checks if the change/click event is considered as user input event.
add_task(async function test_handling_user_input_key() {
return testHandlingUserInputOnChange(async function () {
EventUtils.synthesizeKey("KEY_ArrowDown");
await hideSelectPopup();
});
});
add_task(async function test_handling_user_input_click() {
return testHandlingUserInputOnChange(async function (popup) {
EventUtils.synthesizeMouseAtCenter(popup.lastElementChild, {});
});
});
add_task(async function test_handling_user_input_click() {
return testHandlingUserInputOnChange(async function (popup) {
EventUtils.synthesizeMouseAtCenter(popup.lastElementChild, {});
});
});
|