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