Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: utils/testrunner/html_wrap_task.dart

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

Powered by Google App Engine
This is Rietveld 408576698