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.all_phases_test; | 5 library polymer.test.build.all_phases_test; |
6 | 6 |
7 import 'package:polymer/src/build/common.dart'; | 7 import 'package:polymer/src/build/common.dart'; |
8 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; | 8 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; |
9 import 'package:polymer/transformer.dart'; | 9 import 'package:polymer/transformer.dart'; |
10 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 testPhases('single inline script', phases, { | 58 testPhases('single inline script', phases, { |
59 'a|web/test.html': | 59 'a|web/test.html': |
60 '<!DOCTYPE html><html><head>' | 60 '<!DOCTYPE html><html><head>' |
61 '<script type="application/dart">' | 61 '<script type="application/dart">' |
62 '${_sampleObservable("B", "bar")}</script>', | 62 '${_sampleObservable("B", "bar")}</script>', |
63 }, { | 63 }, { |
64 'a|web/test.html': | 64 'a|web/test.html': |
65 '<!DOCTYPE html><html><head>' | 65 '<!DOCTYPE html><html><head>' |
66 '$WEB_COMPONENTS_TAG' | 66 '$WEB_COMPONENTS_TAG' |
67 '$INTEROP_TAG' | 67 '$INTEROP_TAG' |
| 68 '</head><body>' |
68 '<script src="test.html_bootstrap.dart.js"></script>' | 69 '<script src="test.html_bootstrap.dart.js"></script>' |
69 '</head><body></body></html>', | 70 '</body></html>', |
70 | 71 |
71 'a|web/test.html_bootstrap.dart': | 72 'a|web/test.html_bootstrap.dart': |
72 '''$MAIN_HEADER | 73 '''$MAIN_HEADER |
73 import 'test.html.0.dart' as i0; | 74 import 'test.html.0.dart' as i0; |
74 | 75 |
75 void main() { | 76 void main() { |
76 configureForDeployment([ | 77 configureForDeployment([ |
77 ]); | 78 ]); |
78 i0.main(); | 79 i0.main(); |
79 } | 80 } |
80 '''.replaceAll('\n ', '\n'), | 81 '''.replaceAll('\n ', '\n'), |
81 'a|web/test.html.0.dart': | 82 'a|web/test.html.0.dart': |
82 _sampleObservableOutput("B", "bar"), | 83 _sampleObservableOutput("B", "bar"), |
83 }); | 84 }); |
84 | 85 |
| 86 const onlyOne = 'warning: Only one "application/dart" script tag per document' |
| 87 ' is allowed.'; |
| 88 const moreNotSupported = |
| 89 'warning: more than one Dart script per HTML document is not supported. ' |
| 90 'Script will be ignored.'; |
| 91 |
85 testPhases('several scripts', phases, { | 92 testPhases('several scripts', phases, { |
86 'a|web/test.html': | 93 'a|web/test.html': |
87 '<!DOCTYPE html><html><head>' | 94 '<!DOCTYPE html><html><head>' |
88 '<script type="application/dart" src="a.dart"></script>' | 95 '<script type="application/dart" src="a.dart"></script>' |
89 // TODO(sigmund): provide a way to see logging warnings and errors. | 96 // TODO(sigmund): provide a way to see logging warnings and errors. |
90 // For example, these extra tags produce warnings and are then removed | 97 // For example, these extra tags produce warnings and are then removed |
91 // by the transformers. The test below checks that the output looks | 98 // by the transformers. The test below checks that the output looks |
92 // correct, but we should also validate the messages logged. | 99 // correct, but we should also validate the messages logged. |
93 '<script type="application/dart">' | 100 '<script type="application/dart">' |
94 '${_sampleObservable("B", "bar")}</script>' | 101 '${_sampleObservable("B", "bar")}</script>' |
95 '</head><body><div>' | 102 '</head><body><div>' |
96 '<script type="application/dart">' | 103 '<script type="application/dart">' |
97 '${_sampleObservable("C", "car")}</script>' | 104 '${_sampleObservable("C", "car")}</script>' |
98 '</div>' | 105 '</div>' |
99 '<script type="application/dart" src="d.dart"></script>', | 106 '<script type="application/dart" src="d.dart"></script>', |
100 'a|web/a.dart': _sampleObservable('A', 'foo'), | 107 'a|web/a.dart': _sampleObservable('A', 'foo'), |
101 }, { | 108 }, { |
102 'a|web/test.html': | 109 'a|web/test.html': |
103 '<!DOCTYPE html><html><head>' | 110 '<!DOCTYPE html><html><head>' |
104 '$WEB_COMPONENTS_TAG' | 111 '$WEB_COMPONENTS_TAG' |
105 '$INTEROP_TAG' | 112 '$INTEROP_TAG' |
| 113 '</head><body>' |
106 '<script src="test.html_bootstrap.dart.js"></script>' | 114 '<script src="test.html_bootstrap.dart.js"></script>' |
107 '</head><body>' | |
108 '<div></div>' | 115 '<div></div>' |
109 '</body></html>', | 116 '</body></html>', |
110 | 117 |
111 'a|web/test.html_bootstrap.dart': | 118 'a|web/test.html_bootstrap.dart': |
112 '''$MAIN_HEADER | 119 '''$MAIN_HEADER |
113 import 'a.dart' as i0; | 120 import 'a.dart' as i0; |
114 | 121 |
115 void main() { | 122 void main() { |
116 configureForDeployment([ | 123 configureForDeployment([ |
117 ]); | 124 ]); |
118 i0.main(); | 125 i0.main(); |
119 } | 126 } |
120 '''.replaceAll('\n ', '\n'), | 127 '''.replaceAll('\n ', '\n'), |
121 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), | 128 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), |
122 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), | 129 }, [ |
123 'a|web/test.html.1.dart': _sampleObservableOutput("C", "car"), | 130 // These should not be emitted multiple times. See: |
124 }); | 131 // https://code.google.com/p/dart/issues/detail?id=17197 |
| 132 '$onlyOne (web/test.html 0 81)', |
| 133 '$onlyOne (web/test.html 7 27)', |
| 134 '$onlyOne (web/test.html 14 15)', |
| 135 '$moreNotSupported (web/test.html 0 81)', |
| 136 '$moreNotSupported (web/test.html 7 27)', |
| 137 '$moreNotSupported (web/test.html 14 15)' |
| 138 ]); |
125 | 139 |
126 testPhases('with imports', phases, { | 140 testPhases('with imports', phases, { |
127 'a|web/index.html': | 141 'a|web/index.html': |
128 '<!DOCTYPE html><html><head>' | 142 '<!DOCTYPE html><html><head>' |
129 '<link rel="import" href="test2.html">' | 143 '<link rel="import" href="test2.html">' |
130 '</head><body>' | 144 '</head><body>' |
131 '<script type="application/dart" src="b.dart"></script>', | 145 '<script type="application/dart" src="b.dart"></script>', |
132 'a|web/b.dart': _sampleObservable('B', 'bar'), | 146 'a|web/b.dart': _sampleObservable('B', 'bar'), |
133 'a|web/test2.html': | 147 'a|web/test2.html': |
134 '<!DOCTYPE html><html><head></head><body>' | 148 '<!DOCTYPE html><html><head></head><body>' |
135 '<polymer-element>1' | 149 '<polymer-element>1' |
136 '<script type="application/dart">' | 150 '<script type="application/dart">' |
137 '${_sampleObservable("A", "foo")}</script>' | 151 '${_sampleObservable("A", "foo")}</script>' |
138 '</polymer-element></html>', | 152 '</polymer-element></html>', |
139 }, { | 153 }, { |
140 'a|web/index.html': | 154 'a|web/index.html': |
141 '<!DOCTYPE html><html><head>' | 155 '<!DOCTYPE html><html><head>' |
142 '$WEB_COMPONENTS_TAG' | 156 '$WEB_COMPONENTS_TAG' |
143 '$INTEROP_TAG' | 157 '$INTEROP_TAG' |
144 '</head><body><polymer-element>1</polymer-element>' | 158 '</head><body><polymer-element>1</polymer-element>' |
145 '<script src="index.html_bootstrap.dart.js"></script>' | 159 '<script src="index.html_bootstrap.dart.js"></script>' |
146 '</body></html>', | 160 '</body></html>', |
147 'a|web/index.html_bootstrap.dart': | 161 'a|web/index.html_bootstrap.dart': |
148 '''$MAIN_HEADER | 162 '''$MAIN_HEADER |
149 import 'test2.html.0.dart' as i0; | 163 import 'index.html.0.dart' as i0; |
150 import 'b.dart' as i1; | 164 import 'b.dart' as i1; |
151 | 165 |
152 void main() { | 166 void main() { |
153 configureForDeployment([ | 167 configureForDeployment([ |
154 ]); | 168 ]); |
155 i1.main(); | 169 i1.main(); |
156 } | 170 } |
157 '''.replaceAll('\n ', '\n'), | 171 '''.replaceAll('\n ', '\n'), |
158 'a|web/test2.html.0.dart': _sampleObservableOutput("A", "foo"), | 172 'a|web/index.html.0.dart': _sampleObservableOutput("A", "foo"), |
159 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), | 173 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), |
160 }); | 174 }); |
161 } | 175 } |
162 | 176 |
163 String _sampleObservable(String className, String fieldName) => ''' | 177 String _sampleObservable(String className, String fieldName) => ''' |
164 library ${className}_$fieldName; | 178 library ${className}_$fieldName; |
165 import 'package:observe/observe.dart'; | 179 import 'package:observe/observe.dart'; |
166 | 180 |
167 class $className extends Observable { | 181 class $className extends Observable { |
168 @observable int $fieldName; | 182 @observable int $fieldName; |
169 $className(this.$fieldName); | 183 $className(this.$fieldName); |
170 } | 184 } |
171 '''; | 185 '''; |
172 | 186 |
173 String _sampleObservableOutput(String className, String field, | 187 String _sampleObservableOutput(String className, String field, |
174 {bool includeMain: false}) => | 188 {bool includeMain: false}) => |
175 "library ${className}_$field;\n" | 189 "library ${className}_$field;\n" |
176 "import 'package:observe/observe.dart';\n\n" | 190 "import 'package:observe/observe.dart';\n\n" |
177 "class $className extends ChangeNotifier {\n" | 191 "class $className extends ChangeNotifier {\n" |
178 " @reflectable @observable int get $field => __\$$field; " | 192 " @reflectable @observable int get $field => __\$$field; " |
179 "int __\$$field; " | 193 "int __\$$field; " |
180 "@reflectable set $field(int value) { " | 194 "@reflectable set $field(int value) { " |
181 "__\$$field = notifyPropertyChange(#$field, __\$$field, value); " | 195 "__\$$field = notifyPropertyChange(#$field, __\$$field, value); " |
182 "}\n" | 196 "}\n" |
183 " $className($field) : __\$$field = $field;\n" | 197 " $className($field) : __\$$field = $field;\n" |
184 "}\n"; | 198 "}\n"; |
OLD | NEW |