attribute.html revision 98c1ab155c0e2148f69291b1abe1007c9d5a08e8
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore<html>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore<head>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <title>Attribute Tests</title>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore <script type="text/javascript" src="/build/yui/yui.js"></script>
0a9c6f9f30a66e52ec4ea4ed93504580b3a5669aAdam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore <style type="text/css">
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore #console .yui3-console-entry {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore padding:2px;
0a9c6f9f30a66e52ec4ea4ed93504580b3a5669aAdam Moore margin:0px;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore min-height:0;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore }
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore #console .yui3-console-entry-fail .yui3-console-entry-cat {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore background-color:red;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore #console .yui3-console-entry-pass .yui3-console-entry-cat {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore background-color:green;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
9cdb1aa8d3a7901f789c2ad7a6ea00e804a9abebAdam Moore
9cdb1aa8d3a7901f789c2ad7a6ea00e804a9abebAdam Moore #console .yui3-console-entry-perf .yui3-console-entry-cat {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore background-color:blue;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore #console {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore position:static;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore html, body {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore height:100%;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore </style>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <script type="text/javascript">
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore YUI({useBrowserConsole:false}).use("dump", "attribute-complex", "base", "console", "test", function(Y) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore function areObjectsReallyEqual(o1, o2) {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore Y.ObjectAssert.areEqual(o1, o2);
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore Y.ObjectAssert.areEqual(o2, o1);
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore }
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore function Test(cfg, lazy, silentInit) {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore this._lazyAddAttrs = lazy;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore this._silentInit = silentInit;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Test.superclass.constructor.apply(this, arguments);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore };
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore Test.NAME = 'test';
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Test.ATTRS = {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr1: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: "Foo",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(n) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return n;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr2: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: "Bar",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(n) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return n;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore }
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr3: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value: true
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr4: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: 3
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr5: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value: 3
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr6: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: false,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(lock) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return lock;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr7: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: false
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr8: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value: true
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr9: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value: true
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr10: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: false
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr11: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: true
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr12: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: false
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr13: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: false
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr14: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: false,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(val) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return val;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr15: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: null,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(val) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return false;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr16: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: ['default'],
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore getter: function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return false;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(g) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return g;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore }
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr17: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value: null,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore setter: function(g) {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore return g;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore }
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr18: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore writeOnce: true,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value: null
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore attr19: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore writeOnce: true,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: null
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore attr20: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore writeOnce: true,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: null
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore };
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.extend(Test, Y.Base, {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore foo: function() {}
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore function AttrHost(config) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore AttrHost.superclass.constructor.apply(this, arguments);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore AttrHost.NAME = "attrHost";
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore AttrHost.ATTRS = {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore A: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore value:"AVal",
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore validator: Y.Lang.isString,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore broadcast:1
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore B: {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore validator: function(value) {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore return (value === undefined || Y.Lang.isString(value) || Y.Lang.isNumber(value));
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore broadcast:2
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore C: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore writeOnce: true
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore D: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value:"DVal",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore readOnly: true
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore E: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value:"EVal",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore writeOnce: true
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore DE: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore valueFn: function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return this.get("D") + this.get("E");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore complex: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore X : {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore A: 1
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y : {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore A: 2
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Z : {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore A: 3
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore initOnly : {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore writeOnce:"initOnly"
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore };
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.extend(AttrHost, Y.Base);
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore // -----
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore function ExtendedAttrHost(config) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore AttrHost.superclass.constructor.apply(this, arguments);
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ExtendedAttrHost.NAME = "extendedAttrHost";
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ExtendedAttrHost.ATTRS = {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore A: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value:"ExtAVal"
111837fe5c14f516f4a15878f9bbaf7bb0091364Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore B: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value:"ExtBVal",
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore validator: function(value) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore return ((value == undefined) || Y.Lang.isString(value));
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore D: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value:"ExtDVal",
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore setter: function(val) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore return (Y.Lang.isString(val)) ? val.toUpperCase() : val;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore E: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value:"ExtEVal",
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore getter: function(val) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore return (Y.Lang.isString(val)) ? val.toLowerCase() : val;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore F: {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value:"ExtFVal",
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore setter: function(val) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore return (Y.Lang.isString(val)) ? val : Y.Attribute.INVALID_VALUE;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore }
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore "complex.X.A" : {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore value: 1111
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "complex.Y.A" : {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: 2222,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: function(val) { // Should be ignored. Can't set setters for complex sub vals
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore return val + 10000;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore }
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore },
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore G : {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore valueFn:function(val) {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore // Referring to H before it's set up
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return this.get("H") + 10;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore },
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore H: {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value:5,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore getter: function(val) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return val*5;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore I : {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value:{
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore a: 5
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore getter: "_getI",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore setter: "_setI",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore validator: "_validateI"
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore PassThrough : {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore value: "passthrough",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore getter: function(val) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return this._passthrough;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore setter: function(val) {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore this._passthrough = val;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore }
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore },
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore Z : {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore value: "z",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore getter: function(val) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return val.toUpperCase();
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore }
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore }
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore };
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.extend(ExtendedAttrHost, AttrHost, {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore _validateI : function(val, name) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore if (name.indexOf(".") == -1) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual("I", name);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore } else {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual("I.a", name);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore return true;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore _getI : function(val, name) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore if (name.indexOf(".") == -1) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual("I", name);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore } else {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual("I.a", name);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore return val;
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore },
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore _setI : function(val, name) {
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore if (name.indexOf(".") == -1) {
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore Y.Assert.areEqual("I", name);
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore } else {
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore Y.Assert.areEqual("I.a", name);
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore }
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore }
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore });
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore //---
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore var sharedEventTests = {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore testEventPrevent : function() {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore var h = this.createHost();
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore var expectedEvents = ["BeforeMyNewAVal", "AfterMyNewAVal", "BeforePREVENT"];
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore var actualEvents = [];
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore h.on("AChange", function(e) {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore actualEvents.push("Before" + e.newVal);
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore if (e.newVal == "PREVENT") {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore e.preventDefault();
03f9aefec605c500b64625110a955e65b900b100Adam Moore }
03f9aefec605c500b64625110a955e65b900b100Adam Moore });
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore h.after("AChange", function(e) {
03f9aefec605c500b64625110a955e65b900b100Adam Moore actualEvents.push("After" + e.newVal);
03f9aefec605c500b64625110a955e65b900b100Adam Moore
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore Y.Assert.areEqual("MyNewAVal", this.get("A"));
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore h.set("A", "MyNewAVal");
03f9aefec605c500b64625110a955e65b900b100Adam Moore h.set("A", "PREVENT");
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
03f9aefec605c500b64625110a955e65b900b100Adam Moore },
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore testEventBasic : function() {
03f9aefec605c500b64625110a955e65b900b100Adam Moore var h = this.createHost({A:"MyAVal"});
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore var expectedEvents = ["BeforeMyNewAVal", "AfterMyNewAVal"];
03f9aefec605c500b64625110a955e65b900b100Adam Moore var actualEvents = [];
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore h.on("AChange", function(e) {
03f9aefec605c500b64625110a955e65b900b100Adam Moore actualEvents.push("Before" + e.newVal);
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore Y.Assert.areEqual("A", e.attrName);
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore Y.Assert.areEqual(null, e.subAttrName);
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore Y.Assert.areEqual("MyAVal", e.prevVal);
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore Y.Assert.areEqual("MyNewAVal", e.newVal);
03f9aefec605c500b64625110a955e65b900b100Adam Moore });
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore h.after("AChange", function(e) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore actualEvents.push("After" + e.newVal);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual("A", e.attrName);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(null, e.subAttrName);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore Y.Assert.areEqual("MyAVal", e.prevVal);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore Y.Assert.areEqual("MyNewAVal", e.newVal);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore });
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.set("A", "MyNewAVal");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore },
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore testEventStopImmediatePropagation: function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var h = this.createHost();
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var expectedEvents = ["Before1MyNewAVal", "Before2MyNewAVal", "After1MyNewAVal", "After2MyNewAVal", "Before1STOPAFTER", "Before2STOPAFTER", "After1STOPAFTER", "Before1STOPBEFORE"];
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore var actualEvents = [];
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.on("AChange", function(e) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore actualEvents.push("Before1" + e.newVal);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore if (e.newVal == "STOPBEFORE") {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore e.stopImmediatePropagation();
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore h.after("AChange", function(e) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore actualEvents.push("After1" + e.newVal);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore if (e.newVal == "STOPAFTER") {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore e.stopImmediatePropagation();
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore });
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.on("AChange", function(e) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore actualEvents.push("Before2" + e.newVal);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore });
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.after("AChange", function(e) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore actualEvents.push("After2" + e.newVal);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore });
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.set("A", "MyNewAVal");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.set("A", "STOPAFTER");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.set("A", "STOPBEFORE");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore },
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore testEventValidationReadonlyWriteOnce : function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var h = this.createHost({A:"MyAVal", C:"MyCVal", D:"MyDVal"});
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var expectedEvents = ["BeforeAChange"];
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var actualEvents = [];
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.on("AChange", function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore actualEvents.push("BeforeAChange");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore });
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore h.after("AChange", function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore actualEvents.push("AfterAChange");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore h.on("CChange", function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore actualEvents.push("BeforeCChange");
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore });
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.on("CChange", function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore actualEvents.push("BeforeCChange");
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore });
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.on("DChange", function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore actualEvents.push("BeforeDChange");
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore });
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.on("DChange", function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore actualEvents.push("BeforeDChange");
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore });
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.set("A", 200); // Invalid - before fired, after not fired [ value can be changed to be made valid ]
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.set("C", "MyNewCVal"); // Write Once - neither before nor after are fired
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.set("D", "MyNewDVal"); // Read Only - neither before not after are fired
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore },
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore testEventModify : function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore var h = this.createHost({A:"MyAVal"});
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.on("AChange", function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual("MyAVal", e.prevVal);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore e.newVal = e.newVal.toUpperCase();
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore });
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.after("AChange", function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual("MYNEWAVAL", e.newVal);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore });
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore h.set("A", "MyNewAVal");
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual("MYNEWAVAL", h.get("A"));
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore },
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore testEventSameValue : function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore var h = this.createHost({A:"MyAVal"});
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var expectedEvents = ["BeforeAChange",
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore "BeforeAChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeAChange", "AfterAChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeComplexChange", "AfterComplexChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeComplexChange", "AfterComplexChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeComplexChange", "AfterComplexChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeComplexChange", "AfterComplexChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeComplexChange", "AfterComplexChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforeComplexChange", "AfterComplexChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforePassThroughChange", "AfterPassThroughChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforePassThroughChange",
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore "BeforePassThroughChange", "AfterPassThroughChange"
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ];
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore var actualEvents = [];
h.on("AChange", function(e) {
actualEvents.push("BeforeAChange");
});
h.after("AChange", function(e) {
actualEvents.push("AfterAChange");
Y.Assert.areNotSame(e.newVal, e.preVal);
});
h.on("complexChange", function(e) {
actualEvents.push("BeforeComplexChange");
});
h.after("complexChange", function(e) {
actualEvents.push("AfterComplexChange");
if (!e.subAttrName) {
Y.Assert.areNotSame(e.newVal, e.preVal, "Should not fire after event if object values are same");
}
});
h.on("PassThroughChange", function(e) {
actualEvents.push("BeforePassThroughChange");
});
h.after("PassThroughChange", function(e) {
actualEvents.push("AfterPassThroughChange");
});
h.set("A", h.get("A")); // No Change
h.set("A", "MyAVal"); // No Change
h.set("A", "MyNewAVal"); // Change
h.set("complex", h.get("complex")); // Change, we don't know if something changed inside the object
h.set("complex.Z.A", 3); // Change, even though value of complex is unchanged, we don't deep compare objects.
h.set("complex", Y.clone(h.get("complex"))); // Change, obj reference differs
h.set("complex", {A:1, B:2, C:3}); // Change, obj reference differs
var a = ["A"];
h.set("complex", a); // Change, value changed
a.push("B");
h.set("complex", a); // Change, same object ref, but we don't know if contents changed, so fire event
h.set("PassThrough", "MyPassThrough");
h.set("PassThrough", "MyPassThrough");
h.set("PassThrough", "MyNewPassThrough");
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
},
testEventRegistrationThroughConstructor : function() {
// Initial Set does not fire events
var expectedEvents = ["OnInit", "AfterInit", "OnAChange", "AfterAChange"];
var actualEvents = [];
var h = this.createHost({
on: {
"AChange" : function() {
actualEvents.push("OnAChange");
},
"init" : function() {
actualEvents.push("OnInit");
}
},
after: {
"AChange" : function() {
actualEvents.push("AfterAChange");
},
"init" : function() {
actualEvents.push("AfterInit");
}
}
});
h.set("A", "Foo");
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
}
};
var basicTemplate = {
name: "Core Base Class Tests",
createHost : function(cfg) {
return new AttrHost(cfg);
},
setUp : function() {},
tearDown : function() {},
testDefault : function() {
var h = this.createHost();
Y.Assert.areEqual("AVal", h.get("A"));
Y.Assert.areEqual(undefined, h.get("B"));
Y.Assert.areEqual(undefined, h.get("C"));
Y.Assert.areEqual("DVal", h.get("D")); // Readonly
Y.Assert.areEqual("EVal", h.get("E")); // Write once, but not twice
Y.Assert.areEqual("DValEVal", h.get("DE"));
},
testConstructor : function() {
var h = this.createHost({A:"MyAVal", B:"MyBVal", C:"MyCVal", D:"MyDVal", E:"MyEVal", DE:"MyDEVal"});
h.set("C", "MyNewCVal");
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
Y.Assert.areEqual("MyAVal", h.get("A"));
Y.Assert.areEqual("MyBVal", h.get("B"));
Y.Assert.areEqual("MyCVal", h.get("C")); // Write Once, set in constructor
Y.Assert.areEqual("DVal", h.get("D")); // Read Only
Y.Assert.areEqual("MyEVal", h.get("E")); // Write Once, set in constructor
Y.Assert.areEqual("MyDEVal", h.get("DE"));
},
testSet : function() {
var h = this.createHost();
h.set("A", "MyNewAVal");
h.set("B", "MyNewBVal");
h.set("C", "MyNewCVal");
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
h.set("DE", "MyNewDEVal");
Y.Assert.areEqual("MyNewAVal", h.get("A"));
Y.Assert.areEqual("MyNewBVal", h.get("B"));
Y.Assert.areEqual("MyNewCVal", h.get("C")); // Write once, set on first set.
Y.Assert.areEqual("DVal", h.get("D")); // Read Only
Y.Assert.areEqual("EVal", h.get("E")); // Write Once
Y.Assert.areEqual("MyNewDEVal", h.get("DE"));
},
testWriteOncePostInit : function() {
var h = this.createHost();
h.set("E", "MyNewEVal");
h.set("C", "MyNewCVal");
Y.Assert.areEqual("MyNewCVal", h.get("C")); // Write Once, default value
Y.Assert.areEqual("EVal", h.get("E")); // Write Once, default value
},
testWriteOnce : function() {
var h = this.createHost({E:"MyEVal"});
h.set("E", "MyNewEVal");
Y.Assert.areEqual("MyEVal", h.get("E")); // Write Once, on init
},
testWriteOnceInitOnly : function() {
var h = this.createHost({ initOnly: "initOnlyVal"});
h.set("initOnly", "NewInitOnlyVal");
Y.Assert.areEqual("initOnlyVal", h.get("initOnly"));
},
testWriteOnceInitOnlyNotProvided : function() {
var h1 = this.createHost();
h1.set("initOnly", "InitOnlyVal");
Y.Assert.areEqual(undefined, h1.get("initOnly"));
},
testAdHocGetSet : function() {
var h = this.createHost();
Y.Assert.areEqual(undefined, h.get("AdHoc"));
h.set("AdHoc", "TestAdHoc");
Y.Assert.areEqual("TestAdHoc", h.get("AdHoc"));
h.addAttr("AdHoc", {
setter: function(val) {
return val.toUpperCase();
}
});
h.set("AdHoc", "TestAdHocConfigured");
Y.Assert.areEqual("TESTADHOCCONFIGURED", h.get("AdHoc"));
},
testReset : function() {
var h = this.createHost({A:"MyAVal", B:"MyBVal", C:"MyCVal", D:"MyDVal", E:"MyEVal", DE:"MyDEVal"});
h.set("A", "MyNewAVal");
h.set("B", "MyNewBVal");
h.set("C", "MyNewCVal");
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
h.set("DE", "MyNewDEVal");
Y.Assert.areEqual("MyNewAVal", h.get("A"));
Y.Assert.areEqual("MyNewBVal", h.get("B"));
Y.Assert.areEqual("MyCVal", h.get("C")); // Write once, set on first set.
Y.Assert.areEqual("DVal", h.get("D")); // Read Only
Y.Assert.areEqual("MyEVal", h.get("E")); // Write Once
Y.Assert.areEqual("MyNewDEVal", h.get("DE"));
h.reset("A");
h.reset("D");
Y.Assert.areEqual("MyAVal", h.get("A"));
Y.Assert.areEqual("DVal", h.get("D"));
h.reset();
Y.Assert.areEqual("MyAVal", h.get("A"));
Y.Assert.areEqual("MyBVal", h.get("B"));
Y.Assert.areEqual("MyCVal", h.get("C"));
Y.Assert.areEqual("DVal", h.get("D"));
Y.Assert.areEqual("MyEVal", h.get("E"));
Y.Assert.areEqual("MyDEVal", h.get("DE"));
},
testMassSetGet : function() {
var h = this.createHost();
h.setAttrs({
"A" : "MyNewAVal",
"B": "MyNewBVal",
"C": "MyNewCVal",
"D": "MyNewDVal",
"E": "MyNewEVal",
"DE": "MyNewDEVal",
complex: "MyNewComplexVal"
});
var expectedVals = {
A: "MyNewAVal",
B: "MyNewBVal",
C: "MyNewCVal",
D: "DVal",
E: "EVal",
DE: "MyNewDEVal",
complex: "MyNewComplexVal",
initialized:true,
destroyed:false
};
Y.Assert.areEqual(expectedVals.A, h.get("A"));
Y.Assert.areEqual(expectedVals.B, h.get("B"));
Y.Assert.areEqual(expectedVals.C, h.get("C")); // Write once, set on first set.
Y.Assert.areEqual(expectedVals.D, h.get("D")); // Read Only
Y.Assert.areEqual(expectedVals.E, h.get("E")); // Write Once
Y.Assert.areEqual(expectedVals.DE, h.get("DE"));
areObjectsReallyEqual(expectedVals, h.getAttrs());
},
testModifiedAttrs : function() {
var h = this.createHost();
h.setAttrs({
A: "MyNewAVal",
C: "MyNewCVal",
D: "MyNewDVal"
});
var expectedVals = {
A: "MyNewAVal",
initialized:true
};
areObjectsReallyEqual(expectedVals, h.getAttrs(true));
},
testValidation : function() {
var h = this.createHost();
h.set("A", "MyAVal");
Y.Assert.areEqual("MyAVal", h.get("A"));
h.set("A", 100);
Y.Assert.areEqual("MyAVal", h.get("A")); // Validation should prevent the attribute from being set
h.set("B", "two");
Y.Assert.areEqual("two", h.get("B"));
h.set("B", 2);
Y.Assert.areEqual(2, h.get("B"));
h.set("B", false);
Y.Assert.areEqual(2, h.get("B")); // Validation should prevent the attribute from being set
},
testPrivateSet : function() {
var h = this.createHost();
var expectedEvents = ["BeforeTryDAgain", "AfterTryDAgain", "BeforeTryEAgain", "Aftertryeagain"];
var actualEvents = [];
h.on("DChange", function(e) {
actualEvents.push("Before" + e.newVal);
});
h.on("EChange", function(e) {
actualEvents.push("Before" + e.newVal);
});
h.after("DChange", function(e) {
actualEvents.push("After" + e.newVal);
});
h.after("EChange", function(e) {
actualEvents.push("After" + e.newVal);
});
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
Y.Assert.areEqual("DVal", h.get("D"));
Y.Assert.areEqual("EVal", h.get("E"));
h._set("D", "TryDAgain");
h._set("E", "TryEAgain");
Y.Assert.areEqual("TryDAgain", h.get("D"));
Y.Assert.areEqual("TryEAgain", h.get("E"));
},
testComplexDefault : function() {
var h = this.createHost();
var o = {
X : {
A: 1
},
Y : {
A: 2
},
Z : {
A: 3
}
};
Y.Assert.areEqual(1, h.get("complex.X.A"));
Y.Assert.areEqual(2, h.get("complex.Y.A"));
Y.Assert.areEqual(3, h.get("complex.Z.A"));
areObjectsReallyEqual({A:1}, h.get("complex.X"));
areObjectsReallyEqual({A:2}, h.get("complex.Y"));
areObjectsReallyEqual({A:3}, h.get("complex.Z"));
var val = h.get("complex");
Y.each(val, function(v, k) {
areObjectsReallyEqual(v, o[k]);
});
},
testComplexConstructor : function() {
var h = this.createHost({
"complex.X.A": 11,
"complex.Y.A": 12,
"complex.Z.A": 13,
"complex.W.A": 14 // Does not exist, not allowed to set
});
areObjectsReallyEqual({A:11}, h.get("complex.X"));
areObjectsReallyEqual({A:12}, h.get("complex.Y"));
areObjectsReallyEqual({A:13}, h.get("complex.Z"));
Y.Assert.areEqual(undefined, h.get("complex.W"));
},
testComplexSet : function() {
var h = this.createHost();
h.set("complex.X.A", 111);
Y.Assert.areEqual(111, h.get("complex.X.A"));
h.set("complex.X.B", 112);
Y.Assert.areEqual(112, h.get("complex.X.B"));
areObjectsReallyEqual({A:111, B:112}, h.get("complex.X"));
h.set("complex.W.B", 113);
Y.Assert.areEqual(undefined, h.get("complex.W"));
Y.Assert.areEqual(undefined, h.get("complex.W.B"));
h.set("complex.Y", {B:222});
Y.Assert.areEqual(222, h.get("complex.Y.B"));
Y.Assert.areEqual(undefined, h.get("complex.Y.A"));
},
testComplexEvents : function() {
var h = this.createHost();
var expectedEvents = ["Beforecomplex.X.A", "Aftercomplex.X.A", "Beforecomplex.Y.A", "Aftercomplex.Y.A", "Beforecomplex.Y", "Aftercomplex.Y"];
var actualEvents = [];
h.on("complexChange", function(e) {
actualEvents.push("Before" + e.subAttrName);
if (e.subAttrName == "complex.X.A") {
Y.Assert.areEqual(1111, e.newVal.X.A);
areObjectsReallyEqual({A:1111}, e.newVal.X);
areObjectsReallyEqual({A:2}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y.A") {
Y.Assert.areEqual(2222, e.newVal.Y.A);
areObjectsReallyEqual({A:1111}, e.newVal.X);
areObjectsReallyEqual({A:2222}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y") {
Y.Assert.areEqual(2223, e.newVal.Y);
areObjectsReallyEqual({A:1111}, e.newVal.X);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
});
h.after("complexChange", function(e) {
actualEvents.push("After" + e.subAttrName);
if (e.subAttrName == "complex.X.A") {
Y.Assert.areEqual(1111, e.newVal.X.A);
areObjectsReallyEqual({A:1111}, e.newVal.X);
areObjectsReallyEqual({A:2}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y.A") {
Y.Assert.areEqual(2222, e.newVal.Y.A);
areObjectsReallyEqual({A:1111}, e.newVal.X);
areObjectsReallyEqual({A:2222}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y") {
Y.Assert.areEqual(2223, e.newVal.Y);
areObjectsReallyEqual({A:1111}, e.newVal.X);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
});
h.set("complex.X.A", 1111);
h.set("complex.Y.A", 2222);
h.set("complex.Y", 2223);
h.set("complex.W.A", 3333);
},
testBroadcast : function() {
var h = this.createHost();
var expectedEvents = ["On AChange Y Broadcast", "After AChange Y Broadcast", "On BChange Y Broadcast", "After BChange Y Broadcast", "On BChange YUI Broadcast", "After BChange YUI Broadcast", "On CChange", "After CChange"];
var actualEvents = [];
Y.Global.on("attrHost:AChange", function() {
actualEvents.push("On AChange YUI Broadcast");
});
Y.Global.after("attrHost:AChange", function() {
actualEvents.push("After AChange YUI Broadcast");
});
Y.on("attrHost:AChange", function() {
actualEvents.push("On AChange Y Broadcast");
});
Y.after("attrHost:AChange", function() {
actualEvents.push("After AChange Y Broadcast");
});
Y.Global.on("attrHost:BChange", function() {
actualEvents.push("On BChange YUI Broadcast");
});
Y.Global.after("attrHost:BChange", function() {
actualEvents.push("After BChange YUI Broadcast");
});
Y.on("attrHost:BChange", function() {
actualEvents.push("On BChange Y Broadcast");
});
h.on("CChange", function() {
actualEvents.push("On CChange");
});
h.after("CChange", function() {
actualEvents.push("After CChange");
});
Y.after("attrHost:BChange", function() {
actualEvents.push("After BChange Y Broadcast");
});
Y.Global.on("attrHost:CChange", function() {
actualEvents.push("On CChange YUI Broadcast");
});
Y.Global.after("attrHost:CChange", function() {
actualEvents.push("After CChange YUI Broadcast");
});
Y.on("attrHost:CChange", function() {
actualEvents.push("On CChange Y Broadcast");
});
Y.after("attrHost:CChange", function() {
actualEvents.push("After CChange Y Broadcast");
});
h.set("A", "NewA");
h.set("B", "NewB");
h.set("C", "NewC");
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
},
testInitialValidation: function() {
var h = this.createHost({A:5});
Y.Assert.areEqual("AVal", h.get("A")); // Numerical value validation failure should revert to default value
},
testModifyAttr : function() {
var h = this.createHost();
var expectedEvents = ["On AChange Y Broadcast", "After AChange Y Broadcast"]
var actualEvents = [];
Y.on("attrHost:AChange", function() {
actualEvents.push("On AChange Y Broadcast");
});
Y.after("attrHost:AChange", function() {
actualEvents.push("After AChange Y Broadcast");
});
h.set("A", "NewA");
h.modifyAttr("A", {
getter: function(val, name) {
return val.toUpperCase();
},
setter: function(val, name) {
Y.Assert.fail("Setter should not be called");
},
validator: function(val, name) {
Y.Assert.fail("Validator should not be called");
},
broadcast:0
});
h.set("A", "NewAAfterGetterBroadCast");
h.set("A", 5);
Y.Assert.areEqual("NEWAAFTERGETTERBROADCAST", h.get("A"));
h.modifyAttr("A", {
readOnly:true
});
h.set("A", "NewAAfterReadOnly");
Y.Assert.areEqual("NEWAAFTERGETTERBROADCAST", h.get("A"));
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
},
testProtect : function() {
var h = this.createHost();
var q = h._protectAttrs(AttrHost.ATTRS);
Y.Assert.areNotSame(AttrHost.ATTRS, q);
Y.Assert.areEqual(Y.dump(AttrHost.ATTRS), Y.dump(q));
q.A.newprop = "new prop value";
q.A.value = "modified value";
Y.Assert.areNotEqual(Y.dump(AttrHost.ATTRS), Y.dump(q));
}
};
basicTemplate = Y.merge(basicTemplate, sharedEventTests);
var extendedTemplate = {
name: "Core Extended Class Tests",
createHost : function(cfg) {
return new ExtendedAttrHost(cfg);
},
setUp : function() {},
tearDown : function() {},
testDefault : function() {
var h = this.createHost();
Y.Assert.areEqual("ExtAVal", h.get("A"));
Y.Assert.areEqual("ExtBVal", h.get("B"));
Y.Assert.areEqual(undefined, h.get("C"));
Y.Assert.areEqual("EXTDVAL", h.get("D"));
Y.Assert.areEqual("exteval", h.get("E"));
Y.Assert.areEqual("ExtFVal", h.get("F"));
Y.Assert.areEqual("EXTDVALexteval", h.get("DE"));
},
testConstructor : function() {
var h = this.createHost({A:"MyAVal", B:"MyBVal", C:"MyCVal", D:"MyDVal", E:"MyEVal", F:"MyFVal"});
h.set("C", "MyNewCVal");
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
Y.Assert.areEqual("MyAVal", h.get("A"));
Y.Assert.areEqual("MyBVal", h.get("B"));
Y.Assert.areEqual("MyCVal", h.get("C"));
Y.Assert.areEqual("EXTDVAL", h.get("D"));
Y.Assert.areEqual("myeval", h.get("E"));
Y.Assert.areEqual("MyFVal", h.get("F"));
Y.Assert.areEqual("EXTDVALmyeval", h.get("DE"));
},
testSet : function() {
var h = this.createHost();
h.set("A", "MyNewAVal");
h.set("B", "MyNewBVal");
h.set("C", "MyNewCVal");
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
h.set("F", "MyNewFVal");
h.set("DE", "MyNewDEVal");
Y.Assert.areEqual("MyNewAVal", h.get("A"));
Y.Assert.areEqual("MyNewBVal", h.get("B"));
Y.Assert.areEqual("MyNewCVal", h.get("C"));
Y.Assert.areEqual("EXTDVAL", h.get("D"));
Y.Assert.areEqual("exteval", h.get("E"));
Y.Assert.areEqual("MyNewFVal", h.get("F"));
Y.Assert.areEqual("MyNewDEVal", h.get("DE"));
},
testAdHocGetSet : function() {
var h = this.createHost();
Y.Assert.areEqual(undefined, h.get("AdHoc"));
h.set("AdHoc", "TestAdHoc");
Y.Assert.areEqual("TestAdHoc", h.get("AdHoc"));
},
testReset : function() {
var h = this.createHost({A:"MyAVal", B:"MyBVal", C:"MyCVal", D:"MyDVal", E:"MyEVal", F:"MyFVal", DE:"MyDEVal"});
h.set("A", "MyNewAVal");
h.set("B", "MyNewBVal");
h.set("C", "MyNewCVal");
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
h.set("F", "MyNewFVal");
h.set("DE", "MyNewDEVal");
Y.Assert.areEqual("MyNewAVal", h.get("A"));
Y.Assert.areEqual("MyNewBVal", h.get("B"));
Y.Assert.areEqual("MyCVal", h.get("C")); // Write once, set on first set.
Y.Assert.areEqual("EXTDVAL", h.get("D")); // Read Only
Y.Assert.areEqual("myeval", h.get("E")); // Write Once
Y.Assert.areEqual("MyNewFVal", h.get("F")); // Write Once
Y.Assert.areEqual("MyNewDEVal", h.get("DE"));
h.reset("A");
h.reset("D");
Y.Assert.areEqual("MyAVal", h.get("A"));
Y.Assert.areEqual("EXTDVAL", h.get("D"));
h.reset();
Y.Assert.areEqual("MyAVal", h.get("A"));
Y.Assert.areEqual("MyBVal", h.get("B"));
Y.Assert.areEqual("MyCVal", h.get("C"));
Y.Assert.areEqual("EXTDVAL", h.get("D"));
Y.Assert.areEqual("myeval", h.get("E"));
Y.Assert.areEqual("MyFVal", h.get("F"));
Y.Assert.areEqual("MyDEVal", h.get("DE"));
},
testMassSetGet : function() {
var h = this.createHost();
h.setAttrs({
"A" : "MyNewAVal",
"B": "MyNewBVal",
"C": "MyNewCVal",
"D": "MyNewDVal",
"E": "MyNewEVal",
"F": "MyNewFVal",
"DE": "MyNewDEVal",
complex: "MyNewComplexVal",
"I" : "MyNewIVal",
"PassThrough" : "MyPassThrough",
"Z" : "MyZ"
});
var expectedVals = {
A: "MyNewAVal",
B: "MyNewBVal",
C: "MyNewCVal",
D: "EXTDVAL",
E: "exteval",
F: "MyNewFVal",
DE: "MyNewDEVal",
complex: "MyNewComplexVal",
G: 35,
H: 25,
I: "MyNewIVal",
PassThrough: "MyPassThrough",
Z: "MYZ",
initialized:true,
destroyed:false
};
Y.Assert.areEqual(expectedVals.A, h.get("A"));
Y.Assert.areEqual(expectedVals.B, h.get("B"));
Y.Assert.areEqual(expectedVals.C, h.get("C")); // Write once, set on first set.
Y.Assert.areEqual(expectedVals.D, h.get("D")); // Read Only
Y.Assert.areEqual(expectedVals.E, h.get("E")); // Write Once
Y.Assert.areEqual(expectedVals.F, h.get("F"));
Y.Assert.areEqual(expectedVals.DE, h.get("DE"));
areObjectsReallyEqual(expectedVals, h.getAttrs());
},
testModifiedAttrs : function() {
var h = this.createHost();
h.setAttrs({
A: "MyNewAVal",
C: "MyNewCVal",
D: "MyNewDVal",
F: "MyNewFVal"
});
var expectedVals = {
A: "MyNewAVal",
F: "MyNewFVal",
initialized:true
};
areObjectsReallyEqual(expectedVals, h.getAttrs(true));
},
testValidation : function() {
var h = this.createHost();
h.set("A", "MyAVal");
Y.Assert.areEqual("MyAVal", h.get("A"));
h.set("A", 100);
Y.Assert.areEqual("MyAVal", h.get("A")); // Validation should prevent the attribute from being set
h.set("B", "two");
Y.Assert.areEqual("two", h.get("B"));
h.set("B", 2);
Y.Assert.areEqual("two", h.get("B")); // Validation should prevent the attribute from being set
h.set("B", true);
Y.Assert.areEqual("two", h.get("B")); // Validation should prevent the attribute from being set
h.set("F", "MyNewFVal");
Y.Assert.areEqual("MyNewFVal", h.get("F"));
h.set("F", 3);
Y.Assert.areEqual("MyNewFVal", h.get("F")); // Validation should prevent the attribute from being set
},
testPrivateSet : function() {
var h = this.createHost();
var expectedEvents = ["BeforeTryDAgain", "AfterTRYDAGAIN", "BeforeTryEAgain", "Aftertryeagain" ]; // Last entry: e.newVal is not "get" normalized
var actualEvents = [];
h.on("DChange", function(e) {
actualEvents.push("Before" + e.newVal);
});
h.on("EChange", function(e) {
actualEvents.push("Before" + e.newVal);
});
h.after("DChange", function(e) {
actualEvents.push("After" + e.newVal);
});
h.after("EChange", function(e) {
actualEvents.push("After" + e.newVal);
});
h.set("D", "MyNewDVal");
h.set("E", "MyNewEVal");
Y.Assert.areEqual("EXTDVAL", h.get("D"));
Y.Assert.areEqual("exteval", h.get("E"));
h._set("D", "TryDAgain");
h._set("E", "TryEAgain");
Y.Assert.areEqual("TRYDAGAIN", h.get("D"));
Y.Assert.areEqual("tryeagain", h.get("E"));
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
},
testComplexDefault : function() {
var h = this.createHost();
var o = {
X : {
A: 1111
},
Y : {
A: 2222
},
Z : {
A: 3
}
};
Y.Assert.areEqual(1111, h.get("complex.X.A"));
Y.Assert.areEqual(2222, h.get("complex.Y.A"));
Y.Assert.areEqual(3, h.get("complex.Z.A"));
areObjectsReallyEqual({A:1111}, h.get("complex.X"));
areObjectsReallyEqual({A:2222}, h.get("complex.Y"));
areObjectsReallyEqual({A:3}, h.get("complex.Z"));
var val = h.get("complex");
Y.each(val, function(v, k) {
areObjectsReallyEqual(v, o[k]);
});
},
testComplexConstructor : function() {
var h = this.createHost({
"complex.X.A": 11,
"complex.Y.A": 12,
"complex.Z.A": 13,
"complex.W.A": 14 // Does not exist, not allowed to set
});
areObjectsReallyEqual({A:11}, h.get("complex.X"));
areObjectsReallyEqual({A:12}, h.get("complex.Y"));
areObjectsReallyEqual({A:13}, h.get("complex.Z"));
Y.Assert.areEqual(undefined, h.get("complex.W"));
},
testComplexSet : function() {
var h = this.createHost();
h.set("complex.X.A", 111);
Y.Assert.areEqual(111, h.get("complex.X.A"));
h.set("complex.X.B", 112);
Y.Assert.areEqual(112, h.get("complex.X.B"));
areObjectsReallyEqual({A:111, B:112}, h.get("complex.X"));
h.set("complex.W.B", 113);
Y.Assert.areEqual(undefined, h.get("complex.W"));
Y.Assert.areEqual(undefined, h.get("complex.W.B"));
h.set("complex.Y", {B:222});
Y.Assert.areEqual(222, h.get("complex.Y.B"));
Y.Assert.areEqual(undefined, h.get("complex.Y.A"));
},
testComplexEvents : function() {
var h = this.createHost();
var expectedEvents = ["Beforecomplex.X.A", "Aftercomplex.X.A", "Beforecomplex.Y.A", "Aftercomplex.Y.A", "Beforecomplex.Y", "Aftercomplex.Y"];
var actualEvents = [];
h.on("complexChange", function(e) {
actualEvents.push("Before" + e.subAttrName);
if (e.subAttrName == "complex.X.A") {
Y.Assert.areEqual(11111, e.newVal.X.A);
areObjectsReallyEqual({A:11111}, e.newVal.X);
areObjectsReallyEqual({A:2222}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y.A") {
Y.Assert.areEqual(22222, e.newVal.Y.A);
areObjectsReallyEqual({A:11111}, e.newVal.X);
areObjectsReallyEqual({A:22222}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y") {
Y.Assert.areEqual(22233, e.newVal.Y);
areObjectsReallyEqual({A:11111}, e.newVal.X);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
});
h.after("complexChange", function(e) {
actualEvents.push("After" + e.subAttrName);
if (e.subAttrName == "complex.X.A") {
Y.Assert.areEqual(11111, e.newVal.X.A);
areObjectsReallyEqual({A:11111}, e.newVal.X);
areObjectsReallyEqual({A:2222}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y.A") {
Y.Assert.areEqual(22222, e.newVal.Y.A);
areObjectsReallyEqual({A:11111}, e.newVal.X);
areObjectsReallyEqual({A:22222}, e.newVal.Y);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
if (e.subAttrName == "complex.Y") {
Y.Assert.areEqual(22233, e.newVal.Y);
areObjectsReallyEqual({A:11111}, e.newVal.X);
areObjectsReallyEqual({A:3}, e.newVal.Z);
}
});
h.set("complex.X.A", 11111);
h.set("complex.Y.A", 22222);
h.set("complex.Y", 22233);
h.set("complex.W.A", 33333);
},
testOnDemandInit : function() {
var h = this.createHost();
Y.Assert.areEqual(35, h.get("G"));
Y.Assert.areEqual(25, h.get("H"));
},
testGetterSetterValidatorNameArg : function() {
var h = this.createHost();
h.set("I.a", 6);
h.set("I", {a:7, b:8});
},
testBroadcast : function() {
var h = this.createHost();
var expectedEvents = ["On AChange Y Broadcast", "After AChange Y Broadcast", "On BChange Y Broadcast", "After BChange Y Broadcast", "On BChange YUI Broadcast", "After BChange YUI Broadcast", "On CChange", "After CChange"];
var actualEvents = [];
Y.Global.on("extendedAttrHost:AChange", function() {
actualEvents.push("On AChange YUI Broadcast");
});
Y.Global.after("extendedAttrHost:AChange", function() {
actualEvents.push("After AChange YUI Broadcast");
});
Y.on("extendedAttrHost:AChange", function() {
actualEvents.push("On AChange Y Broadcast");
});
Y.after("extendedAttrHost:AChange", function() {
actualEvents.push("After AChange Y Broadcast");
});
// ---
Y.Global.on("extendedAttrHost:BChange", function() {
actualEvents.push("On BChange YUI Broadcast");
});
Y.Global.after("extendedAttrHost:BChange", function() {
actualEvents.push("After BChange YUI Broadcast");
});
Y.on("extendedAttrHost:BChange", function() {
actualEvents.push("On BChange Y Broadcast");
});
Y.after("extendedAttrHost:BChange", function() {
actualEvents.push("After BChange Y Broadcast");
});
// --
h.on("CChange", function() {
actualEvents.push("On CChange");
});
h.after("CChange", function() {
actualEvents.push("After CChange");
});
Y.Global.on("extendedAttrHost:CChange", function() {
actualEvents.push("On CChange YUI Broadcast");
});
Y.Global.after("extendedAttrHost:CChange", function() {
actualEvents.push("After CChange YUI Broadcast");
});
Y.on("extendedAttrHost:CChange", function() {
actualEvents.push("On CChange Y Broadcast");
});
Y.after("extendedAttrHost:CChange", function() {
actualEvents.push("After CChange Y Broadcast");
});
h.set("A", "NewA");
h.set("B", "NewB");
h.set("C", "NewC");
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
},
testModifyAttr : function() {
var h = this.createHost();
var expectedEvents = ["On AChange Y Broadcast", "After AChange Y Broadcast"]
var actualEvents = [];
Y.on("extendedAttrHost:AChange", function() {
actualEvents.push("On AChange Y Broadcast");
});
Y.after("extendedAttrHost:AChange", function() {
actualEvents.push("After AChange Y Broadcast");
});
h.set("A", "NewA");
h.modifyAttr("A", {
getter: function(val, name) {
return val.toUpperCase();
},
setter: function(val, name) {
Y.Assert.fail("Setter should not be called");
},
validator: function(val, name) {
Y.Assert.fail("Validator should not be called");
},
broadcast:0
});
h.set("A", "NewAAfterGetterBroadCast");
h.set("A", 5);
Y.Assert.areEqual("NEWAAFTERGETTERBROADCAST", h.get("A"));
h.modifyAttr("A", {
readOnly:true
});
h.set("A", "NewAAfterReadOnly");
Y.Assert.areEqual("NEWAAFTERGETTERBROADCAST", h.get("A"));
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
},
testEventSameValueExt : function() {
var h = this.createHost();
var expectedEvents = ["BeforeZChange", "AfterZChange", "BeforeZChange", "AfterZChange"];
var actualEvents = [];
h.on("ZChange", function() {
actualEvents.push("BeforeZChange");
});
h.after("ZChange", function() {
actualEvents.push("AfterZChange");
});
h.set("Z", "MyZ");
h.set("Z", "MYZ");
Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents);
}
};
extendedTemplate = Y.merge(extendedTemplate, sharedEventTests);
var perfTemplate = {
name: "Performance Tests",
testTimeConstruction: function() {
var start, end, n = 20, t, i;
start = new Date().getTime();
for (i = 0; i < n; i++) {
t = new Test(null, false);
t.getAttrs();
t = null;
}
end = new Date().getTime();
Y.log("Construction Time Populated (upfront): " + ((end-start)/n), "perf");
start = new Date().getTime();
for (i = 0; i < n; i++) {
t = new Test();
t.getAttrs();
t = null;
}
end = new Date().getTime();
Y.log("Construction Time Populated (lazy): " + ((end-start)/n), "perf");
start = new Date().getTime();
for (i = 0; i < n; i++) {
t = new Test(null, false);
t = null;
}
end = new Date().getTime();
Y.log("Construction Time (upfront): " + ((end-start)/n), "perf");
start = new Date().getTime();
for (i = 0; i < n; i++) {
t = new Test();
t = null;
}
end = new Date().getTime();
var time = (end-start)/n;
var expectedTime = (Y.UA.ie && Y.UA.ie <= 6) ? 15 : 10;
Y.log("Construction Time (lazy): " + time, "perf");
start = new Date().getTime();
for (i = 0; i < n; i++) {
t = new Test(null, true, true);
t = null;
}
end = new Date().getTime();
Y.log("Construction Time (lazy and silent init): " + ((end-start)/n), "perf");
Y.Assert.isTrue((time < expectedTime));
},
testStateForPerfSwitches : function() {
// Lazy
t = new Test();
var x = t.getAttrs();
// Non Lazy (Upfront)
t = new Test(null, false);
var y = t.getAttrs();
// Lazy and Silent
t = new Test(null, true, true);
var z = t.getAttrs();
Y.Assert.areEqual(Y.dump(x), Y.dump(y), "Lazy vs. Upfront: attr state is not equal");
Y.Assert.areEqual(Y.dump(y), Y.dump(z), "Upfront vs. Lazy and Silent: attr state is not equal");
}
}
var suite = new Y.Test.Suite({name:"Attribute Unit Tests"});
suite.add(new Y.Test.Case(basicTemplate));
suite.add(new Y.Test.Case(extendedTemplate));
suite.add(new Y.Test.Case(basicTemplate));
suite.add(new Y.Test.Case(extendedTemplate)); // run twice, just to make sure static class state not modified
Y.Test.Runner.add(suite);
Y.Test.Runner.setName("Attribute Tests");
Y.Test.Runner.disableLogging();
Y.Test.Runner.run();
var console;
Y.one("#btnRun").set("disabled", false).on("click", function() {
if (!console) {
//create the console
console = new Y.Console({
width:"100%",
height:"95%",
id:"console",
verbose : false,
printTimeout: 0,
newestOnTop : false,
entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
'<span class="{entry_cat_class}">{label}</span>'+
'<span class="{entry_content_class}">{message}</span>'+
'</pre>',
render:true
});
var perfSuite = new Y.Test.Suite({name:"Attribute Performance Tests"});
perfSuite.add(new Y.Test.Case(perfTemplate));
Y.Test.Runner.add(perfSuite);
}
Y.Test.Runner.enableLogging();
Y.Test.Runner.run();
});
});
</script>
</head>
<body class="yui3-skin-sam">
<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
</body>
</html>