aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2012-12-11 09:44:39 -0500
committerScott González <scott.gonzalez@gmail.com>2012-12-11 09:44:39 -0500
commit694987f2f735476e0ebbea1fe80ec8c504af6846 (patch)
treee6aa483baca87879ead1f3c5fca2a8f89c056ad7
parent020abcf8a9494731b3bc58c14e5aac5d8407452a (diff)
downloadjquery-ui-694987f2f735476e0ebbea1fe80ec8c504af6846.tar.gz
jquery-ui-694987f2f735476e0ebbea1fe80ec8c504af6846.zip
Menu tests: Better handling of async focus in IE.
-rw-r--r--tests/unit/menu/menu_events.js199
1 files changed, 108 insertions, 91 deletions
diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js
index a94968138..3c94a5a6c 100644
--- a/tests/unit/menu/menu_events.js
+++ b/tests/unit/menu/menu_events.js
@@ -87,7 +87,7 @@ asyncTest( "handle blur via click outside", function() {
});
});
-test( "handle focus of menu with active item", function() {
+asyncTest( "handle focus of menu with active item", function() {
expect( 1 );
var element = $( "#menu1" ).menu({
focus: function( event ) {
@@ -96,11 +96,19 @@ test( "handle focus of menu with active item", function() {
});
log( "focus", true );
- element.focus();
- element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
- element.focus();
- equal( logOutput(), "focus,0,1,2,2", "current active item remains active" );
+ element[0].focus();
+ setTimeout(function() {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element[0].blur();
+ setTimeout(function() {
+ element[0].focus();
+ setTimeout(function() {
+ equal( logOutput(), "focus,0,1,2,2", "current active item remains active" );
+ start();
+ });
+ });
+ });
});
asyncTest( "handle submenu auto collapse: mouseleave", function() {
@@ -162,7 +170,7 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() {
});
-test( "handle keyboard navigation on menu without scroll and without submenus", function() {
+asyncTest( "handle keyboard navigation on menu without scroll and without submenus", function() {
expect( 12 );
var element = $( "#menu1" ).menu({
select: function( event, ui ) {
@@ -174,54 +182,58 @@ test( "handle keyboard navigation on menu without scroll and without submenus",
});
log( "keydown", true );
- element.focus();
- element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
- equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
+ element[0].focus();
+ setTimeout(function() {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
- equal( logOutput(), "keydown,1", "Keydown UP" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ equal( logOutput(), "keydown,1", "Keydown UP" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
- equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
+ equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
- equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
+ equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
- equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
+ equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
- equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
+ equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
- equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
+ equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
- equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
+ equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
- equal( logOutput(), "keydown,4", "Keydown END" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
+ equal( logOutput(), "keydown,4", "Keydown END" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
- equal( logOutput(), "keydown,0", "Keydown HOME" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
+ equal( logOutput(), "keydown,0", "Keydown HOME" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
- equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
+ equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
+
+ start();
+ });
});
asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() {
@@ -344,7 +356,7 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus"
}
});
-test( "handle keyboard navigation on menu with scroll and without submenus", function() {
+asyncTest( "handle keyboard navigation on menu with scroll and without submenus", function() {
expect( 14 );
var element = $( "#menu3" ).menu({
select: function( event, ui ) {
@@ -356,63 +368,67 @@ test( "handle keyboard navigation on menu with scroll and without submenus", fun
});
log( "keydown", true );
- element.focus();
- element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
- equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
+ element[0].focus();
+ setTimeout(function() {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
- equal( logOutput(), "keydown,1,0", "Keydown UP" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ equal( logOutput(), "keydown,1,0", "Keydown UP" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
- equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
+ equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
- equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
+ equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
- equal( logOutput(), "keydown,10", "Keydown PAGE_DOWN" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
+ equal( logOutput(), "keydown,10", "Keydown PAGE_DOWN" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
- equal( logOutput(), "keydown,20", "Keydown PAGE_DOWN" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
+ equal( logOutput(), "keydown,20", "Keydown PAGE_DOWN" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
- equal( logOutput(), "keydown,10", "Keydown PAGE_UP" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
+ equal( logOutput(), "keydown,10", "Keydown PAGE_UP" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
- equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
+ equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
- equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
+ equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
- equal( logOutput(), "keydown,37", "Keydown END" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
+ equal( logOutput(), "keydown,37", "Keydown END" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
- equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
+ equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
- equal( logOutput(), "keydown,0", "Keydown HOME" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
+ equal( logOutput(), "keydown,0", "Keydown HOME" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
- equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
+ equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );
- log( "keydown", true );
- element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
+
+ start();
+ });
});
asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() {
@@ -561,7 +577,7 @@ asyncTest( "handle keyboard navigation and mouse click on menu with disabled ite
}
});
-test( "handle keyboard navigation with spelling of menu items", function() {
+asyncTest( "handle keyboard navigation with spelling of menu items", function() {
expect( 2 );
var element = $( "#menu2" ).menu({
focus: function( event ) {
@@ -577,8 +593,9 @@ test( "handle keyboard navigation with spelling of menu items", function() {
equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" );
element.simulate( "keydown", { keyCode: 68 } );
equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" );
+ start();
});
- element.focus();
+ element[0].focus();
});
})( jQuery );