mirror of
https://github.com/jlengrand/webcomponentsjs.git
synced 2026-05-10 15:56:07 +00:00
45 lines
1.8 KiB
HTML
45 lines
1.8 KiB
HTML
<!doctype html>
|
|
<!--
|
|
@license
|
|
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
|
|
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
Code distributed by Google as part of the polymer project is also
|
|
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
-->
|
|
<script src="../../../src/ShadowDOM/ShadowDOM.js"></script>
|
|
<script src="../../../../web-component-tester/browser.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.
|
|
|
|
test('unload event works', function(done) {
|
|
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';
|
|
});
|
|
</script>
|