diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/offset/fixed.html | 1 | ||||
-rw-r--r-- | test/data/readywaitloader.js | 6 | ||||
-rw-r--r-- | test/index.html | 4 | ||||
-rw-r--r-- | test/readywait.html | 18 | ||||
-rw-r--r-- | test/unit/ajax.js | 2 | ||||
-rw-r--r-- | test/unit/attributes.js | 227 | ||||
-rw-r--r-- | test/unit/core.js | 38 | ||||
-rw-r--r-- | test/unit/css.js | 44 | ||||
-rw-r--r-- | test/unit/data.js | 19 | ||||
-rw-r--r-- | test/unit/deferred.js | 378 | ||||
-rw-r--r-- | test/unit/effects.js | 41 | ||||
-rw-r--r-- | test/unit/event.js | 191 | ||||
-rw-r--r-- | test/unit/manipulation.js | 6 | ||||
-rw-r--r-- | test/unit/offset.js | 17 | ||||
-rw-r--r-- | test/unit/traversing.js | 100 |
15 files changed, 820 insertions, 272 deletions
diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index 3181718da..81ba4ca7d 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -35,6 +35,7 @@ <body> <div id="fixed-1" class="fixed"></div> <div id="fixed-2" class="fixed"></div> + <div id="fixed-no-top-left" class="fixed"></div> <div id="forceScroll"></div> <div id="marker"></div> <p class="instructions">Click the white box to move the marker to it.</p> diff --git a/test/data/readywaitloader.js b/test/data/readywaitloader.js index 483e07c4d..e07dac7a9 100644 --- a/test/data/readywaitloader.js +++ b/test/data/readywaitloader.js @@ -1,14 +1,14 @@ -// Simple script loader that uses jQuery.readyWait +// Simple script loader that uses jQuery.readyWait via jQuery.holdReady() //Hold on jQuery! -jQuery.readyWait++; +jQuery.holdReady(true); var readyRegExp = /^(complete|loaded)$/; function assetLoaded( evt ){ var node = evt.currentTarget || evt.srcElement; if ( evt.type === "load" || readyRegExp.test(node.readyState) ) { - jQuery.ready(true); + jQuery.holdReady(false); } } diff --git a/test/index.html b/test/index.html index c7c2ae55d..a10655089 100644 --- a/test/index.html +++ b/test/index.html @@ -203,6 +203,10 @@ Z</textarea> <select name="D4" disabled="disabled"> <option selected="selected" value="NO">NO</option> </select> + <input id="list-test" type="text" /> + <datalist id="datalist"> + <option value="option"></option> + </datalist> </form> <div id="moretests"> <form> diff --git a/test/readywait.html b/test/readywait.html index 4f124767a..b4d8111eb 100644 --- a/test/readywait.html +++ b/test/readywait.html @@ -1,13 +1,13 @@ <!DOCTYPE html> <html> <!-- - Test for jQuery.readyWait. Needs to be a + Test for jQuery.holdReady. Needs to be a standalone test since it deals with DOM ready. --> <head> <title> - jQuery.readyWait Test + jQuery.holdReady Test </title> <style> div { margin-top: 10px; } @@ -52,15 +52,17 @@ </head> <body> <h1> - jQuery.readyWait Test + jQuery.holdReady Test </h1> <p> - This is a test page for jQuery.readyWait, that was - added due to this ticket - <a href="http://bugs.jquery.com/ticket/6781">#6781</a>. + This is a test page for jQuery.readyWait and jQuery.holdReady, + see + <a href="http://bugs.jquery.com/ticket/6781">#6781</a> + and + <a href="http://bugs.jquery.com/ticket/8803">#8803</a>. </p> <p> - Test for jQuery.readyWait, which can be used + Test for jQuery.holdReady, which can be used by plugins and other scripts to indicate something important to the page is still loading and needs to block the DOM ready callbacks that are registered @@ -68,7 +70,7 @@ </p> <p> Script loaders are the most likely kind of script - to use jQuery.readyWait, but it could be used by + to use jQuery.holdReady, but it could be used by other things like a script that loads a CSS file and wants to pause the DOM ready callbacks. </p> diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 7c572a32c..e9c7a00c5 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1600,7 +1600,7 @@ test("jQuery.ajax() - malformed JSON", function() { }, error: function(xhr, msg, detailedMsg) { equals( "parsererror", msg, "A parse error occurred." ); - ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" ); + ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" ); start(); } }); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 8cf47bed6..fa30ff042 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -3,38 +3,81 @@ module("attributes", { teardown: moduleTeardown }); var bareObj = function(value) { return value; }; var functionReturningObj = function(value) { return (function() { return value; }); }; -test("jQuery.props: itegrity test", function() { - - expect(1); - - // This must be maintained and equal jQuery.props - // Ensure that accidental or erroneous property - // overwrites don't occur - // This is simply for better code coverage and future proofing. - var propsShouldBe = { - "for": "htmlFor", - "class": "className", - readonly: "readOnly", - maxlength: "maxLength", - cellspacing: "cellSpacing", - rowspan: "rowSpan", - colspan: "colSpan", - tabindex: "tabIndex", - usemap: "useMap", - frameborder: "frameBorder" - }; - - same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check"); +test("jQuery.attrFix integrity test", function() { + expect(1); + + // This must be maintained and equal jQuery.attrFix when appropriate + // Ensure that accidental or erroneous property + // overwrites don't occur + // This is simply for better code coverage and future proofing. + var propsShouldBe; + if ( !jQuery.support.getSetAttribute ) { + propsShouldBe = { + tabindex: "tabIndex", + readonly: "readOnly", + "for": "htmlFor", + "class": "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder" + }; + } else { + propsShouldBe = { + tabindex: "tabIndex", + readonly: "readOnly" + }; + } + + same(propsShouldBe, jQuery.attrFix, "jQuery.attrFix passes integrity check"); }); -test("attr(String)", function() { - expect(37); +test("prop(String, Object)", function() { + expect(19); + equals( jQuery('#text1').prop('value'), "Test", 'Check for value attribute' ); + equals( jQuery('#text1').prop('value', "Test2").prop('defaultValue'), "Test", 'Check for defaultValue attribute' ); + equals( jQuery('#select2').prop('selectedIndex'), 3, 'Check for selectedIndex attribute' ); + equals( jQuery('#foo').prop('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' ); + equals( jQuery('#foo').prop('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' ); + equals( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." ); + + var body = document.body, $body = jQuery( body ); + ok( $body.prop('nextSibling') === null, 'Make sure a null expando returns null' ); + body.foo = 'bar'; + equals( $body.prop('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' ); + body.foo = undefined; + ok( $body.prop('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' ); + + var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option"); + optgroup.appendChild( option ); + select.appendChild( optgroup ); + + equals( jQuery(option).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); + equals( jQuery(document).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." ); + + var attributeNode = document.createAttribute("irrelevant"), + commentNode = document.createComment("some comment"), + textNode = document.createTextNode("some text"), + obj = {}; + jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) { + strictEqual( jQuery(ele).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." ); + }); + + var obj = {}; + jQuery.each( [document, obj], function( i, ele ) { + var $ele = jQuery( ele ); + $ele.prop( "nonexisting", "foo" ); + equal( $ele.prop("nonexisting"), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." ); + }); + jQuery( document ).removeProp("nonexisting"); +}); - // This one sometimes fails randomly ?! - equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' ); +test("attr(String)", function() { + expect(32); - equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' ); equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' ); equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' ); equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' ); @@ -46,60 +89,58 @@ test("attr(String)", function() { equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' ); equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' ); ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); - // Temporarily disabled. See: #4299 - // ok( jQuery('#form').attr('action','newformaction').attr('action').indexOf("newformaction") >= 0, 'Check that action attribute was changed' ); + equals( jQuery('#form').attr('blah', 'blah').attr('blah'), 'blah', 'Set non-existant attribute on a form' ); + equals( jQuery('#foo').attr('height'), undefined, 'Non existent height attribute should return undefined' ); + + // [7472] & [3113] (form contains an input with name="action" or name="id") + var extras = jQuery('<input name="id" name="name" /><input id="target" name="target" />').appendTo('#testForm'); + equals( jQuery('#form').attr('action','newformaction').attr('action'), 'newformaction', 'Check that action attribute was changed' ); + equals( jQuery('#testForm').attr('target'), undefined, 'Retrieving target does not equal the input with name=target' ); + equals( jQuery('#testForm').attr('target', 'newTarget').attr('target'), 'newTarget', 'Set target successfully on a form' ); + equals( jQuery('#testForm').removeAttr('id').attr('id'), undefined, 'Retrieving id does not equal the input with name=id after id is removed [#7472]' ); + // Bug #3685 (form contains input with name="name") + equals( jQuery('#testForm').attr('name'), undefined, 'Retrieving name does not retrieve input with name=name' ); + extras.remove(); + equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' ); equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' ); equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' ); - equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' ); - equals( jQuery('#foo').attr('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' ); - equals( jQuery('#foo').attr('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' ); // using innerHTML in IE causes href attribute to be serialized to the full path jQuery('<a/>').attr({ 'id': 'tAnchor5', 'href': '#5' }).appendTo('#main'); equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' ); - equals( jQuery("<option/>").attr("selected"), false, "Check selected attribute on disconnected element." ); - + // list attribute is readonly by default in browsers that support it + jQuery('#list-test').attr('list', 'datalist'); + equals( jQuery('#list-test').attr('list'), 'datalist', 'Check setting list attribute' ); // Related to [5574] and [5683] var body = document.body, $body = jQuery(body); - ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' ); - ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' ); + strictEqual( $body.attr('foo'), undefined, 'Make sure that a non existent attribute returns undefined' ); body.setAttribute('foo', 'baz'); equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' ); - body.foo = 'bar'; - equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' ); - $body.attr('foo','cool'); equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' ); - body.foo = undefined; - ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' ); - body.removeAttribute('foo'); // Cleanup var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option"); optgroup.appendChild( option ); select.appendChild( optgroup ); - equals( jQuery(option).attr("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); + var $img = jQuery('<img style="display:none" width="215" height="53" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif"/>').appendTo('body'); + equals( $img.attr('width'), "215", "Retrieve width attribute an an element with display:none." ); + equals( $img.attr('height'), "53", "Retrieve height attribute an an element with display:none." ); + + // Check for style support + ok( !!~jQuery('#dl').attr('style').indexOf('position'), 'Check style attribute getter, also normalize css props to lowercase' ); + ok( !!~jQuery('#foo').attr('style', 'position:absolute;').attr('style').indexOf('position'), 'Check style setter' ); ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); - - equals( jQuery(document).attr("nodeName"), "#document", "attr works correctly on document nodes (bug #7451)." ); - - var attributeNode = document.createAttribute("irrelevant"), - commentNode = document.createComment("some comment"), - textNode = document.createTextNode("some text"), - obj = {}; - jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) { - strictEqual( jQuery(ele).attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." ); - }); }); if ( !isLocal ) { @@ -116,8 +157,8 @@ if ( !isLocal ) { test("attr(String, Function)", function() { expect(2); - equals( jQuery('#text1').attr('value', function() { return this.id ;})[0].value, "text1", "Set value from id" ); - equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index"); + equals( jQuery('#text1').attr('value', function() { return this.id; })[0].value, "text1", "Set value from id" ); + equals( jQuery('#text1').attr('title', function(i) { return i; }).attr('title'), "0", "Set value with an index"); }); test("attr(Hash)", function() { @@ -133,7 +174,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(30); + expect(29); var div = jQuery("div").attr("foo", "bar"), fail = false; @@ -153,7 +194,7 @@ test("attr(String, Object)", function() { jQuery("#name").attr('name', 'something'); equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' ); jQuery("#name").attr('name', null); - equals( jQuery("#name").attr('title'), '', 'Remove name attribute' ); + equals( jQuery("#name").attr('name'), undefined, 'Remove name attribute' ); jQuery("#check2").attr('checked', true); equals( document.getElementById('check2').checked, true, 'Set checked attribute' ); jQuery("#check2").attr('checked', false); @@ -163,28 +204,22 @@ test("attr(String, Object)", function() { jQuery("#text1").attr('readonly', false); equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' ); jQuery("#name").attr('maxlength', '5'); - equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' ); + equals( document.getElementById('name').maxLength, 5, 'Set maxlength attribute' ); jQuery("#name").attr('maxLength', '10'); - equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' ); - + equals( document.getElementById('name').maxLength, 10, 'Set maxlength attribute' ); + var $p = jQuery('#firstp').attr('nonexisting', 'foo'); + equals( $p.attr('nonexisting'), 'foo', "attr(name, value) works correctly for non existing attributes (bug #7500)."); + $p.removeAttr('nonexisting'); + var attributeNode = document.createAttribute("irrelevant"), commentNode = document.createComment("some comment"), - textNode = document.createTextNode("some text"), - obj = {}; - jQuery.each( [document, obj, "#firstp"], function( i, ele ) { - var $ele = jQuery( ele ); - $ele.attr( "nonexisting", "foo" ); - equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." ); - }); + textNode = document.createTextNode("some text"); + jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) { var $ele = jQuery( ele ); $ele.attr( "nonexisting", "foo" ); strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." ); }); - //cleanup - jQuery.each( [document, "#firstp"], function( i, ele ) { - jQuery( ele ).removeAttr("nonexisting"); - }); var table = jQuery('#table').append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"), td = table.find('td:first'); @@ -193,15 +228,15 @@ test("attr(String, Object)", function() { td.attr("colspan", "2"); equals( td[0].colSpan, 2, "Check colspan is correctly set" ); table.attr("cellspacing", "2"); - equals( table[0].cellSpacing, 2, "Check cellspacing is correctly set" ); + equals( table[0].cellSpacing, "2", "Check cellspacing is correctly set" ); // for #1070 jQuery("#name").attr('someAttr', '0'); equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' ); jQuery("#name").attr('someAttr', 0); - equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' ); + equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to the number 0' ); jQuery("#name").attr('someAttr', 1); - equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' ); + equals( jQuery("#name").attr('someAttr'), '1', 'Set attribute to the number 1' ); // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); @@ -211,7 +246,8 @@ test("attr(String, Object)", function() { j.removeAttr("name"); QUnit.reset(); - + + // Type var type = jQuery("#check2").attr('type'); var thrown = false; try { @@ -251,6 +287,13 @@ test("attr(String, Object)", function() { } ok( thrown, "Exception thrown when trying to change type property" ); equals( "button", button.attr('type'), "Verify that you can't change the type of a button element" ); + + // Setting attributes on svg elements (bug #3116) + var $svg = jQuery('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="3000" height="3000">' + + '<circle cx="200" cy="200" r="150" />' + + '</svg>').appendTo('body'); + equals( $svg.attr('cx', 100).attr('cx'), "100", "Set attribute on svg element" ); + $svg.remove(); }); test("attr(jquery_method)", function(){ @@ -356,25 +399,32 @@ test("attr('tabindex', value)", function() { }); test("removeAttr(String)", function() { - expect(7); + expect(5); equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" ); + equals( jQuery('#form').removeAttr('id').attr('id'), undefined, 'Remove id' ); + equals( jQuery('#foo').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute' ); + equals( jQuery('#form').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute on a form' ); + equals( jQuery('#fx-test-group').attr('height', '3px').removeAttr('height').css('height'), "1px", 'Removing height attribute has no effect on height set with style attribute' ); +}); +test("removeProp(String)", function() { + expect(6); var attributeNode = document.createAttribute("irrelevant"), commentNode = document.createComment("some comment"), textNode = document.createTextNode("some text"), obj = {}; - //removeAttr only really removes on DOM element nodes handle all other seperatyl - strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" ); + + strictEqual( jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[0].nonexisting, undefined, "removeprop works correctly on DOM element nodes" ); jQuery.each( [document, obj], function( i, ele ) { var $ele = jQuery( ele ); - $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" ); - strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." ); + $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" ); + strictEqual( ele.nonexisting, undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." ); }); jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) { $ele = jQuery( ele ); - $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" ); - strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." ); + $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" ); + strictEqual( ele.nonexisting, undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." ); }); }); @@ -604,21 +654,20 @@ test("addClass(Function)", function() { test("addClass(Function) with incoming value", function() { expect(45); - var div = jQuery("div"), old = div.map(function(){ - return jQuery(this).attr("class"); + return jQuery(this).attr("class") || ""; }); - + div.addClass(function(i, val) { - if ( this.id !== "_firebugConsole" ) { + if ( this.id !== "_firebugConsole") { equals( val, old[i], "Make sure the incoming value is correct." ); return "test"; } }); var pass = true; - for ( var i = 0; i < div.size(); i++ ) { - if ( div.get(i).className.indexOf("test") == -1 ) pass = false; + for ( var i = 0; i < div.length; i++ ) { + if ( div.get(i).className.indexOf("test") == -1 ) pass = false; } ok( pass, "Add Class" ); }); @@ -843,4 +892,4 @@ test("addClass, removeClass, hasClass", function() { ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" ); jq.removeClass("class4"); ok( jq.hasClass("class4")==false, "Check the class has been properly removed" ); -}); +});
\ No newline at end of file diff --git a/test/unit/core.js b/test/unit/core.js index c15884fc6..ed1fb5918 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -12,7 +12,7 @@ test("Basic requirements", function() { }); test("jQuery()", function() { - expect(24); + expect(25); // Basic constructor's behavior @@ -20,6 +20,7 @@ test("jQuery()", function() { equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); equals( jQuery("").length, 0, "jQuery('') === jQuery([])" ); + equals( jQuery("#").length, 0, "jQuery('#') === jQuery([])" ); var obj = jQuery("div"); equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); @@ -171,6 +172,26 @@ test("selector state", function() { ); }); +test( "globalEval", function() { + + expect( 3 ); + + jQuery.globalEval( "var globalEvalTest = true;" ); + ok( window.globalEvalTest, "Test variable declarations are global" ); + + window.globalEvalTest = false; + + jQuery.globalEval( "globalEvalTest = true;" ); + ok( window.globalEvalTest, "Test variable assignments are global" ); + + window.globalEvalTest = false; + + jQuery.globalEval( "this.globalEvalTest = true;" ); + ok( window.globalEvalTest, "Test context (this) is the window object" ); + + window.globalEvalTest = undefined; +}); + if ( !isLocal ) { test("browser", function() { stop(); @@ -468,7 +489,7 @@ test("isWindow", function() { }); test("jQuery('html')", function() { - expect(15); + expect(18); QUnit.reset(); jQuery.foo = false; @@ -500,6 +521,19 @@ test("jQuery('html')", function() { ok( jQuery("<div></div>")[0], "Create a div with closing tag." ); ok( jQuery("<table></table>")[0], "Create a table with closing tag." ); + + // Test very large html string #7990 + var i; + var li = '<li>very large html string</li>'; + var html = ['<ul>']; + for ( i = 0; i < 50000; i += 1 ) { + html.push(li); + } + html.push('</ul>'); + html = jQuery(html.join(''))[0]; + equals( html.nodeName.toUpperCase(), 'UL'); + equals( html.firstChild.nodeName.toUpperCase(), 'LI'); + equals( html.childNodes.length, 50000 ); }); test("jQuery('html', context)", function() { diff --git a/test/unit/css.js b/test/unit/css.js index 555f13575..08f50ef25 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -105,6 +105,38 @@ test("css(String|Hash)", function() { equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." ); }); +test("css() explicit and relative values", function() { + expect(9); + var $elem = jQuery('#nothiddendiv'); + + $elem.css({ width: 1, height: 1 }); + equals( $elem.width(), 1, "Initial css set or width/height works (hash)" ); + + $elem.css({ width: "+=9" }); + equals( $elem.width(), 10, "'+=9' on width (hash)" ); + + $elem.css({ width: "-=9" }); + equals( $elem.width(), 1, "'-=9' on width (hash)" ); + + $elem.css({ width: "+=9px" }); + equals( $elem.width(), 10, "'+=9px' on width (hash)" ); + + $elem.css({ width: "-=9px" }); + equals( $elem.width(), 1, "'-=9px' on width (hash)" ); + + $elem.css( "width", "+=9" ); + equals( $elem.width(), 10, "'+=9' on width (params)" ); + + $elem.css( "width", "-=9" ) ; + equals( $elem.width(), 1, "'-=9' on width (params)" ); + + $elem.css( "width", "+=9px" ); + equals( $elem.width(), 10, "'+=9px' on width (params)" ); + + $elem.css( "width", "-=9px" ); + equals( $elem.width(), 1, "'-=9px' on width (params)" ); +}); + test("css(String, Object)", function() { expect(22); @@ -333,3 +365,15 @@ test("internal ref to elem.runtimeStyle (bug #7608)", function () { ok( result, "elem.runtimeStyle does not throw exception" ); }); + +test("marginRight computed style (bug #3333)", function() { + expect(1); + + var $div = jQuery("#foo"); + $div.css({ + width: "1px", + marginRight: 0 + }); + + equals($div.css("marginRight"), "0px"); +}); diff --git a/test/unit/data.js b/test/unit/data.js index 8fb7f35ad..94fa2a018 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -485,4 +485,21 @@ if (window.JSON && window.JSON.stringify) { equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" ); }); -}
\ No newline at end of file +} + +test("jQuery.data should follow html5 specification regarding camel casing", function() { + expect(6); + + var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>") + .prependTo("body"); + + equals(div.data().foo, "a", "Verify single word data-* key"); + equals(div.data().fooBar, "b", "Verify multiple word data-* key"); + equals(div.data().fooBarBaz, "c", "Verify multiple word data-* key"); + + equals(div.data("foo"), "a", "Verify single word data-* key"); + equals(div.data("fooBar"), "b", "Verify multiple word data-* key"); + equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key"); + + div.remove(); +});
\ No newline at end of file diff --git a/test/unit/deferred.js b/test/unit/deferred.js index 6ba4767a6..c71fbdbe7 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -1,153 +1,273 @@ module("deferred", { teardown: moduleTeardown }); -test("jQuery._Deferred()", function() { +jQuery.each( [ "", " - new operator" ], function( _, withNew ) { - expect( 11 ); + function createDeferred() { + return withNew ? new jQuery._Deferred() : jQuery._Deferred(); + } - var deferred, - object, - test; + test("jQuery._Deferred" + withNew, function() { - deferred = jQuery._Deferred(); + expect( 11 ); - test = false; + var deferred, + object, + test; - deferred.done( function( value ) { - equals( value , "value" , "Test pre-resolve callback" ); - test = true; - } ); + deferred = createDeferred(); - deferred.resolve( "value" ); - - ok( test , "Test pre-resolve callbacks called right away" ); + test = false; - test = false; + deferred.done( function( value ) { + equals( value , "value" , "Test pre-resolve callback" ); + test = true; + } ); - deferred.done( function( value ) { - equals( value , "value" , "Test post-resolve callback" ); - test = true; - } ); + deferred.resolve( "value" ); - ok( test , "Test post-resolve callbacks called right away" ); + ok( test , "Test pre-resolve callbacks called right away" ); - deferred.cancel(); + test = false; - test = true; + deferred.done( function( value ) { + equals( value , "value" , "Test post-resolve callback" ); + test = true; + } ); - deferred.done( function() { - ok( false , "Cancel was ignored" ); - test = false; - } ); + ok( test , "Test post-resolve callbacks called right away" ); - ok( test , "Test cancel" ); + deferred.cancel(); - deferred = jQuery._Deferred().resolve(); + test = true; - try { deferred.done( function() { - throw "Error"; - } , function() { - ok( true , "Test deferred do not cancel on exception" ); + ok( false , "Cancel was ignored" ); + test = false; } ); - } catch( e ) { - strictEqual( e , "Error" , "Test deferred propagates exceptions"); - deferred.done(); - } - test = ""; - deferred = jQuery._Deferred().done( function() { + ok( test , "Test cancel" ); - test += "A"; + deferred = createDeferred().resolve(); - }, function() { + try { + deferred.done( function() { + throw "Error"; + } , function() { + ok( true , "Test deferred do not cancel on exception" ); + } ); + } catch( e ) { + strictEqual( e , "Error" , "Test deferred propagates exceptions"); + deferred.done(); + } - test += "B"; + test = ""; + deferred = createDeferred().done( function() { - } ).resolve(); + test += "A"; - strictEqual( test , "AB" , "Test multiple done parameters" ); + }, function() { + + test += "B"; - test = ""; + } ).resolve(); - deferred.done( function() { + strictEqual( test , "AB" , "Test multiple done parameters" ); + + test = ""; deferred.done( function() { - test += "C"; + deferred.done( function() { + + test += "C"; + } ); + + test += "A"; + + }, function() { + + test += "B"; } ); - test += "A"; + strictEqual( test , "ABC" , "Test done callbacks order" ); - }, function() { + deferred = createDeferred(); - test += "B"; - } ); + deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { + ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); + }); + + // #8421 + deferred = createDeferred(); + deferred.resolveWith().done(function() { + ok( true, "Test resolveWith can be called with no argument" ); + }); + }); +} ); + +jQuery.each( [ "", " - new operator" ], function( _, withNew ) { + + function createDeferred( fn ) { + return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn ); + } + + test("jQuery.Deferred" + withNew, function() { + + expect( 8 ); + + createDeferred().resolve().then( function() { + ok( true , "Success on resolve" ); + ok( this.isResolved(), "Deferred is resolved" ); + }, function() { + ok( false , "Error on resolve" ); + }).always( function() { + ok( true , "Always callback on resolve" ); + }); + + createDeferred().reject().then( function() { + ok( false , "Success on reject" ); + }, function() { + ok( true , "Error on reject" ); + ok( this.isRejected(), "Deferred is rejected" ); + }).always( function() { + ok( true , "Always callback on reject" ); + }); + + createDeferred( function( defer ) { + ok( this === defer , "Defer passed as this & first argument" ); + this.resolve( "done" ); + }).then( function( value ) { + strictEqual( value , "done" , "Passed function executed" ); + }); + }); +} ); - strictEqual( test , "ABC" , "Test done callbacks order" ); +test( "jQuery.Deferred.pipe - filtering (done)", function() { - deferred = jQuery._Deferred(); + expect(3); - deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { - ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); + var defer = jQuery.Deferred(), + piped = defer.pipe(function( a, b ) { + return a * b; + }), + value1, + value2, + value3; + + piped.done(function( result ) { + value3 = result; + }); + + defer.done(function( a, b ) { + value1 = a; + value2 = b; }); - // #8421 - deferred = jQuery._Deferred(); - deferred.resolveWith().done(function() { - ok( true, "Test resolveWith can be called with no argument" ); + defer.resolve( 2, 3 ); + + strictEqual( value1, 2, "first resolve value ok" ); + strictEqual( value2, 3, "second resolve value ok" ); + strictEqual( value3, 6, "result of filter ok" ); + + jQuery.Deferred().reject().pipe(function() { + ok( false, "pipe should not be called on reject" ); }); }); -test("jQuery.Deferred()", function() { +test( "jQuery.Deferred.pipe - filtering (fail)", function() { + + expect(3); - expect( 10 ); + var defer = jQuery.Deferred(), + piped = defer.pipe( null, function( a, b ) { + return a * b; + } ), + value1, + value2, + value3; - jQuery.Deferred( function( defer ) { - strictEqual( this , defer , "Defer passed as this & first argument" ); - this.resolve( "done" ); - }).then( function( value ) { - strictEqual( value , "done" , "Passed function executed" ); + piped.fail(function( result ) { + value3 = result; }); - jQuery.Deferred().resolve().then( function() { - ok( true , "Success on resolve" ); - }, function() { - ok( false , "Error on resolve" ); + defer.fail(function( a, b ) { + value1 = a; + value2 = b; }); - jQuery.Deferred().reject().then( function() { - ok( false , "Success on reject" ); - }, function() { - ok( true , "Error on reject" ); + defer.reject( 2, 3 ); + + strictEqual( value1, 2, "first reject value ok" ); + strictEqual( value2, 3, "second reject value ok" ); + strictEqual( value3, 6, "result of filter ok" ); + + jQuery.Deferred().resolve().pipe( null, function() { + ok( false, "pipe should not be called on resolve" ); + } ); +}); + +test( "jQuery.Deferred.pipe - deferred (done)", function() { + + expect(3); + + var defer = jQuery.Deferred(), + piped = defer.pipe(function( a, b ) { + return jQuery.Deferred(function( defer ) { + defer.reject( a * b ); + }); + }), + value1, + value2, + value3; + + piped.fail(function( result ) { + value3 = result; }); - ( new jQuery.Deferred( function( defer ) { - strictEqual( this , defer , "Defer passed as this & first argument (new)" ); - this.resolve( "done" ); - }) ).then( function( value ) { - strictEqual( value , "done" , "Passed function executed (new)" ); + defer.done(function( a, b ) { + value1 = a; + value2 = b; }); - ( new jQuery.Deferred() ).resolve().then( function() { - ok( true , "Success on resolve (new)" ); - }, function() { - ok( false , "Error on resolve (new)" ); + defer.resolve( 2, 3 ); + + strictEqual( value1, 2, "first resolve value ok" ); + strictEqual( value2, 3, "second resolve value ok" ); + strictEqual( value3, 6, "result of filter ok" ); +}); + +test( "jQuery.Deferred.pipe - deferred (fail)", function() { + + expect(3); + + var defer = jQuery.Deferred(), + piped = defer.pipe( null, function( a, b ) { + return jQuery.Deferred(function( defer ) { + defer.resolve( a * b ); + }); + } ), + value1, + value2, + value3; + + piped.done(function( result ) { + value3 = result; }); - ( new jQuery.Deferred() ).reject().then( function() { - ok( false , "Success on reject (new)" ); - }, function() { - ok( true , "Error on reject (new)" ); + defer.fail(function( a, b ) { + value1 = a; + value2 = b; }); - var tmp = jQuery.Deferred(); + defer.reject( 2, 3 ); - strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" ); - strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" ); + strictEqual( value1, 2, "first reject value ok" ); + strictEqual( value2, 3, "second reject value ok" ); + strictEqual( value3, 6, "result of filter ok" ); }); -test("jQuery.when()", function() { +test( "jQuery.when" , function() { expect( 23 ); @@ -166,57 +286,63 @@ test("jQuery.when()", function() { } , function( message , value ) { - ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) { + ok( jQuery.isFunction( jQuery.when( value ).done(function( resolveValue ) { strictEqual( resolveValue , value , "Test the promise was resolved with " + message ); - } ).promise ) , "Test " + message + " triggers the creation of a new Promise" ); + }).promise ) , "Test " + message + " triggers the creation of a new Promise" ); } ); - ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) { + ok( jQuery.isFunction( jQuery.when().done(function( resolveValue ) { strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" ); - } ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" ); + }).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" ); var cache, i; for( i = 1 ; i < 4 ; i++ ) { jQuery.when( cache || jQuery.Deferred( function() { this.resolve( i ); - }) ).then( function( value ) { + }) ).done(function( value ) { strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) ); cache = value; - }, function() { - ok( false , "Fail called" ); }); } }); -test("jQuery.when() - joined", function() { - - expect(8); - - jQuery.when( 1, 2, 3 ).done( function( a, b, c ) { - strictEqual( a , 1 , "Test first param is first resolved value - non-observables" ); - strictEqual( b , 2 , "Test second param is second resolved value - non-observables" ); - strictEqual( c , 3 , "Test third param is third resolved value - non-observables" ); - }).fail( function() { - ok( false , "Test the created deferred was resolved - non-observables"); - }); - - var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ), - errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" ); - - jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) { - strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" ); - same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" ); - strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" ); - }).fail( function() { - ok( false , "Test the created deferred was resolved - resolved observable"); - }); - - jQuery.when( 1 , errorDeferred , 3 ).done( function() { - ok( false , "Test the created deferred was rejected - rejected observable"); - }).fail( function( error , errorParam ) { - strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" ); - strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" ); - }); +test("jQuery.when - joined", function() { + + expect(25); + + var deferreds = { + value: 1, + success: jQuery.Deferred().resolve( 1 ), + error: jQuery.Deferred().reject( 0 ), + futureSuccess: jQuery.Deferred(), + futureError: jQuery.Deferred() + }, + willSucceed = { + value: true, + success: true, + error: false, + futureSuccess: true, + futureError: false + }; + + jQuery.each( deferreds, function( id1, defer1 ) { + jQuery.each( deferreds, function( id2, defer2 ) { + var shouldResolve = willSucceed[ id1 ] && willSucceed[ id2 ], + expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ], + code = id1 + "/" + id2; + jQuery.when( defer1, defer2 ).done(function( a, b ) { + if ( shouldResolve ) { + same( [ a, b ], expected, code + " => resolve" ); + } + }).fail(function( a, b ) { + if ( !shouldResolve ) { + same( [ a, b ], expected, code + " => resolve" ); + } + }); + } ); + } ); + deferreds.futureSuccess.resolve( 1 ); + deferreds.futureError.reject( 0 ); }); diff --git a/test/unit/effects.js b/test/unit/effects.js index c0a812f45..4f6785111 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -717,59 +717,64 @@ jQuery.each( { var anim = { width: t_w, height: t_h, opacity: t_o }; - elem.animate(anim, 50, function(){ + elem.animate(anim, 50); + + jQuery.when( elem ).done(function( elem ){ + + elem = elem[ 0 ]; + if ( t_w == "show" ) - equals( this.style.display, "block", "Showing, display should block: " + this.style.display); + equals( elem.style.display, "block", "Showing, display should block: " + elem.style.display); if ( t_w == "hide"||t_w == "show" ) - ok(f_w === "" ? this.style.width === f_w : this.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + this.style.width); + ok(f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + elem.style.width); if ( t_h == "hide"||t_h == "show" ) - ok(f_h === "" ? this.style.height === f_h : this.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + this.style.height); + ok(f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + elem.style.height); - var cur_o = jQuery.style(this, "opacity"); + var cur_o = jQuery.style(elem, "opacity"); if ( t_o == "hide" || t_o == "show" ) equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o); if ( t_w == "hide" ) - equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display); + equals(elem.style.display, "none", "Hiding, display should be none: " + elem.style.display); if ( t_o.constructor == Number ) { equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o); - ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o); + ok(jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o); } if ( t_w.constructor == Number ) { - equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width); + equals(elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width); - var cur_w = jQuery.css(this,"width"); + var cur_w = jQuery.css(elem,"width"); - ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w); + ok(elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w); } if ( t_h.constructor == Number ) { - equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height); + equals(elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height); - var cur_h = jQuery.css(this,"height"); + var cur_h = jQuery.css(elem,"height"); - ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w); + ok(elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w); } if ( t_h == "show" ) { - var old_h = jQuery.css(this, "height"); - jQuery(this).append("<br/>Some more text<br/>and some more..."); + var old_h = jQuery.css(elem, "height"); + jQuery(elem).append("<br/>Some more text<br/>and some more..."); if ( /Auto/.test( fn ) ) { - notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto."); + notEqual(jQuery.css(elem, "height"), old_h, "Make sure height is auto."); } else { - equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto."); + equals(jQuery.css(elem, "height"), old_h, "Make sure height is not auto."); } } // manually remove generated element - jQuery(this).remove(); + jQuery(elem).remove(); start(); }); diff --git a/test/unit/event.js b/test/unit/event.js index d54987923..cefdf5833 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -550,6 +550,47 @@ test("bind(name, false), unbind(name, false)", function() { jQuery("#main").unbind("click"); }); +test("live(name, false), die(name, false)", function() { + expect(3); + + var main = 0; + jQuery("#main").live("click", function(e){ main++; }); + jQuery("#ap").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); + + main = 0; + jQuery("#ap").live("click", false); + jQuery("#ap").trigger("click"); + equals( main, 0, "Verify that no bubble happened." ); + + main = 0; + jQuery("#ap").die("click", false); + jQuery("#ap").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); + jQuery("#main").die("click"); +}); + +test("delegate(selector, name, false), undelegate(selector, name, false)", function() { + expect(3); + + var main = 0; + + jQuery("#main").delegate("#ap", "click", function(e){ main++; }); + jQuery("#ap").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); + + main = 0; + jQuery("#ap").delegate("#groups", "click", false); + jQuery("#groups").trigger("click"); + equals( main, 0, "Verify that no bubble happened." ); + + main = 0; + jQuery("#ap").undelegate("#groups", "click", false); + jQuery("#groups").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); + jQuery("#main").undelegate("#ap", "click"); +}); + test("bind()/trigger()/unbind() on plain object", function() { expect( 7 ); @@ -683,6 +724,20 @@ test("hover()", function() { equals( times, 4, "hover handlers fired" ); }); +test("mouseover triggers mouseenter", function() { + expect(1); + + var count = 0, + elem = jQuery("<a />"); + elem.mouseenter(function () { + count++; + }); + elem.trigger('mouseover'); + equals(count, 1, "make sure mouseover triggers a mouseenter" ); + + elem.remove(); +}); + test("trigger() shortcuts", function() { expect(6); @@ -724,10 +779,11 @@ test("trigger() shortcuts", function() { }); test("trigger() bubbling", function() { - expect(14); + expect(17); - var doc = 0, html = 0, body = 0, main = 0, ap = 0; + var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0; + jQuery(window).bind("click", function(e){ win++; }); jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } }); jQuery("html").bind("click", function(e){ html++; }); jQuery("body").bind("click", function(e){ body++; }); @@ -735,15 +791,18 @@ test("trigger() bubbling", function() { jQuery("#ap").bind("click", function(){ ap++; return false; }); jQuery("html").trigger("click"); + equals( win, 1, "HTML bubble" ); equals( doc, 1, "HTML bubble" ); equals( html, 1, "HTML bubble" ); jQuery("body").trigger("click"); + equals( win, 2, "Body bubble" ); equals( doc, 2, "Body bubble" ); equals( html, 2, "Body bubble" ); equals( body, 1, "Body bubble" ); jQuery("#main").trigger("click"); + equals( win, 3, "Main bubble" ); equals( doc, 3, "Main bubble" ); equals( html, 3, "Main bubble" ); equals( body, 2, "Main bubble" ); @@ -916,6 +975,27 @@ test("trigger(eventObject, [data], [fn])", function() { $parent.unbind().remove(); }); +test("jQuery.Event({ /* props */ })", function() { + + expect(4); + + var event = jQuery.Event({ type: "keydown", keyCode: 64 }), + handler = function( event ) { + ok( "keyCode" in event, "Special property 'keyCode' exists" ); + equal( event.keyCode, 64, "event.keyCode has explicit value '64'" ); + }; + + // Supports jQuery.Event implementation + equal( event.type, "keydown", "Verify type" ); + + ok( "keyCode" in event, "Special 'keyCode' property exists" ); + + jQuery("body").bind( "keydown", handler ).trigger( event ); + + jQuery("body").unbind( "keydown" ); + +}); + test("jQuery.Event.currentTarget", function(){ expect(1); @@ -1967,9 +2047,9 @@ test("window resize", function() { }); test("focusin bubbles", function() { - expect(4); - - var input = jQuery( '<input type="text" />' ).prependTo( "body" ), + expect(5); + + var input = jQuery( '<input type="text" />' ).prependTo( "body" ), order = 0; jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){ @@ -1982,24 +2062,108 @@ test("focusin bubbles", function() { // DOM focus method input[0].focus(); + + // To make the next focus test work, we need to take focus off the input. + // This will fire another focusin event, so set order to reflect that. + order = 1; + jQuery("#text1")[0].focus(); + // jQuery trigger, which calls DOM focus order = 0; - input[0].blur(); input.trigger( "focus" ); input.remove(); jQuery( "body" ).unbind( "focusin.focusinBubblesTest" ); }); -/* -test("jQuery(function($) {})", function() { - stop(); - jQuery(function($) { - equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn"); - start(); - }); +test("custom events with colons (#3533, #8272)", function() { + expect(1); + + var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body"); + try { + tab.trigger("back:forth"); + ok( true, "colon events don't throw" ); + } catch ( e ) { + ok( false, "colon events die" ); + }; + tab.remove(); + }); +(function(){ + // This code must be run before DOM ready! + var notYetReady, noEarlyExecution, + order = [], + args = {}; + + notYetReady = !jQuery.isReady; + + test("jQuery.isReady", function() { + expect(2); + + equals(notYetReady, true, "jQuery.isReady should not be true before DOM ready"); + equals(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready"); + }); + + // Create an event handler. + function makeHandler( testId ) { + // When returned function is executed, push testId onto `order` array + // to ensure execution order. Also, store event handler arg to ensure + // the correct arg is being passed into the event handler. + return function( arg ) { + order.push(testId); + args[testId] = arg; + }; + } + + // Bind to the ready event in every possible way. + jQuery(makeHandler("a")); + jQuery(document).ready(makeHandler("b")); + jQuery(document).bind("ready.readytest", makeHandler("c")); + + // Do it twice, just to be sure. + jQuery(makeHandler("d")); + jQuery(document).ready(makeHandler("e")); + jQuery(document).bind("ready.readytest", makeHandler("f")); + + noEarlyExecution = order.length == 0; + + // This assumes that QUnit tests are run on DOM ready! + test("jQuery ready", function() { + expect(10); + + ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready"); + + // Ensure execution order. + same(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in bind-order, but those bound with jQuery(document).bind( 'ready', fn ) will always execute last"); + + // Ensure handler argument is correct. + equals(args.a, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery"); + equals(args.b, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery"); + ok(args.c instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object"); + + order = []; + + // Now that the ready event has fired, again bind to the ready event + // in every possible way. These event handlers should execute immediately. + jQuery(makeHandler("g")); + equals(order.pop(), "g", "Event handler should execute immediately"); + equals(args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery"); + + jQuery(document).ready(makeHandler("h")); + equals(order.pop(), "h", "Event handler should execute immediately"); + equals(args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery"); + + jQuery(document).bind("ready.readytest", makeHandler("never")); + equals(order.length, 0, "Event handler should never execute since DOM ready has already passed"); + + // Cleanup. + jQuery(document).unbind("ready.readytest"); + }); + +})(); + +/* test("event properties", function() { stop(); jQuery("#simon1").click(function(event) { @@ -2008,3 +2172,4 @@ test("event properties", function() { }).click(); }); */ + diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index ff3dff164..e972a4792 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1009,7 +1009,7 @@ test("clone()", function() { }); test("clone(form element) (Bug #3879, #6655)", function() { - expect(6); + expect(5); var element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>"); equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" ); @@ -1019,7 +1019,9 @@ test("clone(form element) (Bug #3879, #6655)", function() { equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" ); equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" ); - equals( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" ); + + // defaultChecked also gets set now due to setAttribute in attr, is this check still valid? + // equals( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" ); element = jQuery("<input type='text' value='foo'>"); clone = element.clone(); diff --git a/test/unit/offset.js b/test/unit/offset.js index 329d69f95..ae0518849 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -265,7 +265,7 @@ testoffset("static", function( jQuery ) { }); testoffset("fixed", function( jQuery ) { - expect(28); + expect(30); jQuery.offset.initialize(); @@ -320,6 +320,17 @@ testoffset("fixed", function( jQuery ) { ok( true, 'Fixed position is not supported' ); } }); + + // Bug 8316 + var $noTopLeft = jQuery('#fixed-no-top-left'); + if ( jQuery.offset.supportsFixedPosition ) { + equals( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" ); + equals( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" ); + } else { + // need to have same number of assertions + ok( true, 'Fixed position is not supported' ); + ok( true, 'Fixed position is not supported' ); + } }); testoffset("table", function( jQuery ) { @@ -422,7 +433,7 @@ test("offsetParent", function(){ equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); }); -function testoffset(name, fn) { +function testoffset( name, fn ) { test(name, function() { // pause execution for now @@ -447,7 +458,7 @@ function testoffset(name, fn) { function loadFixture() { var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ), iframe = jQuery('<iframe />').css({ - width: 500, height: 500, position: 'absolute', top: -600, left: -600, visiblity: 'hidden' + width: 500, height: 500, position: 'absolute', top: -600, left: -600, visibility: 'hidden' }).appendTo('body')[0]; iframe.contentWindow.location = src; return iframe; diff --git a/test/unit/traversing.js b/test/unit/traversing.js index f5108bdef..71bc7f5d5 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -13,8 +13,32 @@ test("find(String)", function() { same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); }); -test("is(String)", function() { - expect(26); +test("find(node|jQuery object)", function() { + expect( 11 ); + + var $foo = jQuery('#foo'), + $blog = jQuery('.blogTest'), + $first = jQuery('#first'), + $two = $blog.add( $first ), + $fooTwo = $foo.add( $blog ); + + equals( $foo.find( $blog ).text(), 'Yahoo', 'Find with blog jQuery object' ); + equals( $foo.find( $blog[0] ).text(), 'Yahoo', 'Find with blog node' ); + equals( $foo.find( $first ).length, 0, '#first is not in #foo' ); + equals( $foo.find( $first[0]).length, 0, '#first not in #foo (node)' ); + ok( $foo.find( $two ).is('.blogTest'), 'Find returns only nodes within #foo' ); + ok( $fooTwo.find( $blog ).is('.blogTest'), 'Blog is part of the collection, but also within foo' ); + ok( $fooTwo.find( $blog[0] ).is('.blogTest'), 'Blog is part of the collection, but also within foo(node)' ); + + equals( $two.find( $foo ).length, 0, 'Foo is not in two elements' ); + equals( $two.find( $foo[0] ).length, 0, 'Foo is not in two elements(node)' ); + equals( $two.find( $first ).length, 0, 'first is in the collection and not within two' ); + equals( $two.find( $first ).length, 0, 'first is in the collection and not within two(node)' ); + +}); + +test("is(String|undefined)", function() { + expect(27); ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' ); ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' ); ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' ); @@ -33,11 +57,13 @@ test("is(String)", function() { ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' ); ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' ); ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); + ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' ); ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' ); ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' ); ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' ); - + ok( !jQuery('#foo').is({ plain: "object" }), 'Check passing invalid object' ); + // test is() with comma-seperated expressions ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); @@ -45,6 +71,36 @@ test("is(String)", function() { ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); }); +test("is(jQuery)", function() { + expect(24); + ok( jQuery('#form').is( jQuery('form') ), 'Check for element: A form is a form' ); + ok( !jQuery('#form').is( jQuery('div') ), 'Check for element: A form is not a div' ); + ok( jQuery('#mark').is( jQuery('.blog') ), 'Check for class: Expected class "blog"' ); + ok( !jQuery('#mark').is( jQuery('.link') ), 'Check for class: Did not expect class "link"' ); + ok( jQuery('#simon').is( jQuery('.blog.link') ), 'Check for multiple classes: Expected classes "blog" and "link"' ); + ok( !jQuery('#simon').is( jQuery('.blogTest') ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); + ok( jQuery('#en').is( jQuery('[lang="en"]') ), 'Check for attribute: Expected attribute lang to be "en"' ); + ok( !jQuery('#en').is( jQuery('[lang="de"]') ), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); + ok( jQuery('#text1').is( jQuery('[type="text"]') ), 'Check for attribute: Expected attribute type to be "text"' ); + ok( !jQuery('#text1').is( jQuery('[type="radio"]') ), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); + ok( jQuery('#text2').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected to be disabled' ); + ok( !jQuery('#text1').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected not disabled' ); + ok( jQuery('#radio2').is( jQuery(':checked') ), 'Check for pseudoclass: Expected to be checked' ); + ok( !jQuery('#radio1').is( jQuery(':checked') ), 'Check for pseudoclass: Expected not checked' ); + ok( jQuery('#foo').is( jQuery(':has(p)') ), 'Check for child: Expected a child "p" element' ); + ok( !jQuery('#foo').is( jQuery(':has(ul)') ), 'Check for child: Did not expect "ul" element' ); + ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)') ), 'Check for childs: Expected "p", "a" and "code" child elements' ); + ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)') ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); + + // Some raw elements + ok( jQuery('#form').is( jQuery('form')[0] ), 'Check for element: A form is a form' ); + ok( !jQuery('#form').is( jQuery('div')[0] ), 'Check for element: A form is not a div' ); + ok( jQuery('#mark').is( jQuery('.blog')[0] ), 'Check for class: Expected class "blog"' ); + ok( !jQuery('#mark').is( jQuery('.link')[0] ), 'Check for class: Did not expect class "link"' ); + ok( jQuery('#simon').is( jQuery('.blog.link')[0] ), 'Check for multiple classes: Expected classes "blog" and "link"' ); + ok( !jQuery('#simon').is( jQuery('.blogTest')[0] ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); +}); + test("index()", function() { expect(1); @@ -82,11 +138,16 @@ test("index(Object|String|undefined)", function() { equals( jQuery('#radio2').index('#form :text') , -1, "Check for index not found within a selector" ); }); -test("filter(Selector)", function() { - expect(5); +test("filter(Selector|undefined)", function() { + expect(9); same( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); + + same( jQuery('p').filter(null).get(), [], "filter(null) should return an empty jQuery object"); + same( jQuery('p').filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); + same( jQuery('p').filter(0).get(), [], "filter(0) should return an empty jQuery object"); + same( jQuery('p').filter('').get(), [], "filter('') should return an empty jQuery object"); // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); @@ -124,7 +185,7 @@ test("filter(jQuery)", function() { }) test("closest()", function() { - expect(11); + expect(13); same( jQuery("body").closest("body").get(), q("body"), "closest(body)" ); same( jQuery("body").closest("html").get(), q("html"), "closest(html)" ); same( jQuery("body").closest("div").get(), [], "closest(div)" ); @@ -158,8 +219,29 @@ test("closest(Array)", function() { same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); }); +<<<<<<< HEAD +test("not(Selector|undefined)", function() { + expect(11); +======= +test("closest(jQuery)", function() { + expect(8); + var $child = jQuery("#nothiddendivchild"), + $parent = jQuery("#nothiddendiv"), + $main = jQuery("#main"), + $body = jQuery("body"); + ok( $child.closest( $parent ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') )" ); + ok( $child.closest( $parent[0] ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') ) :: node" ); + ok( $child.closest( $child ).is('#nothiddendivchild'), "child is included" ); + ok( $child.closest( $child[0] ).is('#nothiddendivchild'), "child is included :: node" ); + equals( $child.closest( document.createElement('div') ).length, 0, "created element is not related" ); + equals( $child.closest( $main ).length, 0, "Main not a parent of child" ); + equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); + ok( $child.closest( $body.add($parent) ).is('#nothiddendiv'), "Closest ancestor retrieved." ); +}); + test("not(Selector)", function() { expect(7); +>>>>>>> 1a167767305202797cf4c839eb64bd7adfb00182 equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" ); same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); @@ -168,6 +250,12 @@ test("not(Selector)", function() { same( jQuery('#ap *').not('code').get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); same( jQuery('#ap *').not('code, #mark').get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); same( jQuery('#ap *').not('#mark, code').get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); + + var all = jQuery('p').get(); + same( jQuery('p').not(null).get(), all, "not(null) should have no effect"); + same( jQuery('p').not(undefined).get(), all, "not(undefined) should have no effect"); + same( jQuery('p').not(0).get(), all, "not(0) should have no effect"); + same( jQuery('p').not('').get(), all, "not('') should have no effect"); }); test("not(Element)", function() { |