chore: remove disable_user_gesture... patch (#23066)

This commit is contained in:
Jeremy Apthorp 2020-04-16 15:22:39 -07:00 committed by GitHub
parent e4c82fdf2d
commit 2541d62486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 125 additions and 93 deletions

View file

@ -12,7 +12,6 @@ render_widget_host_view_base.patch
render_widget_host_view_mac.patch
thread_capabilities.patch
webview_cross_drag.patch
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
gin_enable_disable_v8_platform.patch
blink-worker-enable-csp-in-file-scheme.patch
disable-redraw-lock.patch

View file

@ -1,22 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aleksei Kuzmin <alkuzmin@microsoft.com>
Date: Thu, 20 Sep 2018 17:47:33 -0700
Subject: disable_user_gesture_requirement_for_beforeunload_dialogs.patch
See https://github.com/electron/electron/issues/10754
diff --git a/third_party/blink/renderer/core/dom/document.cc b/third_party/blink/renderer/core/dom/document.cc
index 002633988171955abfa7418dddbaea10dcd99981..4be5be505bd658666f0189e4ec2ab132fc0dde32 100644
--- a/third_party/blink/renderer/core/dom/document.cc
+++ b/third_party/blink/renderer/core/dom/document.cc
@@ -4157,7 +4157,9 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient* chrome_client,
"frame that never had a user gesture since its load. "
"https://www.chromestatus.com/feature/5082396709879808";
Intervention::GenerateReport(frame_, "BeforeUnloadNoGesture", message);
- return true;
+ // TODO(alexeykuzmin): Uncomment `return true` when Electron tests are fixed.
+ // See https://github.com/electron/electron/issues/10754
+ // return true;
}
if (did_allow_navigation) {

View file

@ -185,7 +185,8 @@ describe('BrowserWindow module', () => {
expect(content).to.equal('close');
});
it('should emit beforeunload event', async () => {
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
w.webContents.executeJavaScript('run()', true);
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
e.returnValue = null;
});
@ -2590,7 +2591,8 @@ describe('BrowserWindow module', () => {
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-undefined.html'));
});
it('returning false would prevent close', async () => {
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
w.webContents.executeJavaScript('run()', true);
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
e.returnValue = null;
});
@ -2598,57 +2600,103 @@ describe('BrowserWindow module', () => {
ipcMain.once('onbeforeunload', (e) => { e.returnValue = null; done(); });
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-empty-string.html'));
});
it('emits for each close attempt', (done) => {
let beforeUnloadCount = 0;
ipcMain.on('onbeforeunload', (e) => {
e.returnValue = null;
beforeUnloadCount += 1;
if (beforeUnloadCount < 3) {
it('emits for each close attempt', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
const destroyListener = () => { expect.fail('Close was not prevented'); };
w.webContents.once('destroyed', destroyListener);
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
{
const p = emittedOnce(ipcMain, 'onbeforeunload');
w.close();
} else if (beforeUnloadCount === 3) {
done();
}
});
w.webContents.once('did-finish-load', () => { w.webContents.executeJavaScript('window.close()', true); });
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
});
it('emits for each reload attempt', (done) => {
let beforeUnloadCount = 0;
ipcMain.on('onbeforeunload', (e) => {
const [e] = await p;
e.returnValue = null;
beforeUnloadCount += 1;
if (beforeUnloadCount < 3) {
w.reload();
} else if (beforeUnloadCount === 3) {
done();
}
});
w.webContents.once('did-finish-load', () => {
w.webContents.once('did-finish-load', () => {
expect.fail('Reload was not prevented');
});
w.reload();
});
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
});
it('emits for each navigation attempt', (done) => {
let beforeUnloadCount = 0;
ipcMain.on('onbeforeunload', (e) => {
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
// Hi future test refactorer! I don't know what event this timeout allows
// to occur, but without it, this test becomes flaky at this point and
// sometimes the window gets closed even though a `beforeunload` handler
// has been installed. I looked for events being emitted by the
// `webContents` during this timeout period and found nothing, so it
// might be some sort of internal timeout being applied by the content/
// layer, or blink?
//
// In any case, this incantation reduces flakiness. I'm going to add a
// summoning circle for good measure.
//
// 🕯 🕯
// 🕯 🕯
// 🕯 🕯
await new Promise(resolve => setTimeout(resolve, 1000));
// 🕯 🕯
// 🕯 🕯
// 🕯 🕯
{
const p = emittedOnce(ipcMain, 'onbeforeunload');
w.close();
const [e] = await p;
e.returnValue = null;
beforeUnloadCount += 1;
if (beforeUnloadCount < 3) {
w.loadURL('about:blank');
} else if (beforeUnloadCount === 3) {
done();
}
w.webContents.removeListener('destroyed', destroyListener);
const p = emittedOnce(w.webContents, 'destroyed');
w.close();
await p;
});
w.webContents.once('did-finish-load', () => {
w.webContents.once('did-finish-load', () => {
expect.fail('Navigation was not prevented');
it('emits for each reload attempt', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
const navigationListener = () => { expect.fail('Reload was not prevented'); };
w.webContents.once('did-start-navigation', navigationListener);
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
w.reload();
{
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
e.returnValue = null;
}
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
w.reload();
{
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
e.returnValue = null;
}
w.webContents.removeListener('did-start-navigation', navigationListener);
w.reload();
await emittedOnce(w.webContents, 'did-finish-load');
});
it('emits for each navigation attempt', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
const navigationListener = () => { expect.fail('Reload was not prevented'); };
w.webContents.once('did-start-navigation', navigationListener);
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
w.loadURL('about:blank');
});
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
{
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
e.returnValue = null;
}
await w.webContents.executeJavaScript('preventNextBeforeUnload()', true);
w.loadURL('about:blank');
{
const [e] = await emittedOnce(ipcMain, 'onbeforeunload');
e.returnValue = null;
}
w.webContents.removeListener('did-start-navigation', navigationListener);
w.loadURL('about:blank');
await emittedOnce(w.webContents, 'did-finish-load');
});
});

View file

@ -54,14 +54,16 @@ describe('webContents module', () => {
it('emits if beforeunload returns false', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
w.webContents.executeJavaScript('run()', true);
await emittedOnce(w.webContents, 'will-prevent-unload');
});
it('supports calling preventDefault on will-prevent-unload events', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.once('will-prevent-unload', event => event.preventDefault());
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'close-beforeunload-false.html'));
w.webContents.executeJavaScript('run()', true);
await emittedOnce(w, 'closed');
});
});

View file

@ -1,16 +1,16 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
// Only prevent unload on the first three window closes
var unloadPreventedCount = 0;
window.onbeforeunload = function() {
function preventNextBeforeUnload() {
window.addEventListener('beforeunload', function handler(e) {
e.preventDefault();
e.returnValue = '';
window.removeEventListener('beforeunload', handler)
setTimeout(function() {
require('electron').ipcRenderer.sendSync('onbeforeunload')
}, 0);
if (unloadPreventedCount < 3) {
unloadPreventedCount++;
return false;
}
})
}
</script>
</body>

View file

@ -1,6 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
function run() {
// Only prevent unload on the first window close
var unloadPrevented = false;
window.onbeforeunload = function() {
@ -13,7 +14,11 @@
}
}
// unload events don't get run unless load events have run.
if (document.readyState === 'complete')
window.close()
else
window.onload = () => window.close()
}
</script>
</body>
</html>