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

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/async-queue/tests/async-queue.bak

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!doctype html>
2
 
<html>
3
 
<head>
4
 
    <title>Test Page</title>
5
 
    <style type="text/css">
6
 
        h1 {
7
 
            font: normal 125%/1.4 Arial, sans-serif;
8
 
        }
9
 
        .yui3-skin-sam .yui3-console .yui3-console-content {
10
 
            font-size: 10px;
11
 
            width: 32em;
12
 
        }
13
 
        .yui3-skin-sam .yui3-console .yui3-console-bd {
14
 
            height: 50em;
15
 
        }
16
 
        .yui3-skin-sam .yui3-console-entry-time {
17
 
            display: none;
18
 
        }
19
 
    </style>
20
 
</head>
21
 
<body class="yui3-skin-sam">
22
 
<h1>Tests</h1>
23
 
<div id="testbed"></div>
24
 
 
25
 
<script type="text/javascript" src="../../../build/yui/yui.js"></script>
26
 
<!--script type="text/javascript" src="../../../build/async-queue/async-queue.js"></script-->
27
 
<script type="text/javascript">
28
 
YUI({
29
 
    filter : 'raw'
30
 
}).use('test','console','async-queue','io-base',function (Y) {
31
 
 
32
 
var suite = new Y.Test.Suite("Tests");
33
 
 
34
 
// FIXME: remove this and update the tests to handle the asynchronicity
35
 
Y.AsyncQueue.defaults.timeout = -1;
36
 
 
37
 
function f() {}
38
 
 
39
 
if (!window.console) {
40
 
    console = { log: f };
41
 
}
42
 
 
43
 
suite.add(new Y.Test.Case({
44
 
    name : "Queue isntantiation",
45
 
 
46
 
    test_instantiation : function () {
47
 
        var basic         = new Y.AsyncQueue(),
48
 
            withCallbacks = new Y.AsyncQueue(f,f,f,f);
49
 
 
50
 
        Y.Assert.areSame(true, basic instanceof Y.AsyncQueue);
51
 
 
52
 
        Y.Assert.areSame(0, basic.size());
53
 
        Y.Assert.areSame(0, basic._q.length);
54
 
 
55
 
        Y.Assert.areSame(4, withCallbacks.size());
56
 
        Y.Assert.isFunction(withCallbacks._q[0]);
57
 
        Y.Assert.isFunction(withCallbacks.next());
58
 
        Y.Assert.areSame(f, withCallbacks.next().fn);
59
 
    }
60
 
}));
61
 
 
62
 
suite.add(new Y.Test.Case({
63
 
    name : "queue-base",
64
 
 
65
 
    test_next : function () {
66
 
        var i = 0;
67
 
 
68
 
        YUI({
69
 
            useBrowserConsole : false,
70
 
            logInclude : { TestRunner: true }
71
 
        }).use('queue-base', function (Y) {
72
 
            function inc() { i++; }
73
 
 
74
 
            var callback,
75
 
 
76
 
                q = new Y.Queue(inc, inc, "string", inc);
77
 
            
78
 
            while ((callback = q.next())) {
79
 
                if (Y.Lang.isFunction(callback)) {
80
 
                    callback();
81
 
                }
82
 
            }
83
 
        });
84
 
 
85
 
        Y.Assert.areSame(3, i);
86
 
    }
87
 
}));
88
 
 
89
 
suite.add(new Y.Test.Case({
90
 
    name : "Test API",
91
 
 
92
 
    test_chaining : function () {
93
 
        var q = new Y.AsyncQueue();
94
 
            q.defaults = {
95
 
                timeout : 10
96
 
            };
97
 
 
98
 
        Y.Assert.areSame(q, q.add());
99
 
        Y.Assert.areSame(q, q.add(f));
100
 
        Y.Assert.areSame(q, q.add(f,f,{fn:f,id:'a'},"garbage"));
101
 
 
102
 
        Y.Assert.areSame(q, q.pause());
103
 
        Y.Assert.areSame(q, q.promote('a'));
104
 
        Y.Assert.areSame(q, q.remove('a'));
105
 
        Y.Assert.areSame(q, q.run());
106
 
        Y.Assert.areSame(q, q.stop());
107
 
    },
108
 
 
109
 
    test_add : function () {
110
 
        var q = new Y.AsyncQueue(f);
111
 
 
112
 
        Y.Assert.areSame(1, q.size());
113
 
 
114
 
        q = new Y.AsyncQueue().add(f);
115
 
        Y.Assert.areSame(1, q.size());
116
 
 
117
 
        q.add(f,f).add(f,f,f);
118
 
        Y.Assert.areSame(6, q.size());
119
 
 
120
 
        q.add("Only functions and objects are allowed",
121
 
              undefined,
122
 
              null,
123
 
              1,
124
 
              true);
125
 
 
126
 
        Y.Assert.areSame(6, q.size());
127
 
 
128
 
        q.add({},{}); // empty objects are ok, since config can be defaulted
129
 
        Y.Assert.areSame(8, q.size());
130
 
 
131
 
        // Add from within a callback
132
 
        var count = 0;
133
 
        function x() {
134
 
            count++;
135
 
        }
136
 
        function addToQueue() {
137
 
            this.add(x);
138
 
        }
139
 
 
140
 
        // Three x calls scheduled.  A fourth added during a callback
141
 
        q = new Y.AsyncQueue(x,f,x,addToQueue,f,x).run();
142
 
 
143
 
        Y.Assert.areSame(4,count);
144
 
    },
145
 
 
146
 
    test_remove : function () {
147
 
        function X() {
148
 
            q.run();
149
 
            results += 'X';
150
 
        }
151
 
 
152
 
        var results = '',
153
 
            self = this,
154
 
            q = new Y.AsyncQueue(
155
 
                    function () {
156
 
                        Y.Assert.areSame(7, this.size());
157
 
                        results += 'R';
158
 
                    },
159
 
                    { id: "remove me", fn: X },
160
 
                    {
161
 
                        id: "not removed",
162
 
                        fn: function () {
163
 
                            results += 'E';
164
 
                            this.remove('me too');
165
 
                        },
166
 
                        timeout: 10
167
 
                    },
168
 
                    { id: "me too", fn: X },
169
 
                    function () {
170
 
                        this.remove("fail");
171
 
                        if (q.size() !== 4) {
172
 
                            self.resume(function () {
173
 
                                Y.Assert.fail("Expected 3, got " + q.size() + " - remove(n) should defer until callback completion");
174
 
                            });
175
 
                        }
176
 
                        results += 'M';
177
 
                    },
178
 
                    { id: "fail",
179
 
                     fn: function () {
180
 
                            self.resume(function () {
181
 
                                Y.Assert.fail("This callback should have been removed");
182
 
                            });
183
 
                         }
184
 
                    },
185
 
                    function () {
186
 
                        if (q.size() !== 2) {
187
 
                            self.resume(function () {
188
 
                                Y.Assert.fail("Size should be 1");
189
 
                            });
190
 
                        }
191
 
                        results += 'OV';
192
 
                    },
193
 
                    function () {
194
 
                        self.resume(function () {
195
 
                            results += 'E';
196
 
                            Y.Assert.areSame('REMOVE', results);
197
 
                        });
198
 
                    });
199
 
 
200
 
        Y.Assert.areSame(8, q.size());
201
 
 
202
 
        // Removal when the Queue is inactive is immediate
203
 
        q.remove("remove me");
204
 
        Y.Assert.areSame(7, q.size());
205
 
 
206
 
        q.run();
207
 
        Y.Assert.areSame('R',results);
208
 
        Y.Assert.areSame(6, q.size());
209
 
 
210
 
        q.remove("not removed");
211
 
        Y.Assert.areSame(6, q.size());
212
 
 
213
 
        this.wait();
214
 
    },
215
 
 
216
 
    test_promote : function () {
217
 
        function O() {
218
 
            results += 'O';
219
 
        }
220
 
 
221
 
        var results = '',
222
 
            self = this,
223
 
            q = new Y.AsyncQueue(
224
 
                    function () {
225
 
                        results += "R";
226
 
                    },
227
 
                    {
228
 
                        id: "p",
229
 
                        fn: function () { results += 'P'; }
230
 
                    },
231
 
                    O,
232
 
                    {
233
 
                        id: 'm',
234
 
                        fn: function () {
235
 
                            if (this.count++ > 3) {
236
 
                                results += 'M';
237
 
                            } else if (!this.count) {
238
 
                                q.promote('o');
239
 
                            }
240
 
                        },
241
 
                        context : { count : 0 },
242
 
                        iterations : 5
243
 
                    },
244
 
                    {
245
 
                        id : 'o',
246
 
                        fn: O,
247
 
                        timeout: 10
248
 
                    },
249
 
                    function () { results += 'E'; },
250
 
                    {
251
 
                        id : 't',
252
 
                        fn : function () {
253
 
                            results += 'T';
254
 
                        }
255
 
                    },
256
 
                    function () {
257
 
                        self.resume(function () {
258
 
                            Y.Assert.areSame('PROMOTE', results);
259
 
                        });
260
 
                    });
261
 
 
262
 
        Y.Assert.isUndefined(q._q[0].id);
263
 
 
264
 
        q.promote('p');
265
 
        Y.Assert.areSame('p', q._q[0].id);
266
 
 
267
 
        q.run();
268
 
        Y.Assert.areSame('PROM', results);
269
 
 
270
 
        q.promote('t');
271
 
 
272
 
        this.wait();
273
 
    },
274
 
 
275
 
    test_pause : function () {
276
 
        var results = '',
277
 
            self = this,
278
 
            q = new Y.AsyncQueue(
279
 
                function () { results += 'P'; },
280
 
                {
281
 
                    fn: function () {
282
 
                        results += 'A';
283
 
                    },
284
 
                    timeout : 10
285
 
                },
286
 
                function () {
287
 
                    results += 'U';
288
 
                },
289
 
                function () {
290
 
                    results += 'S';
291
 
                    this.pause();
292
 
 
293
 
                    self.resume(function () {
294
 
                        Y.Assert.areSame('PAUS',results);
295
 
 
296
 
                        setTimeout(function () {
297
 
                            q.run();
298
 
                        },10);
299
 
 
300
 
                        self.wait();
301
 
                    });
302
 
 
303
 
                },
304
 
                function () {
305
 
                    results += 'E';
306
 
                    self.resume(function () {
307
 
                        Y.Assert.areSame('PAUSE',results);
308
 
                    });
309
 
                });
310
 
 
311
 
        Y.Assert.areSame(5,q.size());
312
 
        q.run();
313
 
 
314
 
        // Test during timeout
315
 
        Y.Assert.areSame('P', results);
316
 
        q.pause();
317
 
 
318
 
        setTimeout(function () {
319
 
            self.resume(function () {
320
 
                q.run();
321
 
                self.wait();
322
 
            });
323
 
        }, 20);
324
 
 
325
 
        this.wait();
326
 
    },
327
 
 
328
 
    test_stop : function () {
329
 
        var results = "",
330
 
            self = this,
331
 
            q = new Y.AsyncQueue(
332
 
                    function () { results += 'S'; },
333
 
                    function () { results += 'T'; },
334
 
                    function () { results += 'O'; },
335
 
                    function () { results += 'P'; },
336
 
                    {
337
 
                        fn: function () {
338
 
                            self.resume(function () {
339
 
                                Y.Assert.fail("Synchronous q.stop() should have cleared this async callback");
340
 
                            });
341
 
                        },
342
 
                        timeout: 10
343
 
                    });
344
 
 
345
 
        q.run();
346
 
        q.stop();
347
 
        Y.Assert.areSame('STOP',results);
348
 
        Y.Assert.areSame(0,q.size());
349
 
 
350
 
        setTimeout(function () {
351
 
            self.resume(function () {
352
 
                Y.Assert.areSame('STOP',results);
353
 
            });
354
 
        },100);
355
 
 
356
 
        q.run();
357
 
 
358
 
        this.wait();
359
 
    },
360
 
 
361
 
    test_getCallback : function () {
362
 
        var c,
363
 
            q = new Y.AsyncQueue(
364
 
                    { id : 'a', test: 1 },
365
 
                    { id : 'b', test: 2, fn: function () {
366
 
                            this.pause();
367
 
                        }
368
 
                    },
369
 
                    { id : 'c', test: 3 },
370
 
                    { id : 'd', test: 4,
371
 
                      fn: function () {
372
 
                          Y.Assert.areSame(this._q[0], this.getCallback('d'));
373
 
                      }
374
 
                    },
375
 
                    { id : 'a', test: 5 });
376
 
 
377
 
        q.defaults = { fn: function () {} };
378
 
 
379
 
        c = q.getCallback('a');
380
 
        Y.Assert.isObject(c);
381
 
        Y.Assert.areSame(1, c.test);
382
 
 
383
 
        q.run();
384
 
        c = q.getCallback('a');
385
 
        Y.Assert.isObject(c);
386
 
        Y.Assert.areSame(5, c.test);
387
 
 
388
 
        q.run();
389
 
    },
390
 
 
391
 
    test_isRunning : function () {
392
 
        var self = this,
393
 
            q = new Y.AsyncQueue(
394
 
                    function () {
395
 
                        Y.Assert.areSame(true, this.isRunning());
396
 
                    },
397
 
                    {
398
 
                        fn: function () {
399
 
                            q.pause();
400
 
                            self.resume(function () {
401
 
                                Y.Assert.areSame(false, q.isRunning());
402
 
                            });
403
 
                        },
404
 
                        timeout: 10
405
 
                    });
406
 
 
407
 
        Y.Assert.areSame(false, q.isRunning());
408
 
        q.run();
409
 
 
410
 
        Y.Assert.areSame(true, q.isRunning());
411
 
 
412
 
        /*
413
 
        setTimeout(function () {
414
 
            self.resume(function () {
415
 
                Y.Assert.areSame(false, q.isRunning());
416
 
                q.run(); // run to completion
417
 
                Y.Assert.areSame(false, q.isRunning());
418
 
            });
419
 
        },100);
420
 
        */
421
 
 
422
 
        this.wait();
423
 
    }
424
 
}));
425
 
 
426
 
suite.add(new Y.Test.Case({
427
 
    name : "Test callback config",
428
 
 
429
 
    test_fn : function () {
430
 
        var results = '',
431
 
            q = new Y.AsyncQueue(
432
 
                    function () { results += 'R'; },
433
 
                    {},
434
 
                    function () { results += 'N'; });
435
 
 
436
 
        q.defaults = { fn: function () { results += 'U' } };
437
 
        q.run();
438
 
 
439
 
        Y.Assert.areSame("RUN", results);
440
 
 
441
 
        q.add({ fn : "results += 'X'" },
442
 
              { fn : /results += 'X'/ },
443
 
              { fn : function () { Y.Assert.areSame("RUN", results); } }).run();
444
 
    },
445
 
 
446
 
    test_context : function () {
447
 
        var a = { id : 'a',
448
 
                  test : 'A',
449
 
                  fn : function () {
450
 
                    Y.Assert.areSame('A', this.test);
451
 
                  }
452
 
                },
453
 
 
454
 
            q = new Y.AsyncQueue({ test : 'callbacks exec from Queue ctx by default' },
455
 
                function () { Y.Assert.areSame('X', this.test); },
456
 
                {
457
 
                    fn: function () {
458
 
                        Y.Assert.areSame('X', this.test);
459
 
                        this.test = 'Z';
460
 
                    }
461
 
                },
462
 
                function () { Y.Assert.areSame('Z', this.test); },
463
 
                a,
464
 
                {
465
 
                    fn: function () {
466
 
                        Y.Assert.areSame('B', this.test);
467
 
                    },
468
 
                    context : { test : 'B' }
469
 
                });
470
 
 
471
 
        q.getCallback('a').context = a;
472
 
 
473
 
        q.test = 'X';
474
 
        q.run();
475
 
    },
476
 
 
477
 
    test_args : function () {
478
 
        new Y.AsyncQueue(
479
 
            function () {
480
 
                Y.Assert.areSame(0,arguments.length);
481
 
            },
482
 
            {
483
 
                fn: function () {
484
 
                    Y.ArrayAssert.itemsAreSame([1,2,3],arguments);
485
 
                },
486
 
                args : [1,2,3]
487
 
            },
488
 
            {
489
 
                fn: function () {
490
 
                    Y.ArrayAssert.itemsAreSame(['X'],arguments);
491
 
                },
492
 
                args : 'X'
493
 
            }).run();
494
 
    },
495
 
 
496
 
    test_iterations : function () {
497
 
        var results = '',
498
 
            self = this;
499
 
       
500
 
        new Y.AsyncQueue(
501
 
            function () { results += 'A'; },
502
 
            { fn: function () { results += 'B'; } },
503
 
            { fn: function () { results += 'C'; }, iterations: 3 },
504
 
            { fn: function () { results += 'D'; }, iterations: 3, timeout: 10 },
505
 
            { fn: function () {
506
 
                self.resume(function () {
507
 
                    Y.Assert.areSame('ABCCCDDD', results);
508
 
                });
509
 
              }
510
 
            }).run();
511
 
 
512
 
        this.wait();
513
 
    },
514
 
 
515
 
    test_until : function () {
516
 
        var results = '',
517
 
            self = this;
518
 
       
519
 
        new Y.AsyncQueue(
520
 
            function () { results += 'A'; },
521
 
            {
522
 
                fn: function () {
523
 
                    results += 'B';
524
 
                },
525
 
                until: function () {
526
 
                    this.data = this.data.slice(1);
527
 
                    return !this.data;
528
 
                },
529
 
                data : '1234'
530
 
            },
531
 
            {
532
 
                fn: function () {
533
 
                    results += 'C';
534
 
                },
535
 
                until: function () {
536
 
                    return results.length >= 7;
537
 
                },
538
 
                timeout: 10
539
 
            },
540
 
            { fn: function () {
541
 
                self.resume(function () {
542
 
                    Y.Assert.areSame('ABBBCCC', results);
543
 
                });
544
 
              }
545
 
            }).run();
546
 
 
547
 
        Y.Assert.areSame('ABBB', results);
548
 
 
549
 
        this.wait();
550
 
    },
551
 
 
552
 
    test_timeout : function () {
553
 
        function inc() { ++results; }
554
 
 
555
 
        var results = 0,
556
 
            self = this,
557
 
                // default timeout -1 triggers synchronous mode
558
 
            q = new Y.AsyncQueue(
559
 
                inc, // -1 == sync
560
 
                { fn: inc }, // -1 == sync
561
 
                { fn: inc, timeout: 10, iterations: 4 },
562
 
                { fn: inc, timeout: -300, iterations: 4 }, // neg == sync
563
 
                // garbage timeout doesn't throw error, but is async
564
 
                { fn: inc, timeout: 'a',
565
 
                    until: function () {
566
 
                        return results >= 10;
567
 
                    }
568
 
                },
569
 
                function () {
570
 
                    self.resume(function () {
571
 
                        Y.Assert.areSame(10,results);
572
 
                    });
573
 
                }).run();
574
 
 
575
 
        Y.Assert.areSame(2, results);
576
 
 
577
 
        this.wait();
578
 
    },
579
 
 
580
 
    /*
581
 
    test_waitForIOResponse : function () {
582
 
        function good() {
583
 
            var url = 'queue.html?cachebuster='+Y.guid();
584
 
            Y.io(url, {
585
 
                on : {
586
 
                    success : function () { results.success++; },
587
 
                    failure : function () { results.failure++; }
588
 
                }
589
 
            });
590
 
        }
591
 
 
592
 
        function bad() {
593
 
            var url = Y.guid() + (Math.random() * 1000) + '.html'; // 404
594
 
            Y.io(url, {
595
 
                on : {
596
 
                    success : function () { results.success++; },
597
 
                    failure : function () { results.failure++; }
598
 
                }
599
 
            });
600
 
        }
601
 
 
602
 
        function late() {
603
 
            var url = 'io_timeout.php?cachebuster=' + Y.guid();
604
 
            Y.io(url, {
605
 
                on : {
606
 
                    success : function () { results.success++; },
607
 
                    failure : function () { results.failure++; },
608
 
                    abort   : function () { results.failure++; }
609
 
                },
610
 
                timeout : 10
611
 
            });
612
 
        }
613
 
        
614
 
        function test(s,f,step) {
615
 
            return function () {
616
 
                var msg = "Incorrect number of ",
617
 
                    data;
618
 
 
619
 
                if (results.success !== s) {
620
 
                    msg += 'successes';
621
 
                    data = [s,results.success];
622
 
                } else if (results.failure !== f) {
623
 
                    msg += 'failures';
624
 
                    data = [f,results.failure];
625
 
                } else {
626
 
                    msg = '';
627
 
                }
628
 
 
629
 
                if (msg) {
630
 
                    msg += ' at step ' + step +
631
 
                           '. Expected ' + data[0] + ', got ' + data[1];
632
 
                    q.stop();
633
 
                    self.resume(function () {
634
 
                        Y.Assert.fail(msg);
635
 
                    });
636
 
                }
637
 
            }
638
 
        }
639
 
 
640
 
        var results = { success: 0, failure: 0 },
641
 
            self = this,
642
 
            q = new Y.AsyncQueue(
643
 
                {
644
 
                    fn : good,
645
 
                    waitForIOResponse: true
646
 
                },
647
 
                test(1,0,1),
648
 
                {
649
 
                    fn : function () { good(); good(); good(); },
650
 
                    waitForIOResponse: true
651
 
                },
652
 
                test(4,0,2),
653
 
                {
654
 
                    fn : function () { bad(); good(); late(); },
655
 
                    waitForIOResponse: true
656
 
                },
657
 
                test(5,2,3),
658
 
                {
659
 
                    fn : function () { late(); good(); },
660
 
                    waitForIOResponse: true
661
 
                },
662
 
                test(6,3,4),
663
 
                {
664
 
                    // wait not triggered
665
 
                    fn : function () {
666
 
                        bad(); bad();
667
 
                    }
668
 
                },
669
 
                test(6,3,5),
670
 
                function () { self.resume(function () {}); }).run();
671
 
 
672
 
        this.wait();
673
 
    }
674
 
    */
675
 
}));
676
 
 
677
 
suite.add(new Y.Test.Case({
678
 
    name : "Test Events",
679
 
 
680
 
    test_events : function () {
681
 
        var results = [],
682
 
            self = this,
683
 
            q = new Y.AsyncQueue(
684
 
                function () { results.push("E"); this.pause(); },
685
 
                {
686
 
                    fn: function () { results.push("E"); },
687
 
                    until: function () { return results.length > 25; },
688
 
                    timeout: 10
689
 
                },
690
 
                {
691
 
                    id: 'x',
692
 
                    fn: function () { results.push("X"); }
693
 
                },
694
 
                {
695
 
                    id: 'v',
696
 
                    fn: function () { results.push("V"); },
697
 
                    iterations: 3
698
 
                },
699
 
                {
700
 
                    fn: function () {
701
 
                        results.push("N");
702
 
                        Y.io(Y.guid() + '.html', { // 404
703
 
                            on : {
704
 
                                failure : function () {
705
 
                                    results.push("T");
706
 
                                }
707
 
                            }
708
 
                        });
709
 
                    },
710
 
                    waitForIOResponse : true
711
 
                });
712
 
 
713
 
        q.on('execute',function () { results.push("(onExec)"); });
714
 
        q.after('execute',    function () { results.push("(afterExec)"); });
715
 
 
716
 
        q.on("shift",  function () { results.push("(onShift)"); });
717
 
        q.after("shift",      function () { results.push("(afterShift)"); });
718
 
 
719
 
        q.on("remove", function () { results.push("(onRemove)"); });
720
 
        q.after("remove", function () { results.push("(afterRemove)"); });
721
 
 
722
 
        q.on("add", function (e) { results.push("(onAdd)"); });
723
 
        q.after("add", function (e) {
724
 
            var data = e.added;
725
 
            results.push("(afterAdd)");
726
 
            if (!data || data.length !== 4) {
727
 
                self.resume(function () {
728
 
                    Y.Assert.fail("add args not right");
729
 
                });
730
 
            }
731
 
        });
732
 
 
733
 
        q.on("promote", function () { results.push("(onPromote)"); });
734
 
 
735
 
        q.after("promote", function () {
736
 
            results.push("(afterPromote)");
737
 
            setTimeout(function () {
738
 
                q.run();
739
 
            }, 0);
740
 
        });
741
 
 
742
 
        q.on("complete", function () {
743
 
            results.push("(onComplete)");
744
 
            self.resume(function () {
745
 
                Y.ArrayAssert.itemsAreEqual([
746
 
                    "(onAdd)",
747
 
                    "(afterAdd)",
748
 
 
749
 
                    "(onRemove)",
750
 
                    "(afterRemove)",
751
 
 
752
 
                    "(onExec)",
753
 
                    "E",
754
 
                    "(afterExec)",
755
 
 
756
 
                    "(onShift)",
757
 
                    "(afterShift)",
758
 
 
759
 
                    "(onPromote)",
760
 
                    "(afterPromote)",
761
 
 
762
 
                    "(onExec)",
763
 
                    "V",
764
 
                    "(afterExec)",
765
 
                    "(onExec)",
766
 
                    "V",
767
 
                    "(afterExec)",
768
 
                    "(onExec)",
769
 
                    "V",
770
 
                    "(afterExec)",
771
 
 
772
 
                    "(onShift)",
773
 
                    "(afterShift)",
774
 
 
775
 
                    "(onExec)",
776
 
                    "E",
777
 
                    "(afterExec)",
778
 
                    "(onExec)",
779
 
                    "E",
780
 
                    "(afterExec)",
781
 
 
782
 
                    "(onShift)",
783
 
                    "(afterShift)",
784
 
 
785
 
                    "(onExec)",
786
 
                    "N",
787
 
                    "(afterExec)",
788
 
 
789
 
                    "(onShift)",
790
 
                    "(afterShift)",
791
 
 
792
 
                    /*
793
 
                    "(onExec)",
794
 
                    "T",
795
 
                    "(afterExec)",
796
 
                    "(onShift)",
797
 
                    "(afterShift)",
798
 
                    */
799
 
 
800
 
                    "(onExec)",
801
 
                    "S",
802
 
                    "(afterExec)",
803
 
 
804
 
                    /* // no shift because stop() flushed _q
805
 
                    "(onShift)",
806
 
                    "(afterShift)",
807
 
                    */
808
 
 
809
 
                    "(onComplete)",
810
 
                    ], results);
811
 
            });
812
 
        });
813
 
 
814
 
        q.add(function () { results.push("S"); this.stop(); },f,f,f);
815
 
        q.remove('x');
816
 
 
817
 
        q.run();
818
 
        q.promote('v');
819
 
 
820
 
        this.wait();
821
 
    },
822
 
 
823
 
    test_preventCallback : function () {
824
 
        function inc () { i++; }
825
 
 
826
 
        var i = 0,
827
 
            q = new Y.AsyncQueue(inc,inc,
828
 
                {
829
 
                    foo: true,
830
 
                    fn: inc,
831
 
                    iterations: 20
832
 
                },
833
 
                {
834
 
                    fn: inc,
835
 
                    until : function () {
836
 
                        return i >= 10;
837
 
                    }
838
 
                });
839
 
 
840
 
        q.on('execute', function (e) {
841
 
            if (e.callback.foo) {
842
 
                e.preventDefault();
843
 
            }
844
 
        });
845
 
 
846
 
        q.run();
847
 
 
848
 
        Y.Assert.areSame(10,i);
849
 
 
850
 
        q = new Y.AsyncQueue(inc, inc, inc, inc, inc, inc, inc, inc, inc, inc);
851
 
        q.on('shift', function (e) {
852
 
            if (i % 2) {
853
 
                e.preventDefault();
854
 
                q._q[0].iterations++;
855
 
            }
856
 
        });
857
 
 
858
 
        q.run();
859
 
 
860
 
        Y.Assert.areSame(30, i);
861
 
    }
862
 
}));
863
 
 
864
 
/*
865
 
// Avoiding a Y.Test bug where tests repeat infinitely
866
 
suite.add(new Y.Test.Case({
867
 
    name : "From bugs",
868
 
 
869
 
    // Bug 2528602
870
 
    test_double_exec_when_pause_and_run_async : function () {
871
 
        var q = new Y.AsyncQueue(),
872
 
            register = 0,
873
 
            self = this;
874
 
 
875
 
        q.defaults.timeout = 10;
876
 
        q.add({
877
 
            id: 'one',
878
 
            fn: function() {
879
 
                q.pause();
880
 
                register += 1;
881
 
                q.run();
882
 
            }
883
 
        }, {
884
 
            id: 'two',
885
 
            fn: function() {
886
 
                register += 10;
887
 
            },
888
 
            iterations: 1
889
 
        });
890
 
 
891
 
        q.on( 'complete', function () {
892
 
            self.resume( function () {
893
 
                Y.log( register );
894
 
                Y.Assert.areSame( 11, register );
895
 
            } );
896
 
        } );
897
 
        
898
 
        q.run();
899
 
 
900
 
        this.wait();
901
 
 
902
 
    }
903
 
}));
904
 
*/
905
 
 
906
 
var yconsole = new Y.Console({
907
 
    contentBox:"log",
908
 
    newestOnTop: false,
909
 
    height: '500px'
910
 
}).render();
911
 
 
912
 
//yconsole.hideCategory('info');
913
 
 
914
 
Y.Test.Runner.add(suite);
915
 
 
916
 
Y.Test.Runner.run();
917
 
 
918
 
});
919
 
</script>
920
 
</body>
921
 
</html>