jbarnette-johnson 1.0.0.200806240111

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/CHANGELOG +5 -0
  2. data/MANIFEST +385 -0
  3. data/MINGW32.mk +124 -0
  4. data/README.rdoc +51 -0
  5. data/Rakefile +166 -0
  6. data/bin/johnson +107 -0
  7. data/cross-compile.txt +38 -0
  8. data/ext/spidermonkey/context.c +122 -0
  9. data/ext/spidermonkey/context.h +19 -0
  10. data/ext/spidermonkey/conversions.c +286 -0
  11. data/ext/spidermonkey/conversions.h +18 -0
  12. data/ext/spidermonkey/debugger.c +208 -0
  13. data/ext/spidermonkey/debugger.h +9 -0
  14. data/ext/spidermonkey/extconf.rb +25 -0
  15. data/ext/spidermonkey/extensions.c +37 -0
  16. data/ext/spidermonkey/extensions.h +12 -0
  17. data/ext/spidermonkey/global.c +40 -0
  18. data/ext/spidermonkey/global.h +11 -0
  19. data/ext/spidermonkey/idhash.c +16 -0
  20. data/ext/spidermonkey/idhash.h +8 -0
  21. data/ext/spidermonkey/immutable_node.c.erb +522 -0
  22. data/ext/spidermonkey/immutable_node.h +22 -0
  23. data/ext/spidermonkey/jroot.h +187 -0
  24. data/ext/spidermonkey/js_land_proxy.c +609 -0
  25. data/ext/spidermonkey/js_land_proxy.h +20 -0
  26. data/ext/spidermonkey/ruby_land_proxy.c +537 -0
  27. data/ext/spidermonkey/ruby_land_proxy.h +17 -0
  28. data/ext/spidermonkey/runtime.c +304 -0
  29. data/ext/spidermonkey/runtime.h +25 -0
  30. data/ext/spidermonkey/spidermonkey.c +20 -0
  31. data/ext/spidermonkey/spidermonkey.h +29 -0
  32. data/js/johnson/browser.js +9 -0
  33. data/js/johnson/browser/env.js +687 -0
  34. data/js/johnson/browser/jquery.js +3444 -0
  35. data/js/johnson/browser/xmlsax.js +1564 -0
  36. data/js/johnson/browser/xmlw3cdom.js +4189 -0
  37. data/js/johnson/cli.js +30 -0
  38. data/js/johnson/prelude.js +80 -0
  39. data/js/johnson/template.js +29 -0
  40. data/lib/hoe.rb +748 -0
  41. data/lib/johnson.rb +46 -0
  42. data/lib/johnson/cli.rb +7 -0
  43. data/lib/johnson/cli/options.rb +56 -0
  44. data/lib/johnson/error.rb +4 -0
  45. data/lib/johnson/nodes.rb +7 -0
  46. data/lib/johnson/nodes/binary_node.rb +64 -0
  47. data/lib/johnson/nodes/for.rb +14 -0
  48. data/lib/johnson/nodes/for_in.rb +12 -0
  49. data/lib/johnson/nodes/function.rb +13 -0
  50. data/lib/johnson/nodes/list.rb +27 -0
  51. data/lib/johnson/nodes/node.rb +68 -0
  52. data/lib/johnson/nodes/ternary_node.rb +20 -0
  53. data/lib/johnson/parser.rb +21 -0
  54. data/lib/johnson/parser/syntax_error.rb +13 -0
  55. data/lib/johnson/runtime.rb +55 -0
  56. data/lib/johnson/spidermonkey/context.rb +10 -0
  57. data/lib/johnson/spidermonkey/debugger.rb +67 -0
  58. data/lib/johnson/spidermonkey/immutable_node.rb +280 -0
  59. data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
  60. data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +233 -0
  61. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +52 -0
  62. data/lib/johnson/spidermonkey/runtime.rb +94 -0
  63. data/lib/johnson/version.rb +4 -0
  64. data/lib/johnson/visitable.rb +16 -0
  65. data/lib/johnson/visitors.rb +4 -0
  66. data/lib/johnson/visitors/dot_visitor.rb +167 -0
  67. data/lib/johnson/visitors/ecma_visitor.rb +315 -0
  68. data/lib/johnson/visitors/enumerating_visitor.rb +115 -0
  69. data/lib/johnson/visitors/sexp_visitor.rb +172 -0
  70. data/lib/rails/init.rb +37 -0
  71. data/test/assets/index.html +38 -0
  72. data/test/assets/jquery_test.html +186 -0
  73. data/test/helper.rb +58 -0
  74. data/test/johnson/browser_test.rb +38 -0
  75. data/test/johnson/conversions/array_test.rb +32 -0
  76. data/test/johnson/conversions/boolean_test.rb +17 -0
  77. data/test/johnson/conversions/callable_test.rb +34 -0
  78. data/test/johnson/conversions/file_test.rb +15 -0
  79. data/test/johnson/conversions/nil_test.rb +20 -0
  80. data/test/johnson/conversions/number_test.rb +34 -0
  81. data/test/johnson/conversions/regexp_test.rb +24 -0
  82. data/test/johnson/conversions/string_test.rb +26 -0
  83. data/test/johnson/conversions/struct_test.rb +15 -0
  84. data/test/johnson/conversions/symbol_test.rb +19 -0
  85. data/test/johnson/conversions/thread_test.rb +24 -0
  86. data/test/johnson/error_test.rb +9 -0
  87. data/test/johnson/extensions_test.rb +56 -0
  88. data/test/johnson/nodes/array_literal_test.rb +57 -0
  89. data/test/johnson/nodes/array_node_test.rb +26 -0
  90. data/test/johnson/nodes/binary_node_test.rb +61 -0
  91. data/test/johnson/nodes/bracket_access_test.rb +16 -0
  92. data/test/johnson/nodes/delete_test.rb +11 -0
  93. data/test/johnson/nodes/do_while_test.rb +12 -0
  94. data/test/johnson/nodes/dot_accessor_test.rb +15 -0
  95. data/test/johnson/nodes/export_test.rb +9 -0
  96. data/test/johnson/nodes/for_test.rb +54 -0
  97. data/test/johnson/nodes/function_test.rb +71 -0
  98. data/test/johnson/nodes/if_test.rb +41 -0
  99. data/test/johnson/nodes/import_test.rb +13 -0
  100. data/test/johnson/nodes/label_test.rb +19 -0
  101. data/test/johnson/nodes/object_literal_test.rb +110 -0
  102. data/test/johnson/nodes/return_test.rb +16 -0
  103. data/test/johnson/nodes/semi_test.rb +8 -0
  104. data/test/johnson/nodes/switch_test.rb +55 -0
  105. data/test/johnson/nodes/ternary_test.rb +25 -0
  106. data/test/johnson/nodes/throw_test.rb +9 -0
  107. data/test/johnson/nodes/try_node_test.rb +59 -0
  108. data/test/johnson/nodes/typeof_test.rb +11 -0
  109. data/test/johnson/nodes/unary_node_test.rb +23 -0
  110. data/test/johnson/nodes/void_test.rb +11 -0
  111. data/test/johnson/nodes/while_test.rb +26 -0
  112. data/test/johnson/nodes/with_test.rb +10 -0
  113. data/test/johnson/prelude_test.rb +56 -0
  114. data/test/johnson/runtime_test.rb +46 -0
  115. data/test/johnson/spidermonkey/context_test.rb +21 -0
  116. data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
  117. data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
  118. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +225 -0
  119. data/test/johnson/spidermonkey/runtime_test.rb +17 -0
  120. data/test/johnson/version_test.rb +13 -0
  121. data/test/johnson/visitors/dot_visitor_test.rb +39 -0
  122. data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
  123. data/test/johnson_test.rb +16 -0
  124. data/test/jquery_units/test.js +27 -0
  125. data/test/jquery_units/test_helper.js +197 -0
  126. data/test/jquery_units/units/ajax.js +795 -0
  127. data/test/jquery_units/units/core.js +1563 -0
  128. data/test/jquery_units/units/event.js +299 -0
  129. data/test/jquery_units/units/fx.js +427 -0
  130. data/test/jquery_units/units/offset.js +112 -0
  131. data/test/jquery_units/units/selector.js +224 -0
  132. data/test/jspec/helper.js +7 -0
  133. data/test/jspec/jspec.js +192 -0
  134. data/test/jspec/simple_spec.js +68 -0
  135. data/test/parser_test.rb +276 -0
  136. data/todo/.keep +0 -0
  137. metadata +501 -0
