Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library TestUtils; | 1 library TestUtils; |
| 2 | 2 |
| 3 import 'dart:async'; | 3 import 'dart:async'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 import 'dart:js' as js; | 5 import 'dart:js' as js; |
| 6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 export 'package:web_components/polyfill.dart'; | |
| 9 | 8 |
| 10 /** | 9 /** |
| 11 * Verifies that [actual] has the same graph structure as [expected]. | 10 * Verifies that [actual] has the same graph structure as [expected]. |
| 12 * Detects cycles and DAG structure in Maps and Lists. | 11 * Detects cycles and DAG structure in Maps and Lists. |
| 13 */ | 12 */ |
| 14 verifyGraph(expected, actual) { | 13 verifyGraph(expected, actual) { |
| 15 var eItems = []; | 14 var eItems = []; |
| 16 var aItems = []; | 15 var aItems = []; |
| 17 | 16 |
| 18 message(path, reason) => path == '' | 17 message(path, reason) => path == '' |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 * | 159 * |
| 161 * This is needed to cover timing scenarios which the custom element polyfill | 160 * This is needed to cover timing scenarios which the custom element polyfill |
| 162 * does not cover. | 161 * does not cover. |
| 163 */ | 162 */ |
| 164 void upgradeCustomElements(Node node) { | 163 void upgradeCustomElements(Node node) { |
| 165 if (js.context.hasProperty('CustomElements') && | 164 if (js.context.hasProperty('CustomElements') && |
| 166 js.context['CustomElements'].hasProperty('upgradeAll')) { | 165 js.context['CustomElements'].hasProperty('upgradeAll')) { |
| 167 js.context['CustomElements'].callMethod('upgradeAll', [node]); | 166 js.context['CustomElements'].callMethod('upgradeAll', [node]); |
| 168 } | 167 } |
| 169 } | 168 } |
| 169 | |
|
devoncarew
2017/07/18 19:54:44
Is this the same code you're also adding to `tests
| |
| 170 /** | |
| 171 * A future that completes once all custom elements in the initial HTML page | |
| 172 * have been upgraded. | |
| 173 * | |
| 174 * This is needed because the native implementation can update the elements | |
| 175 * while parsing the HTML document, but the custom element polyfill cannot, | |
| 176 * so it completes this future once all elements are upgraded. | |
| 177 */ | |
| 178 // TODO(jmesserly): rename to webComponentsReady to match the event? | |
| 179 Future customElementsReady = () { | |
| 180 if (_isReady) return new Future.value(); | |
| 181 | |
| 182 // Not upgraded. Wait for the polyfill to fire the WebComponentsReady event. | |
| 183 // Note: we listen on document (not on document.body) to allow this polyfill | |
| 184 // to be loaded in the HEAD element. | |
| 185 return document.on['WebComponentsReady'].first; | |
| 186 }(); | |
| 187 | |
| 188 // Return true if we are using the polyfill and upgrade is complete, or if we | |
| 189 // have native document.register and therefore the browser took care of it. | |
| 190 // Otherwise return false, including the case where we can't find the polyfill. | |
| 191 bool get _isReady { | |
| 192 // If we don't have dart:js, assume things are ready | |
| 193 if (js.context == null) return true; | |
| 194 | |
| 195 var customElements = js.context['CustomElements']; | |
| 196 if (customElements == null) { | |
| 197 // Return true if native document.register, otherwise false. | |
| 198 // (Maybe the polyfill isn't loaded yet. Wait for it.) | |
| 199 return document.supportsRegisterElement; | |
| 200 } | |
| 201 | |
| 202 return customElements['ready'] == true; | |
| 203 } | |
| 204 | |
| 205 /** | |
| 206 * *Note* this API is primarily intended for tests. In other code it is better | |
| 207 * to write it in a style that works with or without the polyfill, rather than | |
| 208 * using this method. | |
| 209 * | |
| 210 * Synchronously trigger evaluation of pending lifecycle events, which otherwise | |
| 211 * need to wait for a [MutationObserver] to signal the changes in the polyfill. | |
| 212 * This method can be used to resolve differences in timing between native and | |
| 213 * polyfilled custom elements. | |
| 214 */ | |
| 215 void customElementsTakeRecords([Node node]) { | |
| 216 var customElements = js.context['CustomElements']; | |
| 217 if (customElements == null) return; | |
| 218 customElements.callMethod('takeRecords', [node]); | |
| 219 } | |
| OLD | NEW |