1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4
<title>YUI focus/blur synth Tests</title>
6
<script src="../../../build/yui/yui.js"></script>
7
<script src="window-focus.js"></script>
9
<body class="yui3-skin-sam">
12
<button id="button-1">Click Me!</button>
13
<a id="anchor-1" href="http://www.yahoo.com">Click Me!</a>
14
<input type="text" id="text-1">
19
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
22
}).use('console', 'test', 'event', 'event-simulate', 'window-focus', function (Y) {
24
var Assert = Y.Assert;
26
new Y.Console({ /*useBrowserConsole: true*/ }).render();
28
Y.Test.Runner.add(new Y.Test.Case({
29
name: "Event Focus And Blur Test",
33
//test_purge_focus: 2528244, // fixed
34
//test_purge_blur: 2528244 // fixed
38
tearDown: function () {
39
Y.one('#container').purge(true);
42
test_add_focus: function(){
48
onFocus = function(e) {
56
Y.on('focus', onFocus, '#container');
58
Y.one('#button-1').focus();
60
if (Y.isWindowInFocus()) {
61
Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
62
Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
63
Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
69
Y.one('#text-1').focus();
70
Y.one('#button-1').focus();
72
Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
73
Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
74
Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
76
Y.one('#button-1').blur();
78
Y.log("Window is not focused.", "warn", "TestRunner");
82
test_remove_focus: function () {
86
onFocus = function(e) {
92
var handle = Y.on('focus', onFocus, '#container');
94
if (Y.isWindowInFocus()) {
95
Y.one('#button-1').focus();
97
Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
101
Y.one('#button-1').blur();
105
Y.one('#button-1').focus();
107
Assert.isFalse(foo, "container should not pickup the focus event after listener is removed");
109
Y.one('#button-1').blur();
111
Y.log("Window is not focused.", "warn", "TestRunner");
115
test_purge_focus: function () {
119
onFocus = function(e) {
125
if (Y.isWindowInFocus()) {
126
Y.on('focus', onFocus, '#container');
128
Y.one('#button-1').focus();
130
Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
132
Y.Event.purgeElement('#container', false, 'focus');
134
Y.one('#button-1').blur();
138
Y.one('#button-1').focus();
140
Assert.isFalse(foo, "container should not pickup the focus event after listener has been purged");
142
Y.log("Window is not focused.", "warn", "TestRunner");
146
test_bubble_order: function () {
148
doc = Y.one(Y.config.doc),
149
body = Y.one('body'),
150
container = Y.one('#container');
152
function onFocus(e) {
156
if (Y.isWindowInFocus()) {
157
container.on('focus', onFocus);
158
doc.on('focus', onFocus);
159
body.on('focus', onFocus);
161
Y.one('#anchor-1').focus();
163
Y.ArrayAssert.itemsAreSame([container, body, doc], from, "Incorrect bubble order");
165
Y.log("Window is not focused.", "warn", "TestRunner");
169
test_add_blur: function () {
175
onBlur = function(e) {
183
if (Y.isWindowInFocus()) {
184
Y.on('blur', onBlur, '#container');
186
Y.one('#button-1').focus();
187
Y.one('#button-1').blur();
189
Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
190
Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
191
Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
197
Y.one('#button-1').focus();
198
Y.one('#text-1').focus();
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");
204
Y.log("Window is not focused.", "warn", "TestRunner");
208
test_remove_blur: function () {
210
onBlur = function(e) {
214
if (Y.isWindowInFocus()) {
215
var handle = Y.on('blur', onBlur, '#container');
217
Y.one('#button-1').focus();
218
Y.one('#button-1').blur();
220
Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
223
Y.one('#button-1').focus();
224
Y.one('#text-1').focus();
225
Assert.isFalse(foo, "container should not pickup the blur event after listener has been removed");
227
Y.log("Window is not focused.", "warn", "TestRunner");
231
test_purge_blur: function () {
233
onBlur = function(e) {
237
if (Y.isWindowInFocus()) {
238
Y.on('blur', onBlur, '#container');
240
Y.one('#button-1').focus();
241
Y.one('#button-1').blur();
242
Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
244
Y.Event.purgeElement('#container', false, 'blur');
245
Y.one('#button-1').focus();
246
Y.one('#text-1').focus();
247
Assert.isFalse(foo, "container should not pickup the blur event after listener has been purged");
249
Y.log("Window is not focused.", "warn", "TestRunner");
255
Y.Test.Runner.setName("EventFocusBlur");