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

Side by Side Diff: tools/testing/dart/html_test.dart

Issue 841193003: cleanup to tools/testing/dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: one last bit Created 5 years, 11 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
« no previous file with comments | « tools/testing/dart/drt_updater.dart ('k') | tools/testing/dart/http_server.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 * Classes and methods for running HTML tests.
7 *
8 * HTML tests are valid HTML files whose names end in _htmltest.html, and that
9 * contain annotations specifying the scripts in the test and the
10 * messages the test should post to its window, in order to pass.
11 */
12 library html_test;
13
14 import "dart:convert";
15 import "dart:io";
16
17 import "path.dart";
18 import "test_suite.dart";
19 import "utils.dart";
20
21 RegExp htmlAnnotation =
22 new RegExp("START_HTML_DART_TEST([\\s\\S]*?)END_HTML_DART_TEST");
23
24 HtmlTestInformation getInformation(String filename) {
25 if (!filename.endsWith("_htmltest.html")) {
26 DebugLogger.warning("File $filename is not an HTML test."
27 " Should end in _htmltest.html.");
28 return null;
29 }
30 String contents = new File(filename).readAsStringSync();
31 var match = htmlAnnotation.firstMatch(contents);
32 if (match == null) return null;
33 var annotation = JSON.decode(match[1]);
34 if (annotation is! Map || annotation['expectedMessages'] is! List ||
35 annotation['scripts'] is! List) {
36 DebugLogger.warning("File $filename does not have expected annotation."
37 " Should have {'scripts':[...], 'expectedMessages':[...]}");
38 return null;
39 }
40 return new HtmlTestInformation(new Path(filename),
41 annotation['expectedMessages'],
42 annotation['scripts']);
43 }
44
45 String getContents(HtmlTestInformation info, bool compileToJS) {
46 String contents = new File(info.filePath.toNativePath()).readAsStringSync();
47 contents = contents.replaceFirst(htmlAnnotation, '');
48 if (compileToJS) {
49 for (String script in info.scripts) {
50 if (dartExtension.hasMatch(script)) {
51 String jsScript = script.replaceFirst(dartExtension, '.js');
52 String tag = '<script src="$script" type="application/dart">';
53 String jsTag = '<script src="$jsScript">';
54 contents = contents.replaceAll(tag, jsTag);
55 }
56 }
57 }
58 return contents;
59 }
60
61 String makeFailingHtmlFile(String message) {
62 return '''
63 <!DOCTYPE html>
64 <html>
65 <head>
66 <script>window.parent.dispatchEvent(new Event('detect_errors'));</script>
67 <title>Failing HTML test</title>
68 </head><body>
69 <h1>Failing HTML test</h1>
70 $message
71 <script>
72 throw "HTML test failed: $message";
73 </script>
74 </body>
75 </html>
76 ''';
77 }
OLDNEW
« no previous file with comments | « tools/testing/dart/drt_updater.dart ('k') | tools/testing/dart/http_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698