focusblur.html revision 288cb1eb48cf1e1756380d500de92f74ac32ec60
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith <a id="anchor-1" href="http://www.yahoo.com">Click Me!</a>
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith filter: 'raw',
63d012ee193ba8c768b2a2aade99081422759213Luke Smith filters: { 'event': 'debug' }
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith }).use('console', 'test', 'event', 'event-simulate', 'window-focus', function (Y) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var Assert = Y.Assert;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith new Y.Console({ /*useBrowserConsole: true*/ }).render();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith name: "Event Focus And Blur Test",
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith //test_purge_focus: 2528244, // fixed
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith //test_purge_blur: 2528244 // fixed
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith tearDown: function () {
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Y.one('#container').purge(true);
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith test_add_focus: function(){
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var foo = false,
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith onFocus = function(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith boundEl = this;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.on('focus', onFocus, '#container');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith foo = false;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith target = null;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith boundEl = null;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#text-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith test_remove_focus: function () {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var foo = false,
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith onFocus = function(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var handle = Y.on('focus', onFocus, '#container');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith foo = false;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isFalse(foo, "container should not pickup the focus event after listener is removed");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith test_purge_focus: function () {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var foo = false,
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith onFocus = function(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.on('focus', onFocus, '#container');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.Event.purgeElement('#container', false, 'focus');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith foo = false;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isFalse(foo, "container should not pickup the focus event after listener has been purged");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith test_bubble_order: function () {
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith var from = [],
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith body = Y.one('body'),
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith container = Y.one('#container');
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith function onFocus(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith container.on('focus', onFocus);
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith doc.on('focus', onFocus);
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith body.on('focus', onFocus);
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#anchor-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.ArrayAssert.itemsAreSame([container, body, doc], from, "Incorrect bubble order");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith test_add_blur: function () {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var foo = false,
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith onBlur = function(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith boundEl = this;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.on('blur', onBlur, '#container');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith foo = false;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith target = null;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith boundEl = null;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#text-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith test_remove_blur: function () {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var foo = false,
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith onBlur = function(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var handle = Y.on('blur', onBlur, '#container');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith foo = false;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#text-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isFalse(foo, "container should not pickup the blur event after listener has been removed");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith test_purge_blur: function () {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith var foo = false,
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith onBlur = function(e) {
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.on('blur', onBlur, '#container');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').blur();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith foo = false;
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.Event.purgeElement('#container', false, 'blur');
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#button-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.one('#text-1').focus();
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Assert.isFalse(foo, "container should not pickup the blur event after listener has been purged");
288cb1eb48cf1e1756380d500de92f74ac32ec60Luke Smith Y.log("Window is not focused.", "warn", "TestRunner");