OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Classes and methods for running HTML tests. | 6 * Classes and methods for running HTML tests. |
7 * | 7 * |
8 * HTML tests are valid HTML files whose names end in _htmltest.html, and that | 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 | 9 * contain annotations specifying the scripts in the test and the |
10 * messages the test should post to its window, in order to pass. | 10 * messages the test should post to its window, in order to pass. |
(...skipping 13 matching lines...) Expand all Loading... |
24 HtmlTestInformation getInformation(String filename) { | 24 HtmlTestInformation getInformation(String filename) { |
25 if (!filename.endsWith("_htmltest.html")) { | 25 if (!filename.endsWith("_htmltest.html")) { |
26 DebugLogger.warning("File $filename is not an HTML test." | 26 DebugLogger.warning("File $filename is not an HTML test." |
27 " Should end in _htmltest.html."); | 27 " Should end in _htmltest.html."); |
28 return null; | 28 return null; |
29 } | 29 } |
30 String contents = new File(filename).readAsStringSync(); | 30 String contents = new File(filename).readAsStringSync(); |
31 var match = htmlAnnotation.firstMatch(contents); | 31 var match = htmlAnnotation.firstMatch(contents); |
32 if (match == null) return null; | 32 if (match == null) return null; |
33 var annotation = JSON.decode(match[1]); | 33 var annotation = JSON.decode(match[1]); |
34 if (annotation is! Map || annotation['expectedMessages'] is! List || | 34 if (annotation is! Map || |
| 35 annotation['expectedMessages'] is! List || |
35 annotation['scripts'] is! List) { | 36 annotation['scripts'] is! List) { |
36 DebugLogger.warning("File $filename does not have expected annotation." | 37 DebugLogger.warning("File $filename does not have expected annotation." |
37 " Should have {'scripts':[...], 'expectedMessages':[...]}"); | 38 " Should have {'scripts':[...], 'expectedMessages':[...]}"); |
38 return null; | 39 return null; |
39 } | 40 } |
40 return new HtmlTestInformation(new Path(filename), | 41 return new HtmlTestInformation(new Path(filename), |
41 annotation['expectedMessages'], | 42 annotation['expectedMessages'], annotation['scripts']); |
42 annotation['scripts']); | |
43 } | 43 } |
44 | 44 |
45 String getContents(HtmlTestInformation info, bool compileToJS) { | 45 String getContents(HtmlTestInformation info, bool compileToJS) { |
46 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); | 46 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); |
47 contents = contents.replaceFirst(htmlAnnotation, ''); | 47 contents = contents.replaceFirst(htmlAnnotation, ''); |
48 if (compileToJS) { | 48 if (compileToJS) { |
49 for (String script in info.scripts) { | 49 for (String script in info.scripts) { |
50 if (dartExtension.hasMatch(script)) { | 50 if (dartExtension.hasMatch(script)) { |
51 String jsScript = script.replaceFirst(dartExtension, '.js'); | 51 String jsScript = script.replaceFirst(dartExtension, '.js'); |
52 String tag = '<script src="$script" type="application/dart">'; | 52 String tag = '<script src="$script" type="application/dart">'; |
(...skipping 15 matching lines...) Expand all Loading... |
68 </head><body> | 68 </head><body> |
69 <h1>Failing HTML test</h1> | 69 <h1>Failing HTML test</h1> |
70 $message | 70 $message |
71 <script> | 71 <script> |
72 throw "HTML test failed: $message"; | 72 throw "HTML test failed: $message"; |
73 </script> | 73 </script> |
74 </body> | 74 </body> |
75 </html> | 75 </html> |
76 '''; | 76 '''; |
77 } | 77 } |
OLD | NEW |