| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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">' |
| 329 '</head><body></body></html>'; | 329 '</head><body></body></html>'; |
| 330 var doc = parseDocument(html); | 330 var doc = parseDocument(html); |
| 331 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent()); | 331 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent()); |
| 332 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 332 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
| 333 var pathInfo = _newPathInfo('a', 'b', true); | 333 var pathInfo = _newPathInfo('a', 'b', true); |
| 334 | 334 |
| 335 var emitter = new MainPageEmitter(fileInfo); | 335 var emitter = new MainPageEmitter(fileInfo, false); |
| 336 emitter.run(doc, pathInfo, null, true); | 336 emitter.run(doc, pathInfo, null, true); |
| 337 expect(doc.outerHtml, equals(html)); | 337 expect(doc.outerHtml, equals(html)); |
| 338 }); | 338 }); |
| 339 | 339 |
| 340 group('transform css urls', () { | 340 group('transform css urls', () { |
| 341 | 341 |
| 342 var html = '<html><head>' | 342 var html = '<html><head>' |
| 343 '<link href="a.css" rel="stylesheet">' | 343 '<link href="a.css" rel="stylesheet">' |
| 344 '</head><body></body></html>'; | 344 '</head><body></body></html>'; |
| 345 | 345 |
| 346 test('html at the top level', () { | 346 test('html at the top level', () { |
| 347 var doc = parseDocument(html); | 347 var doc = parseDocument(html); |
| 348 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 348 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
| 349 filepath: 'a.html'); | 349 filepath: 'a.html'); |
| 350 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 350 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
| 351 // Issue #207 happened because we used to mistakenly take the path of | 351 // Issue #207 happened because we used to mistakenly take the path of |
| 352 // the external file when transforming the urls in the html file. | 352 // the external file when transforming the urls in the html file. |
| 353 fileInfo.externalFile = new Path('dir/a.dart'); | 353 fileInfo.externalFile = new Path('dir/a.dart'); |
| 354 var pathInfo = _newPathInfo('', 'out', true); | 354 var pathInfo = _newPathInfo('', 'out', true); |
| 355 var emitter = new MainPageEmitter(fileInfo); | 355 var emitter = new MainPageEmitter(fileInfo, false); |
| 356 emitter.run(doc, pathInfo, null, true); | 356 emitter.run(doc, pathInfo, null, true); |
| 357 expect(doc.outerHtml, html.replaceAll('a.css', '../a.css')); | 357 expect(doc.outerHtml, html.replaceAll('a.css', '../a.css')); |
| 358 }); | 358 }); |
| 359 | 359 |
| 360 test('file within dir -- base dir match input file dir', () { | 360 test('file within dir -- base dir match input file dir', () { |
| 361 var doc = parseDocument(html); | 361 var doc = parseDocument(html); |
| 362 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 362 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
| 363 filepath: 'dir/a.html'); | 363 filepath: 'dir/a.html'); |
| 364 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 364 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
| 365 // Issue #207 happened because we used to mistakenly take the path of | 365 // Issue #207 happened because we used to mistakenly take the path of |
| 366 // the external file when transforming the urls in the html file. | 366 // the external file when transforming the urls in the html file. |
| 367 fileInfo.externalFile = new Path('dir/a.dart'); | 367 fileInfo.externalFile = new Path('dir/a.dart'); |
| 368 var pathInfo = _newPathInfo('dir/', 'out', true); | 368 var pathInfo = _newPathInfo('dir/', 'out', true); |
| 369 var emitter = new MainPageEmitter(fileInfo); | 369 var emitter = new MainPageEmitter(fileInfo, false); |
| 370 emitter.run(doc, pathInfo, null, true); | 370 emitter.run(doc, pathInfo, null, true); |
| 371 expect(doc.outerHtml, html.replaceAll('a.css', '../dir/a.css')); | 371 expect(doc.outerHtml, html.replaceAll('a.css', '../dir/a.css')); |
| 372 }); | 372 }); |
| 373 | 373 |
| 374 test('file within dir, base dir at top-level', () { | 374 test('file within dir, base dir at top-level', () { |
| 375 var doc = parseDocument(html); | 375 var doc = parseDocument(html); |
| 376 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 376 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
| 377 filepath: 'dir/a.html'); | 377 filepath: 'dir/a.html'); |
| 378 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 378 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
| 379 // Issue #207 happened because we used to mistakenly take the path of | 379 // Issue #207 happened because we used to mistakenly take the path of |
| 380 // the external file when transforming the urls in the html file. | 380 // the external file when transforming the urls in the html file. |
| 381 fileInfo.externalFile = new Path('dir/a.dart'); | 381 fileInfo.externalFile = new Path('dir/a.dart'); |
| 382 var pathInfo = _newPathInfo('', 'out', true); | 382 var pathInfo = _newPathInfo('', 'out', true); |
| 383 var emitter = new MainPageEmitter(fileInfo); | 383 var emitter = new MainPageEmitter(fileInfo, false); |
| 384 emitter.run(doc, pathInfo, null, true); | 384 emitter.run(doc, pathInfo, null, true); |
| 385 expect(doc.outerHtml, html.replaceAll('a.css', '../../dir/a.css')); | 385 expect(doc.outerHtml, html.replaceAll('a.css', '../../dir/a.css')); |
| 386 }); | 386 }); |
| 387 | 387 |
| 388 test('no changes when feature is disabled', () { | 388 test('no changes when feature is disabled', () { |
| 389 var doc = parseDocument(html); | 389 var doc = parseDocument(html); |
| 390 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), | 390 var fileInfo = analyzeNodeForTesting(doc, new Messages.silent(), |
| 391 filepath: 'a.html'); | 391 filepath: 'a.html'); |
| 392 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 392 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
| 393 fileInfo.externalFile = new Path('dir/a.dart'); | 393 fileInfo.externalFile = new Path('dir/a.dart'); |
| 394 var pathInfo = _newPathInfo('', 'out', true); | 394 var pathInfo = _newPathInfo('', 'out', true); |
| 395 var emitter = new MainPageEmitter(fileInfo); | 395 var emitter = new MainPageEmitter(fileInfo, false); |
| 396 emitter.run(doc, pathInfo, null, false); | 396 emitter.run(doc, pathInfo, null, false); |
| 397 expect(doc.outerHtml, html); | 397 expect(doc.outerHtml, html); |
| 398 }); | 398 }); |
| 399 }); | 399 }); |
| 400 }); | 400 }); |
| 401 } | 401 } |
| 402 | 402 |
| 403 _init(Element elem, {int child}) { | 403 _init(Element elem, {int child}) { |
| 404 var info = analyzeElement(elem, new Messages.silent()); | 404 var info = analyzeElement(elem, new Messages.silent()); |
| 405 var printer = new CodePrinter(0); | 405 var printer = new CodePrinter(0); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 432 if (child != null) { | 432 if (child != null) { |
| 433 info = info.children[child]; | 433 info = info.children[child]; |
| 434 } | 434 } |
| 435 new RecursiveEmitter(null, context).visit(info); | 435 new RecursiveEmitter(null, context).visit(info); |
| 436 return context; | 436 return context; |
| 437 } | 437 } |
| 438 | 438 |
| 439 _newPathInfo(String baseDir, String outDir, bool forceMangle) => | 439 _newPathInfo(String baseDir, String outDir, bool forceMangle) => |
| 440 new PathInfo(new Path(baseDir), new Path(outDir), new Path('packages'), | 440 new PathInfo(new Path(baseDir), new Path(outDir), new Path('packages'), |
| 441 forceMangle); | 441 forceMangle); |
| OLD | NEW |