Changeset 2783
- Timestamp:
- 08/19/07 23:37:26 (1 year ago)
- Location:
- trunk/jquery
- Files:
-
- 1 added
- 10 modified
- 1 moved
-
build/runtest/test.js (modified) (1 diff)
-
build/test/data/test.html (added)
-
build/test/data/test.js (modified) (1 diff)
-
build/test/data/test2.html (moved) (moved from trunk/jquery/build/test/data/test2.php) (1 diff)
-
build/test/data/testrunner.js (modified) (3 diffs)
-
build/test/index.html (modified) (1 diff)
-
src/ajax/ajax.js (modified) (4 diffs)
-
src/ajax/ajaxTest.js (modified) (13 diffs)
-
src/event/event.js (modified) (4 diffs)
-
src/fx/fxTest.js (modified) (1 diff)
-
src/jquery/coreTest.js (modified) (5 diffs)
-
src/jquery/jquery.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/build/runtest/test.js
r2292 r2783 12 12 "src/jquery/coreTest.js", 13 13 "src/selector/selectorTest.js", 14 "src/event/eventTest.js" ,15 "src/fx/fxTest.js"14 "src/event/eventTest.js" 15 //"src/fx/fxTest.js", 16 16 //"src/ajax/ajaxTest.js" 17 17 ); -
trunk/jquery/build/test/data/test.js
r612 r2783 1 foobar = "bar";1 var foobar = "bar"; 2 2 $('#ap').html('bar'); 3 3 ok( true, "test.js executed"); -
trunk/jquery/build/test/data/test2.html
r814 r2783 1 1 <script type="text/javascript"> 2 testFoo = "foo"; $('#foo').html('foo');ok( true, "test2.php executed" ); 2 var testFoo = "foo"; 3 $('#foo').html('foo'); 4 ok( true, "test2.html executed" ); 3 5 </script> -
trunk/jquery/build/test/data/testrunner.js
r2123 r2783 14 14 }; 15 15 16 var isLocal = !!(window.location.protocol == 'file:'); 17 16 18 $(function() { 17 19 $('#userAgent').html(navigator.userAgent); … … 40 42 start(); 41 43 }; 42 _config.timeout = setTimeout(handler, _config.asyncTimeout * 1000); 44 // Disabled, caused too many random errors 45 //_config.timeout = setTimeout(handler, _config.asyncTimeout * 1000); 43 46 } 44 47 function start() { 45 if(_config.timeout) 46 clearTimeout(_config.timeout); 47 _config.blocking = false; 48 process(); 48 // A slight delay, to avoid any current callbacks 49 setTimeout(function(){ 50 if(_config.timeout) 51 clearTimeout(_config.timeout); 52 _config.blocking = false; 53 process(); 54 }, 13); 49 55 } 50 56 … … 272 278 * @param String message (optional) 273 279 */ 274 function equals( expected, actual, message) {280 function equals(actual, expected, message) { 275 281 var result = expected == actual; 276 282 message = message || (result ? "okay" : "failed"); -
trunk/jquery/build/test/index.html
r2769 r2783 10 10 <script type="text/javascript" src="../src/selector/selectorTest.js"></script> 11 11 <script type="text/javascript" src="../src/event/eventTest.js"></script> 12 < !--<script type="text/javascript" src="../src/ajax/ajaxTest.js"></script>-->12 <script type="text/javascript" src="../src/ajax/ajaxTest.js"></script> 13 13 <script type="text/javascript" src="../src/fx/fxTest.js"></script> 14 14 </head> -
trunk/jquery/src/ajax/ajax.js
r2770 r2783 80 80 self.html(res.responseText); 81 81 82 self.each( callback, [res.responseText, status, res] ); 82 // Add delay to account for Safari's delay in globalEval 83 setTimeout(function(){ 84 self.each( callback, [res.responseText, status, res] ); 85 }, 13); 83 86 } 84 87 }); … … 571 574 */ 572 575 ajax: function( s ) { 573 // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout 574 s = jQuery.extend({}, jQuery.ajaxSettings, s); 576 // Extend the settings, but re-extend 's' so that it can be 577 // checked again later (in the test suite, specifically) 578 s = jQuery.extend(s, jQuery.extend({}, jQuery.ajaxSettings, s)); 575 579 576 580 // if data available 577 581 if ( s.data ) { 578 582 // convert data if not already a string 579 if (s.processData && typeof s.data != "string") 580 s.data = jQuery.param(s.data); 583 if ( s.processData && typeof s.data != "string" ) 584 s.data = jQuery.param(s.data); 585 581 586 // append data to url for get requests 582 if ( s.type.toLowerCase() == "get" ) {587 if ( s.type.toLowerCase() == "get" ) { 583 588 // "?" + data or "&" + data (in case there are already params) 584 s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data; 589 s.url += (s.url.indexOf("?") > -1 ? "&" : "?") + s.data; 590 585 591 // IE likes to send both get and post data, prevent this 586 592 s.data = null; … … 663 669 664 670 // Fire the global callback 665 if ( s.global )671 if ( s.global ) 666 672 jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 667 673 } else … … 686 692 }; 687 693 688 // don't attach the handler to the request, just poll it instead 689 var ival = setInterval(onreadystatechange, 13); 690 691 // Timeout checker 692 if ( s.timeout > 0 ) 693 setTimeout(function(){ 694 // Check to see if the request is still happening 695 if ( xml ) { 696 // Cancel the request 697 xml.abort(); 698 699 if( !requestDone ) 700 onreadystatechange( "timeout" ); 701 } 702 }, s.timeout); 694 if ( s.async ) { 695 // don't attach the handler to the request, just poll it instead 696 var ival = setInterval(onreadystatechange, 13); 697 698 // Timeout checker 699 if ( s.timeout > 0 ) 700 setTimeout(function(){ 701 // Check to see if the request is still happening 702 if ( xml ) { 703 // Cancel the request 704 xml.abort(); 705 706 if( !requestDone ) 707 onreadystatechange( "timeout" ); 708 } 709 }, s.timeout); 710 } 703 711 704 712 // Send the data -
trunk/jquery/src/ajax/ajaxTest.js
r2286 r2783 1 1 module("ajax"); 2 2 3 // Safari 3 crashes when running these tests, sigh 4 if ( !jQuery.browser.safari ) { 5 3 6 test("serialize()", function() { 4 7 expect(1); 5 var data = $(':input').not('button').serialize();6 8 // ignore button, IE takes text content as value, not relevant for this test 7 ok( data == 'action=Test&text2=Test&radio1=on&radio2=on&check=on&=on&hidden=&foo%5Bbar%5D=&name=name&=foobar&select1=&select2=3&select3=1', 'Check form serialization as query string' ); 8 }); 9 10 test("param", function() { 9 equals( $(':input').not('button').serialize(), 10 'action=Test&text2=Test&radio1=on&radio2=on&check=on&=on&hidden=&foo%5Bbar%5D=&name=name&=foobar&select1=&select2=3&select3=1&test=&id=', 11 'Check form serialization as query string'); 12 }); 13 14 test("$.param()", function() { 11 15 expect(4); 12 16 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; 13 ok( $.param(params) =="foo=bar&baz=42&quux=All%20your%20base%20are%20belong%20to%20us", "simple" );17 equals( $.param(params), "foo=bar&baz=42&quux=All%20your%20base%20are%20belong%20to%20us", "simple" ); 14 18 15 19 params = {someName: [1, 2, 3], regularThing: "blah" }; 16 ok( $.param(params) =="someName=1&someName=2&someName=3®ularThing=blah", "with array" );20 equals( $.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" ); 17 21 18 22 params = {"foo[]":["baz", 42, "All your base are belong to us"]}; 19 ok( $.param(params) =="foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All%20your%20base%20are%20belong%20to%20us", "more array" );23 equals( $.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All%20your%20base%20are%20belong%20to%20us", "more array" ); 20 24 21 25 params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; 22 ok( $.param(params) == "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All%20your%20base%20are%20belong%20to%20us", "even more arrays" ); 23 }); 24 25 test("evalScripts() with no script elements", function() { 26 expect(2); 27 28 var data = "this is just some bogus text"; 29 $('#foo').html(data); 30 ok ( true, 'before evalScripts()'); 31 try { 32 $('#foo').evalScripts(); 33 } catch(e) { 34 ok (false, 'exception evaluating scripts: ' + e.message); 35 } 36 ok ( true, 'after evalScripts()'); 26 equals( $.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All%20your%20base%20are%20belong%20to%20us", "even more arrays" ); 37 27 }); 38 28 39 29 test("synchronous request", function() { 30 expect(1); 40 31 ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" ); 41 32 }); … … 51 42 expect(7); 52 43 stop(true); 44 45 var target = "data/name.html"; 53 46 var count = 0; 54 47 var success = function() { 55 if(count++ == 6)56 start(); 57 } 58 var target = "data/name.html";48 if(count++ == 5) 49 start(); 50 }; 51 59 52 ok( $.get(url(target), success), "get" ); 60 53 ok( $.getIfModified(url(target), success), "getIfModified" ); … … 65 58 }); 66 59 67 test("load(String, Object, Function) - simple: inject text into DOM", function() { 60 test("global ajaxSettings", function() { 61 expect(3); 62 63 var tmp = jQuery.extend({}, jQuery.ajaxSettings); 64 var orig = { url: "data/with_fries.xml", data: null }; 65 var t; 66 67 $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} }); 68 69 t = jQuery.extend({}, orig); 70 $.ajax(t); 71 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending null" ); 72 73 t = jQuery.extend({}, orig); 74 t.data = {}; 75 $.ajax(t); 76 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" ); 77 78 t = jQuery.extend({}, orig); 79 t.data = { zoo: 'a', ping: 'b' }; 80 $.ajax(t); 81 ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" ); 82 83 jQuery.ajaxSettings = tmp; 84 }); 85 86 test("load(String)", function() { 87 expect(1); 88 stop(true); // check if load can be called with only url 89 $('#first').load("data/name.html", start); 90 }); 91 92 test("load(String, Function) - simple: inject text into DOM", function() { 68 93 expect(2); 69 94 stop(); … … 74 99 }); 75 100 76 test("load(String, Object, Function) - inject without callback", function() { 77 expect(1); 78 stop(true); // check if load can be called with only url 79 $('#first').load("data/name.html"); 80 }); 81 82 if ( location.protocol != "file:" ) { 83 84 test("load(String, Object, Function) - check scripts", function() { 101 test("load(String, Function) - check scripts", function() { 85 102 expect(7); 86 103 stop(); … … 88 105 window.foobar = null; 89 106 var verifyEvaluation = function() { 90 ok( foobar =="bar", 'Check if script src was evaluated after load' );91 ok( $('#ap').html() =='bar', 'Check if script evaluation has modified DOM');107 equals( foobar, "bar", 'Check if script src was evaluated after load' ); 108 equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); 92 109 start(); 93 110 }; 94 $('#first').load(url('data/test. php'), function() {111 $('#first').load(url('data/test.html'), function() { 95 112 ok( $('#first').html().match(/^html text/), 'Check content after loading html' ); 113 equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); 114 equals( testFoo, "foo", 'Check if script was evaluated after load' ); 115 setTimeout(verifyEvaluation, 600); 116 }); 117 }); 118 119 test("load(String, Function) - check file with only a script tag", function() { 120 expect(3); 121 stop(); 122 testFoo = undefined; 123 $('#first').load(url('data/test2.html'), function() { 96 124 ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM'); 97 125 ok( testFoo == "foo", 'Check if script was evaluated after load' ); 98 setTimeout(verifyEvaluation, 600); 99 }); 100 }); 101 102 test("load(String, Object, Function) - check file with only a script tag", function() { 126 start(); 127 }); 128 }); 129 130 test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() { 131 expect(2); 132 stop(); 133 $.get(url('data/dashboard.xml'), function(xml) { 134 var content = []; 135 $('tab', xml).each(function() { 136 content.push($(this).text()); 137 }); 138 equals( content[0], 'blabla', 'Check first tab'); 139 equals( content[1], 'blublu', 'Check second tab'); 140 start(); 141 }); 142 }); 143 144 test("$.getIfModified(String, Hash, Function)", function() { 145 expect(1); 146 stop(); 147 $.getIfModified(url("data/name.html"), function(msg) { 148 ok( /^ERROR/.test(msg), 'Check ifModified' ); 149 start(); 150 }); 151 }); 152 153 test("$.getScript(String, Function) - with callback", function() { 154 expect(2); 155 stop(); 156 $.getScript(url("data/test.js"), function() { 157 equals( foobar, "bar", 'Check if script was evaluated' ); 158 setTimeout(start, 100); 159 }); 160 }); 161 162 test("$.getScript(String, Function) - no callback", function() { 163 expect(1); 164 stop(true); 165 $.getScript(url("data/test.js"), start); 166 }); 167 168 test("$.ajax - xml: non-namespace elements inside namespaced elements", function() { 103 169 expect(3); 104 170 stop(); 105 testFoo = undefined; 106 $('#first').load(url('data/test2.php'), function() { 107 ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM'); 108 ok( testFoo == "foo", 'Check if script was evaluated after load' ); 109 start(); 171 $.ajax({ 172 url: url("data/with_fries.xml"), 173 dataType: "xml", 174 success: function(resp) { 175 equals( $("properties", resp).length, 1, 'properties in responseXML' ); 176 equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' ); 177 equals( $("thing", resp).length, 2, 'things in responseXML' ); 178 start(); 179 } 110 180 }); 111 181 }); 112 182 113 183 test("test global handlers - success", function() { 114 expect(8); 115 stop(); 184 expect( isLocal ? 4 : 8 ); 185 stop(); 186 116 187 var counter = { complete: 0, success: 0, error: 0, send: 0 }, 117 188 success = function() { counter.success++ }, … … 121 192 122 193 $('#foo').ajaxStart(complete).ajaxStop(complete).ajaxSend(send).ajaxComplete(complete).ajaxError(error).ajaxSuccess(success); 194 123 195 // start with successful test 124 $.ajax({url: url("data/name.php"), beforeSend: send, success: success, error: error, complete: function() { 125 ok( counter.error == 0, 'Check succesful request' ); 126 ok( counter.success == 2, 'Check succesful request' ); 127 ok( counter.complete == 3, 'Check succesful request' ); 128 ok( counter.send == 2, 'Check succesful request' ); 129 counter.error = counter.success = counter.complete = counter.send = 0; 130 $.ajaxTimeout(500); 131 $.ajax({url: url("data/name.php?wait=5"), beforeSend: send, success: success, error: error, complete: function() { 132 ok( counter.error == 2, 'Check failed request' ); 133 ok( counter.success == 0, 'Check failed request' ); 134 ok( counter.complete == 3, 'Check failed request' ); 135 ok( counter.send == 2, 'Check failed request' ); 136 start(); 137 }}); 196 $.ajax({url: url("data/name.html"), beforeSend: send, success: success, error: error, complete: function() { 197 equals( counter.error, 0, 'Check succesful request, error callback' ); 198 equals( counter.success, 2, 'Check succesful request, success callback' ); 199 equals( counter.complete, 3, 'Check succesful request, complete callback' ); 200 equals( counter.send, 2, 'Check succesful request, send callback' ); 201 202 if ( !isLocal ) { 203 counter.error = counter.success = counter.complete = counter.send = 0; 204 $.ajaxTimeout(500); 205 206 $.ajax({url: url("data/name.php?wait=5"), beforeSend: send, success: success, error: error, complete: function() { 207 equals( counter.error, 2, 'Check failed request, error callback' ); 208 equals( counter.success, 0, 'Check failed request, success callback' ); 209 equals( counter.complete, 3, 'Check failed request, failed callback' ); 210 equals( counter.send, 2, 'Check failed request, send callback' ); 211 start(); 212 }}); 213 } else 214 start(); 138 215 }}); 139 216 }); 140 217 141 218 test("test global handlers - failure", function() { 142 expect(8); 143 stop(); 219 expect( isLocal ? 4 : 8 ); 220 stop(); 221 144 222 var counter = { complete: 0, success: 0, error: 0, send: 0 }, 145 223 success = function() { counter.success++ }, … … 147 225 complete = function() { counter.complete++ }, 148 226 send = function() { counter.send++ }; 227 149 228 $.ajaxTimeout(0); 229 150 230 $('#foo').ajaxStart(complete).ajaxStop(complete).ajaxSend(send).ajaxComplete(complete).ajaxError(error).ajaxSuccess(success); 231 151 232 $.ajax({url: url("data/name.php"), global: false, beforeSend: send, success: success, error: error, complete: function() { 152 233 ok( counter.error == 0, 'Check sucesful request without globals' ); … … 154 235 ok( counter.complete == 0, 'Check sucesful request without globals' ); 155 236 ok( counter.send == 1, 'Check sucesful request without globals' ); 156 counter.error = counter.success = counter.complete = counter.send = 0; 157 $.ajaxTimeout(500); 158 $.ajax({url: url("data/name.php?wait=5"), global: false, beforeSend: send, success: success, error: error, complete: function() { 159 var x = counter; 160 ok( counter.error == 1, 'Check failed request without globals' ); 161 ok( counter.success == 0, 'Check failed request without globals' ); 162 ok( counter.complete == 0, 'Check failed request without globals' ); 163 ok( counter.send == 1, 'Check failed request without globals' ); 164 start(); 165 }}); 237 238 if ( !isLocal ) { 239 counter.error = counter.success = counter.complete = counter.send = 0; 240 $.ajaxTimeout(500); 241 242 $.ajax({url: url("data/name.php?wait=5"), global: false, beforeSend: send, success: success, error: error, complete: function() { 243 var x = counter; 244 ok( counter.error == 1, 'Check failed request without globals' ); 245 ok( counter.success == 0, 'Check failed request without globals' ); 246 ok( counter.complete == 0, 'Check failed request without globals' ); 247 ok( counter.send == 1, 'Check failed request without globals' ); 248 start(); 249 }}); 250 } else 251 start(); 166 252 }}); 167 253 }); 168 254 169 test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() { 170 expect(2); 171 stop(); 172 $.get(url('data/dashboard.xml'), function(xml) { 173 var content = []; 174 $('tab', xml).each(function() { 175 content.push($(this).text()); 176 }); 177 ok( content[0] == 'blabla', 'Check first tab'); 178 ok( content[1] == 'blublu', 'Check second tab'); 179 start(); 180 }); 181 }); 182 183 test("$.getIfModified(String, Hash, Function)", function() { 184 expect(1); 185 stop(); 186 $.getIfModified(url("data/name.php"), function(msg) { 187 ok( /^ERROR/.test(msg), 'Check ifModified' ); 188 start(); 189 }); 190 }); 191 192 test("$.getScript(String, Function) - with callback", function() { 193 expect(2); 194 stop(); 195 $.getScript(url("data/test.js"), function() { 196 ok( foobar == "bar", 'Check if script was evaluated' ); 197 setTimeout(start, 100); 198 }); 199 }); 200 201 test("$.getScript(String, Function) - no callback", function() { 202 expect(1); 203 stop(true); 204 $.getScript(url("data/test.js")); 205 }); 255 test("$.ajax - beforeSend", function() { 256 expect(1); 257 stop(); 258 259 var check = false; 260 261 $.ajaxSetup({ timeout: 0 }); 262 263 $.ajax({ 264 url: url("data/name.html"), 265 beforeSend: function(xml) { 266 check = true; 267 }, 268 success: function(data) { 269 ok( check, "check beforeSend was executed" ); 270 start(); 271 } 272 }); 273 }); 274 275 test("$.ajax - dataType html", function() { 276 expect(5); 277 stop(); 278 279 foobar = null; 280 testFoo = undefined; 281 282 var verifyEvaluation = function() { 283 ok( foobar == "bar", 'Check if script src was evaluated for datatype html' ); 284 start(); 285 }; 286 287 $.ajax({ 288 dataType: "html", 289 url: url("data/test.html"), 290 success: function(data) { 291 $("#ap").html(data); 292 ok( data.match(/^html text/), 'Check content for datatype html' ); 293 ok( testFoo == "foo", 'Check if script was evaluated for datatype html' ); 294 setTimeout(verifyEvaluation, 600); 295 } 296 }); 297 }); 298 299 if ( !isLocal ) { 206 300 207 301 test("$.getJSON(String, Hash, Function) - JSON array", function() { … … 217 311 }); 218 312 219 test("$.getJSON(String, Hash,Function) - JSON object", function() {313 test("$.getJSON(String, Function) - JSON object", function() { 220 314 expect(2); 221 315 stop(); … … 241 335 test("$.ajaxTimeout(Number) - with global timeout", function() { 242 336 stop(); 337 243 338 var passed = 0; 244 var timeout; 339 245 340 $.ajaxTimeout(1000); 341 246 342 var pass = function() { 247 343 passed++; 248 if (passed == 2) {344 if ( passed == 2 ) { 249 345 ok( true, 'Check local and global callbacks after timeout' ); 250 clearTimeout(timeout); 251 $('#main').unbind("ajaxError"); 346 $('#main').unbind("ajaxError"); 252 347 start(); 253 348 } 254 349 }; 255 var fail = function() { 256 ok( false, 'Check for timeout failed' ); 350 351 var fail = function(a,b,c) { 352 ok( false, 'Check for timeout failed ' + a + ' ' + b ); 257 353 start(); 258 354 }; 259 timeout = setTimeout(fail, 1500);355 260 356 $('#main').ajaxError(pass); 357 261 358 $.ajax({ 262 359 type: "GET", … … 265 362 success: fail 266 363 }); 364 267 365 // reset timeout 268 366 $.ajaxTimeout(0); … … 314 412 }); 315 413 }); 316 317 test("$.ajax - dataType html", function() {318 expect(5);319 stop();320 &n
