test: use WebContents event to test beforeunload (#23699)
This commit is contained in:
parent
0dabd5e8c7
commit
08f288faf1
13 changed files with 97 additions and 134 deletions
|
@ -1,15 +1,14 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
function preventNextBeforeUnload() {
|
||||
function installBeforeUnload(removeAfterNTimes) {
|
||||
let count = 0
|
||||
window.addEventListener('beforeunload', function handler(e) {
|
||||
e.preventDefault();
|
||||
e.returnValue = '';
|
||||
window.removeEventListener('beforeunload', handler)
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload')
|
||||
}, 0);
|
||||
return false;
|
||||
setTimeout(() => console.log('beforeunload'))
|
||||
if (++count <= removeAfterNTimes) {
|
||||
e.preventDefault();
|
||||
e.returnValue = '';
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -4,16 +4,11 @@
|
|||
// Only prevent unload on the first window close
|
||||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload');
|
||||
}, 0);
|
||||
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
window.onload = () => window.close();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,23 +1,14 @@
|
|||
<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() {
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload');
|
||||
}, 0);
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
return false;
|
||||
}
|
||||
// Only prevent unload on the first window close
|
||||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
console.log('prevent')
|
||||
return false;
|
||||
}
|
||||
// unload events don't get run unless load events have run.
|
||||
if (document.readyState === 'complete')
|
||||
window.close()
|
||||
else
|
||||
window.onload = () => window.close()
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload');
|
||||
}, 0);
|
||||
}
|
||||
window.onload = () => window.close();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue