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

Unified Diff: LayoutTests/fast/dom/custom/attribute-changed-callback.html

Issue 18789002: Implement Custom Elements' attributeChangedCallback. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | LayoutTests/fast/dom/custom/attribute-changed-callback-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/dom/custom/attribute-changed-callback.html
diff --git a/LayoutTests/fast/dom/custom/attribute-changed-callback.html b/LayoutTests/fast/dom/custom/attribute-changed-callback.html
new file mode 100644
index 0000000000000000000000000000000000000000..cba80ae984c9da70d9af37ebbee4e1905baf3a8f
--- /dev/null
+++ b/LayoutTests/fast/dom/custom/attribute-changed-callback.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<body>
+<script>
+test(function () {
+ var attributeChangedInvocations = 0;
+ function attributeChanged(_, _, _) {
dglazkov 2013/07/06 01:57:45 cute!
+ attributeChangedInvocations++;
+ }
+
+ var getterInvocations = 0;
+ function getter() {
+ getterInvocations++;
+ return attributeChanged;
+ }
+
+ function failer() {
+ assert_unreached('the attribute changed callback must not be retrieved after registration');
+ }
+
+ var proto = Object.create(HTMLElement.prototype, {
+ attributeChangedCallback: {
+ get: getter
+ }
+ });
+ var ctor = document.register('x-a', {prototype: proto});
+ assert_equals(getterInvocations, 1, 'the attribute changed callback must have been retrieved');
+
+ proto.attributeChangedCallback = failer;
+ var element = new ctor();
+ element.setAttribute('a', 'b');
+ assert_equals(attributeChangedInvocations, 1, 'the attribute changed callback retrieved at registration must be invoked');
+}, 'transfer attribute changed callback');
+
+test(function () {
+ var invocations = [];
+ function created() {
+ invocations.push('created');
+ }
+ function attributeChanged(name, oldValue, newValue) {
+ invocations.push(name + ': ' + oldValue + ' => ' + newValue);
+ }
+
+ var proto = Object.create(HTMLElement.prototype);
+ proto.createdCallback = created;
+ proto.attributeChangedCallback = attributeChanged;
+ var B = document.register('x-b', {prototype: proto});
+
+ var b = new B();
+ b.id = 'x';
+ assert_array_equals(invocations, ['created', 'id: null => x'], 'setting a reflected attribute should invoke the attributeChanged callback');
+
+ invocations = [];
+ b.removeAttribute('id');
+ assert_array_equals(invocations, ['id: x => null'], 'removing an attribute should invoke the attributeChangedCallback');
+
+ invocations = [];
+ b.setAttribute('data-x', 'y');
+ assert_array_equals(invocations, ['data-x: null => y'], 'setAttribute should invoke the attributeChangedCallback');
+
+ invocations = [];
+ b.classList.toggle('z');
+ assert_array_equals(invocations, ['class: null => z'], 'changing the class attribute through classList should invoke the attributeChangedCallback');
+}, 'add, change and remove an attribute');
+</script>
« no previous file with comments | « no previous file | LayoutTests/fast/dom/custom/attribute-changed-callback-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698