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

Side by Side Diff: pkg/third_party/html5lib/test/parser_feature_test.dart

Issue 158083002: introduce web_components pkg for consolidated polyfills (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
OLDNEW
1 /** Additional feature tests that aren't based on test data. */ 1 /** Additional feature tests that aren't based on test data. */
2 library parser_feature_test; 2 library parser_feature_test;
3 3
4 import 'package:unittest/unittest.dart'; 4 import 'package:unittest/unittest.dart';
5 import 'package:html5lib/dom.dart'; 5 import 'package:html5lib/dom.dart';
6 import 'package:html5lib/dom_parsing.dart'; 6 import 'package:html5lib/dom_parsing.dart';
7 import 'package:html5lib/parser.dart'; 7 import 'package:html5lib/parser.dart';
8 import 'package:html5lib/src/constants.dart'; 8 import 'package:html5lib/src/constants.dart';
9 import 'package:html5lib/src/tokenizer.dart'; 9 import 'package:html5lib/src/tokenizer.dart';
10 import 'package:html5lib/src/treebuilder.dart'; 10 import 'package:html5lib/src/treebuilder.dart';
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 var text = doc.body.nodes[0].nodes[0]; 86 var text = doc.body.nodes[0].nodes[0];
87 expect(text, new isInstanceOf<Text>()); 87 expect(text, new isInstanceOf<Text>());
88 expect(text.value, textContent); 88 expect(text.value, textContent);
89 expect(text.sourceSpan.start.offset, html.indexOf(textContent)); 89 expect(text.sourceSpan.start.offset, html.indexOf(textContent));
90 expect(text.sourceSpan.length, textContent.length); 90 expect(text.sourceSpan.length, textContent.length);
91 }); 91 });
92 92
93 test('attribute spans', () { 93 test('attribute spans', () {
94 var text = '<element name="x-foo" extends="x-bar" constructor="Foo">'; 94 var text = '<element name="x-foo" extends="x-bar" constructor="Foo">';
95 var doc = parse(text, generateSpans: true); 95 var doc = parse(text, generateSpans: true);
96 var elem = doc.query('element'); 96 var elem = doc.querySelector('element');
97 expect(elem.sourceSpan.start.offset, 0); 97 expect(elem.sourceSpan.start.offset, 0);
98 expect(elem.sourceSpan.end.offset, text.length); 98 expect(elem.sourceSpan.end.offset, text.length);
99 expect(elem.sourceSpan.text, text); 99 expect(elem.sourceSpan.text, text);
100 100
101 expect(elem.attributeSpans['quux'], null); 101 expect(elem.attributeSpans['quux'], null);
102 102
103 var span = elem.attributeSpans['extends']; 103 var span = elem.attributeSpans['extends'];
104 expect(span.start.offset, text.indexOf('extends')); 104 expect(span.start.offset, text.indexOf('extends'));
105 expect(span.text, 'extends="x-bar"'); 105 expect(span.text, 'extends="x-bar"');
106 }); 106 });
107 107
108 test('attribute value spans', () { 108 test('attribute value spans', () {
109 var text = '<element name="x-foo" extends="x-bar" constructor="Foo">'; 109 var text = '<element name="x-foo" extends="x-bar" constructor="Foo">';
110 var doc = parse(text, generateSpans: true); 110 var doc = parse(text, generateSpans: true);
111 var elem = doc.query('element'); 111 var elem = doc.querySelector('element');
112 112
113 expect(elem.attributeValueSpans['quux'], null); 113 expect(elem.attributeValueSpans['quux'], null);
114 114
115 var span = elem.attributeValueSpans['extends']; 115 var span = elem.attributeValueSpans['extends'];
116 expect(span.start.offset, text.indexOf('x-bar')); 116 expect(span.start.offset, text.indexOf('x-bar'));
117 expect(span.text, 'x-bar'); 117 expect(span.text, 'x-bar');
118 }); 118 });
119 119
120 test('attribute spans if no attributes', () { 120 test('attribute spans if no attributes', () {
121 var text = '<element>'; 121 var text = '<element>';
122 var doc = parse(text, generateSpans: true); 122 var doc = parse(text, generateSpans: true);
123 var elem = doc.query('element'); 123 var elem = doc.querySelector('element');
124 124
125 expect(elem.attributeSpans['quux'], null); 125 expect(elem.attributeSpans['quux'], null);
126 expect(elem.attributeValueSpans['quux'], null); 126 expect(elem.attributeValueSpans['quux'], null);
127 }); 127 });
128 128
129 test('attribute spans if no attribute value', () { 129 test('attribute spans if no attribute value', () {
130 var text = '<foo template>'; 130 var text = '<foo template>';
131 var doc = parse(text, generateSpans: true); 131 var doc = parse(text, generateSpans: true);
132 var elem = doc.query('foo'); 132 var elem = doc.querySelector('foo');
133 133
134 expect(elem.attributeSpans['template'].start.offset, 134 expect(elem.attributeSpans['template'].start.offset,
135 text.indexOf('template')); 135 text.indexOf('template'));
136 expect(elem.attributeValueSpans.containsKey('template'), false); 136 expect(elem.attributeValueSpans.containsKey('template'), false);
137 }); 137 });
138 138
139 test('attribute spans null if code parsed without spans', () { 139 test('attribute spans null if code parsed without spans', () {
140 var text = '<element name="x-foo" extends="x-bar" constructor="Foo">'; 140 var text = '<element name="x-foo" extends="x-bar" constructor="Foo">';
141 var doc = parse(text); 141 var doc = parse(text);
142 var elem = doc.query('element'); 142 var elem = doc.querySelector('element');
143 expect(elem.sourceSpan, null); 143 expect(elem.sourceSpan, null);
144 expect(elem.attributeSpans['quux'], null); 144 expect(elem.attributeSpans['quux'], null);
145 expect(elem.attributeSpans['extends'], null); 145 expect(elem.attributeSpans['extends'], null);
146 }); 146 });
147 147
148 test('void element innerHTML', () { 148 test('void element innerHTML', () {
149 var doc = parse('<div></div>'); 149 var doc = parse('<div></div>');
150 expect(doc.body.innerHtml, '<div></div>'); 150 expect(doc.body.innerHtml, '<div></div>');
151 doc = parse('<body><script></script></body>'); 151 doc = parse('<body><script></script></body>');
152 expect(doc.body.innerHtml, '<script></script>'); 152 expect(doc.body.innerHtml, '<script></script>');
(...skipping 14 matching lines...) Expand all
167 var doc = parseFragment('<table><tbody><foo>'); 167 var doc = parseFragment('<table><tbody><foo>');
168 expect(doc.outerHtml, '<foo></foo><table><tbody></tbody></table>'); 168 expect(doc.outerHtml, '<foo></foo><table><tbody></tbody></table>');
169 }); 169 });
170 170
171 group('html serialization', () { 171 group('html serialization', () {
172 test('attribute order', () { 172 test('attribute order', () {
173 // Note: the spec only requires a stable order. 173 // Note: the spec only requires a stable order.
174 // However, we preserve the input order via LinkedHashMap 174 // However, we preserve the input order via LinkedHashMap
175 var doc = parseFragment('<foo d=1 a=2 c=3 b=4>'); 175 var doc = parseFragment('<foo d=1 a=2 c=3 b=4>');
176 expect(doc.outerHtml, '<foo d="1" a="2" c="3" b="4"></foo>'); 176 expect(doc.outerHtml, '<foo d="1" a="2" c="3" b="4"></foo>');
177 expect(doc.query('foo').attributes.remove('a'), '2'); 177 expect(doc.querySelector('foo').attributes.remove('a'), '2');
178 expect(doc.outerHtml, '<foo d="1" c="3" b="4"></foo>'); 178 expect(doc.outerHtml, '<foo d="1" c="3" b="4"></foo>');
179 doc.query('foo').attributes['a'] = '0'; 179 doc.querySelector('foo').attributes['a'] = '0';
180 expect(doc.outerHtml, '<foo d="1" c="3" b="4" a="0"></foo>'); 180 expect(doc.outerHtml, '<foo d="1" c="3" b="4" a="0"></foo>');
181 }); 181 });
182 182
183 test('escaping Text node in <script>', () { 183 test('escaping Text node in <script>', () {
184 var doc = parseFragment('<script>a && b</script>'); 184 var doc = parseFragment('<script>a && b</script>');
185 expect(doc.outerHtml, '<script>a && b</script>'); 185 expect(doc.outerHtml, '<script>a && b</script>');
186 }); 186 });
187 187
188 test('escaping Text node in <span>', () { 188 test('escaping Text node in <span>', () {
189 var doc = parseFragment('<span>a && b</span>'); 189 var doc = parseFragment('<span>a && b</span>');
190 expect(doc.outerHtml, '<span>a &amp;&amp; b</span>'); 190 expect(doc.outerHtml, '<span>a &amp;&amp; b</span>');
191 }); 191 });
192 192
193 test('Escaping attributes', () { 193 test('Escaping attributes', () {
194 var doc = parseFragment('<div class="a<b>">'); 194 var doc = parseFragment('<div class="a<b>">');
195 expect(doc.outerHtml, '<div class="a<b>"></div>'); 195 expect(doc.outerHtml, '<div class="a<b>"></div>');
196 doc = parseFragment('<div class=\'a"b\'>'); 196 doc = parseFragment('<div class=\'a"b\'>');
197 expect(doc.outerHtml, '<div class="a&quot;b"></div>'); 197 expect(doc.outerHtml, '<div class="a&quot;b"></div>');
198 }); 198 });
199 199
200 test('Escaping non-breaking space', () { 200 test('Escaping non-breaking space', () {
201 var text = '<span>foO\u00A0bar</span>'; 201 var text = '<span>foO\u00A0bar</span>';
202 expect(text.codeUnitAt(text.indexOf('O') + 1), 0xA0); 202 expect(text.codeUnitAt(text.indexOf('O') + 1), 0xA0);
203 var doc = parseFragment(text); 203 var doc = parseFragment(text);
204 expect(doc.outerHtml, '<span>foO&nbsp;bar</span>'); 204 expect(doc.outerHtml, '<span>foO&nbsp;bar</span>');
205 }); 205 });
206 206
207 test('Newline after <pre>', () { 207 test('Newline after <pre>', () {
208 var doc = parseFragment('<pre>\n\nsome text</span>'); 208 var doc = parseFragment('<pre>\n\nsome text</span>');
209 expect(doc.query('pre').nodes[0].value, '\nsome text'); 209 expect(doc.querySelector('pre').nodes[0].value, '\nsome text');
210 expect(doc.outerHtml, '<pre>\n\nsome text</pre>'); 210 expect(doc.outerHtml, '<pre>\n\nsome text</pre>');
211 211
212 doc = parseFragment('<pre>\nsome text</span>'); 212 doc = parseFragment('<pre>\nsome text</span>');
213 expect(doc.query('pre').nodes[0].value, 'some text'); 213 expect(doc.querySelector('pre').nodes[0].value, 'some text');
214 expect(doc.outerHtml, '<pre>some text</pre>'); 214 expect(doc.outerHtml, '<pre>some text</pre>');
215 }); 215 });
216 216
217 test('xml namespaces', () { 217 test('xml namespaces', () {
218 // Note: this is a nonsensical example, but it triggers the behavior 218 // Note: this is a nonsensical example, but it triggers the behavior
219 // we're looking for with attribute names in foreign content. 219 // we're looking for with attribute names in foreign content.
220 var doc = parse(''' 220 var doc = parse('''
221 <body> 221 <body>
222 <svg> 222 <svg>
223 <desc xlink:type="simple" 223 <desc xlink:type="simple"
224 xlink:href="http://example.com/logo.png" 224 xlink:href="http://example.com/logo.png"
225 xlink:show="new"></desc> 225 xlink:show="new"></desc>
226 '''); 226 ''');
227 var n = doc.query('desc'); 227 var n = doc.querySelector('desc');
228 var keys = n.attributes.keys.toList(); 228 var keys = n.attributes.keys.toList();
229 expect(keys[0], new isInstanceOf<AttributeName>()); 229 expect(keys[0], new isInstanceOf<AttributeName>());
230 expect(keys[0].prefix, 'xlink'); 230 expect(keys[0].prefix, 'xlink');
231 expect(keys[0].namespace, 'http://www.w3.org/1999/xlink'); 231 expect(keys[0].namespace, 'http://www.w3.org/1999/xlink');
232 expect(keys[0].name, 'type'); 232 expect(keys[0].name, 'type');
233 233
234 expect(n.outerHtml, '<desc xlink:type="simple" ' 234 expect(n.outerHtml, '<desc xlink:type="simple" '
235 'xlink:href="http://example.com/logo.png" xlink:show="new"></desc>'); 235 'xlink:href="http://example.com/logo.png" xlink:show="new"></desc>');
236 }); 236 });
237 }); 237 });
238 238
239 test('error printing without spans', () { 239 test('error printing without spans', () {
240 var parser = new HtmlParser('foo'); 240 var parser = new HtmlParser('foo');
241 var doc = parser.parse(); 241 var doc = parser.parse();
242 expect(doc.body.innerHtml, 'foo'); 242 expect(doc.body.innerHtml, 'foo');
243 expect(parser.errors.length, 1); 243 expect(parser.errors.length, 1);
244 expect(parser.errors[0].errorCode, 'expected-doctype-but-got-chars'); 244 expect(parser.errors[0].errorCode, 'expected-doctype-but-got-chars');
245 expect(parser.errors[0].message, 245 expect(parser.errors[0].message,
246 'Unexpected non-space characters. Expected DOCTYPE.'); 246 'Unexpected non-space characters. Expected DOCTYPE.');
247 expect(parser.errors[0].toString(), 247 expect(parser.errors[0].toString(),
248 'ParserError:1:4: Unexpected non-space characters. ' 248 'ParserError:1:4: Unexpected non-space characters. '
249 'Expected DOCTYPE.'); 249 'Expected DOCTYPE.');
250 }); 250 });
251 } 251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698