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