fix(DomRenderer): correctly handle namespaced attributes

Closes #6363
This commit is contained in:
Victor Berchet
2016-01-08 12:01:29 -08:00
parent f1f5b45361
commit 61cf499b0b
12 changed files with 109 additions and 12 deletions
@@ -1848,7 +1848,7 @@ function declareTests() {
if (!IS_DART) {
var firstAttribute = DOM.getProperty(<Element>use, 'attributes')[0];
expect(firstAttribute.name).toEqual('xlink:href');
expect(firstAttribute.name).toEqual('href');
expect(firstAttribute.namespaceURI).toEqual('http://www.w3.org/1999/xlink');
} else {
// For Dart where '_Attr' has no instance getter 'namespaceURI'
@@ -1860,6 +1860,48 @@ function declareTests() {
}));
});
describe('attributes', () => {
it('should support attributes with namespace',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
async) => {
tcb.overrideView(SomeCmp, new ViewMetadata({template: '<svg:use xlink:href="#id" />'}))
.createAsync(SomeCmp)
.then((fixture) => {
let useEl = DOM.firstChild(fixture.debugElement.nativeElement);
expect(DOM.getAttributeNS(useEl, 'http://www.w3.org/1999/xlink', 'href'))
.toEqual('#id');
async.done();
});
}));
it('should support binding to attributes with namespace',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
async) => {
tcb.overrideView(SomeCmp,
new ViewMetadata({template: '<svg:use [attr.xlink:href]="value" />'}))
.createAsync(SomeCmp)
.then((fixture) => {
let cmp = fixture.debugElement.componentInstance;
let useEl = DOM.firstChild(fixture.debugElement.nativeElement);
cmp.value = "#id";
fixture.detectChanges();
expect(DOM.getAttributeNS(useEl, 'http://www.w3.org/1999/xlink', 'href'))
.toEqual('#id');
cmp.value = null;
fixture.detectChanges();
expect(DOM.hasAttributeNS(useEl, 'http://www.w3.org/1999/xlink', 'href'))
.toEqual(false);
async.done();
});
}));
});
}
});
}
@@ -2439,3 +2481,8 @@ class DirectiveWithPropDecorators {
fireEvent(msg) { ObservableWrapper.callEmit(this.event, msg); }
}
@Component({selector: 'some-cmp'})
class SomeCmp {
value: any;
}