Chromium Code Reviews| 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 custom_element.test.custom_element_test; | 5 library custom_element.test.custom_element_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'package:custom_element/custom_element.dart'; | 9 import 'package:custom_element/custom_element.dart'; |
| 10 import 'package:unittest/html_config.dart'; | 10 import 'package:unittest/html_config.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 useHtmlConfiguration(); | 14 useHtmlConfiguration(); |
| 15 | 15 |
| 16 // Load the MutationObserver polyfill. | 16 setUp(() { |
| 17 HttpRequest.getString('/root_dart/pkg/mutation_observer/lib/' | 17 // Load the MutationObserver polyfill if needed. |
| 18 'mutation_observer.js').then((code) { | 18 if (!MutationObserver.supported) { |
| 19 document.head.children.add(new ScriptElement()..text = code); | 19 var script = new ScriptElement() |
| 20 ..src = '/packages/mutation_observer/mutation_observer.js'; | |
| 21 document.head.append(script); | |
| 22 return script.onLoad.first; | |
|
Jennifer Messerly
2013/09/12 20:43:48
Nice! This blocks the test until it loads? That wa
blois
2013/09/12 21:23:13
The setUp function handles Future return types jus
| |
| 23 } | |
| 24 }); | |
| 20 | 25 |
| 21 customElementTests(); | |
| 22 }); | |
| 23 } | |
| 24 | |
| 25 customElementTests() { | |
| 26 test('register creates the element and calls lifecycle methods', () { | 26 test('register creates the element and calls lifecycle methods', () { |
| 27 // Add element to the page. | 27 // Add element to the page. |
| 28 var element = new Element.html('<fancy-button>foo bar</fancy-button>', | 28 var element = new Element.html('<fancy-button>foo bar</fancy-button>', |
| 29 treeSanitizer: new NullTreeSanitizer()); | 29 treeSanitizer: new NullTreeSanitizer()); |
| 30 document.body.nodes.add(element); | 30 document.body.nodes.add(element); |
| 31 | 31 |
| 32 var xtag = null; | 32 var xtag = null; |
| 33 registerCustomElement('fancy-button', () => xtag = new FancyButton()); | 33 registerCustomElement('fancy-button', () => xtag = new FancyButton()); |
| 34 expect(xtag, isNotNull, reason: 'FancyButton was created'); | 34 expect(xtag, isNotNull, reason: 'FancyButton was created'); |
| 35 expect(element.xtag, xtag, reason: 'xtag pointer should be set'); | 35 expect(element.xtag, xtag, reason: 'xtag pointer should be set'); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 lifecycle.add('removed'); | 92 lifecycle.add('removed'); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * Sanitizer which does nothing. | 97 * Sanitizer which does nothing. |
| 98 */ | 98 */ |
| 99 class NullTreeSanitizer implements NodeTreeSanitizer { | 99 class NullTreeSanitizer implements NodeTreeSanitizer { |
| 100 void sanitizeTree(Node node) {} | 100 void sanitizeTree(Node node) {} |
| 101 } | 101 } |
| OLD | NEW |