2019-05-31 11:56:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-05-31 11:56:07 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {ifEnvSupports} from '../test-util';
|
|
|
|
|
|
|
|
function supportsImports() {
|
|
|
|
return 'import' in document.createElement('link');
|
|
|
|
}
|
|
|
|
(<any>supportsImports).message = 'HTML Imports';
|
|
|
|
|
|
|
|
describe('HTML Imports', ifEnvSupports(supportsImports, function() {
|
|
|
|
const testZone = Zone.current.fork({name: 'test'});
|
|
|
|
|
|
|
|
it('should work with addEventListener', function(done) {
|
|
|
|
let link: HTMLLinkElement;
|
|
|
|
|
|
|
|
testZone.run(function() {
|
|
|
|
link = document.createElement('link');
|
|
|
|
link.rel = 'import';
|
|
|
|
link.href = 'someUrl';
|
|
|
|
link.addEventListener('error', function() {
|
|
|
|
expect(Zone.current).toBe(testZone);
|
|
|
|
document.head.removeChild(link);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
document.head.appendChild(link!);
|
2019-05-31 11:56:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
function supportsOnEvents() {
|
|
|
|
const link = document.createElement('link');
|
|
|
|
const linkPropDesc = Object.getOwnPropertyDescriptor(link, 'onerror');
|
|
|
|
return !(linkPropDesc && linkPropDesc.value === null);
|
|
|
|
}
|
|
|
|
(<any>supportsOnEvents).message = 'Supports HTMLLinkElement#onxxx patching';
|
|
|
|
|
|
|
|
|
|
|
|
ifEnvSupports(supportsOnEvents, function() {
|
|
|
|
it('should work with onerror', function(done) {
|
|
|
|
let link: HTMLLinkElement;
|
|
|
|
|
|
|
|
testZone.run(function() {
|
|
|
|
link = document.createElement('link');
|
|
|
|
link.rel = 'import';
|
|
|
|
link.href = 'anotherUrl';
|
|
|
|
link.onerror = function() {
|
|
|
|
expect(Zone.current).toBe(testZone);
|
|
|
|
document.head.removeChild(link);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
document.head.appendChild(link!);
|
2019-05-31 11:56:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with onload', function(done) {
|
|
|
|
let link: HTMLLinkElement;
|
|
|
|
|
|
|
|
testZone.run(function() {
|
|
|
|
link = document.createElement('link');
|
|
|
|
link.rel = 'import';
|
|
|
|
link.href = '/base/angular/packages/zone.js/test/assets/import.html';
|
|
|
|
link.onload = function() {
|
|
|
|
expect(Zone.current).toBe(testZone);
|
|
|
|
document.head.removeChild(link);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
document.head.appendChild(link!);
|
2019-05-31 11:56:07 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|