aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-03-23 15:59:33 -0400
committertimmywil <tim.willison@thisismedium.com>2011-03-23 15:59:33 -0400
commitd2eafa0bb835ab9dba33d364e052ebc44afd244a (patch)
tree828bc4d818c917d01b68976548fc7a7092ef42bd /test/unit
parent9e5ec378e35a04f123e82cb1cb5b3eb45254f6f4 (diff)
parent7705c35b140f378e407c196599cc738bc54c5cec (diff)
downloadjquery-d2eafa0bb835ab9dba33d364e052ebc44afd244a.tar.gz
jquery-d2eafa0bb835ab9dba33d364e052ebc44afd244a.zip
Merge branch 'master' of git://github.com/jquery/jquery into bug_2773
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/ajax.js12
-rw-r--r--test/unit/core.js223
-rw-r--r--test/unit/deferred.js222
-rw-r--r--test/unit/event.js39
-rw-r--r--test/unit/manipulation.js7
5 files changed, 281 insertions, 222 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 2a2ac46a1..7c572a32c 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -492,7 +492,7 @@ test(".ajax() - hash", function() {
test("jQuery ajax - cross-domain detection", function() {
- expect( 5 );
+ expect( 6 );
var loc = document.location,
otherPort = loc.port === 666 ? 667 : 666,
@@ -508,6 +508,7 @@ test("jQuery ajax - cross-domain detection", function() {
});
jQuery.ajax({
+ dataType: "jsonp",
url: 'app:/path',
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
@@ -535,6 +536,15 @@ test("jQuery ajax - cross-domain detection", function() {
jQuery.ajax({
dataType: "jsonp",
+ url: "about:blank",
+ beforeSend: function( _ , s ) {
+ ok( s.crossDomain , "Test about:blank is detected as cross-domain" );
+ return false;
+ }
+ });
+
+ jQuery.ajax({
+ dataType: "jsonp",
url: loc.protocol + "//" + loc.host,
crossDomain: true,
beforeSend: function( _ , s ) {
diff --git a/test/unit/core.js b/test/unit/core.js
index bce0de0f0..6ee8724de 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -914,221 +914,6 @@ test("jQuery.parseJSON", function(){
}
});
-test("jQuery._Deferred()", function() {
-
- expect( 10 );
-
- var deferred,
- object,
- test;
-
- deferred = jQuery._Deferred();
-
- test = false;
-
- deferred.done( function( value ) {
- equals( value , "value" , "Test pre-resolve callback" );
- test = true;
- } );
-
- deferred.resolve( "value" );
-
- ok( test , "Test pre-resolve callbacks called right away" );
-
- test = false;
-
- deferred.done( function( value ) {
- equals( value , "value" , "Test post-resolve callback" );
- test = true;
- } );
-
- ok( test , "Test post-resolve callbacks called right away" );
-
- deferred.cancel();
-
- test = true;
-
- deferred.done( function() {
- ok( false , "Cancel was ignored" );
- test = false;
- } );
-
- ok( test , "Test cancel" );
-
- deferred = jQuery._Deferred().resolve();
-
- 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 = "";
- deferred = jQuery._Deferred().done( function() {
-
- test += "A";
-
- }, function() {
-
- test += "B";
-
- } ).resolve();
-
- strictEqual( test , "AB" , "Test multiple done parameters" );
-
- test = "";
-
- deferred.done( function() {
-
- deferred.done( function() {
-
- test += "C";
-
- } );
-
- test += "A";
-
- }, function() {
-
- test += "B";
- } );
-
- strictEqual( test , "ABC" , "Test done callbacks order" );
-
- deferred = jQuery._Deferred();
-
- deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
- ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
- });
-});
-
-test("jQuery.Deferred()", function() {
-
- expect( 10 );
-
- 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" );
- });
-
- jQuery.Deferred().resolve().then( function() {
- ok( true , "Success on resolve" );
- }, function() {
- ok( false , "Error on resolve" );
- });
-
- jQuery.Deferred().reject().then( function() {
- ok( false , "Success on reject" );
- }, function() {
- ok( true , "Error on reject" );
- });
-
- ( 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)" );
- });
-
- ( new jQuery.Deferred() ).resolve().then( function() {
- ok( true , "Success on resolve (new)" );
- }, function() {
- ok( false , "Error on resolve (new)" );
- });
-
- ( new jQuery.Deferred() ).reject().then( function() {
- ok( false , "Success on reject (new)" );
- }, function() {
- ok( true , "Error on reject (new)" );
- });
-
- var tmp = jQuery.Deferred();
-
- 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" );
-});
-
-test("jQuery.when()", function() {
-
- expect( 23 );
-
- // Some other objects
- jQuery.each( {
-
- "an empty string": "",
- "a non-empty string": "some string",
- "zero": 0,
- "a number other than zero": 1,
- "true": true,
- "false": false,
- "null": null,
- "undefined": undefined,
- "a plain object": {}
-
- } , function( message , value ) {
-
- ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
- strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
- } ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
-
- } );
-
- ok( jQuery.isFunction( jQuery.when().then( 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" );
-
- var cache, i;
-
- for( i = 1 ; i < 4 ; i++ ) {
- jQuery.when( cache || jQuery.Deferred( function() {
- this.resolve( i );
- }) ).then( 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.sub() - Static Methods", function(){
expect(18);
var Subclass = jQuery.sub();
@@ -1143,16 +928,16 @@ test("jQuery.sub() - Static Methods", function(){
}
});
Subclass.fn.extend({subClassMethod: function() { return this;}});
-
+
//Test Simple Subclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
-
+
//Create a SubSubclass
var SubSubclass = Subclass.sub();
-
+
//Make Sure the SubSubclass inherited properly
ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true');
ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!');
@@ -1169,7 +954,7 @@ test("jQuery.sub() - Static Methods", function(){
ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!');
ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly');
notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
-
+
//This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
diff --git a/test/unit/deferred.js b/test/unit/deferred.js
new file mode 100644
index 000000000..6ba4767a6
--- /dev/null
+++ b/test/unit/deferred.js
@@ -0,0 +1,222 @@
+module("deferred", { teardown: moduleTeardown });
+
+test("jQuery._Deferred()", function() {
+
+ expect( 11 );
+
+ var deferred,
+ object,
+ test;
+
+ deferred = jQuery._Deferred();
+
+ test = false;
+
+ deferred.done( function( value ) {
+ equals( value , "value" , "Test pre-resolve callback" );
+ test = true;
+ } );
+
+ deferred.resolve( "value" );
+
+ ok( test , "Test pre-resolve callbacks called right away" );
+
+ test = false;
+
+ deferred.done( function( value ) {
+ equals( value , "value" , "Test post-resolve callback" );
+ test = true;
+ } );
+
+ ok( test , "Test post-resolve callbacks called right away" );
+
+ deferred.cancel();
+
+ test = true;
+
+ deferred.done( function() {
+ ok( false , "Cancel was ignored" );
+ test = false;
+ } );
+
+ ok( test , "Test cancel" );
+
+ deferred = jQuery._Deferred().resolve();
+
+ 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 = "";
+ deferred = jQuery._Deferred().done( function() {
+
+ test += "A";
+
+ }, function() {
+
+ test += "B";
+
+ } ).resolve();
+
+ strictEqual( test , "AB" , "Test multiple done parameters" );
+
+ test = "";
+
+ deferred.done( function() {
+
+ deferred.done( function() {
+
+ test += "C";
+
+ } );
+
+ test += "A";
+
+ }, function() {
+
+ test += "B";
+ } );
+
+ strictEqual( test , "ABC" , "Test done callbacks order" );
+
+ deferred = jQuery._Deferred();
+
+ deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
+ ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
+ });
+
+ // #8421
+ deferred = jQuery._Deferred();
+ deferred.resolveWith().done(function() {
+ ok( true, "Test resolveWith can be called with no argument" );
+ });
+});
+
+test("jQuery.Deferred()", function() {
+
+ expect( 10 );
+
+ 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" );
+ });
+
+ jQuery.Deferred().resolve().then( function() {
+ ok( true , "Success on resolve" );
+ }, function() {
+ ok( false , "Error on resolve" );
+ });
+
+ jQuery.Deferred().reject().then( function() {
+ ok( false , "Success on reject" );
+ }, function() {
+ ok( true , "Error on reject" );
+ });
+
+ ( 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)" );
+ });
+
+ ( new jQuery.Deferred() ).resolve().then( function() {
+ ok( true , "Success on resolve (new)" );
+ }, function() {
+ ok( false , "Error on resolve (new)" );
+ });
+
+ ( new jQuery.Deferred() ).reject().then( function() {
+ ok( false , "Success on reject (new)" );
+ }, function() {
+ ok( true , "Error on reject (new)" );
+ });
+
+ var tmp = jQuery.Deferred();
+
+ 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" );
+});
+
+test("jQuery.when()", function() {
+
+ expect( 23 );
+
+ // Some other objects
+ jQuery.each( {
+
+ "an empty string": "",
+ "a non-empty string": "some string",
+ "zero": 0,
+ "a number other than zero": 1,
+ "true": true,
+ "false": false,
+ "null": null,
+ "undefined": undefined,
+ "a plain object": {}
+
+ } , function( message , value ) {
+
+ ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
+ strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
+ } ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
+
+ } );
+
+ ok( jQuery.isFunction( jQuery.when().then( 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" );
+
+ var cache, i;
+
+ for( i = 1 ; i < 4 ; i++ ) {
+ jQuery.when( cache || jQuery.Deferred( function() {
+ this.resolve( i );
+ }) ).then( 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" );
+ });
+});
diff --git a/test/unit/event.js b/test/unit/event.js
index b7b260462..1e40e0f3e 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -683,6 +683,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);
@@ -1966,6 +1980,31 @@ test("window resize", function() {
ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." );
});
+test("focusin bubbles", function() {
+ expect(4);
+
+ var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
+ order = 0;
+
+ jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
+ equals( 1, order++, "focusin on the body second" );
+ });
+
+ input.bind( "focusin.focusinBubblesTest", function(){
+ equals( 0, order++, "focusin on the element first" );
+ });
+
+ // DOM focus method
+ input[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();
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 34425ed3a..ff3dff164 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -739,7 +739,7 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});
var testReplaceWith = function(val) {
- expect(20);
+ expect(21);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
@@ -800,6 +800,9 @@ var testReplaceWith = function(val) {
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." );
+ var non_existant = jQuery('#does-not-exist').replaceWith( val("<b>should not throw an error</b>") );
+ equals( non_existant.length, 0, "Length of non existant element." );
+
var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
// TODO: Work on jQuery(...) inline script execution
//$div.replaceWith("<div class='replacewith'></div><script>" +
@@ -827,7 +830,7 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("replaceWith(Function)", function() {
testReplaceWith(functionReturningObj);
- expect(21);
+ expect(22);
var y = jQuery("#yahoo")[0];