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 23 matching lines...) Expand all Loading... | |
34 annotation['scripts'] is! List) { | 34 annotation['scripts'] is! List) { |
35 DebugLogger.warning("File $filename does not have expected annotation." | 35 DebugLogger.warning("File $filename does not have expected annotation." |
36 " Should have {'scripts':[...], 'expectedMessages':[...]}"); | 36 " Should have {'scripts':[...], 'expectedMessages':[...]}"); |
37 return null; | 37 return null; |
38 } | 38 } |
39 return new HtmlTestInformation(new Path(filename), | 39 return new HtmlTestInformation(new Path(filename), |
40 annotation['expectedMessages'], | 40 annotation['expectedMessages'], |
41 annotation['scripts']); | 41 annotation['scripts']); |
42 } | 42 } |
43 | 43 |
44 String getContents(HtmlTestInformation info) { | 44 String getContents(HtmlTestInformation info, bool compileToJS) { |
45 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); | 45 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); |
46 return contents.replaceFirst(htmlAnnotation, ''); | 46 contents = contents.replaceFirst(htmlAnnotation, ''); |
47 if (compileToJS) { | |
48 for (String script in info.scripts) { | |
49 if (dartExtension.hasMatch(script)) { | |
50 String jsScript = script.replaceFirst(dartExtension, '.js'); | |
ricow1
2014/11/11 14:41:53
shouldn't that be replaceLast?
Bill Hesse
2014/11/11 15:18:38
dartExtension is a regexp ending in $.
There is no
| |
51 String tag = '<script src="$script" type="application/dart">'; | |
52 String jsTag = '<script src="$jsScript">'; | |
53 contents = contents.replaceAll(tag, jsTag); | |
54 } | |
55 } | |
56 } | |
57 return contents; | |
47 } | 58 } |
48 | 59 |
49 String makeFailingHtmlFile(String message) { | 60 String makeFailingHtmlFile(String message) { |
50 return ''' | 61 return ''' |
51 <!DOCTYPE html> | 62 <!DOCTYPE html> |
52 <html> | 63 <html> |
53 <head> | 64 <head> |
54 <script>window.parent.dispatchEvent(new Event('detect_errors'));</script> | 65 <script>window.parent.dispatchEvent(new Event('detect_errors'));</script> |
55 <title>Failing HTML test</title> | 66 <title>Failing HTML test</title> |
56 </head><body> | 67 </head><body> |
57 <h1>Failing HTML test</h1> | 68 <h1>Failing HTML test</h1> |
58 $message | 69 $message |
59 <script> | 70 <script> |
60 throw "HTML test failed: $message"; | 71 throw "HTML test failed: $message"; |
61 </script> | 72 </script> |
62 </body> | 73 </body> |
63 </html> | 74 </html> |
64 '''; | 75 '''; |
65 } | 76 } |
OLD | NEW |