| 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.all_phases_test; | |
| 6 | |
| 7 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; | |
| 8 import 'package:polymer/src/build/common.dart'; | |
| 9 import 'package:polymer/src/build/messages.dart'; | |
| 10 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; | |
| 11 import 'package:polymer/transformer.dart'; | |
| 12 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS; | |
| 13 import 'package:unittest/compact_vm_config.dart'; | |
| 14 | |
| 15 import 'common.dart'; | |
| 16 | |
| 17 void main() { | |
| 18 useCompactVMConfiguration(); | |
| 19 var phases = createDeployPhases(new TransformOptions(), | |
| 20 sdkDir: testingDartSdkDirectory); | |
| 21 | |
| 22 testPhases('no changes', phases, { | |
| 23 'a|web/test.html': '<!DOCTYPE html><html></html>', | |
| 24 }, {}, [ | |
| 25 'warning: ${MISSING_INIT_POLYMER.snippet}' | |
| 26 ]); | |
| 27 | |
| 28 testPhases('observable changes', phases, { | |
| 29 'a|web/test.dart': _sampleInput('A', 'foo'), | |
| 30 'a|web/test2.dart': _sampleOutput('B', 'bar'), | |
| 31 }, { | |
| 32 'a|web/test.dart': _sampleOutput('A', 'foo'), | |
| 33 'a|web/test2.dart': _sampleOutput('B', 'bar'), | |
| 34 }); | |
| 35 | |
| 36 testPhases('single script', phases, { | |
| 37 'a|web/test.html': | |
| 38 '<!DOCTYPE html><html><head>' | |
| 39 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 40 '<script type="application/dart" src="a.dart"></script>', | |
| 41 'a|web/a.dart': _sampleInput('A', 'foo'), | |
| 42 }, { | |
| 43 'a|web/test.html': | |
| 44 '<!DOCTYPE html><html><head>' | |
| 45 '$COMPATIBILITY_JS_TAGS' | |
| 46 '</head><body>' | |
| 47 '<script src="test.html_bootstrap.dart.js" async=""></script>' | |
| 48 '</body></html>', | |
| 49 | |
| 50 'a|web/test.html_bootstrap.dart': | |
| 51 '''$MAIN_HEADER | |
| 52 import 'a.dart' as i0; | |
| 53 ${DEFAULT_IMPORTS.join('\n')} | |
| 54 import 'a.dart' as smoke_0; | |
| 55 import 'package:polymer/polymer.dart' as smoke_1; | |
| 56 | |
| 57 void main() { | |
| 58 useGeneratedCode(new StaticConfiguration( | |
| 59 checkedMode: false, | |
| 60 parents: { | |
| 61 smoke_0.XA: smoke_1.PolymerElement, | |
| 62 }, | |
| 63 declarations: { | |
| 64 smoke_0.XA: {}, | |
| 65 })); | |
| 66 configureForDeployment([ | |
| 67 i0.m_foo, | |
| 68 () => Polymer.register('x-A', i0.XA), | |
| 69 ]); | |
| 70 i0.main(); | |
| 71 } | |
| 72 '''.replaceAll('\n ', '\n'), | |
| 73 'a|web/a.dart': _sampleOutput('A', 'foo'), | |
| 74 }, []); | |
| 75 | |
| 76 testPhases('single inline script', phases, { | |
| 77 'a|web/test.html': | |
| 78 '<!DOCTYPE html><html><head>' | |
| 79 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 80 '<script type="application/dart">' | |
| 81 '${_sampleInput("B", "bar")}</script>', | |
| 82 }, { | |
| 83 'a|web/test.html': | |
| 84 '<!DOCTYPE html><html><head>' | |
| 85 '$COMPATIBILITY_JS_TAGS' | |
| 86 '</head><body>' | |
| 87 '<script src="test.html_bootstrap.dart.js" async=""></script>' | |
| 88 '</body></html>', | |
| 89 | |
| 90 'a|web/test.html_bootstrap.dart': | |
| 91 '''$MAIN_HEADER | |
| 92 import 'test.html.0.dart' as i0; | |
| 93 ${DEFAULT_IMPORTS.join('\n')} | |
| 94 import 'test.html.0.dart' as smoke_0; | |
| 95 import 'package:polymer/polymer.dart' as smoke_1; | |
| 96 | |
| 97 void main() { | |
| 98 useGeneratedCode(new StaticConfiguration( | |
| 99 checkedMode: false, | |
| 100 parents: { | |
| 101 smoke_0.XB: smoke_1.PolymerElement, | |
| 102 }, | |
| 103 declarations: { | |
| 104 smoke_0.XB: {}, | |
| 105 })); | |
| 106 configureForDeployment([ | |
| 107 i0.m_bar, | |
| 108 () => Polymer.register('x-B', i0.XB), | |
| 109 ]); | |
| 110 i0.main(); | |
| 111 } | |
| 112 '''.replaceAll('\n ', '\n'), | |
| 113 'a|web/test.html.0.dart': | |
| 114 _sampleOutput("B", "bar"), | |
| 115 }); | |
| 116 | |
| 117 testPhases('several scripts', phases, { | |
| 118 'a|web/test.html': | |
| 119 '<!DOCTYPE html><html><head>' | |
| 120 '<link rel="import" href="packages/polymer/polymer.html">\n' | |
| 121 '<script type="application/dart" src="a.dart"></script>\n' | |
| 122 '<script type="application/dart">' | |
| 123 '${_sampleInput("B", "bar")}</script>' | |
| 124 '</head><body><div>\n' | |
| 125 '<script type="application/dart">' | |
| 126 '${_sampleInput("C", "car")}</script>' | |
| 127 '</div>\n' | |
| 128 '<script type="application/dart" src="d.dart"></script>', | |
| 129 'a|web/a.dart': _sampleInput('A', 'foo'), | |
| 130 }, { | |
| 131 'a|web/test.html': | |
| 132 '<!DOCTYPE html><html><head>' | |
| 133 '$COMPATIBILITY_JS_TAGS\n\n' | |
| 134 '</head><body>' | |
| 135 '<div>\n</div>\n' | |
| 136 '<script src="test.html_bootstrap.dart.js" async=""></script>' | |
| 137 '</body></html>', | |
| 138 'a|web/test.html_bootstrap.dart': | |
| 139 '''$MAIN_HEADER | |
| 140 import 'a.dart' as i0; | |
| 141 import 'test.html.0.dart' as i1; | |
| 142 import 'test.html.1.dart' as i2; | |
| 143 ${DEFAULT_IMPORTS.join('\n')} | |
| 144 import 'a.dart' as smoke_0; | |
| 145 import 'package:polymer/polymer.dart' as smoke_1; | |
| 146 import 'test.html.0.dart' as smoke_2; | |
| 147 import 'test.html.1.dart' as smoke_3; | |
| 148 | |
| 149 void main() { | |
| 150 useGeneratedCode(new StaticConfiguration( | |
| 151 checkedMode: false, | |
| 152 parents: { | |
| 153 smoke_0.XA: smoke_1.PolymerElement, | |
| 154 smoke_2.XB: smoke_1.PolymerElement, | |
| 155 smoke_3.XC: smoke_1.PolymerElement, | |
| 156 }, | |
| 157 declarations: { | |
| 158 smoke_0.XA: {}, | |
| 159 smoke_2.XB: {}, | |
| 160 smoke_3.XC: {}, | |
| 161 })); | |
| 162 configureForDeployment([ | |
| 163 i0.m_foo, | |
| 164 () => Polymer.register('x-A', i0.XA), | |
| 165 i1.m_bar, | |
| 166 () => Polymer.register('x-B', i1.XB), | |
| 167 i2.m_car, | |
| 168 () => Polymer.register('x-C', i2.XC), | |
| 169 ]); | |
| 170 i2.main(); | |
| 171 } | |
| 172 '''.replaceAll('\n ', '\n'), | |
| 173 'a|web/a.dart': _sampleOutput('A', 'foo'), | |
| 174 }, [ | |
| 175 // These should not be emitted multiple times. See: | |
| 176 // https://code.google.com/p/dart/issues/detail?id=17197 | |
| 177 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 2 0)', | |
| 178 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 18 0)', | |
| 179 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 34 0)', | |
| 180 'warning: ${SCRIPT_FILE_NOT_FOUND.create({'url': 'd.dart'}).snippet} ' | |
| 181 '(web/test.html 34 0)', | |
| 182 ]); | |
| 183 | |
| 184 testPhases('with imports', phases, { | |
| 185 'a|web/index.html': | |
| 186 '<!DOCTYPE html><html><head>' | |
| 187 '<link rel="import" href="packages/polymer/polymer.html">' | |
| 188 '<link rel="import" href="packages/a/test2.html">' | |
| 189 '</head><body>' | |
| 190 '<script type="application/dart" src="b.dart"></script>', | |
| 191 'a|web/b.dart': _sampleInput('B', 'bar'), | |
| 192 'a|lib/test2.html': | |
| 193 '<!DOCTYPE html><html><head>' | |
| 194 '<link rel="import" href="../../packages/polymer/polymer.html">' | |
| 195 '</head><body>' | |
| 196 '<polymer-element name="x-a">1' | |
| 197 '<script type="application/dart">' | |
| 198 '${_sampleInput("A", "foo")}</script>' | |
| 199 '</polymer-element></html>', | |
| 200 }, { | |
| 201 'a|web/index.html': | |
| 202 '<!DOCTYPE html><html><head>' | |
| 203 '$COMPATIBILITY_JS_TAGS' | |
| 204 '</head><body>' | |
| 205 '<div hidden="">' | |
| 206 '<polymer-element name="x-a">1</polymer-element>' | |
| 207 '</div>' | |
| 208 '<script src="index.html_bootstrap.dart.js" async=""></script>' | |
| 209 '</body></html>', | |
| 210 'a|web/index.html_bootstrap.dart': | |
| 211 '''$MAIN_HEADER | |
| 212 import 'index.html.0.dart' as i0; | |
| 213 import 'b.dart' as i1; | |
| 214 ${DEFAULT_IMPORTS.join('\n')} | |
| 215 import 'index.html.0.dart' as smoke_0; | |
| 216 import 'package:polymer/polymer.dart' as smoke_1; | |
| 217 import 'b.dart' as smoke_2; | |
| 218 | |
| 219 void main() { | |
| 220 useGeneratedCode(new StaticConfiguration( | |
| 221 checkedMode: false, | |
| 222 parents: { | |
| 223 smoke_2.XB: smoke_1.PolymerElement, | |
| 224 smoke_0.XA: smoke_1.PolymerElement, | |
| 225 }, | |
| 226 declarations: { | |
| 227 smoke_2.XB: {}, | |
| 228 smoke_0.XA: {}, | |
| 229 })); | |
| 230 configureForDeployment([ | |
| 231 i0.m_foo, | |
| 232 () => Polymer.register('x-A', i0.XA), | |
| 233 i1.m_bar, | |
| 234 () => Polymer.register('x-B', i1.XB), | |
| 235 ]); | |
| 236 i1.main(); | |
| 237 } | |
| 238 '''.replaceAll('\n ', '\n'), | |
| 239 'a|web/index.html.0.dart': _sampleOutput("A", "foo"), | |
| 240 'a|web/b.dart': _sampleOutput('B', 'bar'), | |
| 241 }, []); | |
| 242 | |
| 243 testPhases('experimental bootstrap', phases, { | |
| 244 'a|web/index.html': | |
| 245 '<!DOCTYPE html><html><head>' | |
| 246 '<link rel="import" ' | |
| 247 'href="packages/polymer/polymer_experimental.html">' | |
| 248 '<link rel="import" href="packages/a/test2.html">' | |
| 249 '<link rel="import" href="packages/a/load_b.html">', | |
| 250 'a|lib/b.dart': _sampleInput('B', 'bar'), | |
| 251 'a|lib/test2.html': | |
| 252 '<!DOCTYPE html><html><head>' | |
| 253 '<link rel="import" href="../../packages/polymer/polymer.html">' | |
| 254 '</head><body>' | |
| 255 '<polymer-element name="x-a">1' | |
| 256 '<script type="application/dart">' | |
| 257 '${_sampleInput("A", "foo")}</script>' | |
| 258 '</polymer-element></html>', | |
| 259 'a|lib/load_b.html': | |
| 260 '<!DOCTYPE html><html><head></head><body>' | |
| 261 '<script type="application/dart" src="b.dart"></script>', | |
| 262 }, { | |
| 263 'a|web/index.html': | |
| 264 '<!DOCTYPE html><html><head>' | |
| 265 '$COMPATIBILITY_JS_TAGS' | |
| 266 '</head><body>' | |
| 267 '<div hidden="">' | |
| 268 '<polymer-element name="x-a">1</polymer-element>' | |
| 269 '</div>' | |
| 270 '<script src="index.html_bootstrap.dart.js" async=""></script>' | |
| 271 '</body></html>', | |
| 272 'a|web/index.html_bootstrap.dart': | |
| 273 '''$MAIN_HEADER | |
| 274 import 'index.html.0.dart' as i0; | |
| 275 import 'package:a/b.dart' as i1; | |
| 276 ${DEFAULT_IMPORTS.join('\n')} | |
| 277 import 'index.html.0.dart' as smoke_0; | |
| 278 import 'package:polymer/polymer.dart' as smoke_1; | |
| 279 import 'package:a/b.dart' as smoke_2; | |
| 280 | |
| 281 void main() { | |
| 282 useGeneratedCode(new StaticConfiguration( | |
| 283 checkedMode: false, | |
| 284 parents: { | |
| 285 smoke_0.XA: smoke_1.PolymerElement, | |
| 286 smoke_2.XB: smoke_1.PolymerElement, | |
| 287 }, | |
| 288 declarations: { | |
| 289 smoke_0.XA: {}, | |
| 290 smoke_2.XB: {}, | |
| 291 })); | |
| 292 startPolymer([ | |
| 293 i0.m_foo, | |
| 294 () => Polymer.register('x-A', i0.XA), | |
| 295 i1.m_bar, | |
| 296 () => Polymer.register('x-B', i1.XB), | |
| 297 ]); | |
| 298 } | |
| 299 '''.replaceAll('\n ', '\n'), | |
| 300 'a|web/index.html.0.dart': _sampleOutput("A", "foo"), | |
| 301 'a|lib/b.dart': _sampleOutput('B', 'bar'), | |
| 302 }, []); | |
| 303 } | |
| 304 | |
| 305 String _sampleInput(String className, String fieldName) => ''' | |
| 306 library ${className}_$fieldName; | |
| 307 import 'package:observe/observe.dart'; | |
| 308 import 'package:polymer/polymer.dart'; | |
| 309 | |
| 310 class $className extends Observable { | |
| 311 @observable int $fieldName; | |
| 312 $className(this.$fieldName); | |
| 313 } | |
| 314 | |
| 315 @CustomTag('x-$className') | |
| 316 class X${className} extends PolymerElement { | |
| 317 X${className}.created() : super.created(); | |
| 318 } | |
| 319 @initMethod m_$fieldName() {} | |
| 320 main() {} | |
| 321 '''; | |
| 322 | |
| 323 | |
| 324 String _sampleOutput(String className, String fieldName) { | |
| 325 var fieldReplacement = '@reflectable @observable ' | |
| 326 'int get $fieldName => __\$$fieldName; ' | |
| 327 'int __\$$fieldName; ' | |
| 328 '@reflectable set $fieldName(int value) { ' | |
| 329 '__\$$fieldName = notifyPropertyChange(#$fieldName, ' | |
| 330 '__\$$fieldName, value); }'; | |
| 331 return ''' | |
| 332 library ${className}_$fieldName; | |
| 333 import 'package:observe/observe.dart'; | |
| 334 import 'package:polymer/polymer.dart'; | |
| 335 | |
| 336 class $className extends ChangeNotifier { | |
| 337 $fieldReplacement | |
| 338 $className($fieldName) : __\$$fieldName = $fieldName; | |
| 339 } | |
| 340 | |
| 341 @CustomTag('x-$className') | |
| 342 class X${className} extends PolymerElement { | |
| 343 X${className}.created() : super.created(); | |
| 344 } | |
| 345 @initMethod m_$fieldName() {} | |
| 346 main() {} | |
| 347 '''; | |
| 348 } | |
| OLD | NEW |