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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// This test tends to trigger a race in the fullscreen time telemetry,
// where the fullscreen enter and fullscreen exit events (which use the
// same histogram ID) overlap. That causes TelemetryStopwatch to log an
// error.
SimpleTest.ignoreAllUncaughtExceptions(true);
/**
* Spawns content task in browser to enter / leave fullscreen
* @param browser - Browser to use for JS fullscreen requests
* @param {Boolean} fullscreenState - true to enter fullscreen, false to leave
*/
function changeFullscreen(browser, fullscreenState) {
return SpecialPowers.spawn(
browser,
[fullscreenState],
async function (state) {
if (state) {
await content.document.body.requestFullscreen();
} else {
await content.document.exitFullscreen();
}
}
);
}
function triggerInstall(browser, xpi_url) {
return SpecialPowers.spawn(browser, [xpi_url], async function (xpi_url) {
content.location = xpi_url;
});
}
add_setup(async () => {
await SpecialPowers.pushPrefEnv({
// Relax the user input requirements while running this test.
set: [["xpinstall.userActivation.required", false]],
});
});
// This tests if addon installation is blocked when requested in fullscreen
add_task(async function testFullscreenBlockAddonInstallPrompt() {
// Open example.com
await BrowserTestUtils.openNewForegroundTab(gBrowser, TESTROOT);
// Enter and wait for fullscreen
await changeFullscreen(gBrowser.selectedBrowser, true);
await TestUtils.waitForCondition(
() => window.fullScreen,
"Waiting for window to enter fullscreen"
);
// Trigger addon installation and expect it to be blocked
let addonEventPromise = TestUtils.topicObserved(
"addon-install-fullscreen-blocked"
);
await triggerInstall(gBrowser.selectedBrowser, "amosigned.xpi");
await addonEventPromise;
// Test if addon installation prompt has been blocked
let panelOpened;
try {
panelOpened = await TestUtils.waitForCondition(
() => PopupNotifications.isPanelOpen,
100,
10
);
} catch (ex) {
panelOpened = false;
}
is(panelOpened, false, "Addon installation prompt not opened");
window.fullScreen = false;
await BrowserTestUtils.waitForEvent(window, "fullscreenchange");
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
// This tests if the addon install prompt is closed when entering fullscreen
add_task(async function testFullscreenCloseAddonInstallPrompt() {
// Open example.com
await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com");
// Trigger addon installation
let addonEventPromise = TestUtils.topicObserved(
"webextension-permission-prompt"
);
await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[TESTROOT + "amosigned.xpi"],
xpi_url => {
this.content.location = xpi_url;
}
);
// Wait for addon install event
info("Wait for webextension-permission-prompt");
await addonEventPromise;
// Test if addon installation prompt is visible
await TestUtils.waitForCondition(
() => PopupNotifications.isPanelOpen,
"Waiting for addon installation prompt to open"
);
Assert.ok(
PopupNotifications.getNotification(
"addon-webext-permissions",
gBrowser.selectedBrowser
) != null,
"Opened notification is webextension permissions prompt"
);
// Switch to fullscreen and test for addon installation prompt close
await changeFullscreen(gBrowser.selectedBrowser, true);
await TestUtils.waitForCondition(
() => window.fullScreen,
"Waiting for window to enter fullscreen"
);
await TestUtils.waitForCondition(
() => !PopupNotifications.isPanelOpen,
"Waiting for addon installation prompt to close"
);
window.fullScreen = false;
await BrowserTestUtils.waitForEvent(window, "fullscreenchange");
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
|