OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * These are not quite unit tests, since we build on top of the analyzer and the | 6 * These are not quite unit tests, since we build on top of the analyzer and the |
7 * html5parser to build the input for each test. | 7 * html5parser to build the input for each test. |
8 */ | 8 */ |
9 library emitter_test; | 9 library emitter_test; |
10 | 10 |
11 import 'package:html5lib/dom.dart'; | 11 import 'package:html5lib/dom.dart'; |
12 import 'package:unittest/compact_vm_config.dart'; | 12 import 'package:unittest/compact_vm_config.dart'; |
13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
14 import 'package:web_ui/src/analyzer.dart'; | 14 import 'package:web_ui/src/analyzer.dart'; |
15 import 'package:web_ui/src/code_printer.dart'; | 15 import 'package:web_ui/src/code_printer.dart'; |
| 16 import 'package:web_ui/src/dart_parser.dart'; |
16 import 'package:web_ui/src/emitters.dart'; | 17 import 'package:web_ui/src/emitters.dart'; |
17 import 'package:web_ui/src/file_system/path.dart' show Path; | 18 import 'package:web_ui/src/file_system/path.dart' show Path; |
18 import 'package:web_ui/src/html5_utils.dart'; | 19 import 'package:web_ui/src/html5_utils.dart'; |
19 import 'package:web_ui/src/info.dart'; | 20 import 'package:web_ui/src/info.dart'; |
20 import 'package:web_ui/src/messages.dart'; | 21 import 'package:web_ui/src/messages.dart'; |
21 import 'testing.dart'; | 22 import 'testing.dart'; |
22 | 23 |
23 main() { | 24 main() { |
24 useCompactVMConfiguration(); | 25 useCompactVMConfiguration(); |
25 group('emit element field', () { | 26 group('emit element field', () { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 '<html><head>' | 261 '<html><head>' |
261 '<script src="http://ex.com/a.js" type="text/javascript"></script>' | 262 '<script src="http://ex.com/a.js" type="text/javascript"></script>' |
262 '<script src="//example.com/a.js" type="text/javascript"></script>' | 263 '<script src="//example.com/a.js" type="text/javascript"></script>' |
263 '<script src="/a.js" type="text/javascript"></script>' | 264 '<script src="/a.js" type="text/javascript"></script>' |
264 '<link href="http://example.com/a.css" rel="stylesheet">' | 265 '<link href="http://example.com/a.css" rel="stylesheet">' |
265 '<link href="//example.com/a.css" rel="stylesheet">' | 266 '<link href="//example.com/a.css" rel="stylesheet">' |
266 '<link href="/a.css" rel="stylesheet">' | 267 '<link href="/a.css" rel="stylesheet">' |
267 '</head><body></body></html>'; | 268 '</head><body></body></html>'; |
268 var doc = parseDocument(html); | 269 var doc = parseDocument(html); |
269 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent()); | 270 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent()); |
270 fileInfo.userCode = new DartCodeInfo('main', null, [], ''); | 271 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], ''); |
271 var pathInfo = new PathInfo(new Path('a'), new Path('b'), true); | 272 var pathInfo = new PathInfo(new Path('a'), new Path('b'), true); |
272 | 273 |
273 var emitter = new MainPageEmitter(fileInfo); | 274 var emitter = new MainPageEmitter(fileInfo); |
274 emitter.run(doc, pathInfo); | 275 emitter.run(doc, pathInfo); |
275 expect(doc.outerHtml, equals(html)); | 276 expect(doc.outerHtml, equals(html)); |
276 }); | 277 }); |
277 | 278 |
278 group('transform css urls', () { | 279 group('transform css urls', () { |
279 | 280 |
280 var html = '<html><head>' | 281 var html = '<html><head>' |
281 '<link href="a.css" rel="stylesheet">' | 282 '<link href="a.css" rel="stylesheet">' |
282 '</head><body></body></html>'; | 283 '</head><body></body></html>'; |
283 | 284 |
284 test('html at the top level', () { | 285 test('html at the top level', () { |
285 var doc = parseDocument(html); | 286 var doc = parseDocument(html); |
286 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 287 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
287 filepath: 'a.html'); | 288 filepath: 'a.html'); |
288 fileInfo.userCode = new DartCodeInfo('main', null, [], ''); | 289 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], ''); |
289 // Issue #207 happened because we used to mistakenly take the path of | 290 // Issue #207 happened because we used to mistakenly take the path of |
290 // the external file when transforming the urls in the html file. | 291 // the external file when transforming the urls in the html file. |
291 fileInfo.externalFile = new Path('dir/a.dart'); | 292 fileInfo.externalFile = new Path('dir/a.dart'); |
292 var pathInfo = new PathInfo(new Path(''), new Path('out'), true); | 293 var pathInfo = new PathInfo(new Path(''), new Path('out'), true); |
293 var emitter = new MainPageEmitter(fileInfo); | 294 var emitter = new MainPageEmitter(fileInfo); |
294 emitter.run(doc, pathInfo); | 295 emitter.run(doc, pathInfo); |
295 expect(doc.outerHtml, html.replaceAll('a.css', '../a.css')); | 296 expect(doc.outerHtml, html.replaceAll('a.css', '../a.css')); |
296 }); | 297 }); |
297 | 298 |
298 test('file within dir -- base dir match input file dir', () { | 299 test('file within dir -- base dir match input file dir', () { |
299 var doc = parseDocument(html); | 300 var doc = parseDocument(html); |
300 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 301 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
301 filepath: 'dir/a.html'); | 302 filepath: 'dir/a.html'); |
302 fileInfo.userCode = new DartCodeInfo('main', null, [], ''); | 303 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], ''); |
303 // Issue #207 happened because we used to mistakenly take the path of | 304 // Issue #207 happened because we used to mistakenly take the path of |
304 // the external file when transforming the urls in the html file. | 305 // the external file when transforming the urls in the html file. |
305 fileInfo.externalFile = new Path('dir/a.dart'); | 306 fileInfo.externalFile = new Path('dir/a.dart'); |
306 var pathInfo = new PathInfo(new Path('dir/'), new Path('out'), true); | 307 var pathInfo = new PathInfo(new Path('dir/'), new Path('out'), true); |
307 var emitter = new MainPageEmitter(fileInfo); | 308 var emitter = new MainPageEmitter(fileInfo); |
308 emitter.run(doc, pathInfo); | 309 emitter.run(doc, pathInfo); |
309 expect(doc.outerHtml, html.replaceAll('a.css', '../dir/a.css')); | 310 expect(doc.outerHtml, html.replaceAll('a.css', '../dir/a.css')); |
310 }); | 311 }); |
311 | 312 |
312 test('file within dir, base dir at top-level', () { | 313 test('file within dir, base dir at top-level', () { |
313 var doc = parseDocument(html); | 314 var doc = parseDocument(html); |
314 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 315 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
315 filepath: 'dir/a.html'); | 316 filepath: 'dir/a.html'); |
316 fileInfo.userCode = new DartCodeInfo('main', null, [], ''); | 317 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], ''); |
317 // Issue #207 happened because we used to mistakenly take the path of | 318 // Issue #207 happened because we used to mistakenly take the path of |
318 // the external file when transforming the urls in the html file. | 319 // the external file when transforming the urls in the html file. |
319 fileInfo.externalFile = new Path('dir/a.dart'); | 320 fileInfo.externalFile = new Path('dir/a.dart'); |
320 var pathInfo = new PathInfo(new Path(''), new Path('out'), true); | 321 var pathInfo = new PathInfo(new Path(''), new Path('out'), true); |
321 var emitter = new MainPageEmitter(fileInfo); | 322 var emitter = new MainPageEmitter(fileInfo); |
322 emitter.run(doc, pathInfo); | 323 emitter.run(doc, pathInfo); |
323 expect(doc.outerHtml, html.replaceAll('a.css', '../../dir/a.css')); | 324 expect(doc.outerHtml, html.replaceAll('a.css', '../../dir/a.css')); |
324 }); | 325 }); |
325 }); | 326 }); |
326 }); | 327 }); |
(...skipping 27 matching lines...) Expand all Loading... |
354 | 355 |
355 Context _recurse(Element elem, bool isClass, int child) { | 356 Context _recurse(Element elem, bool isClass, int child) { |
356 var info = analyzeElement(elem, new Messages.silent()); | 357 var info = analyzeElement(elem, new Messages.silent()); |
357 var context = new Context(isClass: isClass); | 358 var context = new Context(isClass: isClass); |
358 if (child != null) { | 359 if (child != null) { |
359 info = info.children[child]; | 360 info = info.children[child]; |
360 } | 361 } |
361 new RecursiveEmitter(null, context).visit(info); | 362 new RecursiveEmitter(null, context).visit(info); |
362 return context; | 363 return context; |
363 } | 364 } |
OLD | NEW |