~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/event/tests/event-synthetic-tests.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('event-synthetic-tests', function(Y) {
2
 
 
3
 
Y.Node.prototype.click = function (options) {
4
 
    Y.Event.simulate(this._node, 'click', options);
5
 
};
6
 
Y.NodeList.importMethod(Y.Node.prototype, 'click');
7
 
 
8
 
 
9
 
 
10
 
var suite = new Y.Test.Suite("Y.SyntheticEvent"),
11
 
    areSame = Y.Assert.areSame;
12
 
 
13
 
function initTestbed() {
14
 
    var testbed = Y.one('#testbed'),
15
 
        body;
16
 
 
17
 
    if (!testbed) {
18
 
        body = Y.one('body');
19
 
        testbed = body.create('<div id="testbed"></div>');
20
 
        body.prepend(testbed);
21
 
    }
22
 
 
23
 
    testbed.setContent(
24
 
'<div id="outer">' +
25
 
    '<button id="button1">Button 1 text</button>' +
26
 
    '<ul class="nested">' +
27
 
        '<li id="item1">Item 1</li>' +
28
 
        '<li id="item2" class="nested">Item 2</li>' +
29
 
        '<li id="item3"><p>Item 3</p></li>' +
30
 
    '</ul>' +
31
 
    '<div id="inner">' +
32
 
        '<p id="p1_no">no</p>' +
33
 
        '<p id="p2_yes">yes</p>' +
34
 
        '<div id="inner_1">' +
35
 
            '<p id="inner_1_p1_no"><em>no</em></p>' +
36
 
            '<p id="inner_1_p2_yes">yes</p>' +
37
 
        '</div>' +
38
 
        '<p id="p3_no">no</p>' +
39
 
    '</div>' +
40
 
'</div>');
41
 
}
42
 
 
43
 
function initSynth() {
44
 
    Y.Event.define('synth', {
45
 
        on: function (node, sub, notifier, filter) {
46
 
            var method = (filter) ? 'delegate' : 'on';
47
 
 
48
 
            sub._handle = node[method]('click',
49
 
                Y.bind(notifier.fire, notifier), filter);
50
 
        },
51
 
 
52
 
        delegate: function () {
53
 
            this.on.apply(this, arguments);
54
 
        },
55
 
 
56
 
        detach: function (node, sub) {
57
 
            sub._handle.detach();
58
 
        },
59
 
 
60
 
        detachDelegate: function () {
61
 
            this.detach.apply(this, arguments);
62
 
        }
63
 
    }, true);
64
 
}
65
 
 
66
 
function setUp() {
67
 
    initTestbed();
68
 
    initSynth();
69
 
}
70
 
 
71
 
function destroyTestbed() {
72
 
    var testbed = Y.one('#testbed');
73
 
    if (testbed) {
74
 
        testbed.purge(true).remove();
75
 
    }
76
 
}
77
 
 
78
 
function undefineSynth() {
79
 
    delete Y.Node.DOM_EVENTS.synth;
80
 
    delete Y.Env.evt.plugins.synth;
81
 
}
82
 
 
83
 
function tearDown() {
84
 
    undefineSynth();
85
 
    destroyTestbed();
86
 
}
87
 
 
88
 
/******************************************************************************/
89
 
/******************************  Tests begin here  ****************************/
90
 
/******************************************************************************/
91
 
 
92
 
suite.add(new Y.Test.Case({
93
 
    name: "Y.Event.define",
94
 
 
95
 
    "Y.Event.define(name) should add to DOM_EVENTS": function () {
96
 
        delete Y.Node.DOM_EVENTS.mouseover;
97
 
        
98
 
        Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseover);
99
 
 
100
 
        Y.Event.define('mouseover');
101
 
 
102
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseover);
103
 
    },
104
 
 
105
 
    "Y.Event.define([name1, name2]) should add to DOM_EVENTS": function () {
106
 
        delete Y.Node.DOM_EVENTS.mouseover;
107
 
        delete Y.Node.DOM_EVENTS.mouseout;
108
 
        
109
 
        Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseover);
110
 
        Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseout);
111
 
 
112
 
        Y.Event.define(['mouseover', 'mouseout']);
113
 
 
114
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseover);
115
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseout);
116
 
    },
117
 
 
118
 
    "Y.Event.define(type, {...}) should register a new synth in DOM_EVENTS": function () {
119
 
        Y.Event.define('synth', {
120
 
            index: 0
121
 
        });
122
 
 
123
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth);
124
 
        Y.Assert.isNotUndefined(Y.Env.evt.plugins.synth);
125
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth.eventDef);
126
 
        areSame(0, Y.Node.DOM_EVENTS.synth.eventDef.index);
127
 
    },
128
 
 
129
 
    "Subsequent Y.Event.define() should not overwrite existing synth": function () {
130
 
        Y.Event.define('synth', {
131
 
            index: 1
132
 
        });
133
 
 
134
 
        areSame(0, Y.Node.DOM_EVENTS.synth.eventDef.index);
135
 
    },
136
 
 
137
 
    "Y.Event.define(..., true) should overwrite existing synth": function () {
138
 
        Y.Event.define('synth', {
139
 
            index: 2
140
 
        }, true);
141
 
 
142
 
        areSame(2, Y.Node.DOM_EVENTS.synth.eventDef.index);
143
 
    },
144
 
 
145
 
    "Y.Event.define({ type: ...}) should register a new synth in DOM_EVENTS": function () {
146
 
        delete Y.Node.DOM_EVENTS.synth;
147
 
 
148
 
        Y.Event.define({
149
 
            type: 'synth',
150
 
            index: 3
151
 
        });
152
 
 
153
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth);
154
 
        Y.Assert.isNotUndefined(Y.Env.evt.plugins.synth);
155
 
        Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth.eventDef);
156
 
        areSame(Y.Node.DOM_EVENTS.synth, Y.Env.evt.plugins.synth);
157
 
        areSame(3, Y.Node.DOM_EVENTS.synth.eventDef.index);
158
 
    },
159
 
 
160
 
    "Y.Event.define({...}, true) should overwrite existing synth": function () {
161
 
        Y.Event.define({
162
 
            type: 'synth',
163
 
            index: 2
164
 
        }, true);
165
 
 
166
 
        areSame(2, Y.Node.DOM_EVENTS.synth.eventDef.index);
167
 
    }
168
 
 
169
 
}));
170
 
 
171
 
