| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 for details. All rights reserved. Use of this source code is governed by a | 4 for details. All rights reserved. Use of this source code is governed by a |
| 5 BSD-style license that can be found in the LICENSE file. | 5 BSD-style license that can be found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 <html lang="en"> | 7 <html lang="en"> |
| 8 <head> | 8 <head> |
| 9 <!-- | 9 <!-- |
| 10 This test runs the TodoMVC app, adds a few todos, marks some as done | 10 This test runs the TodoMVC app, adds a few todos, marks some as done |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import 'dart:async'; | 22 import 'dart:async'; |
| 23 import 'dart:html'; | 23 import 'dart:html'; |
| 24 import 'package:mdv/mdv.dart' as mdv; | 24 import 'package:mdv/mdv.dart' as mdv; |
| 25 import 'package:observe/observe.dart'; | 25 import 'package:observe/observe.dart'; |
| 26 import 'package:unittest/unittest.dart'; | 26 import 'package:unittest/unittest.dart'; |
| 27 import 'package:polymer/polymer.dart'; | 27 import 'package:polymer/polymer.dart'; |
| 28 import '../web/model.dart'; | 28 import '../web/model.dart'; |
| 29 | 29 |
| 30 Node findWithText(Node node, String text) { | 30 Node findWithText(Node node, String text) { |
| 31 if (node.text == text) return node; | 31 if (node.text == text) return node; |
| 32 if (node is Element && node.shadowRoot != null) { | 32 if (node is Element && (node as Element).localName == 'polymer-element') { |
| 33 var r = findWithText(node.shadowRoot, text); | 33 return null; |
| 34 } |
| 35 if (node is Element && (node as Element).shadowRoot != null) { |
| 36 var r = findWithText((node as Element).shadowRoot, text); |
| 34 if (r != null) return r; | 37 if (r != null) return r; |
| 35 } | 38 } |
| 36 for (var n in node.nodes) { | 39 for (var n in node.nodes) { |
| 37 var r = findWithText(n, text); | 40 var r = findWithText(n, text); |
| 38 if (r != null) return r; | 41 if (r != null) return r; |
| 39 } | 42 } |
| 40 return null; | 43 return null; |
| 41 } | 44 } |
| 42 | 45 |
| 43 Node findShadowHost(Node node, ShadowRoot root) { | 46 Node findShadowHost(Node node, ShadowRoot root) { |
| 44 if (node is Element) { | 47 if (node is Element) { |
| 45 var shadowRoot = node.shadowRoot; | 48 var shadowRoot = (node as Element).shadowRoot; |
| 46 if (shadowRoot == root) return node; | 49 if (shadowRoot == root) return node; |
| 47 if (shadowRoot != null) { | 50 if (shadowRoot != null) { |
| 48 var r = findShadowHost(shadowRoot, root); | 51 var r = findShadowHost(shadowRoot, root); |
| 49 if (r != null) return r; | 52 if (r != null) return r; |
| 50 } | 53 } |
| 51 } | 54 } |
| 52 for (var n in node.nodes) { | 55 for (var n in node.nodes) { |
| 53 var r = findShadowHost(n, root); | 56 var r = findShadowHost(n, root); |
| 54 if (r != null) return r; | 57 if (r != null) return r; |
| 55 } | 58 } |
| 56 return null; | 59 return null; |
| 57 } | 60 } |
| 58 | 61 |
| 59 main() { | 62 main() { |
| 60 mdv.initialize(); | 63 mdv.initialize(); |
| 61 | 64 |
| 62 Timer.run(() { | 65 Timer.run(() { |
| 63 appModel.todos.add(new Todo('one (unchecked)')); | 66 appModel.todos.add(new Todo('one (unchecked)')); |
| 64 appModel.todos.add(new Todo('two (unchecked)')); | 67 appModel.todos.add(new Todo('two (unchecked)')); |
| 65 appModel.todos.add(new Todo('three (checked)')..done = true); | 68 appModel.todos.add(new Todo('three (checked)')..done = true); |
| 66 appModel.todos.add(new Todo('four (checked)')); | 69 appModel.todos.add(new Todo('four (checked)')); |
| 67 deliverChangeRecords(); | 70 deliverChangeRecords(); |
| 71 // TODO(sigmund): investigate why is not enough to do Timer.run |
| 72 new Timer(new Duration(milliseconds: 200), () { |
| 73 // Note: use query because "document" is unwrapped in ShadowDOM polyfill. |
| 74 var body = query('body'); |
| 68 | 75 |
| 69 // Note: use query because "document" is unwrapped in ShadowDOM polyfill. | 76 var label = findWithText(body, 'four (checked)'); |
| 70 var body = query('body'); | 77 expect(label is LabelElement, isTrue, reason: 'text is in a label'); |
| 71 | 78 |
| 72 var label = findWithText(body, 'four (checked)'); | 79 var host = findShadowHost(body, label.parentNode); |
| 73 expect(label is LabelElement, isTrue, reason: 'text is in a label'); | 80 var node = host.parent.query('input'); |
| 81 expect(node is InputElement, isTrue, reason: 'node is a checkbox'); |
| 82 expect(node.type, 'checkbox', reason: 'node type is checkbox'); |
| 83 expect(node.checked, isFalse, reason: 'element is unchecked'); |
| 74 | 84 |
| 75 var host = findShadowHost(body, label.parentNode); | 85 node.dispatchEvent(new MouseEvent('click', detail: 1)); |
| 76 var node = host.parent.query('input'); | 86 expect(node.checked, isTrue, reason: 'element is checked'); |
| 77 expect(node is InputElement, isTrue, reason: 'node is a checkbox'); | |
| 78 expect(node.type, 'checkbox', reason: 'node type is checkbox'); | |
| 79 expect(node.checked, isFalse, reason: 'element is unchecked'); | |
| 80 | 87 |
| 81 node.dispatchEvent(new MouseEvent('click', detail: 1)); | 88 Timer.run(() { |
| 82 expect(node.checked, isTrue, reason: 'element is checked'); | 89 window.postMessage('done', '*'); |
| 83 | 90 }); |
| 84 window.postMessage('done', '*'); | 91 }); |
| 85 }); | 92 }); |
| 86 } | 93 } |
| 87 </script> | 94 </script> |
| 88 </body> | 95 </body> |
| 89 </html> | 96 </html> |
| OLD | NEW |