@@ -0,0 +1,795 @@
1
+ module("ajax");
2
+
3
+ // Safari 3 randomly crashes when running these tests,
4
+ // but only in the full suite - you can run just the Ajax
5
+ // tests and they'll pass
6
+ //if ( !jQuery.browser.safari ) {
7
+
8
+ if ( !isLocal ) {
9
+
10
+ test("$.ajax() - success callbacks", function() {
11
+ expect( 8 );
12
+
13
+ $.ajaxSetup({ timeout: 0 });
14
+
15
+ stop();
16
+
17
+ setTimeout(function(){
18
+ $('#foo').ajaxStart(function(){
19
+ ok( true, "ajaxStart" );
20
+ }).ajaxStop(function(){
21
+ ok( true, "ajaxStop" );
22
+ start();
23
+ }).ajaxSend(function(){
24
+ ok( true, "ajaxSend" );
25
+ }).ajaxComplete(function(){
26
+ ok( true, "ajaxComplete" );
27
+ }).ajaxError(function(){
28
+ ok( false, "ajaxError" );
29
+ }).ajaxSuccess(function(){
30
+ ok( true, "ajaxSuccess" );
31
+ });
32
+
33
+ $.ajax({
34
+ url: url("data/name.html"),
35
+ beforeSend: function(){ ok(true, "beforeSend"); },
36
+ success: function(){ ok(true, "success"); },
37
+ error: function(){ ok(false, "error"); },
38
+ complete: function(){ ok(true, "complete"); }
39
+ });
40
+ }, 13);
41
+ });
42
+
43
+ test("$.ajax() - error callbacks", function() {
44
+ expect( 8 );
45
+ stop();
46
+
47
+ $('#foo').ajaxStart(function(){
48
+ ok( true, "ajaxStart" );
49
+ }).ajaxStop(function(){
50
+ ok( true, "ajaxStop" );
51
+ start();
52
+ }).ajaxSend(function(){
53
+ ok( true, "ajaxSend" );
54
+ }).ajaxComplete(function(){
55
+ ok( true, "ajaxComplete" );
56
+ }).ajaxError(function(){
57
+ ok( true, "ajaxError" );
58
+ }).ajaxSuccess(function(){
59
+ ok( false, "ajaxSuccess" );
60
+ });
61
+
62
+ $.ajaxSetup({ timeout: 500 });
63
+
64
+ $.ajax({
65
+ url: url("data/name.php?wait=5"),
66
+ beforeSend: function(){ ok(true, "beforeSend"); },
67
+ success: function(){ ok(false, "success"); },
68
+ error: function(){ ok(true, "error"); },
69
+ complete: function(){ ok(true, "complete"); }
70
+ });
71
+ });
72
+
73
+ test("$.ajax() - disabled globals", function() {
74
+ expect( 3 );
75
+ stop();
76
+
77
+ $('#foo').ajaxStart(function(){
78
+ ok( false, "ajaxStart" );
79
+ }).ajaxStop(function(){
80
+ ok( false, "ajaxStop" );
81
+ }).ajaxSend(function(){
82
+ ok( false, "ajaxSend" );
83
+ }).ajaxComplete(function(){
84
+ ok( false, "ajaxComplete" );
85
+ }).ajaxError(function(){
86
+ ok( false, "ajaxError" );
87
+ }).ajaxSuccess(function(){
88
+ ok( false, "ajaxSuccess" );
89
+ });
90
+
91
+ $.ajax({
92
+ global: false,
93
+ url: url("data/name.html"),
94
+ beforeSend: function(){ ok(true, "beforeSend"); },
95
+ success: function(){ ok(true, "success"); },
96
+ error: function(){ ok(false, "error"); },
97
+ complete: function(){
98
+ ok(true, "complete");
99
+ setTimeout(function(){ start(); }, 13);
100
+ }
101
+ });
102
+ });
103
+
104
+ test("$.ajax - xml: non-namespace elements inside namespaced elements", function() {
105
+ expect(3);
106
+ stop();
107
+ $.ajax({
108
+ url: url("data/with_fries.xml"),
109
+ dataType: "xml",
110
+ success: function(resp) {
111
+ equals( $("properties", resp).length, 1, 'properties in responseXML' );
112
+ equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' );
113
+ equals( $("thing", resp).length, 2, 'things in responseXML' );
114
+ start();
115
+ }
116
+ });
117
+ });
118
+
119
+ test("$.ajax - beforeSend", function() {
120
+ expect(1);
121
+ stop();
122
+
123
+ var check = false;
124
+
125
+ $.ajaxSetup({ timeout: 0 });
126
+
127
+ $.ajax({
128
+ url: url("data/name.html"),
129
+ beforeSend: function(xml) {
130
+ check = true;
131
+ },
132
+ success: function(data) {
133
+ ok( check, "check beforeSend was executed" );
134
+ start();
135
+ }
136
+ });
137
+ });
138
+
139
+ var foobar;
140
+
141
+ test("$.ajax - dataType html", function() {
142
+ expect(5);
143
+ stop();
144
+
145
+ foobar = null;
146
+ testFoo = undefined;
147
+
148
+ var verifyEvaluation = function() {
149
+ ok( testFoo == "foo", 'Check if script was evaluated for datatype html' );
150
+ ok( foobar == "bar", 'Check if script src was evaluated for datatype html' );
151
+ start();
152
+ };
153
+
154
+ $.ajax({
155
+ dataType: "html",
156
+ url: url("data/test.html"),
157
+ success: function(data) {
158
+ $("#ap").html(data);
159
+ ok( data.match(/^html text/), 'Check content for datatype html' );
160
+ setTimeout(verifyEvaluation, 600);
161
+ }
162
+ });
163
+ });
164
+
165
+ test("serialize()", function() {
166
+ expect(6);
167
+
168
+ equals( $('#form').serialize(),
169
+ "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
170
+ 'Check form serialization as query string');
171
+
172
+ equals( $('#form :input').serialize(),
173
+ "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
174
+ 'Check input serialization as query string');
175
+
176
+ equals( $('#testForm').serialize(),
177
+ 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
178
+ 'Check form serialization as query string');
179
+
180
+ equals( $('#testForm :input').serialize(),
181
+ 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
182
+ 'Check input serialization as query string');
183
+
184
+ equals( $('#form, #testForm').serialize(),
185
+ "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
186
+ 'Multiple form serialization as query string');
187
+
188
+ equals( $('#form, #testForm :input').serialize(),
189
+ "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
190
+ 'Mixed form/input serialization as query string');
191
+ });
192
+
193
+ test("$.param()", function() {
194
+ expect(4);
195
+ var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
196
+ equals( $.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
197
+
198
+ params = {someName: [1, 2, 3], regularThing: "blah" };
199
+ equals( $.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
200
+
201
+ params = {"foo[]":["baz", 42, "All your base are belong to us"]};
202
+ equals( $.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
203
+
204
+ params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
205
+ equals( $.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
206
+ });
207
+
208
+ test("synchronous request", function() {
209
+ expect(1);
210
+ ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
211
+ });
212
+
213
+ test("synchronous request with callbacks", function() {
214
+ expect(2);
215
+ var result;
216
+ $.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
217
+ ok( /^{ "data"/.test( result ), "check returned text" );
218
+ });
219
+
220
+ test("pass-through request object", function() {
221
+ expect(8);
222
+ stop(true);
223
+
224
+ var target = "data/name.html";
225
+ var successCount = 0;
226
+ var errorCount = 0;
227
+ var errorEx = "";
228
+ var success = function() {
229
+ successCount++;
230
+ };
231
+ $("#foo").ajaxError(function (e, xml, s, ex) {
232
+ errorCount++;
233
+ errorEx += ": " + xml.status;
234
+ });
235
+ $("#foo").one('ajaxStop', function () {
236
+ equals(successCount, 5, "Check all ajax calls successful");
237
+ equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
238
+ $("#foo").unbind('ajaxError');
239
+ start();
240
+ });
241
+
242
+ ok( $.get(url(target), success), "get" );
243
+ ok( $.post(url(target), success), "post" );
244
+ ok( $.getScript(url("data/test.js"), success), "script" );
245
+ ok( $.getJSON(url("data/json_obj.js"), success), "json" );
246
+ ok( $.ajax({url: url(target), success: success}), "generic" );
247
+ });
248
+
249
+ test("ajax cache", function () {
250
+ expect(18);
251
+ stop();
252
+
253
+ var count = 0;
254
+
255
+ $("#firstp").bind("ajaxSuccess", function (e, xml, s) {
256
+ var re = /_=(.*?)(&|$)/g;
257
+ var oldOne = null;
258
+ for (var i = 0; i < 6; i++) {
259
+ var ret = re.exec(s.url);
260
+ if (!ret) {
261
+ break;
262
+ }
263
+ oldOne = ret[1];
264
+ }
265
+ equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
266
+ ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
267
+ if(++count == 6)
268
+ start();
269
+ });
270
+
271
+ ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
272
+ ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
273
+ ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
274
+ ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
275
+ ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
276
+ ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
277
+ });
278
+
279
+ test("global ajaxSettings", function() {
280
+ expect(3);
281
+
282
+ var tmp = jQuery.extend({}, jQuery.ajaxSettings);
283
+ var orig = { url: "data/with_fries.xml", data: null };
284
+ var t;
285
+
286
+ $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
287
+
288
+ t = jQuery.extend({}, orig);
289
+ $.ajax(t);
290
+ ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending null" );
291
+
292
+ t = jQuery.extend({}, orig);
293
+ t.data = {};
294
+ $.ajax(t);
295
+ ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
296
+
297
+ t = jQuery.extend({}, orig);
298
+ t.data = { zoo: 'a', ping: 'b' };
299
+ $.ajax(t);
300
+ 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' }" );
301
+
302
+ jQuery.ajaxSettings = tmp;
303
+ });
304
+
305
+ test("load(String)", function() {
306
+ expect(1);
307
+ stop(true); // check if load can be called with only url
308
+ $('#first').load("data/name.html", start);
309
+ });
310
+
311
+ test("load('url selector')", function() {
312
+ expect(1);
313
+ stop(true); // check if load can be called with only url
314
+ $('#first').load("data/test3.html div.user", function(){
315
+ equals( $(this).children("div").length, 2, "Verify that specific elements were injected" );
316
+ start();
317
+ });
318
+ });
319
+
320
+ test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
321
+ expect(1);
322
+ stop();
323
+ $.ajaxSetup({ dataType: "json" });
324
+ $("#first").ajaxComplete(function (e, xml, s) {
325
+ equals( s.dataType, "html", "Verify the load() dataType was html" );
326
+ $("#first").unbind("ajaxComplete");
327
+ $.ajaxSetup({ dataType: "" });
328
+ start();
329
+ });
330
+ $('#first').load("data/test3.html");
331
+ });
332
+
333
+ test("load(String, Function) - simple: inject text into DOM", function() {
334
+ expect(2);
335
+ stop();
336
+ $('#first').load(url("data/name.html"), function() {
337
+ ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' );
338
+ start();
339
+ });
340
+ });
341
+
342
+ test("load(String, Function) - check scripts", function() {
343
+ expect(7);
344
+ stop();
345
+ window.testFoo = undefined;
346
+ window.foobar = null;
347
+ var verifyEvaluation = function() {
348
+ equals( foobar, "bar", 'Check if script src was evaluated after load' );
349
+ equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
350
+ start();
351
+ };
352
+ $('#first').load(url('data/test.html'), function() {
353
+ ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
354
+ equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
355
+ equals( testFoo, "foo", 'Check if script was evaluated after load' );
356
+ setTimeout(verifyEvaluation, 600);
357
+ });
358
+ });
359
+
360
+ test("load(String, Function) - check file with only a script tag", function() {
361
+ expect(3);
362
+ stop();
363
+ testFoo = undefined;
364
+ $('#first').load(url('data/test2.html'), function() {
365
+ ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM');
366
+ ok( testFoo == "foo", 'Check if script was evaluated after load' );
367
+ start();
368
+ });
369
+ });
370
+
371
+ test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
372
+ expect(2);
373
+ stop();
374
+ $.get(url('data/dashboard.xml'), function(xml) {
375
+ var content = [];
376
+ $('tab', xml).each(function() {
377
+ content.push($(this).text());
378
+ });
379
+ equals( content[0], 'blabla', 'Check first tab');
380
+ equals( content[1], 'blublu', 'Check second tab');
381
+ start();
382
+ });
383
+ });
384
+
385
+ test("$.getScript(String, Function) - with callback", function() {
386
+ expect(2);
387
+ stop();
388
+ window.foobar = null;
389
+ $.getScript(url("data/test.js"), function() {
390
+ equals( foobar, "bar", 'Check if script was evaluated' );
391
+ setTimeout(start, 100);
392
+ });
393
+ });
394
+
395
+ test("$.getScript(String, Function) - no callback", function() {
396
+ expect(1);
397
+ stop(true);
398
+ $.getScript(url("data/test.js"), start);
399
+ });
400
+
401
+ test("$.ajax() - JSONP, Local", function() {
402
+ expect(7);
403
+
404
+ var count = 0;
405
+ function plus(){ if ( ++count == 7 ) start(); }
406
+
407
+ stop();
408
+
409
+ $.ajax({
410
+ url: "data/jsonp.php",
411
+ dataType: "jsonp",
412
+ success: function(data){
413
+ ok( data.data, "JSON results returned (GET, no callback)" );
414
+ plus();
415
+ },
416
+ error: function(data){
417
+ ok( false, "Ajax error JSON (GET, no callback)" );
418
+ plus();
419
+ }
420
+ });
421
+
422
+ $.ajax({
423
+ url: "data/jsonp.php?callback=?",
424
+ dataType: "jsonp",
425
+ success: function(data){
426
+ ok( data.data, "JSON results returned (GET, url callback)" );
427
+ plus();
428
+ },
429
+ error: function(data){
430
+ ok( false, "Ajax error JSON (GET, url callback)" );
431
+ plus();
432
+ }
433
+ });
434
+
435
+ $.ajax({
436
+ url: "data/jsonp.php",
437
+ dataType: "jsonp",
438
+ data: "callback=?",
439
+ success: function(data){
440
+ ok( data.data, "JSON results returned (GET, data callback)" );
441
+ plus();
442
+ },
443
+ error: function(data){
444
+ ok( false, "Ajax error JSON (GET, data callback)" );
445
+ plus();
446
+ }
447
+ });
448
+
449
+ $.ajax({
450
+ url: "data/jsonp.php",
451
+ dataType: "jsonp",
452
+ jsonp: "callback",
453
+ success: function(data){
454
+ ok( data.data, "JSON results returned (GET, data obj callback)" );
455
+ plus();
456
+ },
457
+ error: function(data){
458
+ ok( false, "Ajax error JSON (GET, data obj callback)" );
459
+ plus();
460
+ }
461
+ });
462
+
463
+ $.ajax({
464
+ type: "POST",
465
+ url: "data/jsonp.php",
466
+ dataType: "jsonp",
467
+ success: function(data){
468
+ ok( data.data, "JSON results returned (POST, no callback)" );
469
+ plus();
470
+ },
471
+ error: function(data){
472
+ ok( false, "Ajax error JSON (GET, data obj callback)" );
473
+ plus();
474
+ }
475
+ });
476
+
477
+ $.ajax({
478
+ type: "POST",
479
+ url: "data/jsonp.php",
480
+ data: "callback=?",
481
+ dataType: "jsonp",
482
+ success: function(data){
483
+ ok( data.data, "JSON results returned (POST, data callback)" );
484
+ plus();
485
+ },
486
+ error: function(data){
487
+ ok( false, "Ajax error JSON (POST, data callback)" );
488
+ plus();
489
+ }
490
+ });
491
+
492
+ $.ajax({
493
+ type: "POST",
494
+ url: "data/jsonp.php",
495
+ jsonp: "callback",
496
+ dataType: "jsonp",
497
+ success: function(data){
498
+ ok( data.data, "JSON results returned (POST, data obj callback)" );
499
+ plus();
500
+ },
501
+ error: function(data){
502
+ ok( false, "Ajax error JSON (POST, data obj callback)" );
503
+ plus();
504
+ }
505
+ });
506
+ });
507
+
508
+ test("$.ajax() - JSONP, Remote", function() {
509
+ expect(4);
510
+
511
+ var count = 0;
512
+ function plus(){ if ( ++count == 4 ) start(); }
513
+
514
+ var base = window.location.href.replace(/\?.*$/, "");
515
+
516
+ stop();
517
+
518
+ $.ajax({
519
+ url: base + "data/jsonp.php",
520
+ dataType: "jsonp",
521
+ success: function(data){
522
+ ok( data.data, "JSON results returned (GET, no callback)" );
523
+ plus();
524
+ },
525
+ error: function(data){
526
+ ok( false, "Ajax error JSON (GET, no callback)" );
527
+ plus();
528
+ }
529
+ });
530
+
531
+ $.ajax({
532
+ url: base + "data/jsonp.php?callback=?",
533
+ dataType: "jsonp",
534
+ success: function(data){
535
+ ok( data.data, "JSON results returned (GET, url callback)" );
536
+ plus();
537
+ },
538
+ error: function(data){
539
+ ok( false, "Ajax error JSON (GET, url callback)" );
540
+ plus();
541
+ }
542
+ });
543
+
544
+ $.ajax({
545
+ url: base + "data/jsonp.php",
546
+ dataType: "jsonp",
547
+ data: "callback=?",
548
+ success: function(data){
549
+ ok( data.data, "JSON results returned (GET, data callback)" );
550
+ plus();
551
+ },
552
+ error: function(data){
553
+ ok( false, "Ajax error JSON (GET, data callback)" );
554
+ plus();
555
+ }
556
+ });
557
+
558
+ $.ajax({
559
+ url: base + "data/jsonp.php",
560
+ dataType: "jsonp",
561
+ jsonp: "callback",
562
+ success: function(data){
563
+ ok( data.data, "JSON results returned (GET, data obj callback)" );
564
+ plus();
565
+ },
566
+ error: function(data){
567
+ ok( false, "Ajax error JSON (GET, data obj callback)" );
568
+ plus();
569
+ }
570
+ });
571
+ });
572
+
573
+ test("$.ajax() - script, Remote", function() {
574
+ expect(2);
575
+
576
+ var base = window.location.href.replace(/\?.*$/, "");
577
+
578
+ stop();
579
+
580
+ window.foobar = null;
581
+ $.ajax({
582
+ url: base + "data/test.js",
583
+ dataType: "script",
584
+ success: function(data){
585
+ ok( foobar, "Script results returned (GET, no callback)" );
586
+ start();
587
+ }
588
+ });
589
+ });
590
+
591
+ test("$.ajax() - script, Remote with POST", function() {
592
+ expect(3);
593
+
594
+ var base = window.location.href.replace(/\?.*$/, "");
595
+
596
+ stop();
597
+
598
+ window.foobar = null;
599
+ $.ajax({
600
+ url: base + "data/test.js",
601
+ type: "POST",
602
+ dataType: "script",
603
+ success: function(data, status){
604
+ ok( foobar, "Script results returned (GET, no callback)" );
605
+ equals( status, "success", "Script results returned (GET, no callback)" );
606
+ start();
607
+ }
608
+ });
609
+ });
610
+
611
+ test("$.ajax() - script, Remote with scheme-less URL", function() {
612
+ expect(2);
613
+
614
+ var base = window.location.href.replace(/\?.*$/, "");
615
+ base = base.replace(/^.*?\/\//, "//");
616
+
617
+ stop();
618
+
619
+ window.foobar = null;
620
+ $.ajax({
621
+ url: base + "data/test.js",
622
+ dataType: "script",
623
+ success: function(data){
624
+ ok( foobar, "Script results returned (GET, no callback)" );
625
+ start();
626
+ }
627
+ });
628
+ });
629
+
630
+ test("$.getJSON(String, Hash, Function) - JSON array", function() {
631
+ expect(4);
632
+ stop();
633
+ $.getJSON(url("data/json.php"), {json: "array"}, function(json) {
634
+ ok( json[0].name == 'John', 'Check JSON: first, name' );
635
+ ok( json[0].age == 21, 'Check JSON: first, age' );
636
+ ok( json[1].name == 'Peter', 'Check JSON: second, name' );
637
+ ok( json[1].age == 25, 'Check JSON: second, age' );
638
+ start();
639
+ });
640
+ });
641
+
642
+ test("$.getJSON(String, Function) - JSON object", function() {
643
+ expect(2);
644
+ stop();
645
+ $.getJSON(url("data/json.php"), function(json) {
646
+ ok( json.data.lang == 'en', 'Check JSON: lang' );
647
+ ok( json.data.length == 25, 'Check JSON: length' );
648
+ start();
649
+ });
650
+ });
651
+
652
+ test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() {
653
+ expect(2);
654
+
655
+ var base = window.location.href.replace(/\?.*$/, "");
656
+
657
+ stop();
658
+ $.getJSON(url(base + "data/json.php"), function(json) {
659
+ ok( json.data.lang == 'en', 'Check JSON: lang' );
660
+ ok( json.data.length == 25, 'Check JSON: length' );
661
+ start();
662
+ });
663
+ });
664
+
665
+ test("$.post(String, Hash, Function) - simple with xml", function() {
666
+ expect(4);
667
+ stop();
668
+ $.post(url("data/name.php"), {xml: "5-2"}, function(xml){
669
+ $('math', xml).each(function() {
670
+ ok( $('calculation', this).text() == '5-2', 'Check for XML' );
671
+ ok( $('result', this).text() == '3', 'Check for XML' );
672
+ });
673
+ });
674
+
675
+ $.post(url("data/name.php?xml=5-2"), {}, function(xml){
676
+ $('math', xml).each(function() {
677
+ ok( $('calculation', this).text() == '5-2', 'Check for XML' );
678
+ ok( $('result', this).text() == '3', 'Check for XML' );
679
+ });
680
+ start();
681
+ });
682
+ });
683
+
684
+ test("$.ajaxSetup({timeout: Number}) - with global timeout", function() {
685
+ stop();
686
+
687
+ var passed = 0;
688
+
689
+ $.ajaxSetup({timeout: 1000});
690
+
691
+ var pass = function() {
692
+ passed++;
693
+ if ( passed == 2 ) {
694
+ ok( true, 'Check local and global callbacks after timeout' );
695
+ $('#main').unbind("ajaxError");
696
+ start();
697
+ }
698
+ };
699
+
700
+ var fail = function(a,b,c) {
701
+ ok( false, 'Check for timeout failed ' + a + ' ' + b );
702
+ start();
703
+ };
704
+
705
+ $('#main').ajaxError(pass);
706
+
707
+ $.ajax({
708
+ type: "GET",
709
+ url: url("data/name.php?wait=5"),
710
+ error: pass,
711
+ success: fail
712
+ });
713
+
714
+ // reset timeout
715
+ $.ajaxSetup({timeout: 0});
716
+ });
717
+
718
+ test("$.ajaxSetup({timeout: Number}) with localtimeout", function() {
719
+ stop();
720
+ $.ajaxSetup({timeout: 50});
721
+
722
+ $.ajax({
723
+ type: "GET",
724
+ timeout: 5000,
725
+ url: url("data/name.php?wait=1"),
726
+ error: function() {
727
+ ok( false, 'Check for local timeout failed' );
728
+ start();
729
+ },
730
+ success: function() {
731
+ ok( true, 'Check for local timeout' );
732
+ start();
733
+ }
734
+ });
735
+
736
+ // reset timeout
737
+ $.ajaxSetup({timeout: 0});
738
+ });
739
+
740
+ test("$.ajax - simple get", function() {
741
+ expect(1);
742
+ stop();
743
+ $.ajax({
744
+ type: "GET",
745
+ url: url("data/name.php?name=foo"),
746
+ success: function(msg){
747
+ ok( msg == 'bar', 'Check for GET' );
748
+ start();
749
+ }
750
+ });
751
+ });
752
+
753
+ test("$.ajax - simple post", function() {
754
+ expect(1);
755
+ stop();
756
+ $.ajax({
757
+ type: "POST",
758
+ url: url("data/name.php"),
759
+ data: "name=peter",
760
+ success: function(msg){
761
+ ok( msg == 'pan', 'Check for POST' );
762
+ start();
763
+ }
764
+ });
765
+ });
766
+
767
+ test("ajaxSetup()", function() {
768
+ expect(1);
769
+ stop();
770
+ $.ajaxSetup({
771
+ url: url("data/name.php?name=foo"),
772
+ success: function(msg){
773
+ ok( msg == 'bar', 'Check for GET' );
774
+ start();
775
+ }
776
+ });
777
+ $.ajax();
778
+ });
779
+
780
+ test("custom timeout does not set error message when timeout occurs, see #970", function() {
781
+ stop();
782
+ $.ajax({
783
+ url: "data/name.php?wait=10",
784
+ timeout: 500,
785
+ error: function(request, status) {
786
+ ok( status != null, "status shouldn't be null in error handler" );
787
+ equals( "timeout", status );
788
+ start();
789
+ }
790
+ });
791
+ });
792
+
793
+ }
794
+
795
+ //}