-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(client): fix a false positive page reload error in Safari #3643
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ var util = require('../common/util') | |
function Karma (updater, socket, iframe, opener, navigator, location, document) { | ||
this.updater = updater | ||
var startEmitted = false | ||
var karmaNavigating = false | ||
var self = this | ||
var queryParams = util.parseQueryParams(location.search) | ||
var browserId = queryParams.id || util.generateId('manual-') | ||
|
@@ -83,21 +82,21 @@ function Karma (updater, socket, iframe, opener, navigator, location, document) | |
|
||
var childWindow = null | ||
function navigateContextTo (url) { | ||
karmaNavigating = true | ||
if (self.config.useIframe === false) { | ||
// run in new window | ||
if (self.config.runInParent === false) { | ||
// If there is a window already open, then close it | ||
// DEV: In some environments (e.g. Electron), we don't have setter access for location | ||
if (childWindow !== null && childWindow.closed !== true) { | ||
// The onbeforeunload listener was added by context to catch | ||
// unexpected navigations while running tests. | ||
childWindow.onbeforeunload = undefined | ||
childWindow.close() | ||
} | ||
childWindow = opener(url) | ||
karmaNavigating = false | ||
// run context on parent element (client_with_context) | ||
// using window.__karma__.scriptUrls to get the html element strings and load them dynamically | ||
} else if (url !== 'about:blank') { | ||
karmaNavigating = false | ||
var loadScript = function (idx) { | ||
if (idx < window.__karma__.scriptUrls.length) { | ||
var parser = new DOMParser() | ||
|
@@ -128,15 +127,10 @@ function Karma (updater, socket, iframe, opener, navigator, location, document) | |
} | ||
// run in iframe | ||
} else { | ||
// The onbeforeunload listener was added by the context to catch | ||
// unexpected navigations while running tests. | ||
iframe.contentWindow.onbeforeunload = undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same q |
||
iframe.src = policy.createURL(url) | ||
karmaNavigating = false | ||
} | ||
} | ||
|
||
this.onbeforeunload = function () { | ||
if (!karmaNavigating) { | ||
// TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL) | ||
self.error('Some of your tests did a full page reload!') | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
delete childWindow.onbeforeunload
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onbeforeunload
is a property of thewindow
object, i.e. it has getter and setter.window.onbeforeunload = undefined
will change the underlying value, whiledelete window.onbeforeunload
will remove the property descriptor. Consider the below screenshot:It does not really matter in this case, but I think the current code is more correct.