OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * A pipeline task to create a HTML/CSS wrapper for a test so it can run in DRT. |
| 7 */ |
| 8 class HtmlWrapTask extends PipelineTask { |
| 9 final String _testFileTemplate; |
| 10 final String _htmlSourceFileTemplate; |
| 11 final String _htmlDestFileTemplate; |
| 12 final String _cssSourceFileTemplate; |
| 13 final String _cssDestFileTemplate; |
| 14 |
| 15 HtmlWrapTask(testFileTemplate, htmlSourceFileTemplate, |
| 16 htmlDestFileTemplate, cssSourceFileTemplate, cssDestFileTemplate) : |
| 17 _testFileTemplate = testFileTemplate, |
| 18 _htmlSourceFileTemplate = htmlSourceFileTemplate, |
| 19 _htmlDestFileTemplate = htmlDestFileTemplate, |
| 20 _cssSourceFileTemplate = cssSourceFileTemplate, |
| 21 _cssDestFileTemplate = cssDestFileTemplate; |
| 22 |
| 23 void execute(Path testfile, List stdout, List stderr, bool logging, |
| 24 Function exitHandler) { |
| 25 // If the test already has a corresponding HTML file we copy that, |
| 26 // else we create a new wrapper. |
| 27 var testname = expandMacros(_testFileTemplate, testfile); |
| 28 var htmlSourceName = expandMacros(_htmlSourceFileTemplate, testfile); |
| 29 var htmlDestName = expandMacros(_htmlDestFileTemplate, testfile); |
| 30 var cssSourceName = expandMacros(_cssSourceFileTemplate, testfile); |
| 31 var cssDestName = expandMacros(_cssDestFileTemplate, testfile); |
| 32 |
| 33 var htmlMaster = new File(htmlSourceName); |
| 34 if (htmlMaster.existsSync()) { |
| 35 if (logging) { |
| 36 stdout.add('Copying $htmlSourceName to $htmlDestName'); |
| 37 } |
| 38 copyFile(htmlSourceName, htmlDestName); |
| 39 } else { |
| 40 if (logging) { |
| 41 stdout.add('Creating wrapper $htmlDestName'); |
| 42 } |
| 43 var p = new Path(testname); |
| 44 var runtime = config.runtime; |
| 45 StringBuffer sbuf = new StringBuffer(); |
| 46 sbuf.add(""" |
| 47 <!DOCTYPE html> |
| 48 |
| 49 <html> |
| 50 <head> |
| 51 <meta charset="utf-8"> |
| 52 <title>$testname</title> |
| 53 <link rel="stylesheet" href="${p.filenameWithoutExtension}.css"> |
| 54 <script type='text/javascript'> |
| 55 function handleMessage(m) { |
| 56 if (m.data == 'done') { |
| 57 window.testRunner.notifyDone(); |
| 58 } |
| 59 } |
| 60 |
| 61 if (window.testRunner) { |
| 62 window.testRunner.waitUntilDone(); |
| 63 window.testRunner.dumpAsText(); |
| 64 window.addEventListener("message", handleMessage, false); |
| 65 } |
| 66 """); |
| 67 if (runtime == 'drt-dart') { |
| 68 sbuf.add("if (navigator.webkitStartDart) navigator.webkitStartDart();"); |
| 69 } |
| 70 sbuf.add(""" |
| 71 </script> |
| 72 </head> |
| 73 <body> |
| 74 <h1>$testname</h1> |
| 75 <div id="container"></div> |
| 76 <pre id="console"></pre> |
| 77 <script type='"""); |
| 78 var prefix = flattenPath(p.directoryPath.toString()); |
| 79 if (runtime == 'drt-dart') { |
| 80 sbuf.add("application/dart' src='${prefix}_${p.filename}'>"); |
| 81 } else { |
| 82 sbuf.add("text/javascript' " |
| 83 "src='${prefix}_${p.filenameWithoutExtension}.js'>"); |
| 84 } |
| 85 sbuf.add(""" |
| 86 </script> |
| 87 <script |
| 88 src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"> |
| 89 </script> |
| 90 </body> |
| 91 </html> |
| 92 """); |
| 93 createFile(htmlDestName, sbuf.toString()); |
| 94 } |
| 95 var cssMaster = new File(cssSourceName); |
| 96 if (cssMaster.existsSync()) { |
| 97 if (logging) { |
| 98 stdout.add('Copying $cssSourceName to $cssDestName'); |
| 99 } |
| 100 copyFile(cssSourceName, cssDestName); |
| 101 } else { |
| 102 if (logging) { |
| 103 stdout.add('Creating $cssDestName'); |
| 104 } |
| 105 createFile(cssDestName, """ |
| 106 body { |
| 107 background-color: #F8F8F8; |
| 108 font-family: 'Open Sans', sans-serif; |
| 109 font-size: 14px; |
| 110 font-weight: normal; |
| 111 line-height: 1.2em; |
| 112 margin: 15px; |
| 113 } |
| 114 |
| 115 p { |
| 116 color: #333; |
| 117 } |
| 118 |
| 119 #container { |
| 120 width: 100%; |
| 121 height: 400px; |
| 122 position: relative; |
| 123 border: 1px solid #ccc; |
| 124 background-color: #fff; |
| 125 } |
| 126 |
| 127 #text { |
| 128 font-size: 24pt; |
| 129 text-align: center; |
| 130 margin-top: 140px; |
| 131 } |
| 132 |
| 133 """); |
| 134 } |
| 135 exitHandler(0); |
| 136 } |
| 137 |
| 138 void cleanup(Path testfile, List stdout, List stderr, |
| 139 bool logging, bool keepFiles) { |
| 140 deleteFiles([_htmlDestFileTemplate, _cssDestFileTemplate], testfile, |
| 141 logging, keepFiles, stdout); |
| 142 } |
| 143 } |
OLD | NEW |