~ubuntu-branches/ubuntu/precise/whoopsie-daisy/precise-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-18 13:04:36 UTC
  • Revision ID: package-import@ubuntu.com-20120418130436-vmt93p8fds516lws
Tags: 0.1.32
Fix failing tests on powerpc and ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
YUI.add('event-key-tests', function(Y) {
 
2
 
 
3
Y.Node.prototype.key = function (keyCode, charCode, mods, type) {
 
4
    var simulate = Y.Event.simulate,
 
5
        el       = this._node,
 
6
        config   = Y.merge(mods || {});
 
7
 
 
8
    if (type) {
 
9
        if (type === 'keypress') {
 
10
            config.charCode = config.keyCode = config.which = charCode || keyCode;
 
11
        } else {
 
12
            config.keyCode = config.which = keyCode;
 
13
        }
 
14
        simulate(el, type, config);
 
15
    } else {
 
16
        config.keyCode = config.which = keyCode;
 
17
        simulate(el, 'keydown', config);
 
18
        simulate(el, 'keyup', config);
 
19
 
 
20
        config.charCode = config.keyCode = config.which = charCode || keyCode;
 
21
        simulate(el, 'keypress', config);
 
22
    }
 
23
};
 
24
 
 
25
function setUp() {
 
26
    var testbed = Y.one('#testbed'),
 
27
        body;
 
28
 
 
29
    if (!testbed) {
 
30
        body = Y.one('body');
 
31
        testbed = body.create('<div id="testbed"></div>');
 
32
        body.prepend(testbed);
 
33
    }
 
34
 
 
35
    testbed.setContent(
 
36
    '<ul id="items">' +
 
37
        '<li id="item1">' +
 
38
            '<div id="div1"><input type="text" id="text1" name="text1"></div>' +
 
39
        '</li>' +
 
40
        '<li id="item2">' +
 
41
            '<div id="div2"><input type="text" id="text2" name="text2"></div>' +
 
42
        '</li>' +
 
43
        '<li id="item3">' +
 
44
            '<div id="div3"><textarea id="area1" name="area1"></textarea></div>' +
 
45
        '</li>' +
 
46
    '</ul>');
 
47
}
 
48
 
 
49
function tearDown() {
 
50
    var testbed = Y.one('#testbed');
 
51
 
 
52
    if (testbed) {
 
53
        testbed.remove().destroy(true);
 
54
    }
 
55
}
 
56
 
 
57
var suite = new Y.Test.Suite("event-key");
 
58
 
 
59
suite.add(new Y.Test.Case({
 
60
    name: "node.on('key',...)",
 
61
 
 
62
    setUp: setUp,
 
63
    tearDown: tearDown,
 
64
 
 
65
    "test node.on('key', fn, '65')": function () {
 
66
        var input = Y.one("#text1"),
 
67
            target, type, currentTarget, keyCode, thisObj;
 
68
 
 
69
        input.on("key", function (e) {
 
70
            target = e.target;
 
71
            type = e.type;
 
72
            currentTarget = e.currentTarget;
 
73
            keyCode = e.keyCode;
 
74
            thisObj = this;
 
75
        }, '65');
 
76
 
 
77
        input.key(65);
 
78
 
 
79
        Y.Assert.areSame(input, target);
 
80
        Y.Assert.areSame("key", type);
 
81
        Y.Assert.areSame(input, currentTarget);
 
82
        Y.Assert.areSame(65, keyCode);
 
83
        Y.Assert.areSame(input, thisObj);
 
84
    },
 
85
 
 
86
    "test node.on('key', fn, '65', thisObj)": function () {
 
87
        var input = Y.one("#text1"),
 
88
            obj   = { foo: "foo" },
 
89
            target, type, currentTarget, keyCode, thisObj;
 
90
 
 
91
        input.on("key", function (e) {
 
92
            target = e.target;
 
93
            type = e.type;
 
94
            currentTarget = e.currentTarget;
 
95
            keyCode = e.keyCode;
 
96
            thisObj = this;
 
97
        }, '65', obj);
 
98
 
 
99
        input.key(65);
 
100
 
 
101
        Y.Assert.areSame(input, target);
 
102
        Y.Assert.areSame("key", type);
 
103
        Y.Assert.areSame(input, currentTarget);
 
104
        Y.Assert.areSame(65, keyCode);
 
105
        Y.Assert.areSame(obj, thisObj);
 
106
    },
 
107
 
 
108
    "test node.on('key', fn, '65', thisObj, args)": function () {
 
109
        var input = Y.one("#text1"),
 
110
            obj   = { foo: "foo" },
 
111
            target, type, currentTarget, keyCode, thisObj, arg;
 
112
 
 
113
        input.on("key", function (e, x) {
 
114
            target = e.target;
 
115
            type = e.type;
 
116
            currentTarget = e.currentTarget;
 
117
            keyCode = e.keyCode;
 
118
            thisObj = this;
 
119
            arg = x;
 
120
        }, '65', obj, "ARG!");
 
121
 
 
122
        input.key(65);
 
123
 
 
124
        Y.Assert.areSame(input, target);
 
125
        Y.Assert.areSame("key", type);
 
126
        Y.Assert.areSame(input, currentTarget);
 
127
        Y.Assert.areSame(65, keyCode);
 
128
        Y.Assert.areSame(obj, thisObj);
 
129
        Y.Assert.areSame("ARG!", arg);
 
130
    }
 
131
}));
 
132
 
 
133
suite.add(new Y.Test.Case({
 
134
    name: "nodelist.on('key',...)",
 
135
 
 
136
    setUp: setUp,
 
137
    tearDown: tearDown,
 
138
 
 
139
    "test nodelist.on('key', fn, '65')": function () {
 
140
        var inputs = Y.all("#items input"),
 
141
            item0 = inputs.item(0),
 
142
            item1 = inputs.item(1),
 
143
            target = [],
 
144
            type = [],
 
145
            currentTarget = [],
 
146
            keyCode = [],
 
147
            thisObj = [];
 
148
 
 
149
        inputs.on("key", function (e) {
 
150
            target.push(e.target);
 
151
            type.push(e.type);
 
152
            currentTarget.push(e.currentTarget);
 
153
            keyCode.push(e.keyCode);
 
154
            thisObj.push(this);
 
155
        }, '65');
 
156
 
 
157
        item0.key(65);
 
158
        item1.key(65);
 
159
 
 
160
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
161
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
162
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
163
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
164
        // Synth infrastructure iterates nodelist input for individual
 
165
        // subscription for each node, so 'this' is not the nodelist as
 
166
        // it is with nodelist.on('click');
 
167
        //Y.ArrayAssert.itemsAreSame([inputs, inputs], thisObj);
 
168
        Y.ArrayAssert.itemsAreSame([item0, item1], thisObj);
 
169
    },
 
170
 
 
171
    "test nodelist.on('key', fn, '65', thisObj)": function () {
 
172
        var inputs = Y.all("#items input"),
 
173
            item0 = inputs.item(0),
 
174
            item1 = inputs.item(1),
 
175
            obj = { foo: "foo" },
 
176
            target = [],
 
177
            type = [],
 
178
            currentTarget = [],
 
179
            keyCode = [],
 
180
            thisObj = [];
 
181
 
 
182
        inputs.on("key", function (e) {
 
183
            target.push(e.target);
 
184
            type.push(e.type);
 
185
            currentTarget.push(e.currentTarget);
 
186
            keyCode.push(e.keyCode);
 
187
            thisObj.push(this);
 
188
        }, '65', obj);
 
189
 
 
190
        item0.key(65);
 
191
        item1.key(65);
 
192
 
 
193
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
194
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
195
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
196
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
197
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
 
198
    },
 
199
 
 
200
    "test nodelist.on('key', fn, '65', thisObj, args)": function () {
 
201
        var inputs = Y.all("#items input"),
 
202
            item0 = inputs.item(0),
 
203
            item1 = inputs.item(1),
 
204
            obj = { foo: "foo" },
 
205
            target = [],
 
206
            type = [],
 
207
            currentTarget = [],
 
208
            keyCode = [],
 
209
            thisObj = [],
 
210
            arg = [];
 
211
 
 
212
        inputs.on("key", function (e, x) {
 
213
            target.push(e.target);
 
214
            type.push(e.type);
 
215
            currentTarget.push(e.currentTarget);
 
216
            keyCode.push(e.keyCode);
 
217
            thisObj.push(this);
 
218
            arg.push(x);
 
219
        }, '65', obj, "ARG!");
 
220
 
 
221
        item0.key(65);
 
222
        item1.key(65);
 
223
 
 
224
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
225
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
226
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
227
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
228
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
 
229
        Y.ArrayAssert.itemsAreSame(["ARG!", "ARG!"], arg);
 
230
    }
 
231
}));
 
232
 
 
233
suite.add(new Y.Test.Case({
 
234
    name: "Y.on('key',...)",
 
235
 
 
236
    setUp: setUp,
 
237
    tearDown: tearDown,
 
238
 
 
239
    "test Y.on('key', fn, selector, '65')": function () {
 
240
        var input = Y.one("#text1"),
 
241
            target, type, currentTarget, keyCode, thisObj;
 
242
 
 
243
        Y.on("key", function (e) {
 
244
            target = e.target;
 
245
            type = e.type;
 
246
            currentTarget = e.currentTarget;
 
247
            keyCode = e.keyCode;
 
248
            thisObj = this;
 
249
        }, '#text1', '65');
 
250
 
 
251
        input.key(65);
 
252
 
 
253
        Y.Assert.areSame(input, target);
 
254
        Y.Assert.areSame("key", type);
 
255
        Y.Assert.areSame(input, currentTarget);
 
256
        Y.Assert.areSame(65, keyCode);
 
257
        Y.Assert.areSame(input, thisObj);
 
258
    },
 
259
 
 
260
    "test Y.on('key', fn, node, '65')": function () {
 
261
        var input = Y.one("#text1"),
 
262
            target, type, currentTarget, keyCode, thisObj;
 
263
 
 
264
        Y.on("key", function (e) {
 
265
            target = e.target;
 
266
            type = e.type;
 
267
            currentTarget = e.currentTarget;
 
268
            keyCode = e.keyCode;
 
269
            thisObj = this;
 
270
        }, input, '65');
 
271
 
 
272
        input.key(65);
 
273
 
 
274
        Y.Assert.areSame(input, target);
 
275
        Y.Assert.areSame("key", type);
 
276
        Y.Assert.areSame(input, currentTarget);
 
277
        Y.Assert.areSame(65, keyCode);
 
278
        Y.Assert.areSame(input, thisObj);
 
279
    },
 
280
 
 
281
    "test Y.on('key', fn, selector, '65', thisObj)": function () {
 
282
        var input = Y.one("#text1"),
 
283
            obj   = { foo: "foo" },
 
284
            target, type, currentTarget, keyCode, thisObj;
 
285
 
 
286
        Y.on("key", function (e) {
 
287
            target = e.target;
 
288
            type = e.type;
 
289
            currentTarget = e.currentTarget;
 
290
            keyCode = e.keyCode;
 
291
            thisObj = this;
 
292
        }, '#text1', '65', obj);
 
293
 
 
294
        input.key(65);
 
295
 
 
296
        Y.Assert.areSame(input, target);
 
297
        Y.Assert.areSame("key", type);
 
298
        Y.Assert.areSame(input, currentTarget);
 
299
        Y.Assert.areSame(65, keyCode);
 
300
        Y.Assert.areSame(obj, thisObj);
 
301
    },
 
302
 
 
303
    "test Y.on('key', fn, selector, '65', thisObj, args)": function () {
 
304
        var input = Y.one("#text1"),
 
305
            obj   = { foo: "foo" },
 
306
            target, type, currentTarget, keyCode, thisObj, arg;
 
307
 
 
308
        Y.on("key", function (e, x) {
 
309
            target = e.target;
 
310
            type = e.type;
 
311
            currentTarget = e.currentTarget;
 
312
            keyCode = e.keyCode;
 
313
            thisObj = this;
 
314
            arg = x;
 
315
        }, '#text1', '65', obj, "ARG!");
 
316
 
 
317
        input.key(65);
 
318
 
 
319
        Y.Assert.areSame(input, target);
 
320
        Y.Assert.areSame("key", type);
 
321
        Y.Assert.areSame(input, currentTarget);
 
322
        Y.Assert.areSame(65, keyCode);
 
323
        Y.Assert.areSame(obj, thisObj);
 
324
        Y.Assert.areSame("ARG!", arg);
 
325
    }
 
326
}));
 
327
 
 
328
suite.add(new Y.Test.Case({
 
329
    name: "node.delegate('key',...)",
 
330
 
 
331
    setUp: setUp,
 
332
    tearDown: tearDown,
 
333
 
 
334
    "test node.delegate('key', fn, '65', filter)": function () {
 
335
        var items = Y.one("#items"),
 
336
            item0 = items.one("#text1"),
 
337
            item1 = items.one("#text2"),
 
338
            item2 = items.one("#area1"),
 
339
            target = [],
 
340
            type = [],
 
341
            container = [],
 
342
            currentTarget = [],
 
343
            keyCode = [],
 
344
            thisObj = [];
 
345
 
 
346
        items.delegate("key", function (e) {
 
347
            target.push(e.target);
 
348
            type.push(e.type);
 
349
            currentTarget.push(e.currentTarget);
 
350
            container.push(e.container);
 
351
            keyCode.push(e.keyCode);
 
352
            thisObj.push(this);
 
353
        }, '65', 'input');
 
354
 
 
355
        item0.key(65);
 
356
        item1.key(65);
 
357
        item2.key(65);
 
358
 
 
359
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
360
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
361
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
362
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
363
        Y.ArrayAssert.itemsAreSame([item0, item1], thisObj);
 
364
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
365
    },
 
366
 
 
367
    "test node.delegate('key', fn, '65', filter, thisObj)": function () {
 
368
        var items = Y.one("#items"),
 
369
            item0 = items.one("#text1"),
 
370
            item1 = items.one("#text2"),
 
371
            item2 = items.one("#area1"),
 
372
            obj = { foo: "foo" },
 
373
            target = [],
 
374
            type = [],
 
375
            container = [],
 
376
            currentTarget = [],
 
377
            keyCode = [],
 
378
            thisObj = [];
 
379
 
 
380
        items.delegate("key", function (e) {
 
381
            target.push(e.target);
 
382
            type.push(e.type);
 
383
            currentTarget.push(e.currentTarget);
 
384
            container.push(e.container);
 
385
            keyCode.push(e.keyCode);
 
386
            thisObj.push(this);
 
387
        }, '65', 'input', obj);
 
388
 
 
389
        item0.key(65);
 
390
        item1.key(65);
 
391
        item2.key(65);
 
392
 
 
393
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
394
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
395
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
396
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
397
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
 
398
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
399
    },
 
400
 
 
401
    "test node.delegate('key', fn, '65', filter, thisObj, args)": function () {
 
402
        var items = Y.one("#items"),
 
403
            item0 = items.one("#text1"),
 
404
            item1 = items.one("#text2"),
 
405
            item2 = items.one("#area1"),
 
406
            obj = { foo: "foo" },
 
407
            target = [],
 
408
            type = [],
 
409
            container = [],
 
410
            currentTarget = [],
 
411
            keyCode = [],
 
412
            thisObj = [],
 
413
            args = [];
 
414
 
 
415
        items.delegate("key", function (e, x) {
 
416
            target.push(e.target);
 
417
            type.push(e.type);
 
418
            currentTarget.push(e.currentTarget);
 
419
            container.push(e.container);
 
420
            keyCode.push(e.keyCode);
 
421
            thisObj.push(this);
 
422
            args.push(x);
 
423
        }, '65', 'input', obj, "ARG!");
 
424
 
 
425
        item0.key(65);
 
426
        item1.key(65);
 
427
        item2.key(65);
 
428
 
 
429
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
430
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
431
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
432
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
433
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
 
434
        Y.ArrayAssert.itemsAreSame(["ARG!", "ARG!"], args);
 
435
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
436
    }
 
437
}));
 
438
 
 
439
suite.add(new Y.Test.Case({
 
440
    name: "Y.delegate('key',...)",
 
441
 
 
442
    setUp: setUp,
 
443
    tearDown: tearDown,
 
444
 
 
445
    "test Y.delegate('key', fn, '65', selector, filter)": function () {
 
446
        var items = Y.one("#items"),
 
447
            item0 = items.one("#text1"),
 
448
            item1 = items.one("#text2"),
 
449
            item2 = items.one("#area1"),
 
450
            target = [],
 
451
            type = [],
 
452
            container = [],
 
453
            currentTarget = [],
 
454
            keyCode = [],
 
455
            thisObj = [];
 
456
 
 
457
        Y.delegate("key", function (e) {
 
458
            target.push(e.target);
 
459
            type.push(e.type);
 
460
            currentTarget.push(e.currentTarget);
 
461
            container.push(e.container);
 
462
            keyCode.push(e.keyCode);
 
463
            thisObj.push(this);
 
464
        }, '#items', '65', 'input');
 
465
 
 
466
        item0.key(65);
 
467
        item1.key(65);
 
468
        item2.key(65);
 
469
 
 
470
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
471
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
472
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
473
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
474
        Y.ArrayAssert.itemsAreSame([item0, item1], thisObj);
 
475
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
476
    },
 
477
 
 
478
    "test Y.delegate('key', fn, '65', node, filter)": function () {
 
479
        var items = Y.one("#items"),
 
480
            item0 = items.one("#text1"),
 
481
            item1 = items.one("#text2"),
 
482
            item2 = items.one("#area1"),
 
483
            target = [],
 
484
            type = [],
 
485
            container = [],
 
486
            currentTarget = [],
 
487
            keyCode = [],
 
488
            thisObj = [];
 
489
 
 
490
        Y.delegate("key", function (e) {
 
491
            target.push(e.target);
 
492
            type.push(e.type);
 
493
            currentTarget.push(e.currentTarget);
 
494
            container.push(e.container);
 
495
            keyCode.push(e.keyCode);
 
496
            thisObj.push(this);
 
497
        }, items, '65', 'input');
 
498
 
 
499
        item0.key(65);
 
500
        item1.key(65);
 
501
        item2.key(65);
 
502
 
 
503
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
504
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
505
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
506
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
507
        Y.ArrayAssert.itemsAreSame([item0, item1], thisObj);
 
508
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
509
    },
 
510
 
 
511
    "test Y.delegate('key', fn, '65', selector, filter, thisObj)": function () {
 
512
        var items = Y.one("#items"),
 
513
            item0 = items.one("#text1"),
 
514
            item1 = items.one("#text2"),
 
515
            item2 = items.one("#area1"),
 
516
            obj = { foo: "foo" },
 
517
            target = [],
 
518
            type = [],
 
519
            container = [],
 
520
            currentTarget = [],
 
521
            keyCode = [],
 
522
            thisObj = [];
 
523
 
 
524
        Y.delegate("key", function (e) {
 
525
            target.push(e.target);
 
526
            type.push(e.type);
 
527
            currentTarget.push(e.currentTarget);
 
528
            container.push(e.container);
 
529
            keyCode.push(e.keyCode);
 
530
            thisObj.push(this);
 
531
        }, '#items', '65', 'input', obj);
 
532
 
 
533
        item0.key(65);
 
534
        item1.key(65);
 
535
        item2.key(65);
 
536
 
 
537
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
538
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
539
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
540
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
541
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
 
542
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
543
    },
 
544
 
 
545
    "test Y.delegate('key', fn, '65', selector, filter, thisObj, args)": function () {
 
546
        var items = Y.one("#items"),
 
547
            item0 = items.one("#text1"),
 
548
            item1 = items.one("#text2"),
 
549
            item2 = items.one("#area1"),
 
550
            obj = { foo: "foo" },
 
551
            target = [],
 
552
            type = [],
 
553
            container = [],
 
554
            currentTarget = [],
 
555
            keyCode = [],
 
556
            thisObj = [],
 
557
            args = [];
 
558
 
 
559
        Y.delegate("key", function (e, x) {
 
560
            target.push(e.target);
 
561
            type.push(e.type);
 
562
            currentTarget.push(e.currentTarget);
 
563
            container.push(e.container);
 
564
            keyCode.push(e.keyCode);
 
565
            thisObj.push(this);
 
566
            args.push(x);
 
567
        }, '#items', '65', 'input', obj, "ARG!");
 
568
 
 
569
        item0.key(65);
 
570
        item1.key(65);
 
571
        item2.key(65);
 
572
 
 
573
        Y.ArrayAssert.itemsAreSame([item0, item1], target);
 
574
        Y.ArrayAssert.itemsAreSame(["key", "key"], type);
 
575
        Y.ArrayAssert.itemsAreSame([item0, item1], currentTarget);
 
576
        Y.ArrayAssert.itemsAreSame([65, 65], keyCode);
 
577
        Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
 
578
        Y.ArrayAssert.itemsAreSame(["ARG!", "ARG!"], args);
 
579
        Y.ArrayAssert.itemsAreSame([items, items], container);
 
580
    }
 
581
 
 
582
}));
 
583
 
 
584
suite.add(new Y.Test.Case({
 
585
    name: "key spec/filter",
 
586
 
 
587
    setUp: setUp,
 
588
    tearDown: tearDown,
 
589
 
 
590
    "test 'down:65'": function () {
 
591
        var input = Y.one("#text1"),
 
592
            count = 0;
 
593
 
 
594
        function inc() {
 
595
            count++;
 
596
        }
 
597
 
 
598
        input.on("key", inc, 'down:65');
 
599
 
 
600
        input.key(65);
 
601
        Y.Assert.areSame(1, count);
 
602
 
 
603
        input.key(65, null, null, 'keydown');
 
604
        Y.Assert.areSame(2, count);
 
605
 
 
606
        input.key(65, 65, null, 'keypress');
 
607
        Y.Assert.areSame(2, count);
 
608
 
 
609
        input.key(99);
 
610
        Y.Assert.areSame(2, count);
 
611
    },
 
612
 
 
613
    "test 'up:65'": function () {
 
614
        var input = Y.one("#text1"),
 
615
            count = 0;
 
616
 
 
617
        function inc() {
 
618
            count++;
 
619
        }
 
620
 
 
621
        input.on("key", inc, 'up:65');
 
622
 
 
623
        input.key(65);
 
624
        Y.Assert.areSame(1, count);
 
625
 
 
626
        input.key(65, null, null, 'keyup');
 
627
        Y.Assert.areSame(2, count);
 
628
 
 
629
        input.key(65, 65, null, 'keypress');
 
630
        Y.Assert.areSame(2, count);
 
631
 
 
632
        input.key(99);
 
633
        Y.Assert.areSame(2, count);
 
634
    },
 
635
 
 
636
    "test 'press:65'": function () {
 
637
        var input = Y.one("#text1"),
 
638
            count = 0;
 
639
 
 
640
        function inc() {
 
641
            count++;
 
642
        }
 
643
 
 
644
        input.on("key", inc, 'press:65');
 
645
 
 
646
        input.key(65);
 
647
        Y.Assert.areSame(1, count);
 
648
 
 
649
        input.key(65, null, null, 'keypress');
 
650
        Y.Assert.areSame(2, count);
 
651
 
 
652
        input.key(65, 65, null, 'keyup');
 
653
        Y.Assert.areSame(2, count);
 
654
 
 
655
        input.key(99);
 
656
        Y.Assert.areSame(2, count);
 
657
    },
 
658
 
 
659
    "test 'a'": function () {
 
660
        var input = Y.one("#text1"),
 
661
            count = 0;
 
662
 
 
663
        function inc() {
 
664
            count++;
 
665
        }
 
666
 
 
667
        input.on("key", inc, 'a');
 
668
 
 
669
        input.key(65, 97);
 
670
        Y.Assert.areSame(1, count);
 
671
 
 
672
        input.key(65, null, null, 'keydown');
 
673
        Y.Assert.areSame(1, count);
 
674
 
 
675
        input.key(65, 97, null, 'keypress');
 
676
        Y.Assert.areSame(2, count);
 
677
 
 
678
        input.key(99);
 
679
        Y.Assert.areSame(2, count);
 
680
    },
 
681
 
 
682
    "test 'down:a'": function () {
 
683
        var input = Y.one("#text1"),
 
684
            count = 0;
 
685
 
 
686
        function inc() {
 
687
            count++;
 
688
        }
 
689
 
 
690
        input.on("key", inc, 'down:a');
 
691
 
 
692
        // keydown sends keyCode, which for 'a' is 65, but I can't calculate
 
693
        // the keyCode from a character, only the charCode (97).  So none of
 
694
        // these should match.
 
695
        input.key(65, 97);
 
696
        Y.Assert.areSame(0, count);
 
697
 
 
698
        input.key(65, null, null, 'keydown');
 
699
        Y.Assert.areSame(0, count);
 
700
 
 
701
        input.key(65, 97, null, 'keypress');
 
702
        Y.Assert.areSame(0, count);
 
703
 
 
704
        // FIXME: bug confirmation that a different keyCode will trigger the
 
705
        // subscriber (keyCode 97 is NOT 'a' in keydown phase).
 
706
        input.key(97);
 
707
        Y.Assert.areSame(1, count);
 
708
    },
 
709
 
 
710
    "test 'up:a'": function () {
 
711
        var input = Y.one("#text1"),
 
712
            count = 0;
 
713
 
 
714
        function inc() {
 
715
            count++;
 
716
        }
 
717
 
 
718
        input.on("key", inc, 'up:a');
 
719
 
 
720
        // keydown sends keyCode, which for 'a' is 65, but I can't calculate
 
721
        // the keyCode from a character, only the charCode (97).  So none of
 
722
        // these should match.
 
723
        input.key(65, 97);
 
724
        Y.Assert.areSame(0, count);
 
725
 
 
726
        input.key(65, null, null, 'keyup');
 
727
        Y.Assert.areSame(0, count);
 
728
 
 
729
        input.key(65, 97, null, 'keypress');
 
730
        Y.Assert.areSame(0, count);
 
731
 
 
732
        // FIXME: bug confirmation that a different keyCode will trigger the
 
733
        // subscriber (keyCode 97 is NOT 'a' in keyup phase).
 
734
        input.key(97);
 
735
        Y.Assert.areSame(1, count);
 
736
    },
 
737
 
 
738
    "test 'press:a'": function () {
 
739
        var input = Y.one("#text1"),
 
740
            count = 0;
 
741
 
 
742
        function inc() {
 
743
            count++;
 
744
        }
 
745
 
 
746
        input.on("key", inc, 'press:a');
 
747
 
 
748
        input.key(65, 97);
 
749
        Y.Assert.areSame(1, count);
 
750
 
 
751
        input.key(65, 97, null, 'keypress');
 
752
        Y.Assert.areSame(2, count);
 
753
 
 
754
        input.key(65, 97, null, 'keyup');
 
755
        Y.Assert.areSame(2, count);
 
756
 
 
757
        input.key(99);
 
758
        Y.Assert.areSame(2, count);
 
759
    },
 
760
 
 
761
    "test 'A'": function () {
 
762
        var input = Y.one("#text1"),
 
763
            count = 0;
 
764
 
 
765
        function inc() {
 
766
            count++;
 
767
        }
 
768
 
 
769
        input.on("key", inc, 'A');
 
770
 
 
771
        input.key(65, 65, { shiftKey: true });
 
772
        Y.Assert.areSame(1, count);
 
773
 
 
774
        input.key(65, 97); // 'a'
 
775
        Y.Assert.areSame(1, count);
 
776
 
 
777
        input.key(65, 65, { shiftKey: true }, 'keypress');
 
778
        Y.Assert.areSame(2, count);
 
779
 
 
780
        input.key(99, 99, { shiftKey: true });
 
781
        Y.Assert.areSame(2, count);
 
782
    },
 
783
 
 
784
    "test 'enter', 'esc', 'backspace', 'tab', 'pageup', 'pagedown'": function () {
 
785
        var input = Y.one("#text1"),
 
786
            count = 0,
 
787
            map = {
 
788
                enter    : 13,
 
789
                esc      : 27,
 
790
                backspace: 8,
 
791
                tab      : 9,
 
792
                pageup   : 33,
 
793
                pagedown : 34
 
794
            };
 
795
 
 
796
        function inc() {
 
797
            count++;
 
798
        }
 
799
 
 
800
        Y.Object.each(map, function (code, name) {
 
801
            count = 0;
 
802
            input.on("key", inc, name);
 
803
 
 
804
            input.key(code);
 
805
            Y.Assert.areSame(1, count);
 
806
 
 
807
            // default for named keys is keydown
 
808
            input.key(code, null, null, 'keydown');
 
809
            Y.Assert.areSame(2, count);
 
810
 
 
811
            input.key(code, code, null, 'keypress');
 
812
            Y.Assert.areSame(2, count);
 
813
 
 
814
            input.key(code + 1);
 
815
            Y.Assert.areSame(2, count);
 
816
        });
 
817
    },
 
818
 
 
819
    "test 'a,b'": function () {
 
820
        var input = Y.one("#text1"),
 
821
            count = 0;
 
822
 
 
823
        function inc() {
 
824
            count++;
 
825
        }
 
826
 
 
827
        input.on("key", inc, 'a,b');
 
828
 
 
829
        input.key(65, 97);
 
830
        Y.Assert.areSame(1, count);
 
831
 
 
832
        input.key(66, 98);
 
833
        Y.Assert.areSame(2, count);
 
834
 
 
835
        input.key(65, 97, null, 'keypress');
 
836
        Y.Assert.areSame(3, count);
 
837
 
 
838
        input.key(66, null, null, 'keyup');
 
839
        Y.Assert.areSame(3, count);
 
840
 
 
841
        input.key(99);
 
842
        Y.Assert.areSame(3, count);
 
843
    },
 
844
 
 
845
    "test '65,b,esc'": function () {
 
846
        var input = Y.one("#text1"),
 
847
            count = 0;
 
848
 
 
849
        function inc() {
 
850
            count++;
 
851
        }
 
852
 
 
853
        input.on("key", inc, '65,b,esc');
 
854
 
 
855
        input.key(65, 97);
 
856
        Y.Assert.areSame(1, count);
 
857
 
 
858
        // FIXME: I want this to work, but 'esc' triggers keydown subscription,
 
859
        // which breaks the charCode mapping from 'b'.
 
860
        input.key(66, 98);
 
861
        Y.Assert.areSame(1, count);
 
862
 
 
863
        input.key(27);
 
864
        Y.Assert.areSame(2, count);
 
865
 
 
866
        // subscribed to keydown, so this misses.
 
867
        input.key(65, 97, null, 'keypress');
 
868
        Y.Assert.areSame(2, count);
 
869
 
 
870
        // FIXME: cont.
 
871
        input.key(66, null, null, 'keydown');
 
872
        Y.Assert.areSame(2, count);
 
873
 
 
874
        input.key(27, null, null, 'keydown');
 
875
        Y.Assert.areSame(3, count);
 
876
 
 
877
        input.key(99);
 
878
        Y.Assert.areSame(3, count);
 
879
    },
 
880
 
 
881
    "test 'unknownKeyName'": function () {
 
882
        var input = Y.one("#text1"),
 
883
            count = 0;
 
884
 
 
885
        function inc() {
 
886
            count++;
 
887
        }
 
888
 
 
889
        input.on("key", inc, 'ack!');
 
890
 
 
891
        // Uses first character
 
892
        input.key(65, 97);
 
893
        Y.Assert.areSame(1, count);
 
894
 
 
895
        input.key(65, 97, null, 'keypress');
 
896
        Y.Assert.areSame(2, count);
 
897
 
 
898
        input.key(66, null, null, 'keyup');
 
899
        Y.Assert.areSame(2, count);
 
900
 
 
901
        input.key(99);
 
902
        Y.Assert.areSame(2, count);
 
903
    },
 
904
 
 
905
    "test '65,unknownKeyName'": function () {
 
906
    },
 
907
 
 
908
    "test '65,unknownKeyName+alt'": function () {
 
909
    },
 
910
 
 
911
    "test 'press:a,b'": function () {
 
912
    },
 
913
 
 
914
    "test 'a+shift'": function () {
 
915
        var input = Y.one("#text1"),
 
916
            count = 0;
 
917
 
 
918
        function inc() {
 
919
            count++;
 
920
        }
 
921
 
 
922
        input.on("key", inc, 'press:a,b');
 
923
 
 
924
        input.key(65, 97);
 
925
        Y.Assert.areSame(1, count);
 
926
 
 
927
        input.key(66, 98);
 
928
        Y.Assert.areSame(2, count);
 
929
 
 
930
        input.key(65, 97, null, 'keypress');
 
931
        Y.Assert.areSame(3, count);
 
932
 
 
933
        input.key(66, null, null, 'keyup');
 
934
        Y.Assert.areSame(3, count);
 
935
 
 
936
        input.key(99);
 
937
        Y.Assert.areSame(3, count);
 
938
    },
 
939
 
 
940
    "test 'enter+ctrl'": function () {
 
941
        var input = Y.one("#text1"),
 
942
            count = 0;
 
943
 
 
944
        function inc() {
 
945
            count++;
 
946
        }
 
947
 
 
948
        input.on("key", inc, 'enter+ctrl');
 
949
 
 
950
        input.key(13);
 
951
        Y.Assert.areSame(0, count);
 
952
 
 
953
        input.key(13, null, { ctrlKey: true });
 
954
        Y.Assert.areSame(1, count);
 
955
 
 
956
        input.key(13, 13, { ctrlKey: true }, 'keypress');
 
957
        Y.Assert.areSame(1, count);
 
958
 
 
959
        input.key(13, null, { ctrlKey: true }, 'keydown');
 
960
        Y.Assert.areSame(2, count);
 
961
 
 
962
        input.key(99);
 
963
        Y.Assert.areSame(2, count);
 
964
    },
 
965
 
 
966
    "test 'up:a+alt'": function () {
 
967
    },
 
968
 
 
969
    "test 'a,b+shift+meta'": function () {
 
970
        var input = Y.one("#text1"),
 
971
            count = 0;
 
972
 
 
973
        function inc() {
 
974
            count++;
 
975
        }
 
976
 
 
977
        input.on("key", inc, 'a,b+shift+meta');
 
978
 
 
979
        input.key(65, 97);
 
980
        Y.Assert.areSame(0, count);
 
981
 
 
982
        input.key(65, 97, { ctrlKey: true });
 
983
        Y.Assert.areSame(0, count);
 
984
 
 
985
        input.key(65, 65, { ctrlKey: true, shiftKey: true });
 
986
        Y.Assert.areSame(0, count);
 
987
 
 
988
        input.key(65, 65, { metaKey: true, shiftKey: true });
 
989
        Y.Assert.areSame(1, count);
 
990
 
 
991
        input.key(65, 65, { ctrlKey: true, metaKey: true, shiftKey: true });
 
992
        Y.Assert.areSame(2, count);
 
993
 
 
994
        input.key(66, 66, { metaKey: true, shiftKey: true });
 
995
        Y.Assert.areSame(3, count);
 
996
 
 
997
        input.key(65, 65, { metaKey: true, shiftKey: true }, 'keypress');
 
998
        Y.Assert.areSame(4, count);
 
999
 
 
1000
        input.key(65, null, { metaKey: true, shiftKey: true }, 'keyup');
 
1001
        Y.Assert.areSame(4, count);
 
1002
 
 
1003
        input.key(99, 99, { metaKey: true, shiftKey: true });
 
1004
        Y.Assert.areSame(4, count);
 
1005
    },
 
1006
 
 
1007
    "test spec with spaces 'down:65, 66,   67'": function () {
 
1008
        var input = Y.one("#text1"),
 
1009
            count = 0;
 
1010
 
 
1011
        function inc() {
 
1012
            count++;
 
1013
        }
 
1014
 
 
1015
        input.on("key", inc, 'down:65, 66,   67');
 
1016
 
 
1017
        input.key(65);
 
1018
        Y.Assert.areSame(1, count);
 
1019
 
 
1020
        input.key(66);
 
1021
        Y.Assert.areSame(2, count);
 
1022
 
 
1023
        input.key(67);
 
1024
        Y.Assert.areSame(3, count);
 
1025
 
 
1026
        input.key(65, null, null, 'keyup');
 
1027
        Y.Assert.areSame(3, count);
 
1028
 
 
1029
        input.key(65, null, null, 'keydown');
 
1030
        Y.Assert.areSame(4, count);
 
1031
    },
 
1032
 
 
1033
    "test spec with no keyCodes 'down:'": function () {
 
1034
        var input = Y.one("#text1"),
 
1035
            count = 0;
 
1036
 
 
1037
        function inc() {
 
1038
            count++;
 
1039
        }
 
1040
 
 
1041
        input.on("key", inc, 'down:');
 
1042
 
 
1043
        input.key(65);
 
1044
        Y.Assert.areSame(1, count);
 
1045
 
 
1046
        input.key(66);
 
1047
        Y.Assert.areSame(2, count);
 
1048
 
 
1049
        input.key(67);
 
1050
        Y.Assert.areSame(3, count);
 
1051
 
 
1052
        input.key(65, null, null, 'keyup');
 
1053
        Y.Assert.areSame(3, count);
 
1054
 
 
1055
        input.key(40, null, null, 'keydown');
 
1056
        Y.Assert.areSame(4, count);
 
1057
    },
 
1058
 
 
1059
    "test spec with only modifiers '+ctrl+shift'": function () {
 
1060
        var input = Y.one("#text1"),
 
1061
            count = 0;
 
1062
 
 
1063
        function inc() {
 
1064
            count++;
 
1065
        }
 
1066
 
 
1067
        input.on("key", inc, '+ctrl+shift');
 
1068
 
 
1069
        input.key(65);
 
1070
        Y.Assert.areSame(0, count);
 
1071
 
 
1072
        input.key(65, 65, { shiftKey: true });
 
1073
        Y.Assert.areSame(0, count);
 
1074
 
 
1075
        input.key(65, 97, { ctrlKey: true });
 
1076
        Y.Assert.areSame(0, count);
 
1077
 
 
1078
        input.key(65, 65, { shiftKey: true, ctrlKey: true });
 
1079
        Y.Assert.areSame(1, count);
 
1080
 
 
1081
        input.key(65, 65, { shiftKey: true, ctrlKey: true, metaKey: true });
 
1082
        Y.Assert.areSame(2, count);
 
1083
 
 
1084
        input.key(65, null, { shiftKey: true, ctrlKey: true }, 'keyup');
 
1085
        Y.Assert.areSame(2, count);
 
1086
 
 
1087
        input.key(65, 65, { shiftKey: true, ctrlKey: true }, 'keypress');
 
1088
        Y.Assert.areSame(3, count);
 
1089
    }
 
1090
}));
 
1091
 
 
1092
suite.add(new Y.Test.Case({
 
1093
    name: "detach",
 
1094
 
 
1095
    setUp: setUp,
 
1096
    tearDown: tearDown,
 
1097
 
 
1098
    "test node.on() + node.detach()": function () {
 
1099
    },
 
1100
 
 
1101
    "test Y.on() + node.detach()": function () {
 
1102
    },
 
1103
 
 
1104
    "test node.on() + handle.detach()": function () {
 
1105
    },
 
1106
 
 
1107
    "test node.on('cat|key',...) + node.detach('cat|...')": function () {
 
1108
    },
 
1109
 
 
1110
    "test node.delegate() + node.detach()": function () {
 
1111
    },
 
1112
 
 
1113
    "test node.delegate() + handle.detach()": function () {
 
1114
    }
 
1115
}));
 
1116
 
 
1117
Y.Test.Runner.add(suite);
 
1118
 
 
1119
 
 
1120
}, '@VERSION@' ,{requires:['event-key', 'test']});