| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library polymer.test.build.import_inliner_test; | 5 library polymer.test.build.import_inliner_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'package:polymer/src/build/common.dart'; | 8 import 'package:polymer/src/build/common.dart'; |
| 9 import 'package:polymer/src/build/import_inliner.dart'; | 9 import 'package:polymer/src/build/import_inliner.dart'; |
| 10 import 'package:polymer/src/build/messages.dart'; | 10 import 'package:polymer/src/build/messages.dart'; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 '<link rel="import" href="test2.html">' | 105 '<link rel="import" href="test2.html">' |
| 106 '<script>/*forth*/</script>' | 106 '<script>/*forth*/</script>' |
| 107 '</head></html>', | 107 '</head></html>', |
| 108 'a|web/test2.html': | 108 'a|web/test2.html': |
| 109 '<!DOCTYPE html><html><head><script>/*third*/</script>' | 109 '<!DOCTYPE html><html><head><script>/*third*/</script>' |
| 110 '</head><body><polymer-element>2</polymer-element></html>', | 110 '</head><body><polymer-element>2</polymer-element></html>', |
| 111 'a|web/second.js': '/*second*/' | 111 'a|web/second.js': '/*second*/' |
| 112 }, { | 112 }, { |
| 113 'a|web/test.html': | 113 'a|web/test.html': |
| 114 '<!DOCTYPE html><html><head>' | 114 '<!DOCTYPE html><html><head>' |
| 115 '<script type="text/javascript">/*first*/</script>' |
| 116 '<script src="second.js"></script>' |
| 115 '</head><body>' | 117 '</head><body>' |
| 116 '<div hidden="">' | 118 '<div hidden="">' |
| 117 '<script type="text/javascript">/*first*/</script>' | |
| 118 '<script src="second.js"></script>' | |
| 119 '<script>/*third*/</script>' | 119 '<script>/*third*/</script>' |
| 120 '<polymer-element>2</polymer-element>' | 120 '<polymer-element>2</polymer-element>' |
| 121 '<script>/*forth*/</script>' | 121 '<script>/*forth*/</script>' |
| 122 '</div>' | 122 '</div>' |
| 123 '</body></html>', | 123 '</body></html>', |
| 124 'a|web/test.html._data': EMPTY_DATA, | 124 'a|web/test.html._data': EMPTY_DATA, |
| 125 'a|web/test2.html': | 125 'a|web/test2.html': |
| 126 '<!DOCTYPE html><html><head><script>/*third*/</script>' | 126 '<!DOCTYPE html><html><head><script>/*third*/</script>' |
| 127 '</head><body><polymer-element>2</polymer-element></html>', | 127 '</head><body><polymer-element>2</polymer-element></html>', |
| 128 'a|web/test2.html._data': EMPTY_DATA, | 128 'a|web/test2.html._data': EMPTY_DATA, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 139 '<script type="application/dart">/*fifth*/</script>' | 139 '<script type="application/dart">/*fifth*/</script>' |
| 140 '</head></html>', | 140 '</head></html>', |
| 141 'a|web/test2.html': | 141 'a|web/test2.html': |
| 142 '<!DOCTYPE html><html><head><script>/*third*/</script>' | 142 '<!DOCTYPE html><html><head><script>/*third*/</script>' |
| 143 '<script type="application/dart">/*forth*/</script>' | 143 '<script type="application/dart">/*forth*/</script>' |
| 144 '</head><body><polymer-element>2</polymer-element></html>', | 144 '</head><body><polymer-element>2</polymer-element></html>', |
| 145 'a|web/second.js': '/*second*/' | 145 'a|web/second.js': '/*second*/' |
| 146 }, { | 146 }, { |
| 147 'a|web/test.html': | 147 'a|web/test.html': |
| 148 '<!DOCTYPE html><html><head>' | 148 '<!DOCTYPE html><html><head>' |
| 149 '<script type="text/javascript">/*first*/</script>' |
| 150 '<script src="second.js"></script>' |
| 149 '</head><body>' | 151 '</head><body>' |
| 150 '<div hidden="">' | 152 '<div hidden="">' |
| 151 '<script type="text/javascript">/*first*/</script>' | |
| 152 '<script src="second.js"></script>' | |
| 153 '<script>/*third*/</script>' | 153 '<script>/*third*/</script>' |
| 154 '<polymer-element>2</polymer-element>' | 154 '<polymer-element>2</polymer-element>' |
| 155 '</div>' | 155 '</div>' |
| 156 '</body></html>', | 156 '</body></html>', |
| 157 'a|web/test.html._data': expectedData([ | 157 'a|web/test.html._data': expectedData([ |
| 158 'web/test.html.1.dart','web/test.html.0.dart']), | 158 'web/test.html.1.dart','web/test.html.0.dart']), |
| 159 'a|web/test.html.1.dart': 'library a.web.test2_html_0;\n/*forth*/', | 159 'a|web/test.html.1.dart': 'library a.web.test2_html_0;\n/*forth*/', |
| 160 'a|web/test.html.0.dart': 'library a.web.test_html_0;\n/*fifth*/', | 160 'a|web/test.html.0.dart': 'library a.web.test_html_0;\n/*fifth*/', |
| 161 'a|web/test2.html': | 161 'a|web/test2.html': |
| 162 '<!DOCTYPE html><html><head></head><body>' | 162 '<!DOCTYPE html><html><head>' |
| 163 '<div hidden="">' | |
| 164 '<script>/*third*/</script>' | 163 '<script>/*third*/</script>' |
| 165 '</div>' | 164 '</head><body>' |
| 166 '<polymer-element>2</polymer-element>' | 165 '<polymer-element>2</polymer-element>' |
| 167 '</body></html>', | 166 '</body></html>', |
| 168 'a|web/test2.html._data': expectedData(['web/test2.html.0.dart']), | 167 'a|web/test2.html._data': expectedData(['web/test2.html.0.dart']), |
| 169 'a|web/test2.html.0.dart': 'library a.web.test2_html_0;\n/*forth*/', | 168 'a|web/test2.html.0.dart': 'library a.web.test2_html_0;\n/*forth*/', |
| 170 'a|web/second.js': '/*second*/' | 169 'a|web/second.js': '/*second*/' |
| 171 }); | 170 }); |
| 172 | 171 |
| 173 final cspPhases = [[new ImportInliner( | 172 final cspPhases = [[new ImportInliner( |
| 174 new TransformOptions(contentSecurityPolicy: true))]]; | 173 new TransformOptions(contentSecurityPolicy: true))]]; |
| 175 testPhases('extract Js scripts in CSP mode', cspPhases, | 174 testPhases('extract Js scripts in CSP mode', cspPhases, |
| 176 { | 175 { |
| 177 'a|web/test.html': | 176 'a|web/test.html': |
| 178 '<!DOCTYPE html><html><head>' | 177 '<!DOCTYPE html><html><head>' |
| 179 '<script type="text/javascript">/*first*/</script>' | 178 '<script type="text/javascript">/*first*/</script>' |
| 180 '<script src="second.js"></script>' | 179 '<script src="second.js"></script>' |
| 181 '<link rel="import" href="test2.html">' | 180 '<link rel="import" href="test2.html">' |
| 182 '<script type="application/dart">/*fifth*/</script>' | 181 '<script type="application/dart">/*fifth*/</script>' |
| 183 '</head></html>', | 182 '</head></html>', |
| 184 'a|web/test2.html': | 183 'a|web/test2.html': |
| 185 '<!DOCTYPE html><html><head><script>/*third*/</script>' | 184 '<!DOCTYPE html><html><head><script>/*third*/</script>' |
| 186 '<script type="application/dart">/*forth*/</script>' | 185 '<script type="application/dart">/*forth*/</script>' |
| 187 '</head><body><polymer-element>2</polymer-element></html>', | 186 '</head><body><polymer-element>2</polymer-element></html>', |
| 188 'a|web/second.js': '/*second*/' | 187 'a|web/second.js': '/*second*/' |
| 189 }, { | 188 }, { |
| 190 'a|web/test.html': | 189 'a|web/test.html': |
| 191 '<!DOCTYPE html><html><head>' | 190 '<!DOCTYPE html><html><head>' |
| 191 '<script type="text/javascript" src="test.html.0.js"></script>' |
| 192 '<script src="second.js"></script>' |
| 192 '</head><body>' | 193 '</head><body>' |
| 193 '<div hidden="">' | 194 '<div hidden="">' |
| 194 '<script type="text/javascript" src="test.html.0.js"></script>' | |
| 195 '<script src="second.js"></script>' | |
| 196 '<script src="test.html.2.js"></script>' | 195 '<script src="test.html.2.js"></script>' |
| 197 '<polymer-element>2</polymer-element>' | 196 '<polymer-element>2</polymer-element>' |
| 198 '</div>' | 197 '</div>' |
| 199 '</body></html>', | 198 '</body></html>', |
| 200 'a|web/test.html._data': expectedData([ | 199 'a|web/test.html._data': expectedData([ |
| 201 'web/test.html.3.dart','web/test.html.1.dart']), | 200 'web/test.html.3.dart','web/test.html.1.dart']), |
| 202 'a|web/test.html.3.dart': 'library a.web.test2_html_0;\n/*forth*/', | 201 'a|web/test.html.3.dart': 'library a.web.test2_html_0;\n/*forth*/', |
| 203 'a|web/test.html.1.dart': 'library a.web.test_html_0;\n/*fifth*/', | 202 'a|web/test.html.1.dart': 'library a.web.test_html_0;\n/*fifth*/', |
| 204 'a|web/test.html.0.js': '/*first*/', | 203 'a|web/test.html.0.js': '/*first*/', |
| 205 'a|web/test.html.2.js': '/*third*/', | 204 'a|web/test.html.2.js': '/*third*/', |
| 206 'a|web/test2.html': | 205 'a|web/test2.html': |
| 207 '<!DOCTYPE html><html><head></head><body>' | 206 '<!DOCTYPE html><html><head>' |
| 208 '<div hidden="">' | |
| 209 '<script src="test2.html.0.js"></script>' | 207 '<script src="test2.html.0.js"></script>' |
| 210 '</div>' | 208 '</head><body>' |
| 211 '<polymer-element>2</polymer-element></body></html>', | 209 '<polymer-element>2</polymer-element></body></html>', |
| 212 'a|web/test2.html._data': expectedData(['web/test2.html.1.dart']), | 210 'a|web/test2.html._data': expectedData(['web/test2.html.1.dart']), |
| 213 'a|web/test2.html.0.js': '/*third*/', | 211 'a|web/test2.html.0.js': '/*third*/', |
| 214 'a|web/test2.html.1.dart': 'library a.web.test2_html_0;\n/*forth*/', | 212 'a|web/test2.html.1.dart': 'library a.web.test2_html_0;\n/*forth*/', |
| 215 'a|web/second.js': '/*second*/' | 213 'a|web/second.js': '/*second*/' |
| 216 }); | 214 }); |
| 217 | 215 |
| 218 testPhases('Cleans library names generated from file paths.', phases, | 216 testPhases('Cleans library names generated from file paths.', phases, |
| 219 { | 217 { |
| 220 'a|web/01_test.html': | 218 'a|web/01_test.html': |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 725 |
| 728 testLogOutput( | 726 testLogOutput( |
| 729 (options) => new ImportInliner(options), | 727 (options) => new ImportInliner(options), |
| 730 "missing styles don't throw errors and are not inlined", { | 728 "missing styles don't throw errors and are not inlined", { |
| 731 'a|web/test.html': | 729 'a|web/test.html': |
| 732 '<!DOCTYPE html><html><head>' | 730 '<!DOCTYPE html><html><head>' |
| 733 '<link rel="stylesheet" href="foo.css">' | 731 '<link rel="stylesheet" href="foo.css">' |
| 734 '</head></html>', | 732 '</head></html>', |
| 735 }, { | 733 }, { |
| 736 'a|web/test.html': | 734 'a|web/test.html': |
| 737 '<!DOCTYPE html><html><head></head><body>' | 735 '<!DOCTYPE html><html><head>' |
| 738 '<div hidden="">' | |
| 739 '<link rel="stylesheet" href="foo.css">' | 736 '<link rel="stylesheet" href="foo.css">' |
| 740 '</div>' | 737 '</head><body>' |
| 741 '</body></html>', | 738 '</body></html>', |
| 742 }, [ | 739 }, [ |
| 743 'warning: Failed to inline stylesheet: ' | 740 'warning: Failed to inline stylesheet: ' |
| 744 'Could not find asset a|web/foo.css. (web/test.html 0 27)', | 741 'Could not find asset a|web/foo.css. (web/test.html 0 27)', |
| 745 ]); | 742 ]); |
| 746 | 743 |
| 747 testLogOutput( | 744 testLogOutput( |
| 748 (options) => new ImportInliner(options), | 745 (options) => new ImportInliner(options), |
| 749 "missing html imports throw errors", { | 746 "missing html imports throw errors", { |
| 750 'a|web/test.html': | 747 'a|web/test.html': |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 828 |
| 832 testPhases('shallow, inlines css', phases, { | 829 testPhases('shallow, inlines css', phases, { |
| 833 'a|web/test.html': | 830 'a|web/test.html': |
| 834 '<!DOCTYPE html><html><head>' | 831 '<!DOCTYPE html><html><head>' |
| 835 '<link rel="stylesheet" href="test2.css">' | 832 '<link rel="stylesheet" href="test2.css">' |
| 836 '</head></html>', | 833 '</head></html>', |
| 837 'a|web/test2.css': | 834 'a|web/test2.css': |
| 838 'h1 { font-size: 70px; }', | 835 'h1 { font-size: 70px; }', |
| 839 }, { | 836 }, { |
| 840 'a|web/test.html': | 837 'a|web/test.html': |
| 841 '<!DOCTYPE html><html><head></head><body>' | 838 '<!DOCTYPE html><html><head>' |
| 842 '<div hidden="">' | |
| 843 '<style>h1 { font-size: 70px; }</style>' | 839 '<style>h1 { font-size: 70px; }</style>' |
| 844 '</div>' | 840 '</head><body>' |
| 845 '</body></html>', | 841 '</body></html>', |
| 846 'a|web/test.html._data': EMPTY_DATA, | 842 'a|web/test.html._data': EMPTY_DATA, |
| 847 'a|web/test2.css': | 843 'a|web/test2.css': |
| 848 'h1 { font-size: 70px; }', | 844 'h1 { font-size: 70px; }', |
| 849 }); | 845 }); |
| 850 | 846 |
| 851 testPhases('deep, inlines css', phases, { | 847 testPhases('deep, inlines css', phases, { |
| 852 'a|web/test.html': | 848 'a|web/test.html': |
| 853 '<!DOCTYPE html><html><head>' | 849 '<!DOCTYPE html><html><head>' |
| 854 '<link rel="import" href="test2.html">' | 850 '<link rel="import" href="test2.html">' |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 'a|web/test.html': | 937 'a|web/test.html': |
| 942 '<!DOCTYPE html><html><head>' | 938 '<!DOCTYPE html><html><head>' |
| 943 '<style>.first { color: black }</style>' | 939 '<style>.first { color: black }</style>' |
| 944 '<link rel="stylesheet" href="test2.css">' | 940 '<link rel="stylesheet" href="test2.css">' |
| 945 '<style>.second { color: black }</style>' | 941 '<style>.second { color: black }</style>' |
| 946 '</head></html>', | 942 '</head></html>', |
| 947 'a|web/test2.css': | 943 'a|web/test2.css': |
| 948 'h1 { font-size: 70px; }', | 944 'h1 { font-size: 70px; }', |
| 949 }, { | 945 }, { |
| 950 'a|web/test.html': | 946 'a|web/test.html': |
| 951 '<!DOCTYPE html><html><head></head><body>' | 947 '<!DOCTYPE html><html><head>' |
| 952 '<div hidden="">' | |
| 953 '<style>.first { color: black }</style>' | 948 '<style>.first { color: black }</style>' |
| 954 '<style>h1 { font-size: 70px; }</style>' | 949 '<style>h1 { font-size: 70px; }</style>' |
| 955 '<style>.second { color: black }</style>' | 950 '<style>.second { color: black }</style>' |
| 956 '</div>' | 951 '</head><body>' |
| 957 '</body></html>', | 952 '</body></html>', |
| 958 'a|web/test.html._data': EMPTY_DATA, | 953 'a|web/test.html._data': EMPTY_DATA, |
| 959 'a|web/test2.css': | 954 'a|web/test2.css': |
| 960 'h1 { font-size: 70px; }', | 955 'h1 { font-size: 70px; }', |
| 961 }); | 956 }); |
| 962 | 957 |
| 963 testPhases('inlined tags keep original attributes', phases, { | 958 testPhases('inlined tags keep original attributes', phases, { |
| 964 'a|web/test.html': | 959 'a|web/test.html': |
| 965 '<!DOCTYPE html><html><head>' | 960 '<!DOCTYPE html><html><head>' |
| 966 '<link rel="stylesheet" href="foo.css" no-shim>' | 961 '<link rel="stylesheet" href="foo.css" no-shim>' |
| 967 '<link rel="stylesheet" href="bar.css" shim-shadow foo>' | 962 '<link rel="stylesheet" href="bar.css" shim-shadow foo>' |
| 968 '</head></html>', | 963 '</head></html>', |
| 969 'a|web/foo.css': | 964 'a|web/foo.css': |
| 970 'h1 { font-size: 70px; }', | 965 'h1 { font-size: 70px; }', |
| 971 'a|web/bar.css': | 966 'a|web/bar.css': |
| 972 'h2 { font-size: 35px; }', | 967 'h2 { font-size: 35px; }', |
| 973 }, { | 968 }, { |
| 974 'a|web/test.html': | 969 'a|web/test.html': |
| 975 '<!DOCTYPE html><html><head></head><body>' | 970 '<!DOCTYPE html><html><head>' |
| 976 '<div hidden="">' | |
| 977 '<style no-shim="">h1 { font-size: 70px; }</style>' | 971 '<style no-shim="">h1 { font-size: 70px; }</style>' |
| 978 '<style shim-shadow="" foo="">h2 { font-size: 35px; }</style>' | 972 '<style shim-shadow="" foo="">h2 { font-size: 35px; }</style>' |
| 979 '</div>' | 973 '</head><body>' |
| 980 '</body></html>', | 974 '</body></html>', |
| 981 'a|web/foo.css': | 975 'a|web/foo.css': |
| 982 'h1 { font-size: 70px; }', | 976 'h1 { font-size: 70px; }', |
| 983 'a|web/bar.css': | 977 'a|web/bar.css': |
| 984 'h2 { font-size: 35px; }', | 978 'h2 { font-size: 35px; }', |
| 985 }); | 979 }); |
| 986 | 980 |
| 987 testPhases( | 981 testPhases( |
| 988 'can configure default stylesheet inlining', | 982 'can configure default stylesheet inlining', |
| 989 [[new ImportInliner(new TransformOptions( | 983 [[new ImportInliner(new TransformOptions( |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 | 1181 |
| 1188 testPhases('includes in entry points normalize correctly', phases, { | 1182 testPhases('includes in entry points normalize correctly', phases, { |
| 1189 'a|web/test/test.html': | 1183 'a|web/test/test.html': |
| 1190 '<!DOCTYPE html><html><head>' | 1184 '<!DOCTYPE html><html><head>' |
| 1191 '<script src="packages/a/foo/bar.js"></script>' | 1185 '<script src="packages/a/foo/bar.js"></script>' |
| 1192 '</head></html>', | 1186 '</head></html>', |
| 1193 'a|lib/foo/bar.js': | 1187 'a|lib/foo/bar.js': |
| 1194 'console.log("here");', | 1188 'console.log("here");', |
| 1195 }, { | 1189 }, { |
| 1196 'a|web/test/test.html': | 1190 'a|web/test/test.html': |
| 1197 '<!DOCTYPE html><html><head></head><body>' | 1191 '<!DOCTYPE html><html><head>' |
| 1198 '<div hidden="">' | |
| 1199 '<script src="../packages/a/foo/bar.js"></script>' | 1192 '<script src="../packages/a/foo/bar.js"></script>' |
| 1200 '</div>' | 1193 '</head><body>' |
| 1201 '</body></html>', | 1194 '</body></html>', |
| 1202 }); | 1195 }); |
| 1203 | 1196 |
| 1204 testPhases('two level deep entry points normalize correctly', phases, { | 1197 testPhases('two level deep entry points normalize correctly', phases, { |
| 1205 'a|web/test/well/test.html': | 1198 'a|web/test/well/test.html': |
| 1206 '<!DOCTYPE html><html><head>' | 1199 '<!DOCTYPE html><html><head>' |
| 1207 '<link rel="import" href="../../../packages/a/foo/foo.html">' | 1200 '<link rel="import" href="../../../packages/a/foo/foo.html">' |
| 1208 '</head></html>', | 1201 '</head></html>', |
| 1209 'a|lib/foo/foo.html': | 1202 'a|lib/foo/foo.html': |
| 1210 '<script rel="import" href="../../../packages/b/bar/bar.js"></script>', | 1203 '<script rel="import" href="../../../packages/b/bar/bar.js"></script>', |
| 1211 'b|lib/bar/bar.js': | 1204 'b|lib/bar/bar.js': |
| 1212 'console.log("here");', | 1205 'console.log("here");', |
| 1213 }, { | 1206 }, { |
| 1214 'a|web/test/well/test.html': | 1207 'a|web/test/well/test.html': |
| 1215 '<!DOCTYPE html><html><head></head><body>' | 1208 '<!DOCTYPE html><html><head></head><body>' |
| 1216 '<div hidden="">' | 1209 '<div hidden="">' |
| 1217 '<script rel="import" href="../../packages/b/bar/bar.js"></script>' | 1210 '<script rel="import" href="../../packages/b/bar/bar.js"></script>' |
| 1218 '</div>' | 1211 '</div>' |
| 1219 '</body></html>', | 1212 '</body></html>', |
| 1220 }); | 1213 }); |
| 1221 } | 1214 } |
| OLD | NEW |