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
|
/**
* This test checks whether Autoplay Policy Detection API works correctly under
* different situations of having global permission set for block autoplay.
* This test only checks the sticky user gesture blocking model.
*/
"use strict";
add_setup(async function setSharedPrefs() {
await SpecialPowers.pushPrefEnv({
set: [
["dom.media.autoplay-policy-detection.enabled", true],
["media.autoplay.blocking_policy", 0],
],
});
});
add_task(async function testGlobalPermissionIsAllowed() {
await SpecialPowers.pushPrefEnv({
set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.ALLOWED]],
});
let tab = await createTabAndSetupPolicyAssertFunc("about:blank");
await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
info("global setting allows any autoplay");
content.assertAutoplayPolicy({
resultForElementType: "allowed",
resultForElement: "allowed",
resultForContextType: "allowed",
resultForContext: "allowed",
});
});
BrowserTestUtils.removeTab(tab);
});
add_task(async function testGlobalPermissionIsBlocked() {
await SpecialPowers.pushPrefEnv({
set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED]],
});
let tab = await createTabAndSetupPolicyAssertFunc("about:blank");
await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
info(
"global setting allows inaudible autoplay but audible autoplay is still not allowed"
);
content.assertAutoplayPolicy({
resultForElementType: "allowed-muted",
resultForElement: "allowed-muted",
resultForContextType: "disallowed",
resultForContext: "disallowed",
});
info("tweaking video's muted attribute won't change the result");
content.video.muted = true;
is(
"allowed-muted",
content.navigator.getAutoplayPolicy(content.video),
"getAutoplayPolicy(video) returns correct value"
);
content.video.muted = false;
is(
"allowed-muted",
content.navigator.getAutoplayPolicy(content.video),
"getAutoplayPolicy(video) returns correct value"
);
info(
"activate document by using user gesture, all autoplay will be allowed"
);
content.document.notifyUserGestureActivation();
content.assertAutoplayPolicy({
resultForElementType: "allowed",
resultForElement: "allowed",
resultForContextType: "allowed",
resultForContext: "allowed",
});
});
BrowserTestUtils.removeTab(tab);
});
add_task(async function testGlobalPermissionIsBlockedAll() {
await SpecialPowers.pushPrefEnv({
set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED_ALL]],
});
let tab = await createTabAndSetupPolicyAssertFunc("about:blank");
await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
info("global setting doesn't allow any autoplay");
content.assertAutoplayPolicy({
resultForElementType: "disallowed",
resultForElement: "disallowed",
resultForContextType: "disallowed",
resultForContext: "disallowed",
});
info(
"activate document by using user gesture, all autoplay will be allowed"
);
content.document.notifyUserGestureActivation();
content.assertAutoplayPolicy({
resultForElementType: "allowed",
resultForElement: "allowed",
resultForContextType: "allowed",
resultForContext: "allowed",
});
});
BrowserTestUtils.removeTab(tab);
});
|