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

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

Issue 16374007: First rev of Safe DOM (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 | « tests/html/node_validator_test.dart ('k') | tests/html/svg_test.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 library safe_dom_test; 1 library safe_dom_test;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:html'; 4 import 'dart:html';
5 import '../../pkg/unittest/lib/unittest.dart'; 5 import '../../pkg/unittest/lib/unittest.dart';
6 import '../../pkg/unittest/lib/html_config.dart'; 6 import '../../pkg/unittest/lib/html_config.dart';
7 7
8 main() { 8 main() {
9 useHtmlConfiguration(); 9 useHtmlConfiguration();
10 10
(...skipping 21 matching lines...) Expand all
32 test('Safe DOM', () { 32 test('Safe DOM', () {
33 var fragment = createContextualFragment(unsafeString); 33 var fragment = createContextualFragment(unsafeString);
34 34
35 expect(isSafe(), completion(true), 35 expect(isSafe(), completion(true),
36 reason: 'Expected no unsafe code executed.'); 36 reason: 'Expected no unsafe code executed.');
37 }); 37 });
38 38
39 // Make sure that scripts did get executed, so we know our detection works. 39 // Make sure that scripts did get executed, so we know our detection works.
40 test('Unsafe Execution', () { 40 test('Unsafe Execution', () {
41 var div = new DivElement(); 41 var div = new DivElement();
42 div.innerHtml = unsafeString; 42 div.$dom_innerHtml = unsafeString;
43 // Crashing DRT ?? 43 // Crashing DRT ??
44 // var fragment = createContextualFragment(unsafeString); 44 // var fragment = createContextualFragment(unsafeString);
45 // div.append(fragment); 45 // div.append(fragment);
46 // document.body.append(div) 46 // document.body.append(div)
47 47
48 expect(isSafe(), completion(false), 48 expect(isSafe(), completion(false),
49 reason: 'Expected unsafe code was executed.'); 49 reason: 'Expected unsafe code was executed.');
50 }); 50 });
51 51
52 test('Validity', () { 52 test('Validity', () {
(...skipping 14 matching lines...) Expand all
67 contextElement = doc.$dom_createElement(contextTag); 67 contextElement = doc.$dom_createElement(contextTag);
68 } else { 68 } else {
69 contextElement = doc.body; 69 contextElement = doc.body;
70 } 70 }
71 71
72 if (Range.supportsCreateContextualFragment) { 72 if (Range.supportsCreateContextualFragment) {
73 var range = doc.$dom_createRange(); 73 var range = doc.$dom_createRange();
74 range.selectNode(contextElement); 74 range.selectNode(contextElement);
75 return range.createContextualFragment(html); 75 return range.createContextualFragment(html);
76 } else { 76 } else {
77 contextElement.innerHtml = html; 77 contextElement.unsafeInnerHtml = html;
78 var fragment = new DocumentFragment();; 78 var fragment = new DocumentFragment();;
79 while (contextElement.firstChild != null) { 79 while (contextElement.firstChild != null) {
80 fragment.append(contextElement.firstChild); 80 fragment.append(contextElement.firstChild);
81 } 81 }
82 return fragment; 82 return fragment;
83 } 83 }
84 } 84 }
85 85
86 // Delay to wait for the image load to fail. 86 // Delay to wait for the image load to fail.
87 const Duration imageLoadDelay = const Duration(milliseconds: 500); 87 const Duration imageLoadDelay = const Duration(milliseconds: 500);
88 88
89 Future<bool> isSafe() { 89 Future<bool> isSafe() {
90 return new Future.delayed(imageLoadDelay).then((_) { 90 return new Future.delayed(imageLoadDelay).then((_) {
91 window.postMessage('check_unsafe', '*'); 91 window.postMessage('check_unsafe', '*');
92 }).then((_) { 92 }).then((_) {
93 return window.onMessage.where( 93 return window.onMessage.where(
94 (e) => e.data.startsWith('unsafe_check')).first; 94 (e) => e.data.startsWith('unsafe_check')).first;
95 }).then((e) { 95 }).then((e) {
96 return e.data == 'unsafe_check_passed'; 96 return e.data == 'unsafe_check_passed';
97 }); 97 });
98 } 98 }
OLDNEW
« no previous file with comments | « tests/html/node_validator_test.dart ('k') | tests/html/svg_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698