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
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that temp permissions are persisted through moving tabs to new windows.
add_task(async function testTempPermissionOnTabMove() {
let origin = "https://example.com/";
let principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(origin);
let id = "geo";
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, origin);
SitePermissions.setForPrincipal(
principal,
id,
SitePermissions.BLOCK,
SitePermissions.SCOPE_TEMPORARY,
tab.linkedBrowser
);
Assert.deepEqual(
SitePermissions.getForPrincipal(principal, id, tab.linkedBrowser),
{
state: SitePermissions.BLOCK,
scope: SitePermissions.SCOPE_TEMPORARY,
}
);
let promiseWin = BrowserTestUtils.waitForNewWindow();
gBrowser.replaceTabWithWindow(tab);
let win = await promiseWin;
tab = win.gBrowser.selectedTab;
Assert.deepEqual(
SitePermissions.getForPrincipal(principal, id, tab.linkedBrowser),
{
state: SitePermissions.BLOCK,
scope: SitePermissions.SCOPE_TEMPORARY,
}
);
SitePermissions.removeFromPrincipal(principal, id, tab.linkedBrowser);
await BrowserTestUtils.closeWindow(win);
});
// Test that temp permissions don't affect other tabs of the same URI.
add_task(async function testTempPermissionMultipleTabs() {
let origin = "https://example.com/";
let principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(origin);
let id = "geo";
let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, origin);
let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, origin);
SitePermissions.setForPrincipal(
principal,
id,
SitePermissions.BLOCK,
SitePermissions.SCOPE_TEMPORARY,
tab2.linkedBrowser
);
Assert.deepEqual(
SitePermissions.getForPrincipal(principal, id, tab2.linkedBrowser),
{
state: SitePermissions.BLOCK,
scope: SitePermissions.SCOPE_TEMPORARY,
}
);
Assert.deepEqual(
SitePermissions.getForPrincipal(principal, id, tab1.linkedBrowser),
{
state: SitePermissions.UNKNOWN,
scope: SitePermissions.SCOPE_PERSISTENT,
}
);
let geoIcon = document.querySelector(
".blocked-permission-icon[data-permission-id=geo]"
);
Assert.notEqual(
geoIcon.getBoundingClientRect().width,
0,
"geo anchor should be visible"
);
await BrowserTestUtils.switchTab(gBrowser, tab1);
Assert.equal(
geoIcon.getBoundingClientRect().width,
0,
"geo anchor should not be visible"
);
SitePermissions.removeFromPrincipal(principal, id, tab2.linkedBrowser);
BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2);
});
// Test that temp permissions are cleared when closing tabs.
add_task(async function testTempPermissionOnTabClose() {
let origin = "https://example.com/";
let principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(origin);
let id = "geo";
ok(
!SitePermissions._temporaryPermissions._stateByBrowser.size,
"Temporary permission map should be empty initially."
);
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, origin);
SitePermissions.setForPrincipal(
principal,
id,
SitePermissions.BLOCK,
SitePermissions.SCOPE_TEMPORARY,
tab.linkedBrowser
);
Assert.deepEqual(
SitePermissions.getForPrincipal(principal, id, tab.linkedBrowser),
{
state: SitePermissions.BLOCK,
scope: SitePermissions.SCOPE_TEMPORARY,
}
);
ok(
SitePermissions._temporaryPermissions._stateByBrowser.has(
tab.linkedBrowser
),
"Temporary permission map should have an entry for the browser."
);
BrowserTestUtils.removeTab(tab);
ok(
!SitePermissions._temporaryPermissions._stateByBrowser.size,
"Temporary permission map should be empty after closing the tab."
);
});
|