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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 '<link href="http://example.com/a.css" rel="stylesheet">' | 329 '<link href="http://example.com/a.css" rel="stylesheet">' |
330 '<link href="foobar:a.css" rel="stylesheet">' | 330 '<link href="foobar:a.css" rel="stylesheet">' |
331 '<link href="//example.com/a.css" rel="stylesheet">' | 331 '<link href="//example.com/a.css" rel="stylesheet">' |
332 '<link href="/a.css" rel="stylesheet">' | 332 '<link href="/a.css" rel="stylesheet">' |
333 '</head><body></body></html>'; | 333 '</head><body></body></html>'; |
334 var doc = parseDocument(html); | 334 var doc = parseDocument(html); |
335 var fileInfo = analyzeNodeForTesting(doc, messages); | 335 var fileInfo = analyzeNodeForTesting(doc, messages); |
336 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 336 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
337 var paths = _newPathMapper('a', 'b', true); | 337 var paths = _newPathMapper('a', 'b', true); |
338 | 338 |
339 transformMainHtml(doc, fileInfo, paths, false, true, messages); | 339 transformMainHtml(doc, fileInfo, paths, false, true, messages, 'x'); |
340 expect(doc.outerHtml, | 340 expect(doc.outerHtml, |
341 '\n<!-- This file was auto-generated from ' | 341 '\n<!-- This file was auto-generated from ' |
342 '${fileInfo.inputUrl.resolvedPath}. -->' | 342 '${fileInfo.inputUrl.resolvedPath}. -->' |
343 '\n<html><head>' | 343 '\n<html><head>' |
344 '<style>template { display: none; }</style>' | 344 '<style>template { display: none; }</style>' |
345 '<script src="http://ex.com/a.js" type="text/javascript"></script>' | 345 '<script src="http://ex.com/a.js" type="text/javascript"></script>' |
346 '<script src="foobar:a.js" type="text/javascript"></script>' | 346 '<script src="foobar:a.js" type="text/javascript"></script>' |
347 '<script src="//example.com/a.js" type="text/javascript"></script>' | 347 '<script src="//example.com/a.js" type="text/javascript"></script>' |
348 '<script src="/a.js" type="text/javascript"></script>' | 348 '<script src="/a.js" type="text/javascript"></script>' |
349 '<link href="http://example.com/a.css" rel="stylesheet">' | 349 '<link href="http://example.com/a.css" rel="stylesheet">' |
350 '<link href="foobar:a.css" rel="stylesheet">' | 350 '<link href="foobar:a.css" rel="stylesheet">' |
351 '<link href="//example.com/a.css" rel="stylesheet">' | 351 '<link href="//example.com/a.css" rel="stylesheet">' |
352 '<link href="/a.css" rel="stylesheet">' | 352 '<link href="/a.css" rel="stylesheet">' |
353 '</head><body>' | 353 '</head><body>' |
| 354 '<script type="application/dart" src="x"></script>' |
354 '<script type="text/javascript" src="packages/browser/dart.js">' | 355 '<script type="text/javascript" src="packages/browser/dart.js">' |
355 '</script>\n</body></html>'); | 356 '</script>\n</body></html>'); |
356 }); | 357 }); |
357 | 358 |
358 test('transform css urls', () { | 359 test('transform css urls', () { |
359 var html = '<html><head>' | 360 var html = '<html><head>' |
360 '<link rel="stylesheet" href="a.css">' | 361 '<link rel="stylesheet" href="a.css">' |
361 '</head><body></body></html>'; | 362 '</head><body></body></html>'; |
362 | 363 |
363 var doc = parseDocument(html); | 364 var doc = parseDocument(html); |
364 var fileInfo = analyzeNodeForTesting(doc, messages, filepath: 'a.html'); | 365 var fileInfo = analyzeNodeForTesting(doc, messages, filepath: 'a.html'); |
365 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 366 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
366 // Issue #207 happened because we used to mistakenly take the path of | 367 // Issue #207 happened because we used to mistakenly take the path of |
367 // the external file when transforming the urls in the html file. | 368 // the external file when transforming the urls in the html file. |
368 fileInfo.externalFile = new UrlInfo('', 'dir/a.dart', null); | 369 fileInfo.externalFile = new UrlInfo('', 'dir/a.dart', null); |
369 var paths = _newPathMapper('', 'out', true); | 370 var paths = _newPathMapper('', 'out', true); |
370 transformMainHtml(doc, fileInfo, paths, false, true, messages); | 371 transformMainHtml(doc, fileInfo, paths, false, true, messages, 'x'); |
371 var emitter = new EntryPointEmitter(fileInfo); | 372 var emitter = new EntryPointEmitter(fileInfo); |
372 emitter.run(paths, null, true); | 373 emitter.run(paths, null, true); |
373 | 374 |
374 expect(doc.outerHtml, | 375 expect(doc.outerHtml, |
375 '\n<!-- This file was auto-generated from ' | 376 '\n<!-- This file was auto-generated from ' |
376 '${fileInfo.inputUrl.resolvedPath}. -->' | 377 '${fileInfo.inputUrl.resolvedPath}. -->' |
377 '\n<html><head>' | 378 '\n<html><head>' |
378 '<style>template { display: none; }</style>' | 379 '<style>template { display: none; }</style>' |
379 '<link rel="stylesheet" href="../a.css">' | 380 '<link rel="stylesheet" href="../a.css">' |
380 '</head><body>' | 381 '</head><body>' |
| 382 '<script type="application/dart" src="x"></script>' |
381 '<script type="text/javascript" src="packages/browser/dart.js">' | 383 '<script type="text/javascript" src="packages/browser/dart.js">' |
382 '</script>\n' | 384 '</script>\n' |
383 '</body></html>'); | 385 '</body></html>'); |
384 }); | 386 }); |
385 | 387 |
386 | 388 |
387 test('no css urls if no styles', () { | 389 test('no css urls if no styles', () { |
388 var html = '<html><head></head><body></body></html>'; | 390 var html = '<html><head></head><body></body></html>'; |
389 var doc = parseDocument(html); | 391 var doc = parseDocument(html); |
390 var fileInfo = analyzeNodeForTesting(doc, messages, filepath: 'a.html'); | 392 var fileInfo = analyzeNodeForTesting(doc, messages, filepath: 'a.html'); |
391 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); | 393 fileInfo.inlinedCode = new DartCodeInfo('main', null, [], '', null); |
392 fileInfo.externalFile = new UrlInfo('', 'dir/a.dart', null); | 394 fileInfo.externalFile = new UrlInfo('', 'dir/a.dart', null); |
393 var paths = _newPathMapper('', 'out', true); | 395 var paths = _newPathMapper('', 'out', true); |
394 // TODO(jmesserly): this test is not quite right because we're supplying | 396 // TODO(jmesserly): this test is not quite right because we're supplying |
395 // the hasCss property. We should probably convert this to be a compiler | 397 // the hasCss property. We should probably convert this to be a compiler |
396 // test. | 398 // test. |
397 transformMainHtml(doc, fileInfo, paths, false, true, messages); | 399 transformMainHtml(doc, fileInfo, paths, false, true, messages, 'x'); |
398 var emitter = new EntryPointEmitter(fileInfo); | 400 var emitter = new EntryPointEmitter(fileInfo); |
399 emitter.run(paths, null, true); | 401 emitter.run(paths, null, true); |
400 | 402 |
401 expect(doc.outerHtml, | 403 expect(doc.outerHtml, |
402 '\n<!-- This file was auto-generated from ' | 404 '\n<!-- This file was auto-generated from ' |
403 '${fileInfo.inputUrl.resolvedPath}. -->' | 405 '${fileInfo.inputUrl.resolvedPath}. -->' |
404 '\n<html><head>' | 406 '\n<html><head>' |
405 '<style>template { display: none; }</style>' | 407 '<style>template { display: none; }</style>' |
406 '</head><body>' | 408 '</head><body>' |
| 409 '<script type="application/dart" src="x"></script>' |
407 '<script type="text/javascript" src="packages/browser/dart.js">' | 410 '<script type="text/javascript" src="packages/browser/dart.js">' |
408 '</script>\n' | 411 '</script>\n' |
409 '</body></html>'); | 412 '</body></html>'); |
410 }); | 413 }); |
411 }); | 414 }); |
412 } | 415 } |
413 | 416 |
414 _init(Element body, {int child}) { | 417 _init(Element body, {int child}) { |
415 var info = analyzeElement(body, new Messages.silent()); | 418 var info = analyzeElement(body, new Messages.silent()); |
416 // Get the first element, not the body tag. | 419 // Get the first element, not the body tag. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 info = info.children[child]; | 453 info = info.children[child]; |
451 } | 454 } |
452 new RecursiveEmitter(null, context).visit(info); | 455 new RecursiveEmitter(null, context).visit(info); |
453 return context; | 456 return context; |
454 } | 457 } |
455 | 458 |
456 _newPathMapper(String baseDir, String outDir, bool forceMangle) => | 459 _newPathMapper(String baseDir, String outDir, bool forceMangle) => |
457 new PathMapper(baseDir, outDir, 'packages', forceMangle, true); | 460 new PathMapper(baseDir, outDir, 'packages', forceMangle, true); |
458 | 461 |
459 Element _parseBody(String html) => parseDocument(html).body; | 462 Element _parseBody(String html) => parseDocument(html).body; |
OLD | NEW |