Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / jquery / resources / test / unit / deferred.js
blob6ba4767a6dee7ac4b3ca7279f29bdb04e3641377
1 module("deferred", { teardown: moduleTeardown });
3 test("jQuery._Deferred()", function() {
5 expect( 11 );
7 var deferred,
8 object,
9 test;
11 deferred = jQuery._Deferred();
13 test = false;
15 deferred.done( function( value ) {
16 equals( value , "value" , "Test pre-resolve callback" );
17 test = true;
18 } );
20 deferred.resolve( "value" );
22 ok( test , "Test pre-resolve callbacks called right away" );
24 test = false;
26 deferred.done( function( value ) {
27 equals( value , "value" , "Test post-resolve callback" );
28 test = true;
29 } );
31 ok( test , "Test post-resolve callbacks called right away" );
33 deferred.cancel();
35 test = true;
37 deferred.done( function() {
38 ok( false , "Cancel was ignored" );
39 test = false;
40 } );
42 ok( test , "Test cancel" );
44 deferred = jQuery._Deferred().resolve();
46 try {
47 deferred.done( function() {
48 throw "Error";
49 } , function() {
50 ok( true , "Test deferred do not cancel on exception" );
51 } );
52 } catch( e ) {
53 strictEqual( e , "Error" , "Test deferred propagates exceptions");
54 deferred.done();
57 test = "";
58 deferred = jQuery._Deferred().done( function() {
60 test += "A";
62 }, function() {
64 test += "B";
66 } ).resolve();
68 strictEqual( test , "AB" , "Test multiple done parameters" );
70 test = "";
72 deferred.done( function() {
74 deferred.done( function() {
76 test += "C";
78 } );
80 test += "A";
82 }, function() {
84 test += "B";
85 } );
87 strictEqual( test , "ABC" , "Test done callbacks order" );
89 deferred = jQuery._Deferred();
91 deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
92 ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
93 });
95 // #8421
96 deferred = jQuery._Deferred();
97 deferred.resolveWith().done(function() {
98 ok( true, "Test resolveWith can be called with no argument" );
99 });
102 test("jQuery.Deferred()", function() {
104 expect( 10 );
106 jQuery.Deferred( function( defer ) {
107 strictEqual( this , defer , "Defer passed as this & first argument" );
108 this.resolve( "done" );
109 }).then( function( value ) {
110 strictEqual( value , "done" , "Passed function executed" );
113 jQuery.Deferred().resolve().then( function() {
114 ok( true , "Success on resolve" );
115 }, function() {
116 ok( false , "Error on resolve" );
119 jQuery.Deferred().reject().then( function() {
120 ok( false , "Success on reject" );
121 }, function() {
122 ok( true , "Error on reject" );
125 ( new jQuery.Deferred( function( defer ) {
126 strictEqual( this , defer , "Defer passed as this & first argument (new)" );
127 this.resolve( "done" );
128 }) ).then( function( value ) {
129 strictEqual( value , "done" , "Passed function executed (new)" );
132 ( new jQuery.Deferred() ).resolve().then( function() {
133 ok( true , "Success on resolve (new)" );
134 }, function() {
135 ok( false , "Error on resolve (new)" );
138 ( new jQuery.Deferred() ).reject().then( function() {
139 ok( false , "Success on reject (new)" );
140 }, function() {
141 ok( true , "Error on reject (new)" );
144 var tmp = jQuery.Deferred();
146 strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" );
147 strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" );
150 test("jQuery.when()", function() {
152 expect( 23 );
154 // Some other objects
155 jQuery.each( {
157 "an empty string": "",
158 "a non-empty string": "some string",
159 "zero": 0,
160 "a number other than zero": 1,
161 "true": true,
162 "false": false,
163 "null": null,
164 "undefined": undefined,
165 "a plain object": {}
167 } , function( message , value ) {
169 ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
170 strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
171 } ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
173 } );
175 ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) {
176 strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" );
177 } ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
179 var cache, i;
181 for( i = 1 ; i < 4 ; i++ ) {
182 jQuery.when( cache || jQuery.Deferred( function() {
183 this.resolve( i );
184 }) ).then( function( value ) {
185 strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
186 cache = value;
187 }, function() {
188 ok( false , "Fail called" );
193 test("jQuery.when() - joined", function() {
195 expect(8);
197 jQuery.when( 1, 2, 3 ).done( function( a, b, c ) {
198 strictEqual( a , 1 , "Test first param is first resolved value - non-observables" );
199 strictEqual( b , 2 , "Test second param is second resolved value - non-observables" );
200 strictEqual( c , 3 , "Test third param is third resolved value - non-observables" );
201 }).fail( function() {
202 ok( false , "Test the created deferred was resolved - non-observables");
205 var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ),
206 errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" );
208 jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) {
209 strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" );
210 same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" );
211 strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" );
212 }).fail( function() {
213 ok( false , "Test the created deferred was resolved - resolved observable");
216 jQuery.when( 1 , errorDeferred , 3 ).done( function() {
217 ok( false , "Test the created deferred was rejected - rejected observable");
218 }).fail( function( error , errorParam ) {
219 strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" );
220 strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" );