suite.add(new Y.Test.Case({
172
 
    name: "Y.on",
173
 
 
174
 
    setUp: setUp,
175
 
    tearDown: tearDown,
176
 
 
177
 
    "test Y.on('synth', fn, node)": function () {
178
 
        var target = Y.one("#item3"),
179
 
            type, currentTarget, thisObj;
180
 
 
181
 
        Y.on('synth', function (e) {
182
 
            type = e.type;
183
 
            currentTarget = e.currentTarget;
184
 
            thisObj = this;
185
 
        }, target);
186
 
 
187
 
        target.click();
188
 
 
189
 
        areSame('synth', type);
190
 
        areSame(target, currentTarget);
191
 
        areSame(target, thisObj);
192
 
    },
193
 
 
194
 
    "test Y.on('synth', fn, node, thisObj)": function () {
195
 
        var target = Y.one("#item3"),
196
 
            obj = { foo: 'bar' },
197
 
            type, currentTarget, thisObj, foo;
198
 
 
199
 
        Y.on('synth', function (e) {
200
 
            type = e.type;
201
 
            currentTarget = e.currentTarget;
202
 
            thisObj = this;
203
 
            foo = this.foo;
204
 
        }, target, obj);
205
 
 
206
 
        target.click();
207
 
 
208
 
        areSame('synth', type);
209
 
        areSame(target, currentTarget);
210
 
        areSame(obj, thisObj);
211
 
        areSame(obj.foo, thisObj.foo);
212
 
    },
213
 
 
214
 
    "test Y.on('synth', fn, node, thisObj, arg)": function () {
215
 
        var target = Y.one("#item3"),
216
 
            obj = { foo: 'bar' },
217
 
            type, currentTarget, thisObj, foo, arg;
218
 
 
219
 
        Y.on('synth', function (e, x) {
220
 
            type = e.type;
221
 
            currentTarget = e.currentTarget;
222
 
            thisObj = this;
223
 
            foo = this.foo;
224
 
            arg = x;
225
 
        }, target, obj, 'arg!');
226
 
 
227
 
        target.click();
228
 
 
229
 
        areSame('synth', type);
230
 
        areSame(target, currentTarget);
231
 
        areSame(obj, thisObj);
232
 
        areSame(obj.foo, thisObj.foo);
233
 
        areSame('arg!', arg);
234
 
    },
235
 
 
236
 
    "test Y.on('synth', fn, node, null, arg)": function () {
237
 
        var target = Y.one("#item3"),
238
 
            type, currentTarget, thisObj, arg;
239
 
 
240
 
        Y.on('synth', function (e, x) {
241
 
            type = e.type;
242
 
            currentTarget = e.currentTarget;
243
 
            thisObj = this;
244
 
            arg = x;
245
 
        }, target, null, 'arg!');
246
 
 
247
 
        target.click();
248
 
 
249
 
        areSame('synth', type);
250
 
        areSame(target, currentTarget);
251
 
        areSame(target, thisObj);
252
 
        areSame('arg!', arg);
253
 
    },
254
 
 
255
 
    "test Y.on('synth', fn, el)": function () {
256
 
        var targetEl = Y.DOM.byId('item3'),
257
 
            target = Y.one(targetEl),
258
 
            type, currentTarget, thisObj;
259
 
 
260
 
        Y.on('synth', function (e) {
261
 
            type = e.type;
262
 
            currentTarget = e.currentTarget;
263
 
            thisObj = this;
264
 
        }, targetEl);
265
 
 
266
 
        target.click();
267
 
 
268
 
        areSame('synth', type);
269
 
        areSame(target, currentTarget);
270
 
        areSame(target, thisObj);
271
 
    },
272
 
 
273
 
    "test Y.on('synth', fn, el, thisObj)": function () {
274
 
        var targetEl = Y.DOM.byId("item3"),
275
 
            target = Y.one(targetEl),
276
 
            obj = { foo: 'bar' },
277
 
            type, currentTarget, thisObj, foo;
278
 
 
279
 
        Y.on('synth', function (e) {
280
 
            type = e.type;
281
 
            currentTarget = e.currentTarget;
282
 
            thisObj = this;
283
 
            foo = this.foo;
284
 
        }, targetEl, obj);
285
 
 
286
 
        target.click();
287
 
 
288
 
        areSame('synth', type);
289
 
        areSame(target, currentTarget);
290
 
        areSame(obj, thisObj);
291
 
        areSame(obj.foo, thisObj.foo);
292
 
    },
293
 
 
294
 
    "test Y.on('synth', fn, el, thisObj, arg)": function () {
295
 
        var targetEl = Y.DOM.byId("item3"),
296
 
            target = Y.one(targetEl),
297
 
            obj = { foo: 'bar' },
298
 
            type, currentTarget, thisObj, foo, arg;
299
 
 
300
 
        Y.on('synth', function (e, x) {
301
 
            type = e.type;
302
 
            currentTarget = e.currentTarget;
303
 
            thisObj = this;
304
 
            foo = this.foo;
305
 
            arg = x;
306
 
        }, targetEl, obj, 'arg!');
307
 
 
308
 
        target.click();
309
 
 
310
 
        areSame('synth', type);
311
 
        areSame(target, currentTarget);
312
 
        areSame(obj, thisObj);
313
 
        areSame(obj.foo, thisObj.foo);
314
 
        areSame('arg!', arg);
315
 
    },
316
 
 
317
 
    "test Y.on('synth', fn, el, null, arg)": function () {
318
 
        var targetEl = Y.DOM.byId("item3"),
319
 
            target = Y.one(targetEl),
320
 
            type, currentTarget, thisObj, arg;
321
 
 
322
 
        Y.on('synth', function (e, x) {
323
 
            type = e.type;
324
 
            currentTarget = e.currentTarget;
325
 
            thisObj = this;
326
 
            arg = x;
327
 
        }, targetEl, null, 'arg!');
328
 
 
329
 
        target.click();
330
 
 
331
 
        areSame('synth', type);
332
 
        areSame(target, currentTarget);
333
 
        areSame(target, thisObj);
334
 
        areSame('arg!', arg);
335
 
    },
336
 
 
337
 
    "test Y.on('synth', fn, selectorOne)": function () {
338
 
        var target = Y.one('#item3'),
339
 
            type, currentTarget, thisObj;
340
 
 
341
 
        Y.on('synth', function (e) {
342
 
            type = e.type;
343
 
            currentTarget = e.currentTarget;
344
 
            thisObj = this;
345
 
        }, '#item3');
346
 
 
347
 
        target.click();
348
 
 
349
 
        areSame('synth', type);
350
 
        areSame(target, currentTarget);
351
 
        areSame(target, thisObj);
352
 
    },
353
 
 
354
 
    "test Y.on('synth', fn, selectorOne, thisObj)": function () {
355
 
        var target = Y.one('#item3'),
356
 
            obj = { foo: 'bar' },
357
 
            type, currentTarget, thisObj, foo;
358
 
 
359
 
        Y.on('synth', function (e) {
360
 
            type = e.type;
361
 
            currentTarget = e.currentTarget;
362
 
            thisObj = this;
363
 
            foo = this.foo;
364
 
        }, '#item3', obj);
365
 
 
366
 
        target.click();
367
 
 
368
 
        areSame('synth', type);
369
 
        areSame(target, currentTarget);
370
 
        areSame(obj, thisObj);
371
 
        areSame(obj.foo, thisObj.foo);
372
 
    },
373
 
 
374
 
    "test Y.on('synth', fn, selectorOne, thisObj, arg)": function () {
375
 
        var target = Y.one('#item3'),
376
 
            obj = { foo: 'bar' },
377
 
            type, currentTarget, thisObj, foo, arg;
378
 
 
379
 
        Y.on('synth', function (e, x) {
380
 
            type = e.type;
381
 
            currentTarget = e.currentTarget;
382
 
            thisObj = this;
383
 
            foo = this.foo;
384
 
            arg = x;
385
 
        }, '#item3', obj, 'arg!');
386
 
 
387
 
        target.click();
388
 
 
389
 
        areSame('synth', type);
390
 
        areSame(target, currentTarget);
391
 
        areSame(obj, thisObj);
392
 
        areSame(obj.foo, thisObj.foo);
393
 
        areSame('arg!', arg);
394
 
    },
395
 
 
396
 
    "test Y.on('synth', fn, selectorOne, null, arg)": function () {
397
 
        var target = Y.one('#item3'),
398
 
            type, currentTarget, thisObj, arg;
399
 
 
400
 
        Y.on('synth', function (e, x) {
401
 
            type = e.type;
402
 
            currentTarget = e.currentTarget;
403
 
            thisObj = this;
404
 
            arg = x;
405
 
        }, '#item3', null, 'arg!');
406
 
 
407
 
        target.click();
408
 
 
409
 
        areSame('synth', type);
410
 
        areSame(target, currentTarget);
411
 
        areSame(target, thisObj);
412
 
        areSame('arg!', arg);
413
 
    },
414
 
 
415
 
    "test Y.on('synth', fn, selectorMultiple)": function () {
416
 
        var item1 = Y.one('#item1'),
417
 
            item2 = Y.one('#item2'),
418
 
            item3 = Y.one('#item3'),
419
 
            type = [],
420
 
            currentTarget = [],
421
 
            thisObj = [];
422
 
 
423
 
        Y.on('synth', function (e) {
424
 
            type.push(e.type);
425
 
            currentTarget.push(e.currentTarget);
426
 
            thisObj.push(this);
427
 
        }, '#outer li');
428
 
 
429
 
        item1.click();
430
 
        item2.click();
431
 
        item3.click();
432
 
 
433
 
        Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
434
 
        Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
435
 
        Y.ArrayAssert.itemsAreSame([item1, item2, item3], thisObj);
436
 
    },
437
 
 
438
 
    "test Y.on('synth', fn, selectorMultiple, thisObj)": function () {
439
 
        var item1 = Y.one('#item1'),
440
 
            item2 = Y.one('#item2'),
441
 
            item3 = Y.one('#item3'),
442
 
            obj  = { foo: 'bar' },
443
 
            type = [],
444
 
            currentTarget = [],
445
 
            thisObj = [],
446
 
            foo = [];
447
 
 
448
 
        Y.on('synth', function (e) {
449
 
            type.push(e.type);
450
 
            currentTarget.push(e.currentTarget);
451
 
            thisObj.push(this);
452
 
            foo.push(this.foo);
453
 
        }, '#outer li', obj);
454
 
 
455
 
        item1.click();
456
 
        item2.click();
457
 
        item3.click();
458
 
 
459
 
        Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
460
 
        Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
461
 
        Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
462
 
        Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
463
 
    },
464
 
 
465
 
    "test Y.on('synth', fn, selectorMultiple, thisObj, arg)": function () {
466
 
        var item1 = Y.one('#item1'),
467
 
            item2 = Y.one('#item2'),
468
 
            item3 = Y.one('#item3'),
469
 
            obj  = { foo: 'bar' },
470
 
            type = [],
471
 
            currentTarget = [],
472
 
            thisObj = [],
473
 
            foo = [],
474
 
            arg = [];
475
 
 
476
 
        Y.on('synth', function (e, x) {
477
 
            type.push(e.type);
478
 
            currentTarget.push(e.currentTarget);
479
 
            thisObj.push(this);
480
 
            foo.push(this.foo);
481
 
            arg.push(x);
482
 
        }, '#outer li', obj, 'arg!');
483
 
 
484
 
        item1.click();
485
 
        item2.click();
486
 
        item3.click();
487
 
 
488
 
        Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
489
 
        Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
490
 
        Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
491
 
        Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
492
 
        Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
493
 
    },
494
 
 
495
 
    "test Y.on('synth', fn, selectorMultiple, null, arg)": function () {
496
 
        var item1 = Y.one('#item1'),
497
 
            item2 = Y.one('#item2'),
498
 
            item3 = Y.one('#item3'),
499
 
            type = [],
500
 
            currentTarget = [],
501
 
            thisObj = [],
502
 
            arg = [];
503
 
 
504
 
        Y.on('synth', function (e, x) {
505
 
            type.push(e.type);
506
 
            currentTarget.push(e.currentTarget);
507
 
            thisObj.push(this);
508
 
            arg.push(x);
509
 
        }, '#outer li', null, 'arg!');
510
 
 
511
 
        item1.click();
512
 
        item2.click();
513
 
        item3.click();
514
 
 
515
 
        Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
516
 
        Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
517
 
        Y.ArrayAssert.itemsAreSame([item1, item2, item3], thisObj);
518
 
        Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
519
 
    },
520
 
 
521
 
    "test Y.on('synth', fn, notYetAvailable)": function () {
522
 
        var inner = Y.one('#inner'),
523
 
            test = this,
524
 
            type = [],
525
 
            currentTarget = [],
526
 
            thisObj = [];
527
 
 
528
 
        inner.all('#p4').remove();
529
 
 
530
 
        Y.on('synth', function (e) {
531
 
            type = e.type;
532
 
            currentTarget = e.currentTarget;
533
 
            thisObj = this;
534
 
        }, '#p4');
535
 
 
536
 
        inner.append("<p id='p4'>Added</p>");
537
 
 
538
 
        // This is a tainted test because it's using a different synthetic
539
 
        // event to test that the synthetic event infrastructure is working
540
 
        // properly. The other option is to use Y.later, but that opens a race
541
 
        // condition.  The test is left in place because something is better
542
 
        // than nothing.
543
 
        Y.on("available", function () {
544
 
            test.resume(function () {
545
 
                var p4 = inner.one('#p4');
546
 
                if (p4) {
547
 
                    p4.click();
548
 
                    areSame('synth', type);
549
 
                    areSame(p4, currentTarget);
550
 
                    areSame(p4, thisObj);
551
 
                } else {
552
 
                    Y.Assert.fail("Something is wrong with onAvailable");
553
 
                }
554
 
            });
555
 
        }, '#p4');
556
 
 
557
 
        test.wait();
558
 
    },
559
 
 
560
 
    "test Y.on('synth', fn, notYetAvailable, thisObj)": function () {
561
 
        var inner = Y.one('#inner'),
562
 
            test = this,
563
 
            obj = { foo: 'bar' },
564
 
            type, currentTarget, thisObj, foo;
565
 
 
566
 
        inner.all('#p4').remove();
567
 
 
568
 
        Y.on('synth', function (e) {
569
 
            type = e.type;
570
 
            currentTarget = e.currentTarget;
571
 
            thisObj = this;
572
 
            foo = this.foo;
573
 
        }, '#p4', obj);
574
 
 
575
 
        inner.append("<p id='p4'>Added</p>");
576
 
 
577
 
        // This is a tainted test because it's using a different synthetic
578
 
        // event to test that the synthetic event infrastructure is working
579
 
        // properly. The other option is to use Y.later, but that opens a race
580
 
        // condition.  The test is left in place because something is better
581
 
        // than nothing.
582
 
        Y.on("available", function () {
583
 
            test.resume(function () {
584
 
                var p4 = inner.one('#p4');
585
 
                if (p4) {
586
 
                    p4.click();
587
 
                    areSame('synth', type);
588
 
                    areSame(p4, currentTarget);
589
 
                    areSame(obj, thisObj);
590
 
                    areSame('bar', foo);
591
 
                } else {
592
 
                    Y.Assert.fail("Something is wrong with onAvailable");
593
 
                }
594
 
            });
595
 
        }, '#p4');
596
 
 
597
 
        test.wait();
598
 
    },
599
 
 
600
 
    "test Y.on('synth', fn, notYetAvailable, thisObj, arg)": function () {
601
 
        var inner = Y.one('#inner'),
602
 
            test = this,
603
 
            obj = { foo: 'bar' },
604
 
            type, currentTarget, thisObj, foo, arg;
605
 
 
606
 
        inner.all('#p4').remove();
607
 
 
608
 
        Y.on('synth', function (e, x) {
609
 
            type = e.type;
610
 
            currentTarget = e.currentTarget;
611
 
            thisObj = this;
612
 
            foo = this.foo;
613
 
            arg = x;
614
 
        }, '#p4', obj, 'arg!');
615
 
 
616
 
        inner.append("<p id='p4'>Added</p>");
617
 
 
618
 
        // This is a tainted test because it's using a different synthetic
619
 
        // event to test that the synthetic event infrastructure is working
620
 
        // properly. The other option is to use Y.later, but that opens a race
621
 
        // condition.  The test is left in place because something is better
622
 
        // than nothing.
623
 
        Y.on("available", function () {
624
 
            test.resume(function () {
625
 
                var p4 = inner.one('#p4');
626
 
                if (p4) {
627
 
                    p4.click();
628
 
                    areSame('synth', type);
629
 
                    areSame(p4, currentTarget);
630
 
                    areSame(obj, thisObj);
631
 
                    areSame('bar', foo);
632
 
                    areSame('arg!', arg);
633
 
                } else {
634
 
                    Y.Assert.fail("Something is wrong with onAvailable");
635
 
                }
636
 
            });
637
 
        }, '#p4');
638
 
 
639
 
        test.wait();
640
 
    },
641
 
 
642
 
    "test Y.on('synth', fn, notYetAvailable, null, arg)": function () {
643
 
        var inner = Y.one('#inner'),
644
 
            test = this,
645
 
            type, currentTarget, thisObj, arg;
646
 
 
647
 
        inner.all('#p4').remove();
648
 
 
649
 
        Y.on('synth', function (e, x) {
650
 
            type = e.type;
651
 
            currentTarget = e.currentTarget;
652
 
            thisObj = this;
653
 
            arg = x;
654
 
        }, '#p4', null, 'arg!');
655
 
 
656
 
        inner.append("<p id='p4'>Added</p>");
657
 
 
658
 
        // This is a tainted test because it's using a different synthetic
659
 
        // event to test that the synthetic event infrastructure is working
660
 
        // properly. The other option is to use Y.later, but that opens a race
661
 
        // condition.  The test is left in place because something is better
662
 
        // than nothing.
663
 
        Y.on("available", function () {
664
 
            test.resume(function () {
665
 
                var p4 = inner.one('#p4');
666
 
                if (p4) {
667
 
                    p4.click();
668
 
                    areSame('synth', type);
669
 
                    areSame(p4, currentTarget);
670
 
                    areSame(p4, thisObj);
671
 
                    areSame('arg!', arg);
672
 
                } else {
673
 
                    Y.Assert.fail("Something is wrong with onAvailable");
674
 
                }
675
 
            });
676
 
        }, '#p4');
677
 
 
678
 
        test.wait();
679
 
    },
680
 
 
681
 
    "test Y.on('synth', fn) defaults to window": function (){
682
 
        var handle = Y.on('synth', function (e) {});
683
 
 
684
 
        areSame(Y.one(Y.config.win), handle.sub.node);
685
 
 
686
 
        handle.detach();
687
 
    }
688
 
 
689
 
}));
690
 
 
691
 
