From d74b4dce4f455e02e390011c4086fb82650d210b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Tisza?= Date: Thu, 15 May 2014 19:16:22 +0000 Subject: [PATCH] Fix failing focus tests jQuery 1.9 changes how $.focus() calls are handled: instead of directly calling the handlers, it just invokes the DOM element's focus(), and leaves it to the browser's event handling to trigger them. This can fail for several reasons (e.g. element is not attached to document, element is already focused, browser bugs such as http://bugs.jquery.com/ticket/13363 ), so we are using triggerHandler('focus') instead, which calls the handlers directly without simulating actual browser events. Since these are unit tests verifying event handler attach/unattach behavior, not acceptance tests verifying actual event handling behavior, that should be okay. Change-Id: I65ecda28ace4f380ad33d6212e12069e18001232 --- tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js | 13 +++++++------ tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js b/tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js index b1f12f381..cc64566b9 100644 --- a/tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js @@ -295,8 +295,9 @@ }; // Triggering action events before attaching should do nothing - embed.embedTextHtml.$element.focus(); - embed.embedTextWikitext.$element.focus(); + // use of focus() would run into jQuery bug #14740 and similar issues + embed.embedTextHtml.$element.triggerHandler( 'focus' ); + embed.embedTextWikitext.$element.triggerHandler( 'focus' ); embed.embedSwitch.emit( 'select' ); embed.embedSizeSwitchHtml.getMenu().emit( 'choose', embed.embedSizeSwitchHtml.getMenu().getSelectedItem() ); @@ -316,8 +317,8 @@ embed.attach(); // Action events should be handled now - embed.embedTextHtml.$element.focus(); - embed.embedTextWikitext.$element.focus(); + embed.embedTextHtml.$element.triggerHandler( 'focus' ); + embed.embedTextWikitext.$element.triggerHandler( 'focus' ); embed.embedSwitch.emit( 'select' ); embed.embedSizeSwitchHtml.getMenu().emit( 'choose', embed.embedSizeSwitchHtml.getMenu().getSelectedItem() ); @@ -338,8 +339,8 @@ embed.unattach(); // Triggering action events now that we are unattached should do nothing - embed.embedTextHtml.$element.focus(); - embed.embedTextWikitext.$element.focus(); + embed.embedTextHtml.$element.triggerHandler( 'focus' ); + embed.embedTextWikitext.$element.triggerHandler( 'focus' ); embed.embedSwitch.emit( 'select' ); embed.embedSizeSwitchHtml.getMenu().emit( 'choose', embed.embedSizeSwitchHtml.getMenu().getSelectedItem() ); diff --git a/tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js b/tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js index 9558a29a0..d89dca723 100644 --- a/tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js @@ -69,7 +69,8 @@ }; // Triggering action events before attaching should do nothing - share.pageInput.$element.focus(); + // use of focus() would run into jQuery bug #14740 and similar issues + share.pageInput.$element.triggerHandler( 'focus' ); share.selectAllOnEvent = function () { assert.ok( true, 'selectAllOnEvent was called.' ); @@ -78,7 +79,7 @@ share.attach(); // Action events should be handled now - share.pageInput.$element.focus(); + share.pageInput.$element.triggerHandler( 'focus' ); // Test the unattach part share.selectAllOnEvent = function() { @@ -88,7 +89,7 @@ share.unattach(); // Triggering action events now that we are unattached should do nothing - share.pageInput.$element.focus(); + share.pageInput.$element.triggerHandler( 'focus' ); } ); }( mediaWiki, jQuery ) );