Skip to content
Permalink
Browse files
Run focus test only if document has focus
(cherry picked from commit 0b9a182)
  • Loading branch information
markelog committed Sep 23, 2013
1 parent 9dadd68 commit 33c80f3
Showing 1 changed file with 21 additions and 21 deletions.
@@ -2567,35 +2567,35 @@ test( "make sure events cloned correctly", 18, function() {
clone.find("#check1").trigger("change"); // 0 events should fire
});

asyncTest( "Check order of focusin/focusout events", 2, function() {
var focus, blur,
input = jQuery("#name");
// This test fails in some browsers if document does not have focus
if ( !document.hasFocus || document.hasFocus && document.hasFocus() ) {
test( "Check order of focusin/focusout events", 2, function() {
var focus, blur,
input = jQuery( "#name" );

input.on("focus", function() {
focus = true;
input.on( "focus", function() {
focus = true;

}).on("focusin", function() {
ok( !focus, "Focusin event should fire before focus does" );
}).on( "focusin", function() {
ok( !focus, "Focusin event should fire before focus does" );

}).on("blur", function() {
blur = true;
}).on( "blur", function() {
blur = true;

}).on("focusout", function() {
ok( !blur, "Focusout event should fire before blur does" );
});
}).on( "focusout", function() {
ok( !blur, "Focusout event should fire before blur does" );
});

// gain focus
input.trigger("focus");
// gain focus
input.trigger( "focus" );

// then lose it
jQuery("#search").trigger("focus");
// then lose it
jQuery( "#search" ).trigger( "focus" );

// cleanup
setTimeout(function() {
// cleanup
input.off();
start();
}, 50 );
});
});
}

test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function() {
expect( 1 );

8 comments on commit 33c80f3

@Krinkle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't reproduce this on browserstack (version before this change). I'd recommend reverting this change.

@timmywil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krinkle seems to me this change also affects local testing. I'd rather not have focus tests fail if the document does not have focus.

@markelog
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires more thought anyway, since it minimizes the possible failure with focus tests but not removed it, i.e. even with this fix, we have same failure - http://swarm.jquery.org/result/883577.

@Krinkle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timmywil That is not the justification for this commit. And I'd argue that is a genuine failure resulting from incorrectly running the tests (I'd rather be annoyed by a failing test because I didn't focus my local browser when testing, then having it say Passed and find out we missed a bug or regression).

@markelog So it is confirmed then that this commit should be reverted as it doesn't help, the premise has been invalidated.

@markelog
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not the justification for this commit

Actually, it might be. Besides, we will found out about possible regression in the swarm, if, of course, browserstack browsers always be in focus, otherwise build will always fail, or worse - it will sometimes fail. @dmethvin?

I'd rather be annoyed by a failing test because I didn't focus my local browser when testing, then having it say Passed and find out we missed a bug or regression

You know story about the kid and wolf? Well, right know, it's like that.

And I'd argue that is a genuine failure resulting from incorrectly running the tests

Could you extend on that? Where specifically is problem resides?

should be reverted

I did not said "reverted", i said "requires more thought".

@timmywil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krinkle I agree with the principle, but we are making an exception in this case. This is one test out of many. If the regression is only in this test, I'd question the test more than the code. Besides, we've had lots of issues in the past with automated focus tests. At this point, we would rather have it pass when the document does not have focus.

@dmethvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A flakey test that leads us to ignore unit tests failing is not good. Focus tests are notoriously unreliable since they depend on factors outside the control of the unit tests. So I support this patch.

@Krinkle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmethvin @timmywil @markelog Yes, I could agree (I personally don't, but I can understand).

However in this case I think this commit should be reverted still as it isn't working. The test is still failing in IE8 after this commit as much as it did before this commit: http://swarm.jquery.org/project/jquery. It appears to either be a faulty condition (IE8 is not letting us detect the focus), or the bug is unrelated to the document having focus.

Please sign in to comment.