Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix(browser): patch Window when EventTarget is missing. (#368)
Browse files Browse the repository at this point in the history
In browsers without EventTarget, window.addEventListener() is not patched.

Fixes #367.
  • Loading branch information
alxhub authored and mhevery committed Jun 30, 2016
1 parent 0da535f commit fcef80d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/browser/event-target.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {patchEventTargetMethods} from '../common/utils';

const WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video';
const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex'.split(',');
const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Window,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex'.split(',');
const EVENT_TARGET = 'EventTarget';

export function eventTargetPatch(_global) {
Expand Down
28 changes: 28 additions & 0 deletions test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {ifEnvSupports} from '../test-util';

function windowPrototype() {
return !!(global['Window'] && global['Window'].prototype);
}

describe('Zone', function () {
var rootZone = Zone.current;

Expand Down Expand Up @@ -72,6 +78,28 @@ describe('Zone', function () {
expect(eventListenerSpy).toHaveBeenCalled();
});

it('should support addEventListener on window', ifEnvSupports(windowPrototype, function () {
var hookSpy = jasmine.createSpy('hook');
var eventListenerSpy = jasmine.createSpy('eventListener');
var zone = rootZone.fork({
name: 'spy',
onScheduleTask: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
task: Task): any => {
hookSpy();
return parentZoneDelegate.scheduleTask(targetZone, task);
}
});

zone.run(function() {
window.addEventListener('click', eventListenerSpy);
});

window.dispatchEvent(clickEvent);

expect(hookSpy).toHaveBeenCalled();
expect(eventListenerSpy).toHaveBeenCalled();
}));

it('should support removeEventListener', function () {
var hookSpy = jasmine.createSpy('hook');
var eventListenerSpy = jasmine.createSpy('eventListener');
Expand Down

0 comments on commit fcef80d

Please sign in to comment.