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 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 group('emit main page class', () { | 318 group('emit main page class', () { |
319 | 319 |
320 test('external resource URLs', () { | 320 test('external resource URLs', () { |
321 var html = | 321 var html = |
322 '<html><head>' | 322 '<html><head>' |
323 '<script src="http://ex.com/a.js" type="text/javascript"></script>' | 323 '<script src="http://ex.com/a.js" type="text/javascript"></script>' |
324 '<script src="//example.com/a.js" type="text/javascript"></script>' | 324 '<script src="//example.com/a.js" type="text/javascript"></script>' |
325 '<script src="/a.js" type="text/javascript"></script>' | 325 '<script src="/a.js" type="text/javascript"></script>' |
326 '<link href="http://example.com/a.css" rel="stylesheet">' | 326 '<link href="http://example.com/a.css" rel="stylesheet">' |
327 '<link href="//example.com/a.css" rel="stylesheet">' | 327 '<link href="//example.com/a.css" rel="stylesheet">' |
328 '<link href="/a.css" rel="stylesheet">' | 328 '<link href="/a.css" rel="stylesheet">' |
Siggi Cherem (dart-lang)
2013/03/07 22:14:20
we shouldn't be deleting this entry in the output.
terry
2013/03/08 20:11:24
Yeah, I've reverted this to test w/o polyfill I'll
| |
329 '</head><body></body></html>'; | 329 '</head><body></body></html>'; |
330 var expectedHtml = | |
331 '<html><head>' | |
332 '<script src="http://ex.com/a.js" type="text/javascript"></script>' | |
333 '<script src="//example.com/a.js" type="text/javascript"></script>' | |
334 '<script src="/a.js" type="text/javascript"></script>' | |
335 '<link href="http://example.com/a.css" rel="stylesheet">' | |
336 '<link rel="stylesheet"' | |
337 ' type="text/css" href="mock_testing_file.html.css">' | |
338 '</head><body></body></html>'; | |
330 var doc = parseDocument(html); | 339 var doc = parseDocument(html); |
331 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent()); | 340 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent()); |
332 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 341 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
333 var pathInfo = _newPathInfo('a', 'b', true); | 342 var pathInfo = _newPathInfo('a', 'b', true); |
334 | 343 |
335 var emitter = new MainPageEmitter(fileInfo); | 344 var emitter = new MainPageEmitter(fileInfo); |
336 emitter.run(doc, pathInfo, null, true); | 345 emitter.run(doc, pathInfo, null, true); |
337 expect(doc.outerHtml, equals(html)); | 346 expect(doc.outerHtml, equals(expectedHtml)); |
338 }); | 347 }); |
339 | 348 |
340 group('transform css urls', () { | 349 group('transform css urls', () { |
Siggi Cherem (dart-lang)
2013/03/07 22:14:20
the purpose of this test was to check that transfo
terry
2013/03/08 20:11:24
Done.
| |
341 | 350 |
342 var html = '<html><head>' | 351 var html = '<html><head>' |
343 '<link href="a.css" rel="stylesheet">' | 352 '<link href="a.css" rel="stylesheet">' |
344 '</head><body></body></html>'; | 353 '</head><body></body></html>'; |
345 | 354 var expectedHtml = '<html><head>' |
355 '<link rel="stylesheet" type="text/css" href="a.html.css">' | |
356 '</head><body></body></html>'; | |
346 test('html at the top level', () { | 357 test('html at the top level', () { |
347 var doc = parseDocument(html); | 358 var doc = parseDocument(html); |
348 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 359 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
349 filepath: 'a.html'); | 360 filepath: 'a.html'); |
350 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 361 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
351 // Issue #207 happened because we used to mistakenly take the path of | 362 // Issue #207 happened because we used to mistakenly take the path of |
352 // the external file when transforming the urls in the html file. | 363 // the external file when transforming the urls in the html file. |
353 fileInfo.externalFile = new Path('dir/a.dart'); | 364 fileInfo.externalFile = new Path('dir/a.dart'); |
354 var pathInfo = _newPathInfo('', 'out', true); | 365 var pathInfo = _newPathInfo('', 'out', true); |
355 var emitter = new MainPageEmitter(fileInfo); | 366 var emitter = new MainPageEmitter(fileInfo); |
356 emitter.run(doc, pathInfo, null, true); | 367 emitter.run(doc, pathInfo, null, true); |
357 expect(doc.outerHtml, html.replaceAll('a.css', '../a.css')); | 368 expect(doc.outerHtml, expectedHtml); |
358 }); | 369 }); |
359 | 370 |
360 test('file within dir -- base dir match input file dir', () { | 371 test('file within dir -- base dir match input file dir', () { |
361 var doc = parseDocument(html); | 372 var doc = parseDocument(html); |
362 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 373 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
363 filepath: 'dir/a.html'); | 374 filepath: 'dir/a.html'); |
364 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 375 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
365 // Issue #207 happened because we used to mistakenly take the path of | 376 // Issue #207 happened because we used to mistakenly take the path of |
366 // the external file when transforming the urls in the html file. | 377 // the external file when transforming the urls in the html file. |
367 fileInfo.externalFile = new Path('dir/a.dart'); | 378 fileInfo.externalFile = new Path('dir/a.dart'); |
368 var pathInfo = _newPathInfo('dir/', 'out', true); | 379 var pathInfo = _newPathInfo('dir/', 'out', true); |
369 var emitter = new MainPageEmitter(fileInfo); | 380 var emitter = new MainPageEmitter(fileInfo); |
370 emitter.run(doc, pathInfo, null, true); | 381 emitter.run(doc, pathInfo, null, true); |
371 expect(doc.outerHtml, html.replaceAll('a.css', '../dir/a.css')); | 382 expect(doc.outerHtml, expectedHtml); |
372 }); | 383 }); |
373 | 384 |
374 test('file within dir, base dir at top-level', () { | 385 test('file within dir, base dir at top-level', () { |
375 var doc = parseDocument(html); | 386 var doc = parseDocument(html); |
376 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 387 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
377 filepath: 'dir/a.html'); | 388 filepath: 'dir/a.html'); |
378 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 389 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
379 // Issue #207 happened because we used to mistakenly take the path of | 390 // Issue #207 happened because we used to mistakenly take the path of |
380 // the external file when transforming the urls in the html file. | 391 // the external file when transforming the urls in the html file. |
381 fileInfo.externalFile = new Path('dir/a.dart'); | 392 fileInfo.externalFile = new Path('dir/a.dart'); |
382 var pathInfo = _newPathInfo('', 'out', true); | 393 var pathInfo = _newPathInfo('', 'out', true); |
383 var emitter = new MainPageEmitter(fileInfo); | 394 var emitter = new MainPageEmitter(fileInfo); |
384 emitter.run(doc, pathInfo, null, true); | 395 emitter.run(doc, pathInfo, null, true); |
385 expect(doc.outerHtml, html.replaceAll('a.css', '../../dir/a.css')); | 396 expect(doc.outerHtml, expectedHtml); |
386 }); | 397 }); |
387 | 398 |
388 test('no changes when feature is disabled', () { | 399 test('no changes when feature is disabled', () { |
389 var doc = parseDocument(html); | 400 var doc = parseDocument(html); |
390 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 401 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
391 filepath: 'a.html'); | 402 filepath: 'a.html'); |
392 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 403 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
393 fileInfo.externalFile = new Path('dir/a.dart'); | 404 fileInfo.externalFile = new Path('dir/a.dart'); |
394 var pathInfo = _newPathInfo('', 'out', true); | 405 var pathInfo = _newPathInfo('', 'out', true); |
395 var emitter = new MainPageEmitter(fileInfo); | 406 var emitter = new MainPageEmitter(fileInfo); |
396 emitter.run(doc, pathInfo, null, false); | 407 emitter.run(doc, pathInfo, null, false); |
397 expect(doc.outerHtml, html); | 408 expect(doc.outerHtml, expectedHtml); |
398 }); | 409 }); |
399 }); | 410 }); |
400 }); | 411 }); |
401 } | 412 } |
402 | 413 |
403 _init(Element elem, {int child}) { | 414 _init(Element elem, {int child}) { |
404 var info = analyzeElement(elem, new Messages.silent()); | 415 var info = analyzeElement(elem, new Messages.silent()); |
405 var printer = new CodePrinter(0); | 416 var printer = new CodePrinter(0); |
406 if (child != null) { | 417 if (child != null) { |
407 info = info.children[child]; | 418 info = info.children[child]; |
(...skipping 24 matching lines...) Expand all Loading... | |
432 if (child != null) { | 443 if (child != null) { |
433 info = info.children[child]; | 444 info = info.children[child]; |
434 } | 445 } |
435 new RecursiveEmitter(null, context).visit(info); | 446 new RecursiveEmitter(null, context).visit(info); |
436 return context; | 447 return context; |
437 } | 448 } |
438 | 449 |
439 _newPathInfo(String baseDir, String outDir, bool forceMangle) => | 450 _newPathInfo(String baseDir, String outDir, bool forceMangle) => |
440 new PathInfo(new Path(baseDir), new Path(outDir), new Path('packages'), | 451 new PathInfo(new Path(baseDir), new Path(outDir), new Path('packages'), |
441 forceMangle); | 452 forceMangle); |
OLD | NEW |