focusblur.html revision 85e08d7420a5c71ffdd9517a3179d29b9a32b1df
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 //-->
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots <script type="text/javascript" src="/build/yui/yui-debug.js"></script>
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots <!-- Initialization process //-->
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots filter: 'debug',
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots combine: false,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots useConsole: true,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots logExclude: {deprecated: 1,
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots 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...
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots (new Y.Console()).render();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots // starting the testing process
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots // add the test cases and suites
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots name: "Event Focus And Blur Test",
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");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.areEqual(target, Y.one('#button-1'), "the target is the incorrect node, should be the actual focus 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('#text-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Y.one('#button-1').focus();
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.isTrue(foo, "simple focus 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 focus target");
85e08d7420a5c71ffdd9517a3179d29b9a32b1dfTodd Kloots Assert.areEqual(boundEl, Y.one('#container'), "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");
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 */