Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Unified Diff: sky/tests/custom-elements/callbacks.sky

Issue 943013002: Implement Custom Elements (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: attributeChanged***d***Callback Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/tests/custom-elements/callbacks.sky
diff --git a/sky/tests/custom-elements/callbacks.sky b/sky/tests/custom-elements/callbacks.sky
new file mode 100644
index 0000000000000000000000000000000000000000..b9d640943a6a9bd4915e0e6ab4eb1bc9554a4ee8
--- /dev/null
+++ b/sky/tests/custom-elements/callbacks.sky
@@ -0,0 +1,55 @@
+<sky>
+<script>
+import "../resources/third_party/unittest/unittest.dart";
+import "../resources/unit.dart";
+
+import "dart:sky";
+
+class FooElement extends Element {
+ FooElement() : super("foo");
+
+ attachedCallback() {
+ ++attachedCallbackCount;
+ }
+
+ detachedCallback() {
+ ++detachedCallbackCount;
+ }
+
+ attributeChangedCallback(String name, String oldValue, String newValue) {
+ ++attributeChangedCallbackCount;
+ }
+
+ int attachedCallbackCount = 0;
+ int detachedCallbackCount = 0;
+ int attributeChangedCallbackCount = 0;
+}
+
+
+void main() {
+ initUnit();
+
+ document.registerElement("foo", FooElement);
+
+ test("callbacks should be called", () {
+ Element sky = document.querySelector("sky");
+ FooElement foo = document.createElement("foo");
+ expect(foo.attachedCallbackCount, equals(0));
+ expect(foo.detachedCallbackCount, equals(0));
+ expect(foo.attributeChangedCallbackCount, equals(0));
+ sky.appendChild(foo);
+ expect(foo.attachedCallbackCount, equals(1));
+ expect(foo.detachedCallbackCount, equals(0));
+ expect(foo.attributeChangedCallbackCount, equals(0));
+ foo.setAttribute("bar", "baz");
+ expect(foo.attachedCallbackCount, equals(1));
+ expect(foo.detachedCallbackCount, equals(0));
+ expect(foo.attributeChangedCallbackCount, equals(1));
+ foo.remove();
+ expect(foo.attachedCallbackCount, equals(1));
+ expect(foo.detachedCallbackCount, equals(1));
+ expect(foo.attributeChangedCallbackCount, equals(1));
+ });
+}
+</script>
+</sky>

Powered by Google App Engine
This is Rietveld 408576698