OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library polymer.test.build.html_finalizer_test; |
| 6 |
| 7 import 'package:polymer/src/build/common.dart'; |
| 8 import 'package:polymer/src/build/html_finalizer.dart'; |
| 9 import 'package:polymer/src/build/messages.dart'; |
| 10 import 'package:unittest/compact_vm_config.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 import 'common.dart'; |
| 13 |
| 14 final phases = [[new HtmlFinalizer(new TransformOptions())]]; |
| 15 |
| 16 void main() { |
| 17 useCompactVMConfiguration(); |
| 18 group('csp', cspTests); |
| 19 group('rel=stylesheet', stylesheetTests); |
| 20 group('url attributes', urlAttributeTests); |
| 21 } |
| 22 |
| 23 cspTests() { |
| 24 final cspPhases = |
| 25 [[new HtmlFinalizer(new TransformOptions(contentSecurityPolicy: true))]]; |
| 26 testPhases('extract Js scripts in CSP mode', cspPhases, { |
| 27 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 28 '<script type="text/javascript">/*first*/</script>' |
| 29 '<script src="second.js"></script>' |
| 30 '<script>/*third*/</script>' |
| 31 '<script type="application/dart">/*fourth*/</script>' |
| 32 '</head><body>' |
| 33 '<script>/*fifth*/</script>' |
| 34 '</body></html>', |
| 35 'a|web/second.js': '/*second*/' |
| 36 }, { |
| 37 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 38 '<script type="text/javascript" src="test.html.0.js"></script>' |
| 39 '<script src="second.js"></script>' |
| 40 '<script src="test.html.1.js"></script>' |
| 41 '<script type="application/dart">/*fourth*/</script>' |
| 42 '</head><body>' |
| 43 '<script src="test.html.2.js"></script>' |
| 44 '</body></html>', |
| 45 'a|web/test.html.0.js': '/*first*/', |
| 46 'a|web/test.html.1.js': '/*third*/', |
| 47 'a|web/test.html.2.js': '/*fifth*/', |
| 48 }); |
| 49 } |
| 50 |
| 51 void stylesheetTests() { |
| 52 testPhases('empty stylesheet', phases, { |
| 53 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 54 '<link rel="stylesheet" href="">' // empty href |
| 55 '</head></html>', |
| 56 'a|web/test2.html': '<!DOCTYPE html><html><head>' |
| 57 '<link rel="stylesheet">' // no href |
| 58 '</head></html>', |
| 59 }, { |
| 60 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 61 '<link rel="stylesheet" href="">' // empty href |
| 62 '</head></html>', |
| 63 'a|web/test2.html': '<!DOCTYPE html><html><head>' |
| 64 '<link rel="stylesheet">' // no href |
| 65 '</head></html>', |
| 66 }); |
| 67 |
| 68 testPhases('shallow, inlines css', phases, { |
| 69 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 70 '<link rel="stylesheet" href="test2.css">' |
| 71 '</head></html>', |
| 72 'a|web/test2.css': 'h1 { font-size: 70px; }', |
| 73 }, { |
| 74 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 75 '<style>h1 { font-size: 70px; }</style>' |
| 76 '</head><body>' |
| 77 '</body></html>', |
| 78 }); |
| 79 |
| 80 testPhases('deep, inlines css', phases, { |
| 81 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 82 '<link rel="stylesheet" href="assets/b/test3.css">' |
| 83 '</head></html>', |
| 84 'b|asset/test3.css': |
| 85 'body {\n background: #eaeaea url("../../assets/b/test4.png");\n}\n' |
| 86 '.foo {\n background: url("../../packages/c/test5.png");\n}', |
| 87 'b|asset/test4.png': 'PNG', |
| 88 'c|lib/test5.png': 'PNG', |
| 89 }, { |
| 90 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 91 '<style>' |
| 92 'body {\n background: #eaeaea url(assets/b/test4.png);\n}\n' |
| 93 '.foo {\n background: url(packages/c/test5.png);\n}' |
| 94 '</style>' |
| 95 '</head><body>' |
| 96 '</body></html>', |
| 97 }); |
| 98 |
| 99 testPhases('shallow, inlines css and preserves order', phases, { |
| 100 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 101 '<style>.first { color: black }</style>' |
| 102 '<link rel="stylesheet" href="test2.css">' |
| 103 '<style>.second { color: black }</style>' |
| 104 '</head></html>', |
| 105 'a|web/test2.css': 'h1 { font-size: 70px; }', |
| 106 }, { |
| 107 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 108 '<style>.first { color: black }</style>' |
| 109 '<style>h1 { font-size: 70px; }</style>' |
| 110 '<style>.second { color: black }</style>' |
| 111 '</head><body>' |
| 112 '</body></html>', |
| 113 }); |
| 114 |
| 115 testPhases('inlined tags keep original attributes', phases, { |
| 116 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 117 '<link rel="stylesheet" href="foo.css" no-shim>' |
| 118 '<link rel="stylesheet" href="bar.css" shim-shadow foo>' |
| 119 '</head></html>', |
| 120 'a|web/foo.css': 'h1 { font-size: 70px; }', |
| 121 'a|web/bar.css': 'h2 { font-size: 35px; }', |
| 122 }, { |
| 123 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 124 '<style no-shim="">h1 { font-size: 70px; }</style>' |
| 125 '<style shim-shadow="" foo="">h2 { font-size: 35px; }</style>' |
| 126 '</head><body>' |
| 127 '</body></html>', |
| 128 }); |
| 129 |
| 130 testPhases('can configure default stylesheet inlining', [ |
| 131 [ |
| 132 new HtmlFinalizer( |
| 133 new TransformOptions(inlineStylesheets: {'default': false})) |
| 134 ] |
| 135 ], { |
| 136 'a|web/test.html': '<!DOCTYPE html><html><head></head><body>' |
| 137 '<link rel="stylesheet" href="foo.css">' |
| 138 '</body></html>', |
| 139 'a|web/foo.css': 'h1 { font-size: 70px; }', |
| 140 }, { |
| 141 'a|web/test.html': '<!DOCTYPE html><html><head></head><body>' |
| 142 '<link rel="stylesheet" href="foo.css">' |
| 143 '</body></html>', |
| 144 }); |
| 145 |
| 146 testPhases('can override default stylesheet inlining', [ |
| 147 [ |
| 148 new HtmlFinalizer(new TransformOptions( |
| 149 inlineStylesheets: { |
| 150 'default': false, |
| 151 'web/foo.css': true, |
| 152 'b|lib/baz.css': true, |
| 153 })) |
| 154 ] |
| 155 ], { |
| 156 'a|web/test.html': '<!DOCTYPE html><html><head></head><body>' |
| 157 '<link rel="stylesheet" href="bar.css">' |
| 158 '<link rel="stylesheet" href="foo.css">' |
| 159 '<link rel="stylesheet" href="packages/b/baz.css">' |
| 160 '<link rel="stylesheet" href="packages/c/buz.css">' |
| 161 '</body></html>', |
| 162 'a|web/foo.css': 'h1 { font-size: 70px; }', |
| 163 'a|web/bar.css': 'h1 { font-size: 35px; }', |
| 164 'b|lib/baz.css': 'h1 { font-size: 20px; }', |
| 165 'c|lib/buz.css': 'h1 { font-size: 10px; }', |
| 166 }, { |
| 167 'a|web/test.html': '<!DOCTYPE html><html><head></head><body>' |
| 168 '<link rel="stylesheet" href="bar.css">' |
| 169 '<style>h1 { font-size: 70px; }</style>' |
| 170 '<style>h1 { font-size: 20px; }</style>' |
| 171 '<link rel="stylesheet" href="packages/c/buz.css">' |
| 172 '</body></html>', |
| 173 }); |
| 174 |
| 175 testLogOutput((options) => new HtmlFinalizer(options), |
| 176 'warns about multiple inlinings of the same css', { |
| 177 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 178 '<link rel="stylesheet" href="packages/a/foo.css">' |
| 179 '<link rel="stylesheet" href="packages/a/foo.css">' |
| 180 '</head><body></body></html>', |
| 181 'a|lib/foo.css': 'body {position: relative;}', |
| 182 }, {}, [ |
| 183 'warning: ${CSS_FILE_INLINED_MULTIPLE_TIMES.create( |
| 184 {'url': 'lib/foo.css'}).snippet}' |
| 185 ' (web/test.html 0 76)', |
| 186 ]); |
| 187 |
| 188 testPhases('doesn\'t warn about multiple css inlinings if overriden', [ |
| 189 [ |
| 190 new HtmlFinalizer( |
| 191 new TransformOptions(inlineStylesheets: {'lib/foo.css': true})) |
| 192 ] |
| 193 ], { |
| 194 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 195 '<link rel="stylesheet" href="packages/a/foo.css">' |
| 196 '<link rel="stylesheet" href="packages/a/foo.css">' |
| 197 '</head><body></body></html>', |
| 198 'a|lib/foo.css': 'body {position: relative;}', |
| 199 }, {}, []); |
| 200 } |
| 201 |
| 202 void urlAttributeTests() { |
| 203 testLogOutput((options) => new HtmlFinalizer(options), |
| 204 'warnings are given about _* attributes', { |
| 205 'a|web/test.html': '<!DOCTYPE html><html><head></head><body>' |
| 206 '<img src="foo/{{bar}}">' |
| 207 '<a _href="foo/bar">test</a>' |
| 208 '</body></html>', |
| 209 }, {}, [ |
| 210 'warning: When using bindings with the "src" attribute you may ' |
| 211 'experience errors in certain browsers. Please use the "_src" ' |
| 212 'attribute instead. (web/test.html 0 40)', |
| 213 'warning: The "_href" attribute is only supported when using ' |
| 214 'bindings. Please change to the "href" attribute. ' |
| 215 '(web/test.html 0 63)', |
| 216 ]); |
| 217 } |
OLD | NEW |