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

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

Issue 1154423009: Make it easier and more efficient to use trusted HTML text (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Formatting Created 5 years, 6 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// This tests HTML validation and sanitization, which is very important
6 /// for prevent XSS or other attacks. If you suppress this, or parts of it
7 /// please make it a critical bug and bring it to the attention of the
8 /// dart:html maintainers.
9 library trusted_html_tree_sanitizer_test;
10
11 import 'dart:html';
12 import 'dart:svg' as svg;
13 import 'package:unittest/unittest.dart';
14 import 'package:unittest/html_individual_config.dart';
15 import 'utils.dart';
16 import 'dart:js' as js;
17
18 var oldAdoptNode;
19 var jsDocument;
20
21 /// We want to verify that with the trusted sanitizer we are not
22 /// creating a document fragment. So make DocumentFragment operation
23 /// throw.
24 makeDocumentFragmentAdoptionThrow() {
25 var document = js.context['document'];
26 jsDocument = new js.JsObject.fromBrowserObject(document);
27 oldAdoptNode = jsDocument['adoptNode'];
28 jsDocument['adoptNode'] = null;
29 }
30
31 restoreOldAdoptNode() {
32 jsDocument['adoptNode'] = oldAdoptNode;
33 }
34
35 main() {
36 useHtmlIndividualConfiguration();
37
38 group('not_create_document_fragment', () {
39 setUp(makeDocumentFragmentAdoptionThrow);
40 tearDown(restoreOldAdoptNode);
41
42 test('setInnerHtml', () {
43 document.body.setInnerHtml('<div foo="baz">something</div>',
44 treeSanitizer: NodeTreeSanitizer.trusted);
45 expect(document.body.innerHtml, '<div foo="baz">something</div>');
46 });
47
48 test("appendHtml", () {
49 var oldStuff = document.body.innerHtml;
50 var newStuff = '<div rumplestiltskin="value">content</div>';
51 document.body.appendHtml(newStuff,
52 treeSanitizer: NodeTreeSanitizer.trusted);
53 expect(document.body.innerHtml, oldStuff + newStuff);
54 });
55 });
56
57 group('untrusted', () {
58 setUp(makeDocumentFragmentAdoptionThrow);
59 tearDown(restoreOldAdoptNode);
60 test('untrusted', () {
61 expect(() => document.body.innerHtml = "<p>anything</p>", throws);
62 });
63 });
64 }
OLDNEW
« no previous file with comments | « tests/html/node_validator_important_if_you_suppress_make_the_bug_critical_test.dart ('k') | tools/dom/src/Validators.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698