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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests that by setting a Picture-in-Picture toggle position policy
* in the sharedData structure, that the toggle position can be
* change for a particular URI.
*/
add_task(async () => {
let positionPolicies = [
TOGGLE_POLICIES.TOP,
TOGGLE_POLICIES.ONE_QUARTER,
TOGGLE_POLICIES.MIDDLE,
TOGGLE_POLICIES.THREE_QUARTERS,
TOGGLE_POLICIES.BOTTOM,
];
for (let policy of positionPolicies) {
Services.ppmm.sharedData.set(SHARED_DATA_KEY, {
"*://example.com/*": { policy },
});
Services.ppmm.sharedData.flush();
let expectations = {
"with-controls": { canToggle: true, policy },
"no-controls": { canToggle: true, policy },
};
// For <video> elements with controls, the video controls overlap the
// toggle when its on the bottom and can't be clicked, so we'll ignore
// that case.
if (policy == TOGGLE_POLICIES.BOTTOM) {
expectations["with-controls"] = { canToggle: true };
}
await testToggle(TEST_PAGE, expectations);
// And ensure that other pages aren't affected by this override.
await testToggle(TEST_PAGE_2, {
"with-controls": { canToggle: true },
"no-controls": { canToggle: true },
});
}
Services.ppmm.sharedData.set(SHARED_DATA_KEY, {});
Services.ppmm.sharedData.flush();
});
/**
* Tests that by setting a Picture-in-Picture toggle hidden policy
* in the sharedData structure, that the toggle can be suppressed.
*/
add_task(async () => {
Services.ppmm.sharedData.set(SHARED_DATA_KEY, {
"*://example.com/*": { policy: TOGGLE_POLICIES.HIDDEN },
});
Services.ppmm.sharedData.flush();
await testToggle(TEST_PAGE, {
"with-controls": { canToggle: false, policy: TOGGLE_POLICIES.HIDDEN },
"no-controls": { canToggle: false, policy: TOGGLE_POLICIES.HIDDEN },
});
// And ensure that other pages aren't affected by this override.
await testToggle(TEST_PAGE_2, {
"with-controls": { canToggle: true },
"no-controls": { canToggle: true },
});
Services.ppmm.sharedData.set(SHARED_DATA_KEY, {});
Services.ppmm.sharedData.flush();
});
/**
* Tests that policies are re-evaluated if the page URI is transitioned
* via the history API.
*/
add_task(async () => {
Services.ppmm.sharedData.set(SHARED_DATA_KEY, {
"*://example.com/*/test-page.html": { policy: TOGGLE_POLICIES.HIDDEN },
});
Services.ppmm.sharedData.flush();
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: TEST_PAGE,
},
async browser => {
await ensureVideosReady(browser);
await SimpleTest.promiseFocus(browser);
await testToggleHelper(
browser,
"no-controls",
false,
TOGGLE_POLICIES.HIDDEN
);
await SpecialPowers.spawn(browser, [], async function () {
content.history.pushState({}, "2", "otherpage.html");
});
// Since we no longer match the policy URI, we should be able
// to use the Picture-in-Picture toggle.
await testToggleHelper(browser, "no-controls", true);
// Now use the history API to put us back at the original location,
// which should have the HIDDEN policy re-applied.
await SpecialPowers.spawn(browser, [], async function () {
content.history.pushState({}, "Return", "test-page.html");
});
await testToggleHelper(
browser,
"no-controls",
false,
TOGGLE_POLICIES.HIDDEN
);
}
);
Services.ppmm.sharedData.set(SHARED_DATA_KEY, {});
Services.ppmm.sharedData.flush();
});
|