2009-01-21 03:25:02 +00:00
|
|
|
/*
|
2009-01-22 01:45:42 +00:00
|
|
|
* selector unit tests
|
2009-01-21 03:25:02 +00:00
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2009-09-01 08:16:10 +00:00
|
|
|
module("core - selectors");
|
2009-01-21 03:25:02 +00:00
|
|
|
|
|
|
|
function isFocusable(selector, msg) {
|
2012-04-23 16:55:11 +00:00
|
|
|
QUnit.push($(selector).is(':focusable'), null, null, msg + " - selector " + selector + " is focusable");
|
2009-01-21 03:25:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isNotFocusable(selector, msg) {
|
2012-04-23 16:55:11 +00:00
|
|
|
QUnit.push($(selector).length && !$(selector).is(':focusable'), null, null, msg + " - selector " + selector + " is not focusable");
|
2009-01-21 03:25:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isTabbable(selector, msg) {
|
2012-04-23 16:55:11 +00:00
|
|
|
QUnit.push($(selector).is(':tabbable'), null, null, msg + " - selector " + selector + " is tabbable");
|
2009-01-21 03:25:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isNotTabbable(selector, msg) {
|
2012-04-23 16:55:11 +00:00
|
|
|
QUnit.push($(selector).length && !$(selector).is(':tabbable'), null, null, msg + " - selector " + selector + " is not tabbable");
|
2009-01-21 03:25:02 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 01:45:42 +00:00
|
|
|
test("data", function() {
|
|
|
|
expect(15);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-22 01:45:42 +00:00
|
|
|
var el;
|
|
|
|
function shouldHaveData(msg) {
|
|
|
|
ok(el.is(':data(test)'), msg);
|
|
|
|
}
|
|
|
|
function shouldNotHaveData(msg) {
|
|
|
|
ok(!el.is(':data(test)'), msg);
|
|
|
|
}
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>');
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldNotHaveData('data never set');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', null);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldNotHaveData('data is null');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', true);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to true');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', false);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldNotHaveData('data set to false');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', 0);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldNotHaveData('data set to 0');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', 1);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to 1');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', '');
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldNotHaveData('data set to empty string');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', 'foo');
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to string');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', []);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to empty array');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', [1]);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to array');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', {});
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to empty object');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', {foo: 'bar'});
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to object');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', new Date());
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to date');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', /test/);
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to regexp');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-04 01:43:52 +00:00
|
|
|
el = $('<div>').data('test', function() {});
|
2009-01-22 01:45:42 +00:00
|
|
|
shouldHaveData('data set to function');
|
|
|
|
});
|
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
test("focusable - visible, enabled elements", function() {
|
2011-08-12 13:37:48 +00:00
|
|
|
expect(18);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-12 13:37:48 +00:00
|
|
|
isNotFocusable('#formNoTabindex', 'form');
|
|
|
|
isFocusable('#formTabindex', 'form with tabindex');
|
2009-01-21 03:25:02 +00:00
|
|
|
isFocusable('#visibleAncestor-inputTypeNone', 'input, no type');
|
|
|
|
isFocusable('#visibleAncestor-inputTypeText', 'input, type text');
|
|
|
|
isFocusable('#visibleAncestor-inputTypeCheckbox', 'input, type checkbox');
|
|
|
|
isFocusable('#visibleAncestor-inputTypeRadio', 'input, type radio');
|
|
|
|
isFocusable('#visibleAncestor-inputTypeButton', 'input, type button');
|
|
|
|
isNotFocusable('#visibleAncestor-inputTypeHidden', 'input, type hidden');
|
|
|
|
isFocusable('#visibleAncestor-button', 'button');
|
|
|
|
isFocusable('#visibleAncestor-select', 'select');
|
|
|
|
isFocusable('#visibleAncestor-textarea', 'textarea');
|
|
|
|
isFocusable('#visibleAncestor-object', 'object');
|
|
|
|
isFocusable('#visibleAncestor-anchorWithHref', 'anchor with href');
|
|
|
|
isNotFocusable('#visibleAncestor-anchorWithoutHref', 'anchor without href');
|
|
|
|
isNotFocusable('#visibleAncestor-span', 'span');
|
|
|
|
isNotFocusable('#visibleAncestor-div', 'div');
|
|
|
|
isFocusable("#visibleAncestor-spanWithTabindex", 'span with tabindex');
|
|
|
|
isFocusable("#visibleAncestor-divWithNegativeTabindex", 'div with tabindex');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("focusable - disabled elements", function() {
|
|
|
|
expect(9);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotFocusable('#disabledElement-inputTypeNone', 'input, no type');
|
|
|
|
isNotFocusable('#disabledElement-inputTypeText', 'input, type text');
|
|
|
|
isNotFocusable('#disabledElement-inputTypeCheckbox', 'input, type checkbox');
|
|
|
|
isNotFocusable('#disabledElement-inputTypeRadio', 'input, type radio');
|
|
|
|
isNotFocusable('#disabledElement-inputTypeButton', 'input, type button');
|
|
|
|
isNotFocusable('#disabledElement-inputTypeHidden', 'input, type hidden');
|
|
|
|
isNotFocusable('#disabledElement-button', 'button');
|
|
|
|
isNotFocusable('#disabledElement-select', 'select');
|
|
|
|
isNotFocusable('#disabledElement-textarea', 'textarea');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("focusable - hidden styles", function() {
|
|
|
|
expect(8);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotFocusable('#displayNoneAncestor-input', 'input, display: none parent');
|
|
|
|
isNotFocusable('#displayNoneAncestor-span', 'span with tabindex, display: none parent');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotFocusable('#visibilityHiddenAncestor-input', 'input, visibility: hidden parent');
|
|
|
|
isNotFocusable('#visibilityHiddenAncestor-span', 'span with tabindex, visibility: hidden parent');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotFocusable('#displayNone-input', 'input, display: none');
|
|
|
|
isNotFocusable('#visibilityHidden-input', 'input, visibility: hidden');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotFocusable('#displayNone-span', 'span with tabindex, display: none');
|
|
|
|
isNotFocusable('#visibilityHidden-span', 'span with tabindex, visibility: hidden');
|
|
|
|
});
|
|
|
|
|
2010-07-22 02:10:16 +00:00
|
|
|
test("focusable - natively focusable with various tabindex", function() {
|
2009-01-21 03:25:02 +00:00
|
|
|
expect(4);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isFocusable('#inputTabindex0', 'input, tabindex 0');
|
|
|
|
isFocusable('#inputTabindex10', 'input, tabindex 10');
|
|
|
|
isFocusable('#inputTabindex-1', 'input, tabindex -1');
|
|
|
|
isFocusable('#inputTabindex-50', 'input, tabindex -50');
|
|
|
|
});
|
|
|
|
|
2010-07-22 02:10:16 +00:00
|
|
|
test("focusable - not natively focusable with various tabindex", function() {
|
2009-01-21 03:25:02 +00:00
|
|
|
expect(4);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isFocusable('#spanTabindex0', 'span, tabindex 0');
|
|
|
|
isFocusable('#spanTabindex10', 'span, tabindex 10');
|
|
|
|
isFocusable('#spanTabindex-1', 'span, tabindex -1');
|
|
|
|
isFocusable('#spanTabindex-50', 'span, tabindex -50');
|
|
|
|
});
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
test("focusable - area elements", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
isFocusable('#areaCoordsHref', 'coords and href');
|
|
|
|
isFocusable('#areaNoCoordsHref', 'href but no coords');
|
|
|
|
isNotFocusable('#areaNoImg', 'not associated with an image');
|
|
|
|
});
|
|
|
|
|
2012-10-23 19:12:54 +00:00
|
|
|
test( "focusable - dimensionless parent with overflow", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
isFocusable( "#dimensionlessParent", "input" );
|
|
|
|
});
|
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
test("tabbable - visible, enabled elements", function() {
|
2011-08-12 13:37:48 +00:00
|
|
|
expect(18);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2011-08-12 13:37:48 +00:00
|
|
|
isNotTabbable('#formNoTabindex', 'form');
|
|
|
|
isTabbable('#formTabindex', 'form with tabindex');
|
2009-01-21 03:25:02 +00:00
|
|
|
isTabbable('#visibleAncestor-inputTypeNone', 'input, no type');
|
|
|
|
isTabbable('#visibleAncestor-inputTypeText', 'input, type text');
|
|
|
|
isTabbable('#visibleAncestor-inputTypeCheckbox', 'input, type checkbox');
|
|
|
|
isTabbable('#visibleAncestor-inputTypeRadio', 'input, type radio');
|
|
|
|
isTabbable('#visibleAncestor-inputTypeButton', 'input, type button');
|
|
|
|
isNotTabbable('#visibleAncestor-inputTypeHidden', 'input, type hidden');
|
|
|
|
isTabbable('#visibleAncestor-button', 'button');
|
|
|
|
isTabbable('#visibleAncestor-select', 'select');
|
|
|
|
isTabbable('#visibleAncestor-textarea', 'textarea');
|
|
|
|
isTabbable('#visibleAncestor-object', 'object');
|
|
|
|
isTabbable('#visibleAncestor-anchorWithHref', 'anchor with href');
|
|
|
|
isNotTabbable('#visibleAncestor-anchorWithoutHref', 'anchor without href');
|
|
|
|
isNotTabbable('#visibleAncestor-span', 'span');
|
|
|
|
isNotTabbable('#visibleAncestor-div', 'div');
|
|
|
|
isTabbable("#visibleAncestor-spanWithTabindex", 'span with tabindex');
|
|
|
|
isNotTabbable("#visibleAncestor-divWithNegativeTabindex", 'div with tabindex');
|
|
|
|
});
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
test("tabbable - disabled elements", function() {
|
2009-01-21 03:25:02 +00:00
|
|
|
expect(9);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotTabbable('#disabledElement-inputTypeNone', 'input, no type');
|
|
|
|
isNotTabbable('#disabledElement-inputTypeText', 'input, type text');
|
|
|
|
isNotTabbable('#disabledElement-inputTypeCheckbox', 'input, type checkbox');
|
|
|
|
isNotTabbable('#disabledElement-inputTypeRadio', 'input, type radio');
|
|
|
|
isNotTabbable('#disabledElement-inputTypeButton', 'input, type button');
|
|
|
|
isNotTabbable('#disabledElement-inputTypeHidden', 'input, type hidden');
|
|
|
|
isNotTabbable('#disabledElement-button', 'button');
|
|
|
|
isNotTabbable('#disabledElement-select', 'select');
|
|
|
|
isNotTabbable('#disabledElement-textarea', 'textarea');
|
|
|
|
});
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
test("tabbable - hidden styles", function() {
|
2009-01-21 03:25:02 +00:00
|
|
|
expect(8);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotTabbable('#displayNoneAncestor-input', 'input, display: none parent');
|
|
|
|
isNotTabbable('#displayNoneAncestor-span', 'span with tabindex, display: none parent');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotTabbable('#visibilityHiddenAncestor-input', 'input, visibility: hidden parent');
|
|
|
|
isNotTabbable('#visibilityHiddenAncestor-span', 'span with tabindex, visibility: hidden parent');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotTabbable('#displayNone-input', 'input, display: none');
|
|
|
|
isNotTabbable('#visibilityHidden-input', 'input, visibility: hidden');
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isNotTabbable('#displayNone-span', 'span with tabindex, display: none');
|
|
|
|
isNotTabbable('#visibilityHidden-span', 'span with tabindex, visibility: hidden');
|
|
|
|
});
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
test("tabbable - natively tabbable with various tabindex", function() {
|
2009-01-21 03:25:02 +00:00
|
|
|
expect(4);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isTabbable('#inputTabindex0', 'input, tabindex 0');
|
|
|
|
isTabbable('#inputTabindex10', 'input, tabindex 10');
|
|
|
|
isNotTabbable('#inputTabindex-1', 'input, tabindex -1');
|
|
|
|
isNotTabbable('#inputTabindex-50', 'input, tabindex -50');
|
|
|
|
});
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
test("tabbable - not natively tabbable with various tabindex", function() {
|
2009-01-21 03:25:02 +00:00
|
|
|
expect(4);
|
2012-04-23 16:55:11 +00:00
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
isTabbable('#spanTabindex0', 'span, tabindex 0');
|
|
|
|
isTabbable('#spanTabindex10', 'span, tabindex 10');
|
|
|
|
isNotTabbable('#spanTabindex-1', 'span, tabindex -1');
|
|
|
|
isNotTabbable('#spanTabindex-50', 'span, tabindex -50');
|
|
|
|
});
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
test("tabbable - area elements", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2010-07-22 14:33:42 +00:00
|
|
|
isTabbable('#areaCoordsHref', 'coords and href');
|
|
|
|
isTabbable('#areaNoCoordsHref', 'href but no coords');
|
|
|
|
isNotTabbable('#areaNoImg', 'not associated with an image');
|
|
|
|
});
|
|
|
|
|
2012-10-23 19:12:54 +00:00
|
|
|
test( "tabbable - dimensionless parent with overflow", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
isTabbable( "#dimensionlessParent", "input" );
|
|
|
|
});
|
|
|
|
|
2009-01-21 03:25:02 +00:00
|
|
|
})(jQuery);
|