| OLD | NEW |
| 1 library ng_bind_html_spec; | 1 library ng_bind_html_spec; |
| 2 | 2 |
| 3 import 'dart:html' as dom; | |
| 4 import '../_specs.dart'; | 3 import '../_specs.dart'; |
| 5 | 4 |
| 6 main() { | 5 main() { |
| 7 describe('BindHtmlDirective', () { | 6 describe('BindHtmlDirective', () { |
| 7 TestBed _; |
| 8 |
| 9 beforeEach(inject((TestBed tb) => _ = tb)); |
| 8 | 10 |
| 9 it('should sanitize and set innerHtml and sanitize and set html', | 11 it('should sanitize and set innerHtml and sanitize and set html', |
| 10 inject((Scope scope, Injector injector, Compiler compiler, DirectiveMa
p directives) { | 12 inject((Scope scope, Injector injector, Compiler compiler) { |
| 11 var element = $('<div ng-bind-html="htmlVar"></div>'); | 13 var element = $('<div ng-bind-html="htmlVar"></div>'); |
| 12 compiler(element, directives)(injector, element); | 14 compiler(element)(injector, element); |
| 13 scope.context['htmlVar'] = '<a href="http://www.google.com"><b>Google!</b>
</a>'; | 15 scope.htmlVar = '<a href="http://www.google.com"><b>Google!</b></a>'; |
| 14 scope.apply(); | 16 scope.$digest(); |
| 15 // Sanitization removes the href attribute on the <a> tag. | 17 // Sanitization removes the href attribute on the <a> tag. |
| 16 expect(element.html()).toEqual('<a><b>Google!</b></a>'); | 18 expect(element.html()).toEqual('<a><b>Google!</b></a>'); |
| 17 })); | 19 })); |
| 18 | |
| 19 it('should use injected NodeValidator and override default sanitize behavior
', | |
| 20 module((Module module) { | |
| 21 module.factory(dom.NodeValidator, (_) { | |
| 22 final validator = new NodeValidatorBuilder(); | |
| 23 validator.allowNavigation(new AnyUriPolicy()); | |
| 24 validator.allowTextElements(); | |
| 25 return validator; | |
| 26 }); | |
| 27 | |
| 28 inject((Scope scope, Injector injector, Compiler compiler, DirectiveMap di
rectives) { | |
| 29 var element = $('<div ng-bind-html="htmlVar"></div>'); | |
| 30 compiler(element, directives)(injector, element); | |
| 31 scope.context['htmlVar'] = '<a href="http://www.google.com"><b>Google!</
b></a>'; | |
| 32 scope.apply(); | |
| 33 // Sanitation allows href attributes per injected sanitizer. | |
| 34 expect(element.html()).toEqual('<a href="http://www.google.com"><b>Googl
e!</b></a>'); | |
| 35 }); | |
| 36 })); | |
| 37 }); | 20 }); |
| 38 } | 21 } |
| 39 | |
| 40 class AnyUriPolicy implements UriPolicy { | |
| 41 bool allowsUri(String uri) => true; | |
| 42 } | |
| OLD | NEW |