~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/tests/event/tests/src/event-synthetic.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

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