Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: tests/html/node_validator_test.dart

Issue 23793004: Adding an easy way to allow inline style attributes through sanitization (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/NodeValidatorBuilder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library validator_test; 5 library validator_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:svg' as svg; 9 import 'dart:svg' as svg;
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 validator, 80 validator,
81 '<select>' 81 '<select>'
82 '<option>a</option>' 82 '<option>a</option>'
83 '</select>'); 83 '</select>');
84 84
85 testHtml('blocks sequential script elements', 85 testHtml('blocks sequential script elements',
86 validator, 86 validator,
87 '<div><script></script><script></script></div>', 87 '<div><script></script><script></script></div>',
88 '<div></div>'); 88 '<div></div>');
89 89
90 testHtml('blocks inline styles',
91 validator,
92 '<div style="background: red"></div>',
93 '<div></div>');
94
90 testHtml('blocks namespaced attributes', 95 testHtml('blocks namespaced attributes',
91 validator, 96 validator,
92 '<div ns:foo="foo"></div>', 97 '<div ns:foo="foo"></div>',
93 '<div></div>'); 98 '<div></div>');
94 99
95 testHtml('blocks namespaced common attributes', 100 testHtml('blocks namespaced common attributes',
96 validator, 101 validator,
97 '<div ns:class="foo"></div>', 102 '<div ns:class="foo"></div>',
98 '<div></div>'); 103 '<div></div>');
99 104
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 '<foreignobject width="100" height="150">' 371 '<foreignobject width="100" height="150">'
367 '<body xmlns="http://www.w3.org/1999/xhtml">' 372 '<body xmlns="http://www.w3.org/1999/xhtml">'
368 '<div>Some content</div>' 373 '<div>Some content</div>'
369 '</body>' 374 '</body>'
370 '</foreignobject>' 375 '</foreignobject>'
371 '</svg>', 376 '</svg>',
372 '<svg xmlns="http://www.w3.org/2000/svg>' 377 '<svg xmlns="http://www.w3.org/2000/svg>'
373 '<foreignobject width="100" height="150"></foreignobject>' 378 '<foreignobject width="100" height="150"></foreignobject>'
374 '</svg>'); 379 '</svg>');
375 }); 380 });
381
382 group('allowInlineStyles', () {
383 var validator = new NodeValidatorBuilder()
384 ..allowTextElements()
385 ..allowInlineStyles();
386
387 testHtml('allows inline styles',
388 validator,
389 '<span style="background-color:red">text</span>');
390
391 testHtml('blocks other attributes',
392 validator,
393 '<span class="red-span"></span>',
394 '<span></span>');
395
396 validator = new NodeValidatorBuilder()
397 ..allowTextElements()
398 ..allowInlineStyles(tagName: 'span');
399
400 testHtml('scoped allows inline styles on spans',
401 validator,
402 '<span style="background-color:red">text</span>');
403
404 testHtml('scoped blocks inline styles on LIs',
405 validator,
406 '<li style="background-color:red">text</li>',
407 '<li>text</li>');
408 });
376 }); 409 });
377 410
378 group('throws', () { 411 group('throws', () {
379 var validator = new NodeValidator.throws(new NodeValidatorBuilder.common()); 412 var validator = new NodeValidator.throws(new NodeValidatorBuilder.common());
380 413
381 var validationError = throwsArgumentError; 414 var validationError = throwsArgumentError;
382 415
383 test('does not throw on valid syntax', () { 416 test('does not throw on valid syntax', () {
384 expect(() { 417 expect(() {
385 document.body.createFragment('<div></div>', validator: validator); 418 document.body.createFragment('<div></div>', validator: validator);
(...skipping 29 matching lines...) Expand all
415 '<image xlink:href="foo" data-foo="bar"/>' 448 '<image xlink:href="foo" data-foo="bar"/>'
416 '</svg>'; 449 '</svg>';
417 450
418 var fragment = new DocumentFragment.svg(svgText); 451 var fragment = new DocumentFragment.svg(svgText);
419 var element = fragment.nodes.first; 452 var element = fragment.nodes.first;
420 expect(element is svg.SvgSvgElement, isTrue); 453 expect(element is svg.SvgSvgElement, isTrue);
421 expect(element.children[0] is svg.ImageElement, isTrue); 454 expect(element.children[0] is svg.ImageElement, isTrue);
422 }); 455 });
423 }); 456 });
424 } 457 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/NodeValidatorBuilder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698