mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
103 lines
4.8 KiB
JavaScript
103 lines
4.8 KiB
JavaScript
/**
|
|
* This test page is for selector tests that address selector issues that have already been addressed in jQuery functions
|
|
* and which only work because jQuery has hooked into Sizzle.
|
|
* These tests may or may not fail in an independent Sizzle.
|
|
*/
|
|
|
|
module("selector - jQuery only", { teardown: moduleTeardown });
|
|
|
|
testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQuery, window, document ) {
|
|
expect(34);
|
|
|
|
/**
|
|
* Returns an array of elements with the given IDs, eg.
|
|
*/
|
|
function q() {
|
|
var r = [],
|
|
i = 0;
|
|
|
|
for ( ; i < arguments.length; i++ ) {
|
|
r.push( document.getElementById( arguments[i] ) );
|
|
}
|
|
return r;
|
|
}
|
|
|
|
/**
|
|
* Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
|
|
* @param {String} a - Assertion name
|
|
* @param {String} b - Sizzle selector
|
|
* @param {String} c - Array of ids to construct what is expected
|
|
*/
|
|
function t( a, b, c ) {
|
|
var f = jQuery(b).get(),
|
|
s = "",
|
|
i = 0;
|
|
|
|
for ( ; i < f.length; i++ ) {
|
|
s += (s && ",") + '"' + f[i].id + '"';
|
|
}
|
|
|
|
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
|
|
}
|
|
|
|
// ====== All known boolean attributes, including html5 booleans ======
|
|
// autobuffer, autofocus, autoplay, async, checked,
|
|
// compact, controls, declare, defer, disabled,
|
|
// formnovalidate, hidden, indeterminate (property only),
|
|
// ismap, itemscope, loop, multiple, muted, nohref, noresize,
|
|
// noshade, nowrap, novalidate, open, pubdate, readonly, required,
|
|
// reversed, scoped, seamless, selected, truespeed, visible (skipping visible attribute, which is on a barprop object)
|
|
|
|
t( "Attribute Exists", "[autobuffer]", ["video1"]);
|
|
t( "Attribute Exists", "[autofocus]", ["text1"]);
|
|
t( "Attribute Exists", "[autoplay]", ["video1"]);
|
|
t( "Attribute Exists", "[async]", ["script1"]);
|
|
t( "Attribute Exists", "[checked]", ["check1"]);
|
|
t( "Attribute Exists", "[compact]", ["dl"]);
|
|
t( "Attribute Exists", "[controls]", ["video1"]);
|
|
t( "Attribute Exists", "[declare]", ["object1"]);
|
|
t( "Attribute Exists", "[defer]", ["script1"]);
|
|
t( "Attribute Exists", "[disabled]", ["check1"]);
|
|
t( "Attribute Exists", "[formnovalidate]", ["form1"]);
|
|
t( "Attribute Exists", "[hidden]", ["div1"]);
|
|
t( "Attribute Exists", "[indeterminate]", []);
|
|
t( "Attribute Exists", "[ismap]", ["img1"]);
|
|
t( "Attribute Exists", "[itemscope]", ["div1"]);
|
|
// t( "Attribute Exists", "[loop]", ["video1"]); // IE 6/7 cannot differentiate here. loop is also used on img, input, and marquee tags as well as video/audio. getAttributeNode unfortunately only retrieves the property value.
|
|
t( "Attribute Exists", "[multiple]", ["select1"]);
|
|
t( "Attribute Exists", "[muted]", ["audio1"]);
|
|
// t( "Attribute Exists", "[nohref]", ["area1"]); // IE 6/7 keep this set to false regardless of presence. The attribute node is not retrievable.
|
|
t( "Attribute Exists", "[noresize]", ["textarea1"]);
|
|
t( "Attribute Exists", "[noshade]", ["hr1"]);
|
|
t( "Attribute Exists", "[nowrap]", ["td1", "div1"]);
|
|
t( "Attribute Exists", "[novalidate]", ["form1"]);
|
|
t( "Attribute Exists", "[open]", ["details1"]);
|
|
t( "Attribute Exists", "[pubdate]", ["article1"]);
|
|
t( "Attribute Exists", "[readonly]", ["text1"]);
|
|
t( "Attribute Exists", "[required]", ["text1"]);
|
|
t( "Attribute Exists", "[reversed]", ["ol1"]);
|
|
t( "Attribute Exists", "[scoped]", ["style1"]);
|
|
t( "Attribute Exists", "[seamless]", ["iframe1"]);
|
|
// t( "Attribute Exists", "[selected]", ["option1"]); // IE8's querySelectorAll fails here. Redirecting to oldSizzle would work, but it would require an additional support test as well as a check for the selected attribute within the qsa logic
|
|
t( "Attribute Exists", "[truespeed]", ["marquee1"]);
|
|
|
|
// Enumerated attributes (these are not boolean content attributes)
|
|
jQuery.each([ "draggable", "contenteditable", "aria-disabled" ], function( i, val ) {
|
|
t( "Enumerated attribute", "[" + val + "]", ["div1"]);
|
|
});
|
|
t( "Enumerated attribute", "[spellcheck]", ["span1"]);
|
|
|
|
// t( "tabindex selector does not retrieve all elements in IE6/7(#8473)", "form, [tabindex]", ["form1", "text1"]); // Uncomment this when the tabindex attrHook is deprecated
|
|
|
|
t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"]);
|
|
});
|
|
|
|
testIframe("selector/sizzle_cache", "Sizzle cache collides with multiple Sizzles on a page", function( jQuery, window, document ) {
|
|
var $cached = window.$cached;
|
|
|
|
expect(3);
|
|
deepEqual( $cached('.test a').get(), [ document.getElementById('collision') ], "Select collision anchor with first sizzle" );
|
|
equal( jQuery('.evil a').length, 0, "Select nothing with second sizzle" );
|
|
equal( jQuery('.evil a').length, 0, "Select nothing again with second sizzle" );
|
|
});
|