~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/tests/event/tests/focusblur.html

  • 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
 
<!DOCTYPE HTML>
2
 
<html>
3
 
<head>
4
 
    <title>YUI focus/blur synth Tests</title>
5
 
 
6
 
    <script src="../../../build/yui/yui.js"></script>
7
 
    <script src="window-focus.js"></script>
8
 
</head>
9
 
<body class="yui3-skin-sam">
10
 
 
11
 
    <div id="container">
12
 
        <div class="not-focusable">
13
 
            <button id="button-1">Click Me!</button>
14
 
            <a id="anchor-1" href="http://www.yahoo.com">Click Me!</a>
15
 
            <input type="text" id="text-1">
16
 
        </div>
17
 
    </div>
18
 
 
19
 
    <script>
20
 
        YUI({
21
 
            //lazyEventFacade: true,
22
 
            filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
23
 
            allowRollup: false
24
 
        }).use('console', 'test', 'event', 'event-simulate', 'node-event-delegate', 'window-focus', function (Y) {
25
 
 
26
 
            var Assert = Y.Assert;
27
 
 
28
 
            new Y.Console({ /*useBrowserConsole: true*/ }).render();
29
 
 
30
 
            Y.Test.Runner.add(new Y.Test.Case({
31
 
                name: "Event Focus And Blur Test",
32
 
 
33
 
                _should: {
34
 
                    fail: {
35
 
                        //test_purge_focus: 2528244, // fixed
36
 
                        //test_purge_blur: 2528244   // fixed
37
 
                    }
38
 
                },
39
 
 
40
 
                tearDown: function () {
41
 
                    Y.one('#container').purge(true);
42
 
                },
43
 
 
44
 
                test_add_focus: function(){
45
 
 
46
 
                    var foo = false,
47
 
                        target,
48
 
                        boundEl,
49
 
                        handle,
50
 
 
51
 
                        onFocus = function(e) {
52
 
 
53
 
                            foo = true;
54
 
                            boundEl = this;
55
 
                            target = e.target;
56
 
 
57
 
                        };
58
 
 
59
 
                    handle = Y.on('focus', onFocus, '#container');
60
 
 
61
 
                    Y.one('#button-1').focus();
62
 
 
63
 
                    if (Y.isWindowInFocus()) {
64
 
                        Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
65
 
                        Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
66
 
                        Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
67
 
 
68
 
                        foo = false;
69
 
                        target = null;
70
 
                        boundEl = null;
71
 
 
72
 
                        Y.one('#text-1').focus();
73
 
                        Y.one('#button-1').focus();
74
 
 
75
 
                        Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
76
 
                        Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
77
 
                        Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
78
 
 
79
 
                        Y.one('#button-1').blur();
80
 
                    } else {
81
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
82
 
                    }
83
 
 
84
 
                    handle.detach();
85
 
 
86
 
                },
87
 
 
88
 
                test_remove_focus: function () {
89
 
 
90
 
                    var foo = false,
91
 
 
92
 
                        onFocus = function(e) {
93
 
 
94
 
                            foo = true;
95
 
 
96
 
                        };
97
 
 
98
 
                    var handle = Y.on('focus', onFocus, '#container');
99
 
 
100
 
                    if (Y.isWindowInFocus()) {
101
 
                        Y.one('#button-1').focus();
102
 
 
103
 
                        Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
104
 
 
105
 
                        handle.detach();
106
 
 
107
 
                        Y.one('#button-1').blur();
108
 
 
109
 
                        foo = false;
110
 
 
111
 
                        Y.one('#button-1').focus();
112
 
 
113
 
                        Assert.isFalse(foo, "container should not pickup the focus event after listener is removed");
114
 
 
115
 
                        Y.one('#button-1').blur();
116
 
                    } else {
117
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
118
 
                    }
119
 
                },
120
 
 
121
 
                test_purge_focus: function () {
122
 
 
123
 
                    var foo = false,
124
 
 
125
 
                        onFocus = function(e) {
126
 
 
127
 
                            foo = true;
128
 
 
129
 
                        };
130
 
 
131
 
                    if (Y.isWindowInFocus()) {
132
 
                        Y.on('focus', onFocus, '#container');
133
 
 
134
 
                        Y.one('#button-1').focus();
135
 
 
136
 
                        Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
137
 
 
138
 
                        Y.Event.purgeElement('#container', false, 'focus');
139
 
 
140
 
                        Y.one('#button-1').blur();
141
 
 
142
 
                        foo = false;
143
 
 
144
 
                        Y.one('#button-1').focus();
145
 
 
146
 
                        Assert.isFalse(foo, "container should not pickup the focus event after listener has been purged");
147
 
                    } else {
148
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
149
 
                    }
150
 
                },
151
 
 
152
 
                test_bubble_order: function () {
153
 
                    var from = [],
154
 
                        doc  = Y.one(Y.config.doc),
155
 
                        body = Y.one('body'),
156
 
                        container = Y.one('#container'),
157
 
                        handles = [];
158
 
 
159
 
                    function onFocus(e) {
160
 
                        from.push(this);
161
 
                    }
162
 
 
163
 
                    if (Y.isWindowInFocus()) {
164
 
                        handles.push(
165
 
                            container.on('focus', onFocus),
166
 
                            doc.on('focus', onFocus),
167
 
                            body.on('focus', onFocus));
168
 
 
169
 
                        Y.one('#anchor-1').focus();
170
 
 
171
 
                        new Y.EventHandle(handles).detach();
172
 
 
173
 
                        Y.ArrayAssert.itemsAreSame([container, body, doc], from, "Incorrect bubble order");
174
 
                    } else {
175
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
176
 
                    }
177
 
                },
178
 
 
179
 
                test_add_blur: function () {
180
 
 
181
 
                    var foo = false,
182
 
                        target,
183
 
                        boundEl,
184
 
                        handle,
185
 
 
186
 
                        onBlur = function(e) {
187
 
 
188
 
                            foo = true;
189
 
                            boundEl = this;
190
 
                            target = e.target;
191
 
 
192
 
                        };
193
 
 
194
 
                    if (Y.isWindowInFocus()) {
195
 
                        handle = Y.on('blur', onBlur, '#container');
196
 
 
197
 
                        Y.one('#button-1').focus();
198
 
                        Y.one('#button-1').blur();
199
 
 
200
 
                        Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
201
 
                        Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
202
 
                        Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
203
 
 
204
 
                        foo = false;
205
 
                        target = null;
206
 
                        boundEl = null;
207
 
 
208
 
                        Y.one('#button-1').focus();
209
 
                        Y.one('#text-1').focus();
210
 
 
211
 
                        Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
212
 
                        Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
213
 
                        Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
214
 
                    } else {
215
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
216
 
                    }
217
 
                },
218
 
 
219
 
                test_remove_blur: function () {
220
 
                    var foo = false,
221
 
                        onBlur = function(e) {
222
 
                            foo = true;
223
 
                        };
224
 
 
225
 
                    if (Y.isWindowInFocus()) {
226
 
                        var handle = Y.on('blur', onBlur, '#container');
227
 
 
228
 
                        Y.one('#button-1').focus();
229
 
                        Y.one('#button-1').blur();
230
 
 
231
 
                        Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
232
 
                        foo = false;
233
 
                        handle.detach();
234
 
                        Y.one('#button-1').focus();
235
 
                        Y.one('#text-1').focus();
236
 
                        Assert.isFalse(foo, "container should not pickup the blur event after listener has been removed");
237
 
                    } else {
238
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
239
 
                    }
240
 
                },
241
 
 
242
 
                test_purge_blur: function () {
243
 
                    var foo = false,
244
 
                        onBlur = function(e) {
245
 
                            foo = true;
246
 
                        };
247
 
 
248
 
                    if (Y.isWindowInFocus()) {
249
 
                        Y.on('blur', onBlur, '#container');
250
 
 
251
 
                        Y.one('#button-1').focus();
252
 
                        Y.one('#button-1').blur();
253
 
                        Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
254
 
                        foo = false;
255
 
                        Y.Event.purgeElement('#container', false, 'blur');
256
 
                        Y.one('#button-1').focus();
257
 
                        Y.one('#text-1').focus();
258
 
                        Assert.isFalse(foo, "container should not pickup the blur event after listener has been purged");
259
 
                    } else {
260
 
                        Y.log("Window is not focused.", "warn", "TestRunner");
261
 
                    }
262
 
                },
263
 
 
264
 
                "test delegating with filter matching non-focusable elements": function () {
265
 
                    var button       = Y.one('#button-1'),
266
 
                        container    = Y.one('#container'),
267
 
                        notFocusable = Y.one('.not-focusable'),
268
 
                        called, handle;
269
 
 
270
 
                    if (Y.isWindowInFocus()) {
271
 
                        handle = container.delegate('focus', function (e) {
272
 
                            called = true;
273
 
                            Assert.areSame(button, e.target);
274
 
                            Assert.areSame(notFocusable, e.currentTarget);
275
 
                            Assert.areSame(notFocusable, this);
276
 
                            Assert.areSame(container, e.container);
277
 
                        }, '.not-focusable');
278
 
 
279
 
                        Y.one('#button-1').focus();
280
 
 
281
 
                        handle.detach();
282
 
 
283
 
                        Assert.isTrue(called);
284
 
                    }
285
 
 
286
 
                },
287
 
 
288
 
                "test stopping propagation for on() subs": function () {
289
 
                    var handles = [],
290
 
                        outerCalled, innerCalled;
291
 
 
292
 
                    // Make sure button-1 isn't focused
293
 
                    Y.one('#anchor-1').focus();
294
 
 
295
 
                    handles.push(Y.one('#container').on('focus', function () {
296
 
                        outerCalled = true;
297
 
                    }));
298
 
                    handles.push(Y.one('.not-focusable').on('focus', function (e) {
299
 
                        innerCalled = true;
300
 
                        e.stopPropagation();
301
 
                    }));
302
 
 
303
 
                    Y.one('#button-1').focus();
304
 
 
305
 
                    new Y.EventHandle(handles).detach();
306
 
 
307
 
                    Assert.isTrue(innerCalled);
308
 
                    Assert.isUndefined(outerCalled);
309
 
                },
310
 
 
311
 
                "test stopping propagation for delegate() subs matching the same node": function () {
312
 
                    var handles = [],
313
 
                        called = 0;
314
 
 
315
 
                    // Matches at the same level, stopProp should not prevent
316
 
                    // both delegate callbacks
317
 
                    handles.push(
318
 
                        Y.one('#container').delegate('focus', function (e) {
319
 
                            called++;
320
 
                            e.stopPropagation();
321
 
                        }, '.not-focusable'),
322
 
                        Y.one('doc').delegate('focus', function () {
323
 
                            called++;
324
 
                        }, '.not-focusable'));
325
 
 
326
 
                    Y.one('#anchor-1').focus();
327
 
 
328
 
                    new Y.EventHandle(handles).detach();
329
 
 
330
 
                    Assert.areSame(2, called);
331
 
                },
332
 
 
333
 
                "test stopping propagation for delegate() subs not matching the same node": function () {
334
 
                    var handles = [],
335
 
                        called = 0;
336
 
 
337
 
                    // Matches at the same level, stopProp should not prevent
338
 
                    // both delegate callbacks
339
 
                    handles.push(
340
 
                        Y.one('#container').delegate('focus', function (e) {
341
 
                            called++;
342
 
                            e.stopPropagation();
343
 
                        }, '.not-focusable'),
344
 
                        Y.one('doc').delegate('focus', function () {
345
 
                            called++;
346
 
                        }, '#container'));
347
 
 
348
 
                    Y.one('#button-1').focus();
349
 
 
350
 
                    new Y.EventHandle(handles).detach();
351
 
 
352
 
                    Assert.areSame(1, called);
353
 
                },
354
 
 
355
 
                "test stopImmediatePropagation for on() and delegate() subs": function () {
356
 
                    var handles = [],
357
 
                        called = 0;
358
 
 
359
 
                    handles.push(
360
 
                        Y.one('#container').delegate('focus', function (e) {
361
 
                            called++;
362
 
                            e.stopImmediatePropagation();
363
 
                        }, '.not-focusable'),
364
 
                        Y.one('doc').delegate('focus', function () {
365
 
                            called++;
366
 
                        }, '.not-focusable'));
367
 
 
368
 
                    Y.one('#anchor-1').focus();
369
 
 
370
 
                    new Y.EventHandle(handles).detach();
371
 
 
372
 
                    Assert.areSame(1, called);
373
 
                },
374
 
 
375
 
                "test callback order from a mix of subs": function () {
376
 
                    var order = [],
377
 
                        handles = [];
378
 
 
379
 
                    handles.push(
380
 
                        Y.one('#container').delegate('focus', function () {
381
 
                            order.push(2);
382
 
                        }, '.not-focusable'),
383
 
                        Y.one('#button-1').on('focus', function () {
384
 
                            order.push(1);
385
 
                        }),
386
 
                        Y.one('doc').delegate('focus', function () {
387
 
                            order.push(3);
388
 
                        }, '.not-focusable'),
389
 
                        Y.one('#container').on('focus', function () {
390
 
                            order.push(4);
391
 
                        })
392
 
                    );
393
 
 
394
 
                    Y.one('#button-1').focus();
395
 
 
396
 
                    Y.ArrayAssert.itemsAreSame([1, 2, 3, 4], order);
397
 
                }
398
 
 
399
 
            }));
400
 
 
401
 
            Y.Test.Runner.setName("EventFocusBlur");
402
 
            Y.Test.Runner.run();
403
 
 
404
 
        });
405
 
    </script>
406
 
</body>
407
 
</html>