Index: samples/third_party/todomvc/test/todomvc_markdone_test.html |
diff --git a/samples/third_party/todomvc/test/todomvc_markdone_test.html b/samples/third_party/todomvc/test/todomvc_markdone_test.html |
index b819198bb8ea89c683bf93488e87b85a2456a3da..3219312d63afb3aa01adcb50e2dc81dc558ca246 100644 |
--- a/samples/third_party/todomvc/test/todomvc_markdone_test.html |
+++ b/samples/third_party/todomvc/test/todomvc_markdone_test.html |
@@ -14,53 +14,73 @@ programatically, and clicks on a checkbox to mark others via the UI. |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
<link rel="import" href="../web/app.html"> |
<link rel="stylesheet" href="../web/base.css"> |
- <script src="packages/web_ui/testing/testing.js"></script> |
+ <script src="packages/polymer/testing/testing.js"></script> |
<title>Dart • TodoMVC</title> |
</head><body> |
<todo-app></todo-app> |
<script type="application/dart"> |
-import 'dart:async'; |
import 'dart:html'; |
import 'package:unittest/unittest.dart'; |
-import 'package:web_ui/web_ui.dart'; |
+import 'package:polymer/polymer.dart'; |
import '../web/model.dart'; |
+Node findWithText(Node node, String text) { |
+ if (node.text == text) return node; |
+ if (node is Element && (node as Element).localName == 'polymer-element') { |
+ return null; |
+ } |
+ if (node is Element && (node as Element).shadowRoot != null) { |
+ var r = findWithText((node as Element).shadowRoot, text); |
+ if (r != null) return r; |
+ } |
+ for (var n in node.nodes) { |
+ var r = findWithText(n, text); |
+ if (r != null) return r; |
+ } |
+ return null; |
+} |
+ |
+Node findShadowHost(Node node, ShadowRoot root) { |
+ if (node is Element) { |
+ var shadowRoot = (node as Element).shadowRoot; |
+ if (shadowRoot == root) return node; |
+ if (shadowRoot != null) { |
+ var r = findShadowHost(shadowRoot, root); |
+ if (r != null) return r; |
+ } |
+ } |
+ for (var n in node.nodes) { |
+ var r = findShadowHost(n, root); |
+ if (r != null) return r; |
+ } |
+ return null; |
+} |
+ |
main() { |
- Timer.run(() { |
- useShadowDom = false; |
- app.todos.add(new Todo('one (unchecked)')); |
- app.todos.add(new Todo('two (unchecked)')); |
- app.todos.add(new Todo('three (checked)')..done = true); |
- app.todos.add(new Todo('four (checked)')); |
- deliverChangesSync(); |
+ appModel.todos.add(new Todo('one (unchecked)')); |
+ appModel.todos.add(new Todo('two (unchecked)')); |
+ appModel.todos.add(new Todo('three (checked)')..done = true); |
+ appModel.todos.add(new Todo('four (checked)')); |
+ |
+ performMicrotaskCheckpoint(); |
+ var body = query('body'); |
- // To ensure we click in the correct place, we calculate x, y offset where |
- // we want to click based on the coordinates given by content shell, and |
- // then adapt those offset in the current window. This makes is possible to |
- // debug the application in Dartium reliably. |
+ var label = findWithText(body, 'four (checked)'); |
+ expect(label is LabelElement, isTrue, reason: 'text is in a label'); |
- var bounding = document.body.getBoundingClientRect(); |
- // The x, y location of body in the content shell output was: (117, 130) |
- // and location of the node we want to click was: (119, 398) |
- int x = bounding.left.toInt() + (119 - 117); |
- int y = bounding.top.toInt() + (398 - 130); |
- var node = document.elementFromPoint(x, y); |
- expect(node is InputElement, isTrue, |
- reason: '$x, $y points to a checkbox'); |
- expect(node.checked, isFalse, reason: 'element is unchecked'); |
- Element parent = node.parent; |
- expect(parent.query('label').text, equals('four (checked)')); |
- node.dispatchEvent(new MouseEvent('click', detail: 1)); |
- expect(node.checked, isTrue, reason: 'element is checked'); |
+ var host = findShadowHost(body, label.parentNode); |
+ var node = host.parent.query('input'); |
+ expect(node is InputElement, isTrue, reason: 'node is a checkbox'); |
+ expect(node.type, 'checkbox', reason: 'node type is checkbox'); |
+ expect(node.checked, isFalse, reason: 'element is unchecked'); |
- // Ideally the test above would work also with shadow DOM (pending that |
- // 'elementFromPoint' is fixed to return also nodes under the shadow DOM). |
- // The next extra check is only valid when polyfilling the shadow DOM: |
- expect(node, same(document.queryAll('input[type=checkbox]')[4])); |
+ node.dispatchEvent(new MouseEvent('click', detail: 1)); |
+ expect(node.checked, isTrue, reason: 'element is checked'); |
+ performMicrotaskCheckpoint(); |
- window.postMessage('done', '*'); |
- }); |
+ window.postMessage('done', '*'); |
} |
+ |
</script> |
</body> |
</html> |