Skip to content

Commit

Permalink
Adjust the focus input tests so they won't fail when the browser is o…
Browse files Browse the repository at this point in the history
…ut of focus
  • Loading branch information
timmywil committed Nov 8, 2011
1 parent 5d3cc64 commit d4e5c22
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/unit/selector.js
Expand Up @@ -434,25 +434,34 @@ test("pseudo - misc", function() {
ok( (window.Sizzle || window.jQuery.find).matchesSelector( jQuery("#button_" + type)[0], ":" + type ), "Button Matches :" + type );
});


document.body.removeChild( tmp );

var input = document.createElement("input");
input.type = "text";
input.id = "focus-input";

document.body.appendChild( input );

input.focus();

t( "Element focused", "input:focus", [ "focus-input" ] );
// Inputs can't be focused unless the document has focus
if ( document.activeElement !== input || (document.hasFocus && !document.hasFocus()) ||
(document.querySelectorAll && !document.querySelectorAll('input:focus').length) ) {
ok( true, "The input was not focused. Skip checking the :focus match." );
ok( true, "The input was not focused. Skip checking the :focus match." );

ok( (window.Sizzle || window.jQuery.find).matchesSelector( input, ":focus" ), ":focus Matches" );
} else {
t( "Element focused", "input:focus", [ "focus-input" ] );
ok( (window.Sizzle || window.jQuery.find).matchesSelector( input, ":focus" ), ":focus Matches" );
}

input.blur();

ok( !(window.Sizzle || window.jQuery.find).matchesSelector( input, ":focus" ), ":focus Doesn't Match" );
// When IE is out of focus, blur does not work. Force it here.
if ( document.activeElement === input ) {
document.body.focus();
}

ok( !(window.Sizzle || window.jQuery.find).matchesSelector( input, ":focus" ), ":focus Doesn't Match" );
document.body.removeChild( input );
});

Expand Down

0 comments on commit d4e5c22

Please sign in to comment.