focusblur.html revision 37afd8be00b8e92463a3fdcaa6fc1b2809b8256e
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots <a id="anchor-1" href="http://www.yahoo.com">Click Me!</a>
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots <!-- YUI3 Core //-->
cb4f4f79feb7498d1f3406b88fb62209e5f5a444Adam Moore <script type="text/javascript" src="/build/yui/yui.js"></script>
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots <!-- Initialization process //-->
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith filter: 'raw',
cb4f4f79feb7498d1f3406b88fb62209e5f5a444Adam Moore logExclude: { Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true}
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots }).use('console', 'test', 'event', 'event-simulate', function (Y) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var Assert = Y.Assert;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots // creating the console...
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith new Y.Console({ useBrowserConsole: true }).render();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots // starting the testing process
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots // add the test cases and suites
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith test_purge_focus: true,
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith test_purge_blur: true
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots name: "Event Focus And Blur Test",
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith tearDown: function () {
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Y.one('#container').purge(true);
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots test_add_focus: function(){
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var foo = false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots onFocus = function(e) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots boundEl = this;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.on('focus', onFocus, '#container');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots foo = false;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots target = null;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots boundEl = null;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#text-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Assert.areEqual(Y.one('#button-1'), target, "the target is the incorrect node, should be the actual focus target");
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Assert.areEqual(Y.one('#container'), boundEl, "the default scope should be the bound element");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots test_remove_focus: function () {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var foo = false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots onFocus = function(e) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var handle = Y.on('focus', onFocus, '#container');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots foo = false;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isFalse(foo, "container should not pickup the focus event after listener is removed");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots test_purge_focus: function () {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var foo = false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots onFocus = function(e) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.on('focus', onFocus, '#container');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.Event.purgeElement('#container', false, 'focus');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots foo = false;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isFalse(foo, "container should not pickup the focus event after listener has been purged");
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) {
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith container.on('focus', onFocus);
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith doc.on('focus', onFocus);
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith body.on('focus', onFocus);
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Y.one('#button-1').focus();
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith Y.ArrayAssert.itemsAreSame([container, body, doc], from);//,
37afd8be00b8e92463a3fdcaa6fc1b2809b8256eLuke Smith //"Incorrect bubble order");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots test_add_blur: function () {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var foo = false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots onBlur = function(e) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots boundEl = this;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.on('blur', onBlur, '#container');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots foo = false;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots target = null;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots boundEl = null;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#text-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple blur fails, container should pickup the focus event");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual blur target");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.areEqual(boundEl, Y.one('#container'), "the default scope should be the bound element");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots test_remove_blur: function () {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var foo = false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots onBlur = function(e) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var handle = Y.on('blur', onBlur, '#container');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots foo = false;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#text-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isFalse(foo, "container should not pickup the blur event after listener has been removed");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots test_purge_blur: function () {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots var foo = false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots onBlur = function(e) {
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.on('blur', onBlur, '#container');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').blur();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus fails, container should pickup the focus event");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots foo = false;
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.Event.purgeElement('#container', false, 'blur');
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#text-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isFalse(foo, "container should not pickup the blur event after listener has been purged");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots //run all tests
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots /* finishing the testing process */