chore(browsers): fix failing tests in Firefox

Closes #3386
This commit is contained in:
Marc Laval 2015-07-27 11:47:25 +02:00
parent 53788ef827
commit 8822460858
10 changed files with 23 additions and 14 deletions

View File

@ -188,6 +188,9 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
void preventDefault(Event evt) { void preventDefault(Event evt) {
evt.preventDefault(); evt.preventDefault();
} }
bool isPrevented(Event evt) {
return evt.defaultPrevented;
}
String getInnerHTML(Element el) => el.innerHtml; String getInnerHTML(Element el) => el.innerHtml;
String getOuterHTML(Element el) => el.outerHtml; String getOuterHTML(Element el) => el.outerHtml;
void setInnerHTML(Element el, String value) { void setInnerHTML(Element el, String value) {

View File

@ -104,6 +104,9 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
evt.preventDefault(); evt.preventDefault();
evt.returnValue = false; evt.returnValue = false;
} }
isPrevented(evt: Event): boolean {
return evt.defaultPrevented || isPresent(evt.returnValue) && !evt.returnValue;
}
getInnerHTML(el): string { return el.innerHTML; } getInnerHTML(el): string { return el.innerHTML; }
getOuterHTML(el): string { return el.outerHTML; } getOuterHTML(el): string { return el.outerHTML; }
nodeName(node: Node): string { return node.nodeName; } nodeName(node: Node): string { return node.nodeName; }

View File

@ -43,6 +43,7 @@ export class DomAdapter {
createMouseEvent(eventType): any { throw _abstract(); } createMouseEvent(eventType): any { throw _abstract(); }
createEvent(eventType: string): any { throw _abstract(); } createEvent(eventType: string): any { throw _abstract(); }
preventDefault(evt) { throw _abstract(); } preventDefault(evt) { throw _abstract(); }
isPrevented(evt): boolean { throw _abstract(); }
getInnerHTML(el): string { throw _abstract(); } getInnerHTML(el): string { throw _abstract(); }
getOuterHTML(el): string { throw _abstract(); } getOuterHTML(el): string { throw _abstract(); }
nodeName(node): string { throw _abstract(); } nodeName(node): string { throw _abstract(); }

View File

@ -102,6 +102,9 @@ class Html5LibDomAdapter implements DomAdapter {
preventDefault(evt) { preventDefault(evt) {
throw 'not implemented'; throw 'not implemented';
} }
isPrevented(evt) {
throw 'not implemented';
}
getInnerHTML(el) { getInnerHTML(el) {
return el.innerHtml; return el.innerHtml;
} }

View File

@ -154,6 +154,7 @@ export class Parse5DomAdapter extends DomAdapter {
return evt; return evt;
} }
preventDefault(evt) { evt.returnValue = false; } preventDefault(evt) { evt.returnValue = false; }
isPrevented(evt): boolean { return isPresent(evt.returnValue) && !evt.returnValue; }
getInnerHTML(el): string { return serializer.serialize(this.templateAwareRoot(el)); } getInnerHTML(el): string { return serializer.serialize(this.templateAwareRoot(el)); }
getOuterHTML(el): string { getOuterHTML(el): string {
serializer.html = ''; serializer.html = '';

View File

@ -79,7 +79,7 @@ export class DomView {
allowDefaultBehavior = allowDefaultBehavior =
this.eventDispatcher.dispatchRenderEvent(elementIndex, eventName, evalLocals); this.eventDispatcher.dispatchRenderEvent(elementIndex, eventName, evalLocals);
if (!allowDefaultBehavior) { if (!allowDefaultBehavior) {
event.preventDefault(); DOM.preventDefault(event);
} }
} }
return allowDefaultBehavior; return allowDefaultBehavior;

View File

@ -900,14 +900,14 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(DOM.getChecked(rootTC.componentViewChildren[0].nativeElement)) var dispatchedEvent = DOM.createMouseEvent('click');
.toBeFalsy(); var dispatchedEvent2 = DOM.createMouseEvent('click');
expect(DOM.getChecked(rootTC.componentViewChildren[1].nativeElement))
.toBeFalsy();
DOM.dispatchEvent(rootTC.componentViewChildren[0].nativeElement, DOM.dispatchEvent(rootTC.componentViewChildren[0].nativeElement,
DOM.createMouseEvent('click')); dispatchedEvent);
DOM.dispatchEvent(rootTC.componentViewChildren[1].nativeElement, DOM.dispatchEvent(rootTC.componentViewChildren[1].nativeElement,
DOM.createMouseEvent('click')); dispatchedEvent2);
expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
expect(DOM.isPrevented(dispatchedEvent2)).toBe(false);
expect(DOM.getChecked(rootTC.componentViewChildren[0].nativeElement)) expect(DOM.getChecked(rootTC.componentViewChildren[0].nativeElement))
.toBeFalsy(); .toBeFalsy();
expect(DOM.getChecked(rootTC.componentViewChildren[1].nativeElement)) expect(DOM.getChecked(rootTC.componentViewChildren[1].nativeElement))

View File

@ -34,7 +34,7 @@ export function main() {
expect(clone).not.toBe(el1); expect(clone).not.toBe(el1);
DOM.setAttribute(clone, 'test', '1'); DOM.setAttribute(clone, 'test', '1');
expect(DOM.getOuterHTML(clone)).toEqual('<div x="y" test="1">a<span>b</span></div>'); expect(stringifyElement(clone)).toEqual('<div test="1" x="y">a<span>b</span></div>');
expect(DOM.getAttribute(el1, 'test')).toBeFalsy(); expect(DOM.getAttribute(el1, 'test')).toBeFalsy();
var cNodes = DOM.childNodes(clone); var cNodes = DOM.childNodes(clone);

View File

@ -267,8 +267,8 @@ export function main() {
tb.merge([rootProtoViewDto, componentProtoViewDto]) tb.merge([rootProtoViewDto, componentProtoViewDto])
.then(mergeMappings => { .then(mergeMappings => {
var domPv = resolveInternalDomProtoView(mergeMappings.mergedProtoViewRef); var domPv = resolveInternalDomProtoView(mergeMappings.mergedProtoViewRef);
expect(DOM.getInnerHTML(templateRoot(domPv))) expect(stringifyElement(templateRoot(domPv)))
.toEqual('<root class="ng-binding" a="b"></root>'); .toEqual('<template><root a="b" class="ng-binding"></root></template>');
async.done(); async.done();
}); });
}); });

View File

@ -541,8 +541,7 @@ export function main() {
rootTC.detectChanges(); rootTC.detectChanges();
var dispatchedEvent = clickOnElement(rootTC); var dispatchedEvent = clickOnElement(rootTC);
expect(dispatchedEvent.defaultPrevented || !dispatchedEvent.returnValue) expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
.toBe(true);
// router navigation is async. // router navigation is async.
rtr.subscribe((_) => { rtr.subscribe((_) => {
@ -563,8 +562,7 @@ export function main() {
rootTC.detectChanges(); rootTC.detectChanges();
var dispatchedEvent = clickOnElement(rootTC); var dispatchedEvent = clickOnElement(rootTC);
expect(dispatchedEvent.defaultPrevented || !dispatchedEvent.returnValue) expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
.toBe(true);
// router navigation is async. // router navigation is async.
rtr.subscribe((_) => { rtr.subscribe((_) => {