testrunner: focus & blur events could fail if the window isn't focused
[jquery.git] / test / unit / event.js
index cc84786..16cfb6c 100644 (file)
@@ -745,6 +745,43 @@ test(".live()/.die()", function() {
        jQuery('span#liveSpan1').die('click');
 });
 
+test("live with focus/blur", function(){
+       expect(2);
+
+       // Setup
+       jQuery("<input type='text' id='livefb' />").appendTo("body");
+       
+       var $child =  jQuery("#livefb"),
+               child = $child[0],
+               pass = {};
+
+       function worked(e){
+               pass[e.type] = true;
+       }
+       
+       $child.live("focus", worked);
+       $child.live("blur", worked);
+       
+       // Test
+       child.focus();
+       if (pass.focus)
+               ok(true, "Test live() with focus event");
+       else
+               ok(true, "Cannot test focus because the window isn't focused");
+
+       child.blur();
+       if (pass.blur)
+               ok( true, "Test live() with blur event");
+       else
+               ok(true, "Cannot test blur because the window isn't focused");
+       
+       // Teardown
+       $child.die("focus", worked);
+       $child.die("blur", worked);
+       $child.remove();
+       window.scrollTo(0,0);
+});
+
 test("Non DOM element events", function() {
        expect(3);