suite.add(new Y.Test.Case({
692
 
    name: 'node.on',
693
 
 
694
 
    setUp: setUp,
695
 
    tearDown: tearDown,
696
 
 
697
 
    "test node.on(x, fn)": function () {
698
 
        var target = Y.one("#item3"),
699
 
            type, currentTarget, thisObj;
700
 
 
701
 
        target.on('synth', function (e) {
702
 
            type = e.type;
703
 
            currentTarget = e.currentTarget;
704
 
            thisObj = this;
705
 
        });
706
 
 
707
 
        target.click();
708
 
 
709
 
        areSame('synth', type);
710
 
        areSame(target, currentTarget);
711
 
        areSame(target, thisObj);
712
 
    },
713
 
 
714
 
    "test node.on(x, fn, thisObj)": function () {
715
 
        var target = Y.one("#item3"),
716
 
            obj = { foo: 'bar' },
717
 
            type, currentTarget, thisObj, foo;
718
 
 
719
 
        target.on('synth', function (e) {
720
 
            type = e.type;
721
 
            currentTarget = e.currentTarget;
722
 
            thisObj = this;
723
 
            foo = this.foo;
724
 
        }, obj);
725
 
 
726
 
        target.click();
727
 
 
728
 
        areSame('synth', type);
729
 
        areSame(target, currentTarget);
730
 
        areSame(obj, thisObj);
731
 
        areSame(obj.foo, thisObj.foo);
732
 
    },
733
 
 
734
 
    "test node.on(x, fn, thisObj, arg)": function () {
735
 
        var target = Y.one("#item3"),
736
 
            obj = { foo: 'bar' },
737
 
            type, currentTarget, thisObj, foo, arg;
738
 
 
739
 
        target.on('synth', function (e, x) {
740
 
            type = e.type;
741
 
            currentTarget = e.currentTarget;
742
 
            thisObj = this;
743
 
            foo = this.foo;
744
 
            arg = x;
745
 
        }, obj, 'arg!');
746
 
 
747
 
        target.click();
748
 
 
749
 
        areSame('synth', type);
750
 
        areSame(target, currentTarget);
751
 
        areSame(obj, thisObj);
752
 
        areSame(obj.foo, thisObj.foo);
753
 
        areSame('arg!', arg);
754
 
    },
755
 
 
756
 
    "test node.on(x, fn, null, arg)": function () {
757
 
        var target = Y.one("#item3"),
758
 
            type, currentTarget, thisObj, arg;
759
 
 
760
 
        target.on('synth', function (e, x) {
761
 
            type = e.type;
762
 
            currentTarget = e.currentTarget;
763
 
            thisObj = this;
764
 
            arg = x;
765
 
        }, null, 'arg!');
766
 
 
767
 
        target.click();
768
 
 
769
 
        areSame('synth', type);
770
 
        areSame(target, currentTarget);
771
 
        areSame(target, thisObj);
772
 
        areSame('arg!', arg);
773
 
    }
774
 
}));
775
 
 
776
 
