This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #499 from Polymer/polymer_issue_421_take2
Re-land fix for unload/beforeunload events
- Loading branch information
Showing
3 changed files
with
65 additions
and
5 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<script src="../../../tools/test/chai/chai.js"></script> | ||
<script src="../../../tools/test/htmltest.js"></script> | ||
<script src="../../shadowdom.js"></script> | ||
<script> | ||
// Note: this test will navigate away from the page. It is designed to be run | ||
// in an iframe. Use ShadowDOM/test/runner.html?grep=unload for running it by | ||
// itself. | ||
|
||
function runTest() { | ||
var assert = chai.assert; | ||
var doc = ShadowDOMPolyfill.wrap(document); | ||
var win = ShadowDOMPolyfill.wrap(window); | ||
|
||
// Note: IE gives `window` as the target for beforeunload/unload. Others give | ||
// document. It's not clear than anyone gets it right, my reading of the | ||
// current spec is target should be window for beforeunload, but is overridden | ||
// to be document for unload. Both events are dispatched on window: | ||
// http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#unloading-documents | ||
var expectedTarget = /Trident/.test(navigator.userAgent) ? win : doc; | ||
|
||
var beforeunloadCalled = 0; | ||
window.addEventListener('beforeunload', function(e) { | ||
beforeunloadCalled++; | ||
assert.equal(e.target, expectedTarget); | ||
}); | ||
|
||
window.addEventListener('unload', function(e) { | ||
assert.equal(beforeunloadCalled, 1); | ||
assert.equal(e.target, expectedTarget); | ||
done(); | ||
}); | ||
|
||
location.href = 'about:blank'; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function(e) { | ||
// Note: setTimeout makes IE happy. If document.readyState == 'interactive' | ||
// at the time we run the tests, IE won't fire an unload in the iframe. | ||
setTimeout(runTest, 0); | ||
}); | ||
|
||
</script> |
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