Skip to content

Commit

Permalink
Use win.destroy to destroy Electron windows, log more events (#5603)
Browse files Browse the repository at this point in the history
* Use win.destroy to destroy windows, log more events

* fix test

* Add tests for onbeforeunload, beforeunload exiting successfully

* add window.open beforeunload tests

* beforeunload, not beforeload

* just destroy those child windows
  • Loading branch information
flotwig authored and brian-mann committed Nov 7, 2019
1 parent 9aeadbd commit f5b0909
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>

<script>
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = 'Dialog';
return;
})
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>

<script>
window.onbeforeunload = function (e) {
e.preventDefault();
e.returnValue = 'Dialog';
return;
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('will exit even if an beforeload event dialog is present in a child window', function () {
cy.window().invoke('open', '/fixtures/blocking_beforeunload_event.html')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('will exit even if an beforeload event dialog is present', function () {
cy.visit('/fixtures/blocking_beforeunload_event.html')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('will exit even if an onbeforeunload dialog is present in a child window', function () {
cy.window().invoke('open', '/fixtures/blocking_onbeforeunload.html')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('will exit even if an onbeforeunload dialog is present', function () {
cy.visit('/fixtures/blocking_onbeforeunload.html')
})
17 changes: 15 additions & 2 deletions packages/server/lib/browsers/electron.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ plugins = require("../plugins")
savedState = require("../saved_state")
profileCleaner = require("../util/profile_cleaner")

## additional events that are nice to know about to be logged
## https://electronjs.org/docs/api/browser-window#instance-events
ELECTRON_DEBUG_EVENTS = [
'close'
'responsive',
'session-end'
'unresponsive'
]

tryToCall = (win, method) ->
try
if not win.isDestroyed()
Expand Down Expand Up @@ -61,7 +70,7 @@ module.exports = {
## close child on parent close
_win.on "close", ->
if not child.isDestroyed()
child.close()
child.destroy()
}

_.defaultsDeep({}, options, defaults)
Expand Down Expand Up @@ -99,6 +108,10 @@ module.exports = {
if options.show
menu.set({withDevTools: true})

ELECTRON_DEBUG_EVENTS.forEach (e) ->
win.on e, ->
debug("%s fired on the BrowserWindow %o", e, { browserWindowUrl: url })

Promise.try =>
@_attachDebugger(win.webContents)
.then =>
Expand Down Expand Up @@ -226,7 +239,7 @@ module.exports = {

return _.extend events, {
browserWindow: win
kill: -> tryToCall(win, "close")
kill: -> tryToCall(win, "destroy")
removeAllListeners: -> tryToCall(win, "removeAllListeners")
}
}
2 changes: 1 addition & 1 deletion packages/server/test/integration/cypress_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ describe "lib/cypress", ->
# like calling client.close() if available to let the
# browser free any resources
ee.emit("exit")
ee.close = ->
ee.destroy = ->
ee.emit("closed")
ee.isDestroyed = -> false
ee.loadURL = ->
Expand Down

4 comments on commit f5b0909

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5b0909 Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/linux-x64/circle-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-187618/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.6.1/circle-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-187572/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5b0909 Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/darwin-x64/circle-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-187786/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.6.1/circle-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-187621/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5b0909 Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/win32-x64/appveyor-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-28701659/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.6.1/win32-x64/appveyor-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-28701659/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5b0909 Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/win32-ia32/appveyor-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-28701659/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.6.1/win32-ia32/appveyor-develop-f5b09091ea6c9ba244de4313ac323bd7c4699f33-28701659/cypress.zip

Please sign in to comment.