suite.add(new Y.Test.Case({
777
 
    name: 'nodelist.on',
778
 
 
779
 
    setUp: setUp,
780
 
    tearDown: tearDown,
781
 
 
782
 
    "test nodelist.on(x, fn)": function () {
783
 
        var targets = Y.all("#inner p"),
784
 
            type = [],
785
 
            currentTarget = [],
786
 
            thisObj = [];
787
 
 
788
 
        targets.on('synth', function (e) {
789
 
            type.push(e.type);
790
 
            currentTarget.push(e.currentTarget);
791
 
            thisObj.push(this);
792
 
        });
793
 
 
794
 
        Y.one("#p1_no").click();
795
 
        Y.one("#p3_no").click();
796
 
        Y.one("#inner_1_p1_no").click();
797
 
 
798
 
        Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
799
 
        Y.ArrayAssert.itemsAreSame(
800
 
            [Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
801
 
            currentTarget);
802
 
        Y.ArrayAssert.itemsAreSame([targets, targets, targets], thisObj);
803
 
    },
804
 
 
805
 
    "test nodelist.on(x, fn, thisObj)": function () {
806
 
        var targets = Y.all("#inner p"),
807
 
            obj = { foo: 'bar' },
808
 
            type = [],
809
 
            currentTarget = [],
810
 
            thisObj = [],
811
 
            foo = [];
812
 
 
813
 
        targets.on('synth', function (e) {
814
 
            type.push(e.type);
815
 
            currentTarget.push(e.currentTarget);
816
 
            thisObj.push(this);
817
 
            foo.push(this.foo);
818
 
        }, obj);
819
 
 
820
 
        Y.one("#p1_no").click();
821
 
        Y.one("#p3_no").click();
822
 
        Y.one("#inner_1_p1_no").click();
823
 
 
824
 
        Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
825
 
        Y.ArrayAssert.itemsAreSame(
826
 
            [Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
827
 
            currentTarget);
828
 
        Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
829
 
        Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
830
 
    },
831
 
 
832
 
    "test nodelist.on(x, fn, thisObj, arg)": function () {
833
 
        var targets = Y.all("#inner p"),
834
 
            obj = { foo: 'bar' },
835
 
            type = [],
836
 
            currentTarget = [],
837
 
            thisObj = [],
838
 
            foo = [],
839
 
            arg = [];
840
 
 
841
 
        targets.on('synth', function (e, x) {
842
 
            type.push(e.type);
843
 
            currentTarget.push(e.currentTarget);
844
 
            thisObj.push(this);
845
 
            foo.push(this.foo);
846
 
            arg.push(x);
847
 
        }, obj, 'arg!');
848
 
 
849
 
        Y.one("#p1_no").click();
850
 
        Y.one("#p3_no").click();
851
 
        Y.one("#inner_1_p1_no").click();
852
 
 
853
 
        Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
854
 
        Y.ArrayAssert.itemsAreSame(
855
 
            [Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
856
 
            currentTarget);
857
 
        Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
858
 
        Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
859
 
        Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
860
 
    },
861
 
 
862
 
    "test nodelist.on(x, fn, null, arg)": function () {
863
 
        var targets = Y.all("#inner p"),
864
 
            type = [],
865
 
            currentTarget = [],
866
 
            thisObj = [],
867
 
            arg = [];
868
 
 
869
 
        targets.on('synth', function (e, x) {
870
 
            type.push(e.type);
871
 
            currentTarget.push(e.currentTarget);
872
 
            thisObj.push(this);
873
 
            arg.push(x);
874
 
        }, null, 'arg!');
875
 
 
876
 
        Y.one("#p1_no").click();
877
 
        Y.one("#p3_no").click();
878
 
        Y.one("#inner_1_p1_no").click();
879
 
 
880
 
        Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
881
 
        Y.ArrayAssert.itemsAreSame(
882
 
            [Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
883
 
            currentTarget);
884
 
        Y.ArrayAssert.itemsAreSame([targets, targets, targets], thisObj);
885
 
        Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
886
 
    }
887
 
}));
888
 
 
889
 
suite.add(new Y.Test.Case({
890
 
    name: 'preventDups',
891
 
 
892
 
    setUp: initTestbed,
893
 
    tearDown: tearDown,
894
 
 
895
 
    initUniqueSynth: function () {
896
 
        Y.Event.define('synth', {
897
 
            preventDups: true,
898
 
 
899
 
            on: function (node, sub, notifier, filter) {
900
 
                var method = (filter) ? 'delegate' : 'on';
901
 
 
902
 
                sub._handle = node[method]('click',
903
 
                    Y.bind(notifier.fire, notifier), filter);
904
 
            },
905
 
 
906
 
            detach: function (node, sub) {
907
 
                sub._handle.detach();
908
 
            }
909
 
        }, true);
910
 
    },
911
 
 
912
 
    "node.on(x, fn) + node.on(x, fn) should  allow dups": function () {
913
 
        initSynth();
914
 
 
915
 
        var target = Y.one("#item1"),
916
 
            count = 0;
917
 
 
918
 
        function increment() {
919
 
            count++;
920
 
        }
921
 
 
922
 
        target.on('synth', increment);
923
 
        target.on('synth', increment);
924
 
 
925
 
        Y.one("#item1").click();
926
 
 
927
 
        areSame(2, count);
928
 
    },
929
 
 
930
 
    "Y.on(x, fn) + node.on(x, fn) should allow dups": function () {
931
 
        initSynth();
932
 
 
933
 
        var count = 0;
934
 
 
935
 
        function increment() {
936
 
            count++;
937
 
        }
938
 
 
939
 
        Y.one('#item1').on('synth', increment);
940
 
        Y.on('synth', increment, '#item1');
941
 
 
942
 
        Y.one("#item1").click();
943
 
 
944
 
        areSame(2, count);
945
 
    },
946
 
 
947
 
    "nodelist.on(x, fn) + node.on(x, fn) should allow dups": function () {
948
 
        initSynth();
949
 
 
950
 
        var count = 0;
951
 
 
952
 
        function increment() {
953
 
            count++;
954
 
        }
955
 
 
956
 
        Y.all("#item1").on('synth', increment);
957
 
        Y.one("#item1").on('synth', increment);
958
 
 
959
 
        Y.one("#item1").click();
960
 
 
961
 
        areSame(2, count);
962
 
    },
963
 
 
964
 
    "preventDups:true node.on(x, fn) + node.on(x, fn) should prevent dups": function () {
965
 
        this.initUniqueSynth();
966
 
 
967
 
        var target = Y.one("#item1"),
968
 
            count = 0;
969
 
 
970
 
        function increment() {
971
 
            count++;
972
 
        }
973
 
 
974
 
        target.on('synth', increment);
975
 
        target.on('synth', increment);
976
 
 
977
 
        Y.one("#item1").click();
978
 
 
979
 
        areSame(1, count);
980
 
    },
981
 
 
982
 
    "preventDups:true Y.on(x, fn) + node.on(x, fn) should prevent dups": function () {
983
 
        this.initUniqueSynth();
984
 
 
985
 
        var count = 0;
986
 
 
987
 
        function increment() {
988
 
            count++;
989
 
        }
990
 
 
991
 
        Y.one('#item1').on('synth', increment);
992
 
        Y.on('synth', increment, '#item1');
993
 
 
994
 
        Y.one("#item1").click();
995
 
 
996
 
        areSame(1, count);
997
 
    },
998
 
 
999
 
    "preventDups:true nodelist.on(x, fn) + node.on(x, fn) should prevent dups": function () {
1000
 
        this.initUniqueSynth();
1001
 
 
1002
 
        var count = 0;
1003
 
 
1004
 
        function increment() {
1005
 
            count++;
1006
 
        }
1007
 
 
1008
 
        Y.all("#item1").on('synth', increment);
1009
 
        Y.one("#item1").on('synth', increment);
1010
 
 
1011
 
        Y.one("#item1").click();
1012
 
 
1013
 
        areSame(1, count);
1014
 
    }
1015
 
}));
1016
 
 
1017
 
suite.add(new Y.Test.Case({
1018
 
    name: "node.delegate",
1019
 
 
1020
 
    setUp: setUp,
1021
 
    tearDown: tearDown,
1022
 
 
1023
 
    "test node.delegate(synth, fn, filter)": function () {
1024
 
        var count = 0,
1025
 
            type = [],
1026
 
            target = [],
1027
 
            currentTarget = [],
1028
 
            thisObj = [],
1029
 
            container = [],
1030
 
            inner = Y.one("#inner"),
1031
 
            a = Y.one("#p1_no"),
1032
 
            b = Y.one("#inner_1_p1_no em");
1033
 
 
1034
 
        inner.delegate('synth', function (e) {
1035
 
            count++;
1036
 
            type.push(e.type);
1037
 
            target.push(e.target);
1038
 
            currentTarget.push(e.currentTarget);
1039
 
            thisObj.push(this);
1040
 
            container.push(e.container);
1041
 
        }, 'p');
1042
 
 
1043
 
        a.click();
1044
 
 
1045
 
        areSame(1, count);
1046
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1047
 
        Y.ArrayAssert.itemsAreSame([a], target);
1048
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1049
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1050
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1051
 
 
1052
 
        b.click();
1053
 
 
1054
 
        areSame(2, count);
1055
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1056
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1057
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1058
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1059
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1060
 
    },
1061
 
 
1062
 
    "test node.delegate(synth, fn, filter, thisObj)": function () {
1063
 
        var count = 0,
1064
 
            obj = { foo: "bar" },
1065
 
            type = [],
1066
 
            target = [],
1067
 
            currentTarget = [],
1068
 
            thisObj = [],
1069
 
            foo = [],
1070
 
            container = [],
1071
 
            inner = Y.one("#inner"),
1072
 
            a = Y.one("#p1_no"),
1073
 
            b = Y.one("#inner_1_p1_no em");
1074
 
 
1075
 
        inner.delegate('synth', function (e) {
1076
 
            count++;
1077
 
            type.push(e.type);
1078
 
            target.push(e.target);
1079
 
            currentTarget.push(e.currentTarget);
1080
 
            thisObj.push(this);
1081
 
            foo.push(this.foo);
1082
 
            container.push(e.container);
1083
 
        }, 'p', obj);
1084
 
 
1085
 
        a.click();
1086
 
 
1087
 
        areSame(1, count);
1088
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1089
 
        Y.ArrayAssert.itemsAreSame([a], target);
1090
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1091
 
        Y.ArrayAssert.itemsAreSame([obj], thisObj);
1092
 
        Y.ArrayAssert.itemsAreSame(["bar"], foo);
1093
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1094
 
 
1095
 
        b.click();
1096
 
 
1097
 
        areSame(2, count);
1098
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1099
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1100
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1101
 
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1102
 
        Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1103
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1104
 
    },
1105
 
 
1106
 
    "test node.delegate(synth, fn, filter, thisObj, arg)": function () {
1107
 
        var count = 0,
1108
 
            obj = { foo: "bar" },
1109
 
            type = [],
1110
 
            target = [],
1111
 
            currentTarget = [],
1112
 
            thisObj = [],
1113
 
            foo = [],
1114
 
            arg = [],
1115
 
            container = [],
1116
 
            inner = Y.one("#inner"),
1117
 
            a = Y.one("#p1_no"),
1118
 
            b = Y.one("#inner_1_p1_no em");
1119
 
 
1120
 
        inner.delegate('synth', function (e, x) {
1121
 
            count++;
1122
 
            type.push(e.type);
1123
 
            target.push(e.target);
1124
 
            currentTarget.push(e.currentTarget);
1125
 
            thisObj.push(this);
1126
 
            foo.push(this.foo);
1127
 
            arg.push(x);
1128
 
            container.push(e.container);
1129
 
        }, 'p', obj, 'arg!');
1130
 
 
1131
 
        a.click();
1132
 
 
1133
 
        areSame(1, count);
1134
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1135
 
        Y.ArrayAssert.itemsAreSame([a], target);
1136
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1137
 
        Y.ArrayAssert.itemsAreSame([obj], thisObj);
1138
 
        Y.ArrayAssert.itemsAreSame(["bar"], foo);
1139
 
        Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1140
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1141
 
 
1142
 
        b.click();
1143
 
 
1144
 
        areSame(2, count);
1145
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1146
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1147
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1148
 
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1149
 
        Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1150
 
        Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1151
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1152
 
    },
1153
 
 
1154
 
    "test node.delegate(synth, fn, filter, null, arg)": function () {
1155
 
        var count = 0,
1156
 
            type = [],
1157
 
            target = [],
1158
 
            currentTarget = [],
1159
 
            thisObj = [],
1160
 
            arg = [],
1161
 
            container = [],
1162
 
            inner = Y.one("#inner"),
1163
 
            a = Y.one("#p1_no"),
1164
 
            b = Y.one("#inner_1_p1_no em");
1165
 
 
1166
 
        inner.delegate('synth', function (e, x) {
1167
 
            count++;
1168
 
            type.push(e.type);
1169
 
            target.push(e.target);
1170
 
            currentTarget.push(e.currentTarget);
1171
 
            thisObj.push(this);
1172
 
            arg.push(x);
1173
 
            container.push(e.container);
1174
 
        }, 'p', null, "arg!");
1175
 
 
1176
 
        a.click();
1177
 
 
1178
 
        areSame(1, count);
1179
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1180
 
        Y.ArrayAssert.itemsAreSame([a], target);
1181
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1182
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1183
 
        Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1184
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1185
 
 
1186
 
        b.click();
1187
 
 
1188
 
        areSame(2, count);
1189
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1190
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1191
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1192
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1193
 
        Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1194
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1195
 
    }
1196
 
 
1197
 
}));
1198
 
 
1199
 
suite.add(new Y.Test.Case({
1200
 
    name: "Y.delegate",
1201
 
 
1202
 
    setUp: setUp,
1203
 
    tearDown: tearDown,
1204
 
 
1205
 
    "test Y.delegate(synth, fn, node, filter)": function () {
1206
 
        var count = 0,
1207
 
            type = [],
1208
 
            target = [],
1209
 
            currentTarget = [],
1210
 
            thisObj = [],
1211
 
            container = [],
1212
 
            inner = Y.one("#inner"),
1213
 
            a = Y.one("#p1_no"),
1214
 
            b = Y.one("#inner_1_p1_no em");
1215
 
 
1216
 
        Y.delegate('synth', function (e) {
1217
 
            count++;
1218
 
            type.push(e.type);
1219
 
            target.push(e.target);
1220
 
            currentTarget.push(e.currentTarget);
1221
 
            thisObj.push(this);
1222
 
            container.push(e.container);
1223
 
        }, inner, 'p');
1224
 
 
1225
 
        a.click();
1226
 
 
1227
 
        areSame(1, count);
1228
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1229
 
        Y.ArrayAssert.itemsAreSame([a], target);
1230
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1231
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1232
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1233
 
 
1234
 
        b.click();
1235
 
 
1236
 
        areSame(2, count);
1237
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1238
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1239
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1240
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1241
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1242
 
    },
1243
 
 
1244
 
    "test Y.delegate(synth, fn, el, filter)": function () {
1245
 
        var count = 0,
1246
 
            type = [],
1247
 
            target = [],
1248
 
            currentTarget = [],
1249
 
            thisObj = [],
1250
 
            container = [],
1251
 
            inner = Y.one("#inner"),
1252
 
            a = Y.one("#p1_no"),
1253
 
            b = Y.one("#inner_1_p1_no em");
1254
 
 
1255
 
        Y.delegate('synth', function (e) {
1256
 
            count++;
1257
 
            type.push(e.type);
1258
 
            target.push(e.target);
1259
 
            currentTarget.push(e.currentTarget);
1260
 
            thisObj.push(this);
1261
 
            container.push(e.container);
1262
 
        }, inner._node, 'p');
1263
 
 
1264
 
        a.click();
1265
 
 
1266
 
        areSame(1, count);
1267
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1268
 
        Y.ArrayAssert.itemsAreSame([a], target);
1269
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1270
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1271
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1272
 
 
1273
 
        b.click();
1274
 
 
1275
 
        areSame(2, count);
1276
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1277
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1278
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1279
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1280
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1281
 
    },
1282
 
 
1283
 
    "test Y.delegate(synth, fn, selectorOne, filter)": function () {
1284
 
        var count = 0,
1285
 
            type = [],
1286
 
            target = [],
1287
 
            currentTarget = [],
1288
 
            thisObj = [],
1289
 
            container = [],
1290
 
            inner = Y.one("#inner"),
1291
 
            a = Y.one("#p1_no"),
1292
 
            b = Y.one("#inner_1_p1_no em");
1293
 
 
1294
 
        Y.delegate('synth', function (e) {
1295
 
            count++;
1296
 
            type.push(e.type);
1297
 
            target.push(e.target);
1298
 
            currentTarget.push(e.currentTarget);
1299
 
            thisObj.push(this);
1300
 
            container.push(e.container);
1301
 
        }, "#inner", 'p');
1302
 
 
1303
 
        a.click();
1304
 
 
1305
 
        areSame(1, count);
1306
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1307
 
        Y.ArrayAssert.itemsAreSame([a], target);
1308
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1309
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1310
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1311
 
 
1312
 
        b.click();
1313
 
 
1314
 
        areSame(2, count);
1315
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1316
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1317
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1318
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1319
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1320
 
    },
1321
 
 
1322
 
    "test Y.delegate(synth, fn, node, filter, thisObj)": function () {
1323
 
        var count = 0,
1324
 
            obj = { foo: "bar" },
1325
 
            type = [],
1326
 
            target = [],
1327
 
            currentTarget = [],
1328
 
            thisObj = [],
1329
 
            foo = [],
1330
 
            container = [],
1331
 
            inner = Y.one("#inner"),
1332
 
            a = Y.one("#p1_no"),
1333
 
            b = Y.one("#inner_1_p1_no em");
1334
 
 
1335
 
        Y.delegate('synth', function (e) {
1336
 
            count++;
1337
 
            type.push(e.type);
1338
 
            target.push(e.target);
1339
 
            currentTarget.push(e.currentTarget);
1340
 
            thisObj.push(this);
1341
 
            foo.push(this.foo);
1342
 
            container.push(e.container);
1343
 
        }, inner, 'p', obj);
1344
 
 
1345
 
        a.click();
1346
 
 
1347
 
        areSame(1, count);
1348
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1349
 
        Y.ArrayAssert.itemsAreSame([a], target);
1350
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1351
 
        Y.ArrayAssert.itemsAreSame([obj], thisObj);
1352
 
        Y.ArrayAssert.itemsAreSame(["bar"], foo);
1353
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1354
 
 
1355
 
        b.click();
1356
 
 
1357
 
        areSame(2, count);
1358
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1359
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1360
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1361
 
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1362
 
        Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1363
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1364
 
    },
1365
 
 
1366
 
    "test Y.delegate(synth, fn, node, filter, thisObj, arg)": function () {
1367
 
        var count = 0,
1368
 
            obj = { foo: "bar" },
1369
 
            type = [],
1370
 
            target = [],
1371
 
            currentTarget = [],
1372
 
            thisObj = [],
1373
 
            foo = [],
1374
 
            arg = [],
1375
 
            container = [],
1376
 
            inner = Y.one("#inner"),
1377
 
            a = Y.one("#p1_no"),
1378
 
            b = Y.one("#inner_1_p1_no em");
1379
 
 
1380
 
        Y.delegate('synth', function (e, x) {
1381
 
            count++;
1382
 
            type.push(e.type);
1383
 
            target.push(e.target);
1384
 
            currentTarget.push(e.currentTarget);
1385
 
            thisObj.push(this);
1386
 
            foo.push(this.foo);
1387
 
            arg.push(x);
1388
 
            container.push(e.container);
1389
 
        }, inner, 'p', obj, 'arg!');
1390
 
 
1391
 
        a.click();
1392
 
 
1393
 
        areSame(1, count);
1394
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1395
 
        Y.ArrayAssert.itemsAreSame([a], target);
1396
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1397
 
        Y.ArrayAssert.itemsAreSame([obj], thisObj);
1398
 
        Y.ArrayAssert.itemsAreSame(["bar"], foo);
1399
 
        Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1400
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1401
 
 
1402
 
        b.click();
1403
 
 
1404
 
        areSame(2, count);
1405
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1406
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1407
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1408
 
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1409
 
        Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1410
 
        Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1411
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1412
 
    },
1413
 
 
1414
 
    "test Y.delegate(synth, fn, node, filter, null, arg)": function () {
1415
 
        var count = 0,
1416
 
            type = [],
1417
 
            target = [],
1418
 
            currentTarget = [],
1419
 
            thisObj = [],
1420
 
            arg = [],
1421
 
            container = [],
1422
 
            inner = Y.one("#inner"),
1423
 
            a = Y.one("#p1_no"),
1424
 
            b = Y.one("#inner_1_p1_no em");
1425
 
 
1426
 
        Y.delegate('synth', function (e, x) {
1427
 
            count++;
1428
 
            type.push(e.type);
1429
 
            target.push(e.target);
1430
 
            currentTarget.push(e.currentTarget);
1431
 
            thisObj.push(this);
1432
 
            arg.push(x);
1433
 
            container.push(e.container);
1434
 
        }, inner, 'p', null, "arg!");
1435
 
 
1436
 
        a.click();
1437
 
 
1438
 
        areSame(1, count);
1439
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1440
 
        Y.ArrayAssert.itemsAreSame([a], target);
1441
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1442
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1443
 
        Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1444
 
        Y.ArrayAssert.itemsAreSame([inner], container);
1445
 
 
1446
 
        b.click();
1447
 
 
1448
 
        areSame(2, count);
1449
 
        Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1450
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1451
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1452
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1453
 
        Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1454
 
        Y.ArrayAssert.itemsAreSame([inner, inner], container);
1455
 
    },
1456
 
 
1457
 
    "test Y.delegate(synth, fn, notAvailableYet, filter)": function () {
1458
 
        var inner = Y.one('#inner'),
1459
 
            test = this,
1460
 
            count = 0,
1461
 
            type = [],
1462
 
            target = [],
1463
 
            currentTarget = [],
1464
 
            thisObj = [],
1465
 
            container = [];
1466
 
 
1467
 
        inner.empty();
1468
 
 
1469
 
        Y.delegate('synth', function (e) {
1470
 
            count++;
1471
 
            type.push(e.type);
1472
 
            target.push(e.target);
1473
 
            currentTarget.push(e.currentTarget);
1474
 
            thisObj.push(this);
1475
 
            container.push(e.container);
1476
 
        }, '#inner_1', 'p');
1477
 
 
1478
 
        inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1479
 
 
1480
 
        // This is a tainted test because it's using a different synthetic
1481
 
        // event to test that the synthetic event infrastructure is working
1482
 
        // properly. The other option is to use Y.later, but that opens a race
1483
 
        // condition.  The test is left in place because something is better
1484
 
        // than nothing.
1485
 
        Y.on("available", function () {
1486
 
            test.resume(function () {
1487
 
                var a = inner.one('#pass1'),
1488
 
                    b = inner.one('#pass2-trigger'),
1489
 
                    inner1 = inner.one('#inner_1');
1490
 
 
1491
 
                if (a && b && inner1) {
1492
 
                    a.click();
1493
 
 
1494
 
                    areSame(1, count);
1495
 
                    Y.ArrayAssert.itemsAreSame(['synth'], type);
1496
 
                    Y.ArrayAssert.itemsAreSame([a], target);
1497
 
                    Y.ArrayAssert.itemsAreSame([a], currentTarget);
1498
 
                    Y.ArrayAssert.itemsAreSame([a], thisObj);
1499
 
                    Y.ArrayAssert.itemsAreSame([inner1], container);
1500
 
 
1501
 
                    b.click();
1502
 
 
1503
 
                    areSame(2, count);
1504
 
                    Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1505
 
                    Y.ArrayAssert.itemsAreSame([a, b], target);
1506
 
                    Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1507
 
                    Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1508
 
                    Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1509
 
                } else {
1510
 
                    Y.Assert.fail("Something is wrong with onAvailable");
1511
 
                }
1512
 
            });
1513
 
        }, '#pass2-trigger');
1514
 
 
1515
 
        test.wait();
1516
 
    },
1517
 
 
1518
 
    "test Y.delegate(synth, fn, notAvailableYet, filter, thisObj)": function () {
1519
 
        var inner = Y.one('#inner'),
1520
 
            obj = { foo: 'bar' },
1521
 
            test = this,
1522
 
            count = 0,
1523
 
            type = [],
1524
 
            target = [],
1525
 
            currentTarget = [],
1526
 
            thisObj = [],
1527
 
            foo = [],
1528
 
            container = [];
1529
 
 
1530
 
        inner.empty();
1531
 
 
1532
 
        Y.delegate('synth', function (e) {
1533
 
            count++;
1534
 
            type.push(e.type);
1535
 
            target.push(e.target);
1536
 
            currentTarget.push(e.currentTarget);
1537
 
            thisObj.push(this);
1538
 
            foo.push(this.foo);
1539
 
            container.push(e.container);
1540
 
        }, '#inner_1', 'p', obj);
1541
 
 
1542
 
        inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1543
 
 
1544
 
        // This is a tainted test because it's using a different synthetic
1545
 
        // event to test that the synthetic event infrastructure is working
1546
 
        // properly. The other option is to use Y.later, but that opens a race
1547
 
        // condition.  The test is left in place because something is better
1548
 
        // than nothing.
1549
 
        Y.on("available", function () {
1550
 
            test.resume(function () {
1551
 
                var a = inner.one('#pass1'),
1552
 
                    b = inner.one('#pass2-trigger'),
1553
 
                    inner1 = inner.one('#inner_1');
1554
 
 
1555
 
                if (a && b && inner1) {
1556
 
                    a.click();
1557
 
 
1558
 
                    areSame(1, count);
1559
 
                    Y.ArrayAssert.itemsAreSame(['synth'], type);
1560
 
                    Y.ArrayAssert.itemsAreSame([a], target);
1561
 
                    Y.ArrayAssert.itemsAreSame([a], currentTarget);
1562
 
                    Y.ArrayAssert.itemsAreSame([obj], thisObj);
1563
 
                    Y.ArrayAssert.itemsAreSame(["bar"], foo);
1564
 
                    Y.ArrayAssert.itemsAreSame([inner1], container);
1565
 
 
1566
 
                    b.click();
1567
 
 
1568
 
                    areSame(2, count);
1569
 
                    Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1570
 
                    Y.ArrayAssert.itemsAreSame([a, b], target);
1571
 
                    Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1572
 
                    Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1573
 
                    Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1574
 
                    Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1575
 
                } else {
1576
 
                    Y.Assert.fail("Something is wrong with onAvailable");
1577
 
                }
1578
 
            });
1579
 
        }, '#pass2-trigger');
1580
 
 
1581
 
        test.wait();
1582
 
    },
1583
 
 
1584
 
    "test Y.delegate(synth, fn, notAvailableYet, filter, thisObj, arg)": function () {
1585
 
        var inner = Y.one('#inner'),
1586
 
            obj = { foo: 'bar' },
1587
 
            test = this,
1588
 
            count = 0,
1589
 
            type = [],
1590
 
            target = [],
1591
 
            currentTarget = [],
1592
 
            thisObj = [],
1593
 
            foo = [],
1594
 
            arg = [],
1595
 
            container = [];
1596
 
 
1597
 
        inner.empty();
1598
 
 
1599
 
        Y.delegate('synth', function (e, x) {
1600
 
            count++;
1601
 
            type.push(e.type);
1602
 
            target.push(e.target);
1603
 
            currentTarget.push(e.currentTarget);
1604
 
            thisObj.push(this);
1605
 
            foo.push(this.foo);
1606
 
            arg.push(x);
1607
 
            container.push(e.container);
1608
 
        }, '#inner_1', 'p', obj, "arg!");
1609
 
 
1610
 
        inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1611
 
 
1612
 
        // This is a tainted test because it's using a different synthetic
1613
 
        // event to test that the synthetic event infrastructure is working
1614
 
        // properly. The other option is to use Y.later, but that opens a race
1615
 
        // condition.  The test is left in place because something is better
1616
 
        // than nothing.
1617
 
        Y.on("available", function () {
1618
 
            test.resume(function () {
1619
 
                var a = inner.one('#pass1'),
1620
 
                    b = inner.one('#pass2-trigger'),
1621
 
                    inner1 = inner.one('#inner_1');
1622
 
 
1623
 
                if (a && b && inner1) {
1624
 
                    a.click();
1625
 
 
1626
 
                    areSame(1, count);
1627
 
                    Y.ArrayAssert.itemsAreSame(['synth'], type);
1628
 
                    Y.ArrayAssert.itemsAreSame([a], target);
1629
 
                    Y.ArrayAssert.itemsAreSame([a], currentTarget);
1630
 
                    Y.ArrayAssert.itemsAreSame([obj], thisObj);
1631
 
                    Y.ArrayAssert.itemsAreSame(["bar"], foo);
1632
 
                    Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1633
 
                    Y.ArrayAssert.itemsAreSame([inner1], container);
1634
 
 
1635
 
                    b.click();
1636
 
 
1637
 
                    areSame(2, count);
1638
 
                    Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1639
 
                    Y.ArrayAssert.itemsAreSame([a, b], target);
1640
 
                    Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1641
 
                    Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1642
 
                    Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1643
 
                    Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1644
 
                    Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1645
 
                } else {
1646
 
                    Y.Assert.fail("Something is wrong with onAvailable");
1647
 
                }
1648
 
            });
1649
 
        }, '#pass2-trigger');
1650
 
 
1651
 
        test.wait();
1652
 
    },
1653
 
 
1654
 
    "test Y.delegate(synth, fn, notAvailableYet, filter, null, arg)": function () {
1655
 
        var inner = Y.one('#inner'),
1656
 
            test = this,
1657
 
            count = 0,
1658
 
            type = [],
1659
 
            target = [],
1660
 
            currentTarget = [],
1661
 
            thisObj = [],
1662
 
            arg = [],
1663
 
            container = [];
1664
 
 
1665
 
        inner.empty();
1666
 
 
1667
 
        Y.delegate('synth', function (e, x) {
1668
 
            count++;
1669
 
            type.push(e.type);
1670
 
            target.push(e.target);
1671
 
            currentTarget.push(e.currentTarget);
1672
 
            thisObj.push(this);
1673
 
            arg.push(x);
1674
 
            container.push(e.container);
1675
 
        }, '#inner_1', 'p', null, "arg!");
1676
 
 
1677
 
        inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1678
 
 
1679
 
        // This is a tainted test because it's using a different synthetic
1680
 
        // event to test that the synthetic event infrastructure is working
1681
 
        // properly. The other option is to use Y.later, but that opens a race
1682
 
        // condition.  The test is left in place because something is better
1683
 
        // than nothing.
1684
 
        Y.on("available", function () {
1685
 
            test.resume(function () {
1686
 
                var a = inner.one('#pass1'),
1687
 
                    b = inner.one('#pass2-trigger'),
1688
 
                    inner1 = inner.one('#inner_1');
1689
 
 
1690
 
                if (a && b && inner1) {
1691
 
                    a.click();
1692
 
 
1693
 
                    areSame(1, count);
1694
 
                    Y.ArrayAssert.itemsAreSame(['synth'], type);
1695
 
                    Y.ArrayAssert.itemsAreSame([a], target);
1696
 
                    Y.ArrayAssert.itemsAreSame([a], currentTarget);
1697
 
                    Y.ArrayAssert.itemsAreSame([a], thisObj);
1698
 
                    Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1699
 
                    Y.ArrayAssert.itemsAreSame([inner1], container);
1700
 
 
1701
 
                    b.click();
1702
 
 
1703
 
                    areSame(2, count);
1704
 
                    Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1705
 
                    Y.ArrayAssert.itemsAreSame([a, b], target);
1706
 
                    Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1707
 
                    Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1708
 
                    Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1709
 
                    Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1710
 
                } else {
1711
 
                    Y.Assert.fail("Something is wrong with onAvailable");
1712
 
                }
1713
 
            });
1714
 
        }, '#pass2-trigger');
1715
 
 
1716
 
        test.wait();
1717
 
    },
1718
 
 
1719
 
    "test Y.delegate(synth, fn, selectorMulti, filter)": function () {
1720
 
        var count = 0,
1721
 
            type = [],
1722
 
            target = [],
1723
 
            currentTarget = [],
1724
 
            thisObj = [],
1725
 
            container = [],
1726
 
            nested = Y.one('.nested'),
1727
 
            inner = Y.one('#inner'),
1728
 
            a = Y.one('#item3 p'),
1729
 
            b = Y.one("#inner_1_p1_no em");
1730
 
 
1731
 
        Y.delegate('synth', function (e) {
1732
 
            count++;
1733
 
            type.push(e.type);
1734
 
            target.push(e.target);
1735
 
            currentTarget.push(e.currentTarget);
1736
 
            thisObj.push(this);
1737
 
            container.push(e.container);
1738
 
        }, ".nested, #inner", 'p');
1739
 
 
1740
 
        a.click();
1741
 
 
1742
 
        areSame(1, count);
1743
 
        Y.ArrayAssert.itemsAreSame(['synth'], type);
1744
 
        Y.ArrayAssert.itemsAreSame([a], target);
1745
 
        Y.ArrayAssert.itemsAreSame([a], currentTarget);
1746
 
        Y.ArrayAssert.itemsAreSame([a], thisObj);
1747
 
        Y.ArrayAssert.itemsAreSame([nested], container);
1748
 
 
1749
 
        b.click();
1750
 
 
1751
 
        areSame(2, count);
1752
 
        Y.ArrayAssert.itemsAreSame(['synth', 'synth'], type);
1753
 
        Y.ArrayAssert.itemsAreSame([a, b], target);
1754
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1755
 
        Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1756
 
        Y.ArrayAssert.itemsAreSame([nested, inner], container);
1757
 
 
1758
 
    }
1759
 
}));
1760
 
 
1761
 
suite.add(new Y.Test.Case({
1762
 
    name: "Detach",
1763
 
 
1764
 
    setUp: setUp,
1765
 
    tearDown: tearDown,
1766
 
 
1767
 
    _should: {
1768
 
        fail: {
1769
 
            // TODO: Can this be made to work?
1770
 
            "test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": true,
1771
 
            "test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": true,
1772
 
            "test nodelist.on('cat|__', fn) + node.detach('cat|*')": true,
1773
 
            "test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": true,
1774
 
            "test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": true,
1775
 
            "test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": true
1776
 
        }
1777
 
    },
1778
 
 
1779
 
    "test node.on() + node.detach(synth, fn)": function () {
1780
 
        var count = 0,
1781
 
            target = Y.one('#button1');
1782
 
 
1783
 
        function fn() {
1784
 
            count++;
1785
 
        }
1786
 
 
1787
 
        target.on('synth', fn);
1788
 
 
1789
 
        target.click();
1790
 
 
1791
 
        areSame(1, count);
1792
 
 
1793
 
        target.detach('synth', fn);
1794
 
 
1795
 
        target.click();
1796
 
 
1797
 
        areSame(1, count);
1798
 
 
1799
 
        target.on('synth', fn);
1800
 
        target.on('synth', fn);
1801
 
        target.on('click', fn);
1802
 
 
1803
 
        target.click();
1804
 
 
1805
 
        areSame(4, count);
1806
 
 
1807
 
        target.detach('synth', fn);
1808
 
 
1809
 
        target.click();
1810
 
 
1811
 
        areSame(5, count);
1812
 
    },
1813
 
 
1814
 
    "test node.on(synth, fn, thisObj) + node.detach(synth, fn)": function () {
1815
 
        var count = 0,
1816
 
            a = {},
1817
 
            b = {},
1818
 
            target = Y.one('#button1');
1819
 
 
1820
 
        function fn() {
1821
 
            count++;
1822
 
        }
1823
 
 
1824
 
        target.on('synth', fn, a);
1825
 
 
1826
 
        target.click();
1827
 
 
1828
 
        areSame(1, count);
1829
 
 
1830
 
        target.detach('synth', fn);
1831
 
 
1832
 
        target.click();
1833
 
 
1834
 
        areSame(1, count);
1835
 
 
1836
 
        target.on('synth', fn, a);
1837
 
        target.on('synth', fn, b);
1838
 
 
1839
 
        target.click();
1840
 
 
1841
 
        areSame(3, count);
1842
 
 
1843
 
        target.detach('synth', fn);
1844
 
 
1845
 
        target.click();
1846
 
 
1847
 
        areSame(3, count);
1848
 
    },
1849
 
 
1850
 
    "test node.on() + node.detach(synth)": function () {
1851
 
        var count = 0,
1852
 
            target = Y.one('#button1');
1853
 
 
1854
 
        function fn() {
1855
 
            count++;
1856
 
        }
1857
 
 
1858
 
        target.on('synth', fn);
1859
 
 
1860
 
        target.click();
1861
 
 
1862
 
        areSame(1, count);
1863
 
 
1864
 
        target.detach('synth');
1865
 
 
1866
 
        target.click();
1867
 
 
1868
 
        areSame(1, count);
1869
 
 
1870
 
        target.on('synth', fn);
1871
 
        target.on('synth', fn);
1872
 
        target.on('click', fn);
1873
 
 
1874
 
        target.click();
1875
 
 
1876
 
        areSame(4, count);
1877
 
 
1878
 
        target.detach('synth');
1879
 
 
1880
 
        target.click();
1881
 
 
1882
 
        areSame(5, count);
1883
 
    },
1884
 
 
1885
 
    "test node.on() + node.detach()": function () {
1886
 
        var count = 0,
1887
 
            target = Y.one('#button1');
1888
 
 
1889
 
        function fn() {
1890
 
            count++;
1891
 
        }
1892
 
 
1893
 
        target.on('synth', fn);
1894
 
 
1895
 
        target.click();
1896
 
 
1897
 
        areSame(1, count);
1898
 
 
1899
 
        target.detach();
1900
 
 
1901
 
        target.click();
1902
 
 
1903
 
        areSame(1, count);
1904
 
 
1905
 
        target.on('synth', fn);
1906
 
        target.on('synth', fn);
1907
 
        target.on('click', fn);
1908
 
 
1909
 
        target.click();
1910
 
 
1911
 
        areSame(4, count);
1912
 
 
1913
 
        target.detach();
1914
 
 
1915
 
        target.click();
1916
 
 
1917
 
        areSame(4, count);
1918
 
    },
1919
 
 
1920
 
    "test node.on() + node.detachAll()": function () {
1921
 
        var count = 0,
1922
 
            target = Y.one('#button1');
1923
 
 
1924
 
        function fn() {
1925
 
            count++;
1926
 
        }
1927
 
 
1928
 
        target.on('synth', fn);
1929
 
 
1930
 
        target.click();
1931
 
 
1932
 
        areSame(1, count);
1933
 
 
1934
 
        target.detachAll();
1935
 
 
1936
 
        target.click();
1937
 
 
1938
 
        areSame(1, count);
1939
 
 
1940
 
        target.on('synth', fn);
1941
 
        target.on('synth', fn);
1942
 
        target.on('click', fn);
1943
 
 
1944
 
        target.click();
1945
 
 
1946
 
        areSame(4, count);
1947
 
 
1948
 
        target.detachAll();
1949
 
 
1950
 
        target.click();
1951
 
 
1952
 
        areSame(4, count);
1953
 
    },
1954
 
 
1955
 
    "test node.on() + node.purge(true, synth)": function () {
1956
 
        var count = 0,
1957
 
            target = Y.one('#button1');
1958
 
 
1959
 
        function fn() {
1960
 
            count++;
1961
 
        }
1962
 
 
1963
 
        target.on('synth', fn);
1964
 
 
1965
 
        target.click();
1966
 
 
1967
 
        areSame(1, count);
1968
 
 
1969
 
        target.purge(true, 'synth');
1970
 
 
1971
 
        target.click();
1972
 
 
1973
 
        areSame(1, count);
1974
 
 
1975
 
        target.on('synth', fn);
1976
 
        target.on('synth', fn);
1977
 
        target.on('click', fn);
1978
 
 
1979
 
        target.click();
1980
 
 
1981
 
        areSame(4, count);
1982
 
 
1983
 
        target.purge(true, 'synth');
1984
 
 
1985
 
        target.click();
1986
 
 
1987
 
        areSame(5, count);
1988
 
    },
1989
 
 
1990
 
    "test node.on() + parent.purge(true, synth)": function () {
1991
 
        var count = 0,
1992
 
            target = Y.one('#button1'),
1993
 
            parent = target.get('parentNode');
1994
 
 
1995
 
        function fn() {
1996
 
            count++;
1997
 
        }
1998
 
 
1999
 
        target.on('synth', fn);
2000
 
 
2001
 
        target.click();
2002
 
 
2003
 
        areSame(1, count);
2004
 
 
2005
 
        parent.purge(true, 'synth');
2006
 
 
2007
 
        target.click();
2008
 
 
2009
 
        areSame(1, count);
2010
 
 
2011
 
        target.on('synth', fn);
2012
 
        target.on('synth', fn);
2013
 
        target.on('click', fn);
2014
 
 
2015
 
        target.click();
2016
 
 
2017
 
        areSame(4, count);
2018
 
 
2019
 
        parent.purge(true, 'synth');
2020
 
 
2021
 
        target.click();
2022
 
 
2023
 
        areSame(5, count);
2024
 
    },
2025
 
 
2026
 
    "test nodelist.on(synth, fn) + node.detach(synth, fn)": function () {
2027
 
        var count = 0,
2028
 
            all = Y.all('.nested li'),
2029
 
            item = all.item(0);
2030
 
 
2031
 
        function increment() {
2032
 
            count++;
2033
 
        }
2034
 
 
2035
 
        all.on('synth', increment);
2036
 
 
2037
 
        item.click();
2038
 
 
2039
 
        areSame(1, count);
2040
 
 
2041
 
        item.detach('synth', increment);
2042
 
 
2043
 
        item.click();
2044
 
 
2045
 
        areSame(1, count);
2046
 
    },
2047
 
 
2048
 
    "test nodelist.on(synth, fn) + node.detach(synth)": function () {
2049
 
        var count = 0,
2050
 
            all = Y.all('.nested li'),
2051
 
            item = all.item(0);
2052
 
 
2053
 
        function increment() {
2054
 
            count++;
2055
 
        }
2056
 
 
2057
 
        all.on('synth', increment);
2058
 
 
2059
 
        item.click();
2060
 
 
2061
 
        areSame(1, count);
2062
 
 
2063
 
        item.detach('synth');
2064
 
 
2065
 
        item.click();
2066
 
 
2067
 
        areSame(1, count);
2068
 
    },
2069
 
 
2070
 
    "test node.on(synth, fn) + nodelist.detach(synth, fn)": function () {
2071
 
        var count = 0,
2072
 
            all = Y.all('.nested li'),
2073
 
            item = all.item(0);
2074
 
 
2075
 
        function increment() {
2076
 
            count++;
2077
 
        }
2078
 
 
2079
 
        item.on('synth', increment);
2080
 
 
2081
 
        item.click();
2082
 
 
2083
 
        areSame(1, count);
2084
 
 
2085
 
        all.detach('synth', increment);
2086
 
 
2087
 
        item.click();
2088
 
 
2089
 
        areSame(1, count);
2090
 
    },
2091
 
 
2092
 
    "test node.on(synth, fn) + nodelist.detach(synth)": function () {
2093
 
        var count = 0,
2094
 
            all = Y.all('.nested li'),
2095
 
            item = all.item(0);
2096
 
 
2097
 
        function increment() {
2098
 
            count++;
2099
 
        }
2100
 
 
2101
 
        item.on('synth', increment);
2102
 
 
2103
 
        item.click();
2104
 
 
2105
 
        areSame(1, count);
2106
 
 
2107
 
        all.detach('synth');
2108
 
 
2109
 
        item.click();
2110
 
 
2111
 
        areSame(1, count);
2112
 
    },
2113
 
 
2114
 
    "test node.on() + handle.detach()": function () {
2115
 
        var count = 0,
2116
 
            item = Y.one('#button1'),
2117
 
            sub;
2118
 
 
2119
 
        function increment() {
2120
 
            count++;
2121
 
        }
2122
 
 
2123
 
        sub = item.on('synth', increment);
2124
 
 
2125
 
        item.click();
2126
 
 
2127
 
        areSame(1, count);
2128
 
 
2129
 
        sub.detach();
2130
 
 
2131
 
        item.click();
2132
 
 
2133
 
        areSame(1, count);
2134
 
    },
2135
 
 
2136
 
    "test nodelist.on() + handle.detach()": function () {
2137
 
        var count = 0,
2138
 
            items = Y.all('.nested li'),
2139
 
            one = items.item(0),
2140
 
            two = items.item(1),
2141
 
            three = items.item(2),
2142
 
            sub;
2143
 
 
2144
 
        function increment() {
2145
 
            count++;
2146
 
        }
2147
 
 
2148
 
        sub = items.on('synth', increment);
2149
 
 
2150
 
        one.click();
2151
 
        areSame(1, count);
2152
 
 
2153
 
        two.click();
2154
 
        areSame(2, count);
2155
 
 
2156
 
        three.click();
2157
 
        areSame(3, count);
2158
 
 
2159
 
        sub.detach();
2160
 
 
2161
 
        one.click();
2162
 
        areSame(3, count);
2163
 
 
2164
 
        two.click();
2165
 
        areSame(3, count);
2166
 
 
2167
 
        three.click();
2168
 
        areSame(3, count);
2169
 
    },
2170
 
 
2171
 
    "test nodelist.on() + nodelist.detach(synth, fn)": function () {
2172
 
        var count = 0,
2173
 
            items = Y.all('.nested li');
2174
 
 
2175
 
        function fn() {
2176
 
            count++;
2177
 
        }
2178
 
 
2179
 
        items.on('synth', fn);
2180
 
 
2181
 
        items.item(0).click();
2182
 
        items.item(1).click();
2183
 
        items.item(2).click();
2184
 
 
2185
 
        areSame(3, count);
2186
 
 
2187
 
        items.detach('synth', fn);
2188
 
 
2189
 
        count = 0;
2190
 
        items.item(0).click();
2191
 
        items.item(1).click();
2192
 
        items.item(2).click();
2193
 
 
2194
 
        areSame(0, count);
2195
 
 
2196
 
        items.on('synth', fn);
2197
 
        items.on('synth', fn);
2198
 
        items.on('click', fn);
2199
 
 
2200
 
        count = 0;
2201
 
        items.item(0).click();
2202
 
        items.item(1).click();
2203
 
        items.item(2).click();
2204
 
 
2205
 
        areSame(9, count);
2206
 
 
2207
 
        items.detach('synth', fn);
2208
 
 
2209
 
        count = 0;
2210
 
        items.item(0).click();
2211
 
        items.item(1).click();
2212
 
        items.item(2).click();
2213
 
 
2214
 
        areSame(3, count);
2215
 
    },
2216
 
 
2217
 
    "test nodelist.on(synth, fn, thisObj) + nodelist.detach(synth, fn)": function () {
2218
 
        var count = 0,
2219
 
            a = {},
2220
 
            b = {},
2221
 
            items = Y.all('.nested li');
2222
 
 
2223
 
        function fn() {
2224
 
            count++;
2225
 
        }
2226
 
 
2227
 
        items.on('synth', fn, a);
2228
 
 
2229
 
        items.item(0).click();
2230
 
        items.item(1).click();
2231
 
        items.item(2).click();
2232
 
 
2233
 
        areSame(3, count);
2234
 
 
2235
 
        items.detach('synth', fn);
2236
 
 
2237
 
        count = 0;
2238
 
        items.item(0).click();
2239
 
        items.item(1).click();
2240
 
        items.item(2).click();
2241
 
 
2242
 
        areSame(0, count);
2243
 
 
2244
 
        items.on('synth', fn, a);
2245
 
        items.on('synth', fn, b);
2246
 
 
2247
 
        count = 0;
2248
 
        items.item(0).click();
2249
 
        items.item(1).click();
2250
 
        items.item(2).click();
2251
 
 
2252
 
        areSame(6, count);
2253
 
 
2254
 
        items.detach('synth', fn);
2255
 
 
2256
 
        count = 0;
2257
 
        items.item(0).click();
2258
 
        items.item(1).click();
2259
 
        items.item(2).click();
2260
 
 
2261
 
        areSame(0, count);
2262
 
    },
2263
 
 
2264
 
    "test nodelist.on() + nodelist.detach(synth)": function () {
2265
 
        var count = 0,
2266
 
            items = Y.all('.nested li');
2267
 
 
2268
 
        function fn() {
2269
 
            count++;
2270
 
        }
2271
 
 
2272
 
        items.on('synth', fn);
2273
 
 
2274
 
        items.item(0).click();
2275
 
        items.item(1).click();
2276
 
        items.item(2).click();
2277
 
 
2278
 
        areSame(3, count);
2279
 
 
2280
 
        items.detach('synth');
2281
 
 
2282
 
        count = 0;
2283
 
        items.item(0).click();
2284
 
        items.item(1).click();
2285
 
        items.item(2).click();
2286
 
 
2287
 
        areSame(0, count);
2288
 
 
2289
 
        items.on('synth', fn);
2290
 
        items.on('synth', fn);
2291
 
        items.on('click', fn);
2292
 
 
2293
 
        count = 0;
2294
 
        items.item(0).click();
2295
 
        items.item(1).click();
2296
 
        items.item(2).click();
2297
 
 
2298
 
        areSame(9, count);
2299
 
 
2300
 
        items.detach('synth');
2301
 
 
2302
 
        count = 0;
2303
 
        items.item(0).click();
2304
 
        items.item(1).click();
2305
 
        items.item(2).click();
2306
 
 
2307
 
        areSame(3, count);
2308
 
    },
2309
 
 
2310
 
    "test nodelist.on() + nodelist.detach()": function () {
2311
 
        var count = 0,
2312
 
            items = Y.all('.nested li');
2313
 
 
2314
 
        function fn() {
2315
 
            count++;
2316
 
        }
2317
 
 
2318
 
        items.on('synth', fn);
2319
 
 
2320
 
        items.item(0).click();
2321
 
        items.item(1).click();
2322
 
        items.item(2).click();
2323
 
 
2324
 
        areSame(3, count);
2325
 
 
2326
 
        items.detach();
2327
 
 
2328
 
        count = 0;
2329
 
        items.item(0).click();
2330
 
        items.item(1).click();
2331
 
        items.item(2).click();
2332
 
 
2333
 
        areSame(0, count);
2334
 
 
2335
 
        items.on('synth', fn);
2336
 
        items.on('synth', fn);
2337
 
        items.on('click', fn);
2338
 
 
2339
 
        count = 0;
2340
 
        items.item(0).click();
2341
 
        items.item(1).click();
2342
 
        items.item(2).click();
2343
 
 
2344
 
        areSame(9, count);
2345
 
 
2346
 
        items.detach();
2347
 
 
2348
 
        count = 0;
2349
 
        items.item(0).click();
2350
 
        items.item(1).click();
2351
 
        items.item(2).click();
2352
 
 
2353
 
        areSame(0, count);
2354
 
    },
2355
 
 
2356
 
    "test nodelist.on() + nodelist.detachAll()": function () {
2357
 
        var count = 0,
2358
 
            items = Y.all('.nested li');
2359
 
 
2360
 
        function fn() {
2361
 
            count++;
2362
 
        }
2363
 
 
2364
 
        items.on('synth', fn);
2365
 
 
2366
 
        items.item(0).click();
2367
 
        items.item(1).click();
2368
 
        items.item(2).click();
2369
 
 
2370
 
        areSame(3, count);
2371
 
 
2372
 
        items.detachAll();
2373
 
 
2374
 
        count = 0;
2375
 
        items.item(0).click();
2376
 
        items.item(1).click();
2377
 
        items.item(2).click();
2378
 
 
2379
 
        areSame(0, count);
2380
 
 
2381
 
        items.on('synth', fn);
2382
 
        items.on('synth', fn);
2383
 
        items.on('click', fn);
2384
 
 
2385
 
        count = 0;
2386
 
        items.item(0).click();
2387
 
        items.item(1).click();
2388
 
        items.item(2).click();
2389
 
 
2390
 
        areSame(9, count);
2391
 
 
2392
 
        items.detachAll();
2393
 
 
2394
 
        count = 0;
2395
 
        items.item(0).click();
2396
 
        items.item(1).click();
2397
 
        items.item(2).click();
2398
 
 
2399
 
        areSame(0, count);
2400
 
    },
2401
 
 
2402
 
    "test nodelist.on() + parent.purge(true, synth)": function () {
2403
 
        var count = 0,
2404
 
            items = Y.all('.nested li'),
2405
 
            parent = items.item(0).get('parentNode');
2406
 
 
2407
 
        function fn() {
2408
 
            count++;
2409
 
        }
2410
 
 
2411
 
        items.on('synth', fn);
2412
 
 
2413
 
        items.item(0).click();
2414
 
        items.item(1).click();
2415
 
        items.item(2).click();
2416
 
 
2417
 
        areSame(3, count);
2418
 
 
2419
 
        parent.purge(true, 'synth');
2420
 
 
2421
 
        count = 0;
2422
 
        items.item(0).click();
2423
 
        items.item(1).click();
2424
 
        items.item(2).click();
2425
 
 
2426
 
        areSame(0, count);
2427
 
 
2428
 
        items.on('synth', fn);
2429
 
        items.on('synth', fn);
2430
 
        items.on('click', fn);
2431
 
 
2432
 
        count = 0;
2433
 
        items.item(0).click();
2434
 
        items.item(1).click();
2435
 
        items.item(2).click();
2436
 
 
2437
 
        areSame(9, count);
2438
 
 
2439
 
        parent.purge(true, 'synth');
2440
 
 
2441
 
        count = 0;
2442
 
        items.item(0).click();
2443
 
        items.item(1).click();
2444
 
        items.item(2).click();
2445
 
 
2446
 
        areSame(3, count);
2447
 
    },
2448
 
 
2449
 
    "test node.on('cat|__', fn) + node.detach('cat|___')": function () {
2450
 
        var count = 0,
2451
 
            item = Y.one('#button1');
2452
 
 
2453
 
        function increment() {
2454
 
            count++;
2455
 
        }
2456
 
 
2457
 
        item.on('cat|synth', increment);
2458
 
 
2459
 
        item.click();
2460
 
 
2461
 
        areSame(1, count);
2462
 
 
2463
 
        item.detach('cat|synth');
2464
 
 
2465
 
        item.click();
2466
 
 
2467
 
        areSame(1, count);
2468
 
    },
2469
 
 
2470
 
    "test node.on('cat|__', fn) + node.detach('cat|___', fn)": function () {
2471
 
        var count = 0,
2472
 
            item = Y.one('#button1');
2473
 
 
2474
 
        function increment() {
2475
 
            count++;
2476
 
        }
2477
 
 
2478
 
        item.on('cat|synth', increment);
2479
 
 
2480
 
        item.click();
2481
 
 
2482
 
        areSame(1, count);
2483
 
 
2484
 
        item.detach('cat|synth', increment);
2485
 
 
2486
 
        item.click();
2487
 
 
2488
 
        areSame(1, count);
2489
 
    },
2490
 
 
2491
 
    "test node.on('cat|__', fn) + node.detach('cat|*')": function () {
2492
 
        var count = 0,
2493
 
            item = Y.one('#button1');
2494
 
 
2495
 
        function increment() {
2496
 
            count++;
2497
 
        }
2498
 
 
2499
 
        item.on('cat|synth', increment);
2500
 
 
2501
 
        item.click();
2502
 
 
2503
 
        areSame(1, count);
2504
 
 
2505
 
        item.detach('cat|*');
2506
 
 
2507
 
        item.click();
2508
 
 
2509
 
        areSame(1, count);
2510
 
    },
2511
 
 
2512
 
    "test Y.on('cat|__', fn, sel) + node.detach('cat|___')": function () {
2513
 
        var count = 0,
2514
 
            item = Y.one('#button1');
2515
 
 
2516
 
        function increment() {
2517
 
            count++;
2518
 
        }
2519
 
 
2520
 
        Y.on('cat|synth', increment, '#button1');
2521
 
 
2522
 
        item.click();
2523
 
 
2524
 
        areSame(1, count);
2525
 
 
2526
 
        item.detach('cat|synth');
2527
 
 
2528
 
        item.click();
2529
 
 
2530
 
        areSame(1, count);
2531
 
    },
2532
 
 
2533
 
    "test Y.on('cat|__', fn, sel) + node.detach('cat|___', fn)": function () {
2534
 
        var count = 0,
2535
 
            item = Y.one('#button1');
2536
 
 
2537
 
        function increment() {
2538
 
            count++;
2539
 
        }
2540
 
 
2541
 
        Y.on('cat|synth', increment, '#button1');
2542
 
 
2543
 
        item.click();
2544
 
 
2545
 
        areSame(1, count);
2546
 
 
2547
 
        item.detach('cat|synth', increment);
2548
 
 
2549
 
        item.click();
2550
 
 
2551
 
        areSame(1, count);
2552
 
    },
2553
 
 
2554
 
    "test Y.on('cat|__', fn) + node.detach('cat|*')": function () {
2555
 
        var count = 0,
2556
 
            item = Y.one('#button1');
2557
 
 
2558
 
        function increment() {
2559
 
            count++;
2560
 
        }
2561
 
 
2562
 
        Y.on('cat|synth', increment, '#button1');
2563
 
 
2564
 
        item.click();
2565
 
 
2566
 
        areSame(1, count);
2567
 
 
2568
 
        item.detach('cat|*');
2569
 
 
2570
 
        item.click();
2571
 
 
2572
 
        areSame(1, count);
2573
 
    },
2574
 
 
2575
 
    "test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": function () {
2576
 
        var count = 0,
2577
 
            items = Y.all('#inner p');
2578
 
 
2579
 
        function increment() {
2580
 
            count++;
2581
 
        }
2582
 
 
2583
 
        items.on('cat|synth', increment);
2584
 
 
2585
 
        items.click();
2586
 
 
2587
 
        areSame(5, count);
2588
 
 
2589
 
        items.detach('cat|synth');
2590
 
 
2591
 
        items.click();
2592
 
 
2593
 
        areSame(5, count);
2594
 
    },
2595
 
 
2596
 
    "test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": function () {
2597
 
        var count = 0,
2598
 
            items = Y.all('#inner p');
2599
 
 
2600
 
        function increment() {
2601
 
            count++;
2602
 
        }
2603
 
 
2604
 
        items.on('cat|synth', increment);
2605
 
 
2606
 
        items.click();
2607
 
 
2608
 
        areSame(5, count);
2609
 
 
2610
 
        items.detach('cat|synth', increment);
2611
 
 
2612
 
        items.click();
2613
 
 
2614
 
        areSame(5, count);
2615
 
    },
2616
 
 
2617
 
    "test nodelist.on('cat|__', fn) + node.detach('cat|*')": function () {
2618
 
        var count = 0,
2619
 
            items = Y.all('#inner p');
2620
 
 
2621
 
        function increment() {
2622
 
            count++;
2623
 
        }
2624
 
 
2625
 
        items.on('cat|synth', increment);
2626
 
 
2627
 
        items.click();
2628
 
 
2629
 
        areSame(5, count);
2630
 
 
2631
 
        items.detach('cat|*');
2632
 
 
2633
 
        items.click();
2634
 
 
2635
 
        areSame(5, count);
2636
 
    },
2637
 
 
2638
 
    "test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": function () {
2639
 
        var count = 0,
2640
 
            items = Y.all('#inner p');
2641
 
 
2642
 
        function increment() {
2643
 
            count++;
2644
 
        }
2645
 
 
2646
 
        Y.on('cat|synth', increment, '#inner p');
2647
 
 
2648
 
        items.click();
2649
 
 
2650
 
        areSame(5, count);
2651
 
 
2652
 
        items.detach('cat|synth');
2653
 
 
2654
 
        items.click();
2655
 
 
2656
 
        areSame(5, count);
2657
 
    },
2658
 
 
2659
 
    "test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": function () {
2660
 
        var count = 0,
2661
 
            items = Y.all('#inner p');
2662
 
 
2663
 
        function increment() {
2664
 
            count++;
2665
 
        }
2666
 
 
2667
 
        Y.on('cat|synth', increment, '#inner p');
2668
 
 
2669
 
        items.click();
2670
 
 
2671
 
        areSame(5, count);
2672
 
 
2673
 
        items.detach('cat|synth', increment);
2674
 
 
2675
 
        items.click();
2676
 
 
2677
 
        areSame(5, count);
2678
 
    },
2679
 
 
2680
 
    "test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": function () {
2681
 
        var count = 0,
2682
 
            items = Y.all('#inner p');
2683
 
 
2684
 
        function increment() {
2685
 
            count++;
2686
 
        }
2687
 
 
2688
 
        Y.on('cat|synth', increment, '#inner p');
2689
 
 
2690
 
        items.click();
2691
 
 
2692
 
        areSame(5, count);
2693
 
 
2694
 
        items.detach('cat|*');
2695
 
 
2696
 
        items.click();
2697
 
 
2698
 
        areSame(5, count);
2699
 
    }
2700
 
    // Y.on('cat|_', fn, multiSelector) + nodelist.detach('cat|_'[, fn]);
2701
 
}));
2702
 
 
2703
 
suite.add(new Y.Test.Case({
2704
 
    name: "processArgs",
2705
 
 
2706
 
    setUp: function () {
2707
 
        initTestbed();
2708
 
 
2709
 
        var config = {
2710
 
            processArgs: function (args, delegate) {
2711
 
               return [args.splice(3,1)[0], delegate];
2712
 
            },
2713
 
 
2714
 
            on: function (node, sub, notifier, filter) {
2715
 
                var method = (filter) ? 'delegate' : 'on';
2716
 
 
2717
 
                sub._handle = node[method]('click', function (e) {
2718
 
                    e.sub = sub;
2719
 
                    notifier.fire(e);
2720
 
                }, filter);
2721
 
            },
2722
 
 
2723
 
            detach: function (node, sub) {
2724
 
                sub._handle.detach();
2725
 
            }
2726
 
        };
2727
 
        config.delegate = config.on;
2728
 
        config.detachDelegate = config.detach;
2729
 
 
2730
 
        Y.Event.define('synth', config, true);
2731
 
    },
2732
 
    tearDown: tearDown,
2733
 
 
2734
 
    "test Y.on('synth', fn, selector, extra)": function () {
2735
 
        var test = this,
2736
 
            target = Y.one("#item3"),
2737
 
            type, currentTarget, thisObj, extra, callbackArgs;
2738
 
 
2739
 
        Y.on('synth', function (e) {
2740
 
            type = e.type;
2741
 
            currentTarget = e.currentTarget;
2742
 
            thisObj = this;
2743
 
            extra = e.sub._extra[0];
2744
 
            callbackArgs = arguments.length;
2745
 
        }, '#item3', 'EXTRA');
2746
 
 
2747
 
        target.click();
2748
 
 
2749
 
        areSame('synth', type);
2750
 
        areSame(target, currentTarget);
2751
 
        areSame(target, thisObj);
2752
 
        areSame('EXTRA', extra);
2753
 
        areSame(1, callbackArgs);
2754
 
    },
2755
 
 
2756
 
    "Y.on('synth', fn, '#not-here-yet', extra) should resubscribe with original arguments": function () {
2757
 
        var test = this,
2758
 
            target, type, currentTarget, thisObj, extra, callbackArgs;
2759
 
 
2760
 
        Y.on('synth', function (e) {
2761
 
            type = e.type;
2762
 
            currentTarget = e.currentTarget;
2763
 
            thisObj = this;
2764
 
            extra = e.sub._extra[0];
2765
 
            callbackArgs = arguments.length;
2766
 
        }, '#item4', 'EXTRA');
2767
 
 
2768
 
        setTimeout(function () {
2769
 
            target = Y.Node.create('<li id="item4"><p>Item 4</p></li>');
2770
 
            Y.one(".nested").append(target);
2771
 
 
2772
 
            setTimeout(function () {
2773
 
                test.resume(function () {
2774
 
                    target.click();
2775
 
                    areSame('synth', type);
2776
 
                    areSame(target, currentTarget);
2777
 
                    areSame(target, thisObj);
2778
 
                    areSame('EXTRA', extra);
2779
 
                    areSame(1, callbackArgs);
2780
 
                });
2781
 
            }, 300);
2782
 
        }, 100);
2783
 
 
2784
 
        test.wait(3000);
2785
 
    }
2786
 
 
2787
 
}));
2788
 
 
2789
 
suite.add(new Y.Test.Case({
2790
 
    name: "Notifier",
2791
 
 
2792
 
    setUp: setUp,
2793
 
    tearDown: tearDown
2794
 
 
2795
 
 
2796
 
}));
2797
 
 
2798
 
Y.Test.Runner.add(suite);
2799
 
 
2800
 
 
2801
 
}, '@VERSION@' ,{requires:['event-synthetic', 'test', 'node-event-simulate']});