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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
Index: utils/testrunner/html_wrap_task.dart
===================================================================
--- utils/testrunner/html_wrap_task.dart (revision 0)
+++ utils/testrunner/html_wrap_task.dart (revision 0)
@@ -0,0 +1,129 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Create HTML wrapper for a test so it can run in DRT.
+class HtmlWrapTask extends PipelineTask {
+ String testFileTemplate;
+ String htmlSourceFileTemplate;
+ String htmlDestFileTemplate;
+ String cssSourceFileTemplate;
+ String cssDestFileTemplate;
+
+ HtmlWrapTask(this.testFileTemplate, this.htmlSourceFileTemplate,
+ this.htmlDestFileTemplate, this.cssSourceFileTemplate,
+ this.cssDestFileTemplate);
+
+ void execute(Path testfile, List stdout, List stderr, bool verboseLogging,
+ Function exitHandler) {
+ // If the test already has a corresponding HTML file we copy that,
+ // else we create a new wrapper.
+ var testname = concretize(testFileTemplate, testfile);
+ var htmlSourceName = concretize(htmlSourceFileTemplate, testfile);
+ var htmlDestName = concretize(htmlDestFileTemplate, testfile);
+ var cssSourceName = concretize(cssSourceFileTemplate, testfile);
+ var cssDestName = concretize(cssDestFileTemplate, testfile);
+
+ var htmlMaster = new File(htmlSourceName);
+ if (htmlMaster.existsSync()) {
+ if (verboseLogging) {
+ stdout.add('Copying $htmlSourceName to $htmlDestName');
+ }
+ copyFile(htmlSourceName, htmlDestName);
+ } else {
+ if (verboseLogging) {
+ stdout.add('Creating wrapper $htmlDestName');
+ }
+ var p = new Path(testname);
+ var runtime = configuration['runtime'];
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.add("""
+<!DOCTYPE html>
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>$testname</title>
+ <link rel="stylesheet" href="${p.filenameWithoutExtension}.css">
+ <script type='text/javascript'>
+function handleMessage(m) {
+ if (m.data == 'done') {
+ window.testRunner.notifyDone();
+ }
+}
+
+ if (window.testRunner) {
+ window.testRunner.waitUntilDone();
+ window.testRunner.dumpAsText();
+ window.addEventListener("message", handleMessage, false);
+ }
+""");
+ if (runtime == 'drt-dart') {
+ sbuf.add("if (navigator.webkitStartDart) navigator.webkitStartDart();");
+ }
+ sbuf.add("""
+ </script>
+</head>
+<body>
+ <h1>$testname</h1>
+ <div id="container"></div>
+ <pre id="console"></pre>
+ <script type='""");
+ if (runtime == 'drt-dart') {
+ sbuf.add("application/dart' src='${p.filename}'>");
+ } else {
+ sbuf.add("text/javascript' src='${p.filenameWithoutExtension}.js'>");
+ }
+ sbuf.add("""
+ </script>
+ <script
+src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js">
+ </script>
+</body>
+</html>
+""");
+ createFile(htmlDestName, sbuf.toString());
+ }
+ var cssMaster = new File(cssSourceName);
+ if (cssMaster.existsSync()) {
+ if (verboseLogging) {
+ stdout.add('Copying $cssSourceName to $cssDestName');
+ }
+ copyFile(cssSourceName, cssDestName);
+ } else {
+ if (verboseLogging) {
+ stdout.add('Creating $cssDestName');
+ }
+ createFile(cssDestName, """
+body {
+background-color: #F8F8F8;
+font-family: 'Open Sans', sans-serif;
+font-size: 14px;
+font-weight: normal;
+line-height: 1.2em;
+margin: 15px;
+}
+
+p {
+color: #333;
+}
+
+#container {
+width: 100%;
+height: 400px;
+position: relative;
+border: 1px solid #ccc;
+background-color: #fff;
+}
+
+#text {
+font-size: 24pt;
+text-align: center;
+margin-top: 140px;
+}
+
+""");
+ }
+ exitHandler(0);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698