1
YUI.add('get-tests', function(Y) {
3
Y.GetTests = new Y.Test.Suite("Get Suite");
4
Y.GetTests.TEST_FILES_BASE = "getfiles/";
6
var FILENAME = /[abc]\.js/;
8
// TODO: Should get.js stick this somewhere public?
9
Y.GetTests.ONLOAD_SUPPORTED = {
11
css: !(Y.UA.webkit || Y.UA.gecko)
14
function areObjectsReallyEqual(o1, o2, msg) {
15
Y.ObjectAssert.areEqual(o1, o2, msg);
16
Y.ObjectAssert.areEqual(o2, o1, msg);
19
function randUrl(url) {
20
return url + ((url.indexOf("?") !== -1) ? "&" : "?") + "dt=" + new Date().getTime();
23
function path(urls, guid) {
24
var base = Y.GetTests.TEST_FILES_BASE;
26
if (typeof urls === "string") {
27
urls = base + randUrl(urls);
29
for (var i = 0; i < urls.length; i++) {
30
urls[i] = base + randUrl(urls[i]);
36
Y.GetTests.Scripts = new Y.Test.Case({
44
createInsertBeforeNode: function() {
45
this.ib = Y.Node.create('<div id="insertBeforeMe"></div>');
46
Y.Node.one("body").appendChild(this.ib);
49
removeInsertBeforeNode: function() {
55
tearDown: function() {
59
this.removeInsertBeforeNode();
62
'test: single script, success': function() {
71
var trans = Y.Get.script(path("a.js"), {
73
data: {a:1, b:2, c:3},
76
onProgress: function(o) {
77
var file = o.url.match(FILENAME);
78
progress.push(file[0]);
81
onSuccess: function(o) {
85
test.resume(function() {
89
Y.Assert.areEqual("a.js", G_SCRIPTS[0], "a.js does not seem to be loaded");
90
Y.ArrayAssert.itemsAreEqual(G_SCRIPTS, progress, "Progress does not match G_SCRIPTS");
92
Y.Assert.areEqual(1, G_SCRIPTS.length, "More/Less than 1 script was loaded");
93
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
95
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
96
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
97
Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
98
Y.Assert.isUndefined(o.statusText, "Payload should not have a statusText");
99
Y.Assert.isUndefined(o.msg, "Payload should not have a msg");
101
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
107
onFailure: function(o) {
108
test.resume(function() {
109
Y.Assert.fail("onFailure shouldn't have been called");
118
'test: single script, failure': function() {
127
// TODO: abort() is the only thing which causes onFailure to be hit. 404s don't. Fix when we can fail on 404s
128
// Not sure how robust it is to do this inline (that is, could onSuccess fire before abort is hit).
130
var trans = Y.Get.script(path("a.js"), {
132
data: {a:1, b:2, c:3},
133
context: {bar:"foo"},
135
onSuccess: function(o) {
136
test.resume(function() {
137
Y.Assert.fail("onSuccess shouldn't have been called");
142
onFailure: function(o) {
146
test.resume(function() {
150
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
152
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
153
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
154
Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
155
Y.Assert.isUndefined(o.statusText, "Payload should not have a statusText");
156
Y.Assert.isString(o.msg, "Payload should have a msg");
158
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
165
Y.Get.abort(trans.tId);
170
'test: single script success, end': function() {
179
var trans = Y.Get.script(path("a.js"), {
181
data: {a:1, b:2, c:3},
182
context: {bar:"foo"},
184
onSuccess: function() {
186
Y.Assert.areEqual("a.js", G_SCRIPTS[0], "a.js does not seem to be loaded");
187
Y.Assert.areEqual(1, G_SCRIPTS.length, "More/Less than 1 script was loaded");
188
Y.Assert.areEqual(1, counts.success, "onSuccess called more than once");
191
onFailure: function() {
192
Y.Assert.fail("onFailure shouldn't have been called");
195
onEnd : function(o) {
199
test.resume(function() {
201
Y.Assert.areEqual(1, counts.end,"onEnd called more than once");
202
Y.Assert.areEqual(1, counts.success, "onEnd called before onSuccess");
203
Y.Assert.areEqual("OK", o.statusText, "Expected OK result");
205
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
206
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
207
Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
208
Y.Assert.areEqual("OK", o.statusText, "Payload should have an OK statusText");
209
Y.Assert.isUndefined(o.msg, "Payload should have an undefined msg");
211
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
221
'test: single script failure, end': function() {
230
var trans = Y.Get.script(path("a.js"), {
232
data: {a:1, b:2, c:3},
233
context: {bar:"foo"},
235
onFailure: function() {
237
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
240
onSuccess: function() {
241
Y.Assert.fail("onSuccess shouldn't have been called");
244
onEnd : function(o) {
248
test.resume(function() {
250
Y.Assert.areEqual(1, counts.end,"onEnd called more than once");
251
Y.Assert.areEqual(1, counts.failure, "onEnd called before onFailure");
252
Y.Assert.areEqual("failure", o.statusText, "Expected failure result");
254
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
255
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
256
Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
257
Y.Assert.areEqual("failure", o.statusText, "Payload should have a failure statusText");
258
Y.Assert.isString(o.msg, "Payload should have a failure msg");
260
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
267
Y.Get.abort(trans.tId);
272
'test: multiple script, success': function() {
281
var trans = Y.Get.script(path(["b.js", "a.js", "c.js"]), {
283
data: {a:1, b:2, c:3},
284
context: {bar:"foo"},
286
onFailure: function(o) {
287
test.resume(function() {
288
Y.Assert.fail("onFailure shouldn't have been called");
293
onProgress: function(o) {
294
var file = o.url.match(/[abc]\.js/);
295
progress.push(file[0]);
298
onSuccess: function(o) {
302
test.resume(function() {
304
Y.Assert.areEqual(3, G_SCRIPTS.length, "More/Less than 3 scripts loaded");
305
Y.ArrayAssert.itemsAreEqual(["b.js", "a.js", "c.js"], G_SCRIPTS, "Unexpected script order");
306
Y.ArrayAssert.itemsAreEqual(G_SCRIPTS, progress, "Progress does not match G_SCRIPTS");
308
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
310
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
311
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
312
Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
313
Y.Assert.isUndefined(o.statusText, "Payload should have an undefined statusText");
314
Y.Assert.isUndefined(o.msg, "Payload should have an undefined msg");
316
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
326
'test: multiple script, failure': function() {
334
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
336
data: {a:1, b:2, c:3},
337
context: {bar:"foo"},
339
onSuccess: function(o) {
340
test.resume(function() {
341
Y.Assert.fail("onSuccess shouldn't have been called");
345
onFailure: function(o) {
349
test.resume(function() {
351
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
353
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
354
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
356
// TODO: We can't control which script it will fail on. Fix when we can (when we have built in server env).
357
// Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
359
Y.Assert.isUndefined(o.statusText, "Payload should have an undefined statusText");
360
Y.Assert.isString(o.msg, "Payload should have a failure msg");
362
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
369
Y.Get.abort(trans.tId);
374
'test: multiple script, success, end': function() {
384
var trans = Y.Get.script(path(["c.js", "b.js", "a.js"]), {
386
data: {a:1, b:2, c:3},
387
context: {bar:"foo"},
389
onSuccess: function() {
392
Y.Assert.areEqual(3, G_SCRIPTS.length, "More/Less than 3 scripts loaded");
393
Y.ArrayAssert.itemsAreEqual(["c.js", "b.js", "a.js"], G_SCRIPTS, "Unexpected script order");
394
Y.ArrayAssert.itemsAreEqual(G_SCRIPTS, progress, "Progress does not match G_SCRIPTS");
395
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
398
onProgress: function(o) {
399
var file = o.url.match(/[abc]\.js/);
400
progress.push(file[0]);
403
onFailure: function() {
404
Y.Assert.fail("onFailure shouldn't have been called");
407
onEnd : function(o) {
411
test.resume(function() {
413
Y.Assert.areEqual(1, counts.end,"onEnd called more than once");
414
Y.Assert.areEqual(1, counts.success, "onEnd called before onSuccess");
416
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
417
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
418
Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
419
Y.Assert.areEqual("OK", o.statusText, "Payload should have an OK statusText");
420
Y.Assert.isUndefined(o.msg, "Payload should have an undefined msg");
422
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
433
'test: multiple script, failure, end': function() {
442
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
444
data: {a:1, b:2, c:3},
445
context: {bar:"foo"},
447
onSuccess: function() {
448
Y.Assert.fail("onSuccess shouldn't have been called");
451
onFailure: function() {
453
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
456
onEnd : function(o) {
460
test.resume(function() {
462
Y.Assert.areEqual(1, counts.end,"onEnd called more than once");
463
Y.Assert.areEqual(1, counts.failure, "onEnd called before onFailure");
465
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
466
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
468
//Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
470
Y.Assert.areEqual("failure", o.statusText, "Payload should have a failure statusText");
471
Y.Assert.isString(o.msg, "Payload should have a failure msg");
473
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
480
Y.Get.abort(trans.tId);
485
'test: async multiple script, success': function() {
494
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
496
data: {a:1, b:2, c:3},
497
context: {bar:"foo"},
499
onFailure: function(o) {
500
test.resume(function() {
501
Y.Assert.fail("onFailure shouldn't have been called");
506
onProgress: function(o) {
507
var file = o.url.match(/[abc]\.js/);
508
progress.push(file[0]);
511
onSuccess: function(o) {
515
test.resume(function() {
517
Y.Assert.areEqual(3, G_SCRIPTS.length, "More/Less than 3 scripts loaded");
518
Y.ArrayAssert.itemsAreEqual(G_SCRIPTS, progress, "Progress does not match G_SCRIPTS");
519
Y.ArrayAssert.containsItems( ["c.js", "a.js", "b.js"], G_SCRIPTS, "Unexpected script contents");
520
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
522
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
523
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
524
Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
525
Y.Assert.isUndefined(o.statusText, "Payload should have an undefined statusText");
526
Y.Assert.isUndefined(o.msg, "Payload should have an undefined msg");
528
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
539
'test: async multiple script, success, end': function() {
548
var trans = Y.Get.script(path(["c.js", "a.js", "b.js"]), {
550
data: {a:1, b:2, c:3},
551
context: {bar:"foo"},
553
onSuccess: function() {
555
Y.Assert.areEqual(3, G_SCRIPTS.length, "More/Less than 3 scripts loaded");
556
Y.ArrayAssert.containsItems(["a.js", "b.js", "c.js"], G_SCRIPTS, "Unexpected script contents");
557
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
560
onFailure: function() {
561
Y.Assert.fail("onFailure shouldn't have been called");
564
onEnd : function(o) {
568
test.resume(function() {
570
Y.Assert.areEqual(1, counts.end,"onEnd called more than once");
571
Y.Assert.areEqual(1, counts.success, "onEnd called before onSuccess");
573
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
574
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
575
Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
576
Y.Assert.areEqual("OK", o.statusText, "Payload should have an OK statusText");
577
Y.Assert.isUndefined(o.msg, "Payload should have an undefined msg");
579
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
592
// THE ASYNC FAILURE TESTS NEED TO BE AT THE END,
593
// BECAUSE ABORTING THEM WILL NOT STOP PARALLEL SCRIPTS
594
// FROM DOWNLOADING (at least currently) AND SINCE WE USE
595
// A GLOBAL, IT POLLUTES THE NEXT SUCCESS TEST
597
// TODO: Maybe we can explore the idea of moving from global to something instance based?
599
'test: async multiple script, failure': function() {
607
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
609
data: {a:1, b:2, c:3},
610
context: {bar:"foo"},
612
onSuccess: function(o) {
613
test.resume(function() {
614
Y.Assert.fail("onSuccess shouldn't have been called");
618
onFailure: function(o) {
622
test.resume(function() {
624
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
626
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
627
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
629
// Can't control which script it will abort at. Also async will keep on downloading
630
// Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
632
Y.Assert.isUndefined(o.statusText, "Payload should have an undefined statusText");
633
Y.Assert.isString(o.msg, "Payload should have a failure msg");
635
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
643
Y.Get.abort(trans.tId);
648
'test: async multiple script, failure, end': function() {
657
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
659
data: {a:1, b:2, c:3},
660
context: {bar:"foo"},
662
onSuccess: function() {
663
Y.Assert.fail("onSuccess shouldn't have been called");
666
onFailure: function() {
668
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
671
onEnd : function(o) {
675
test.resume(function() {
677
Y.Assert.areEqual(1, counts.end,"onEnd called more than once");
678
Y.Assert.areEqual(1, counts.failure, "onEnd called before onFailure");
680
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
681
Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
683
//Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
685
Y.Assert.areEqual("failure", o.statusText, "Payload should have a failure statusText");
686
Y.Assert.isString(o.msg, "Payload should have a failure msg");
688
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
696
Y.Get.abort(trans.tId);
701
'test: insertBefore, single' : function() {
705
test.createInsertBeforeNode();
707
var trans = Y.Get.script(path("a.js"), {
709
insertBefore: "insertBeforeMe",
711
onSuccess: function(o) {
712
test.resume(function() {
714
var n = Y.Node.one(o.nodes[0]);
715
var insertBefore = Y.Node.one("#insertBeforeMe");
717
Y.Assert.isTrue(n.compareTo(insertBefore.previous()), "Not inserted before insertBeforeMe");
723
onFailure: function(o) {
724
test.resume(function() {
725
Y.Assert.fail("onFailure shouldn't have been called");
734
'test: insertBefore, multiple' : function() {
738
test.createInsertBeforeNode();
740
var trans = Y.Get.script(path(["a.js", "b.js"]), {
742
insertBefore: "insertBeforeMe",
744
onSuccess: function(o) {
745
test.resume(function() {
747
var insertBefore = Y.Node.one("#insertBeforeMe");
749
for (var i = o.nodes.length-1; i >= 0; i--) {
750
var n = Y.Node.one(o.nodes[i]);
751
Y.Assert.isTrue(n.compareTo(insertBefore.previous()), "Not inserted before insertBeforeMe");
759
onFailure: function(o) {
760
test.resume(function() {
761
Y.Assert.fail("onFailure shouldn't have been called");
770
'test: async, insertBefore, multiple' : function() {
774
test.createInsertBeforeNode();
776
var trans = Y.Get.script(path(["a.js", "b.js"]), {
778
insertBefore: "insertBeforeMe",
780
onSuccess: function(o) {
781
test.resume(function() {
783
var insertBefore = Y.Node.one("#insertBeforeMe");
785
for (var i = o.nodes.length-1; i >= 0; i--) {
786
var n = Y.Node.one(o.nodes[i]);
787
Y.Assert.isTrue(n.compareTo(insertBefore.previous()), "Not inserted before insertBeforeMe");
795
onFailure: function(o) {
796
test.resume(function() {
797
Y.Assert.fail("onFailure shouldn't have been called");
807
'test: charset, single' : function() {
811
var trans = Y.Get.script(path("a.js"), {
813
charset: "ISO-8859-1",
815
onSuccess: function(o) {
816
test.resume(function() {
818
var node = document.getElementById(o.nodes[0].id);
820
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
821
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
827
onFailure: function(o) {
828
test.resume(function() {
829
Y.Assert.fail("onFailure shouldn't have been called");
838
'test: charset, multiple' : function() {
842
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
844
charset: "ISO-8859-1",
846
onSuccess: function(o) {
848
test.resume(function() {
850
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
852
for (var i = 0; i < o.nodes.length; i++) {
854
var node = document.getElementById(o.nodes[i].id);
856
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
857
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
864
onFailure: function(o) {
865
test.resume(function() {
866
Y.Assert.fail("onFailure shouldn't have been called");
875
'test: async, charset, multiple' : function() {
879
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
881
charset: "ISO-8859-1",
883
onSuccess: function(o) {
885
test.resume(function() {
887
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
889
for (var i = 0; i < o.nodes.length; i++) {
891
var node = document.getElementById(o.nodes[i].id);
893
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
894
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
901
onFailure: function(o) {
902
test.resume(function() {
903
Y.Assert.fail("onFailure shouldn't have been called");
914
'test: attributes, single' : function() {
918
var trans = Y.Get.script(path("a.js"), {
921
"defer":true, // Too much potential to interfere with global test structure?
922
"charset": "ISO-8859-1",
926
onSuccess: function(o) {
927
test.resume(function() {
929
var node = document.getElementById(o.nodes[0].id);
931
Y.Assert.areEqual("myscripts", node.title, "title property not set");
932
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
933
Y.Assert.areEqual(true, node.defer, "defer property not set");
935
Y.Assert.areEqual("myscripts", node.getAttribute("title"), "title attribute not set");
936
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
938
// Needs cross browser normalization, IE8 returns "defer", Safari returns "true" etc.
939
// Y.Assert.areEqual("true", node.getAttribute("defer"), "defer attribute not set");
945
onFailure: function(o) {
946
test.resume(function() {
947
Y.Assert.fail("onFailure shouldn't have been called");
956
'test: attributes, multiple' : function() {
960
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
963
"defer":true, // Too much potential to interfere with global test structure?
964
"charset": "ISO-8859-1",
968
onSuccess: function(o) {
970
test.resume(function() {
972
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
974
for (var i = 0; i < o.nodes.length; i++) {
976
var node = document.getElementById(o.nodes[i].id);
978
Y.Assert.areEqual("myscripts", node.title, "title property not set");
979
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
980
Y.Assert.areEqual(true, node.defer, "defer property not set");
982
Y.Assert.areEqual("myscripts", node.getAttribute("title"), "title attribute not set");
983
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
990
onFailure: function(o) {
991
test.resume(function() {
992
Y.Assert.fail("onFailure shouldn't have been called");
1001
'test: async, attributes, multiple' : function() {
1005
var trans = Y.Get.script(path(["a.js", "b.js", "c.js"]), {
1008
"defer":true, // Too much potential to interfere with global test structure?
1009
"charset": "ISO-8859-1",
1010
"title": "myscripts"
1013
onSuccess: function(o) {
1015
test.resume(function() {
1017
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
1019
for (var i = 0; i < o.nodes.length; i++) {
1021
var node = document.getElementById(o.nodes[i].id);
1023
Y.Assert.areEqual("myscripts", node.title, "title property not set");
1024
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1025
Y.Assert.areEqual(true, node.defer, "defer property not set");
1027
Y.Assert.areEqual("myscripts", node.getAttribute("title"), "title attribute not set");
1028
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1035
onFailure: function(o) {
1036
test.resume(function() {
1037
Y.Assert.fail("onFailure shouldn't have been called");
1048
'ignore: abort' : function() {
1049
// Covered above, but worth testing payload also
1052
'ignore: timeout' : function() {
1053
// Need delay.js always available to test this reliably. Leaving out for now
1056
'test: purgethreshold' : function() {
1062
// Purge only happens at the start of a queue call.
1064
Y.Get.script(path("a.js"), {
1066
purgethreshold: 1000, // Just to make sure we're not purged as part of the default 20 script purge.
1068
onSuccess: function(o) {
1070
nodes = nodes.concat(o.nodes);
1072
Y.Get.script(path("b.js"), {
1074
purgethreshold: 1000, // Just to make sure we're not purged as part of the default 20 script purge.
1076
onSuccess: function(o) {
1078
nodes = nodes.concat(o.nodes);
1080
Y.Assert.areEqual(2, nodes.length, "2 nodes should have been added");
1082
for (var i = 0; i < nodes.length; i++) {
1083
var node = Y.Node.one(nodes[i]);
1084
Y.Assert.isTrue(node.inDoc(), "Scripts should still be in the document");
1086
// Convert to id, for final doc check, because purge destroys parentNode
1087
nodeIds[i] = node.get("id");
1090
Y.Get.script(path("c.js"), {
1094
onSuccess: function(o) {
1096
test.resume(function() {
1098
for (var i = 0; i < nodeIds.length; i++) {
1099
Y.Assert.isNull(Y.Node.one(nodeIds[i]), "Script from previous transaction was not purged");
1102
Y.Assert.isTrue(Y.Node.one(o.nodes[0]).inDoc());
1118
Y.GetTests.CSS = new Y.Test.Case({
1123
this.na = Y.Node.create('<div class="get_test_a">get_test_a</div>');
1124
this.nb = Y.Node.create('<div class="get_test_b">get_test_b</div>');
1125
this.nc = Y.Node.create('<div class="get_test_c">get_test_c</div>');
1129
var b = Y.Node.one("body");
1134
this.onload = Y.GetTests.ONLOAD_SUPPORTED['css'];
1137
createInsertBeforeNode: function() {
1138
this.ib = Y.Node.create('<link id="insertBeforeMe" href="' + path("ib.css?delay=0") + '" rel="stylesheet" type="text/css" charset="utf-8">');
1139
Y.Node.one("head").appendChild(this.ib);
1142
removeInsertBeforeNode: function() {
1144
this.ib.remove(true);
1148
tearDown: function() {
1149
this.na.remove(true);
1150
this.nb.remove(true);
1151
this.nc.remove(true);
1153
this.o && this.o.purge();
1154
this.removeInsertBeforeNode();
1157
'test: single css, success': function() {
1164
// Using test.onload to switch test behavior for IE/Opera vs. others.
1165
// In IE/Opera we don't need to artifical timeout, since we're notified
1166
// onload. For the others, onSuccess is called synchronously.
1168
var trans = Y.Get.css(path("a.css?delay=50"), {
1170
data: {a:1, b:2, c:3},
1171
context: {bar:"foo"},
1173
onSuccess: function(o) {
1177
setTimeout(function() {
1178
test.resume(function() {
1181
Y.Assert.areEqual("1111", this.na.getComputedStyle("zIndex"), "a.css does not seem to be loaded");
1182
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
1184
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
1186
// TODO: Test infrastructure won't let us easily get a populated trans reference and also wait (AFAICT). So commenting this out.
1187
// Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
1189
Y.Assert.areEqual(1, o.nodes.length, "Payload nodes property has unexpected length");
1190
Y.Assert.isUndefined(o.statusText, "Payload should not have a statusText");
1191
Y.Assert.isUndefined(o.msg, "Payload should not have a msg");
1193
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
1197
}, test.onload ? 0 : 200); // need arbit delay to make sure CSS is applied
1205
onFailure: function(o) {
1206
Y.Assert.fail("onFailure shouldn't have been called");
1215
'test: multiple css, success': function() {
1223
var trans = Y.Get.css(path(["a.css?delay=50", "b.css?delay=100", "c.css?delay=75"]), {
1225
data: {a:1, b:2, c:3},
1226
context: {bar:"foo"},
1228
onFailure: function(o) {
1229
Y.Assert.fail("onFailure shouldn't have been called");
1232
onSuccess: function(o) {
1236
setTimeout(function() {
1237
test.resume(function() {
1240
Y.Assert.areEqual("1111", this.na.getComputedStyle("zIndex"), "a.css does not seem to be loaded");
1241
Y.Assert.areEqual("1234", this.nb.getComputedStyle("zIndex"), "b.css does not seem to be loaded");
1242
Y.Assert.areEqual("4321", this.nc.getComputedStyle("zIndex"), "c.css does not seem to be loaded");
1243
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
1245
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
1247
//Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
1249
Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
1250
Y.Assert.isUndefined(o.statusText, "Payload should not have a statusText");
1251
Y.Assert.isUndefined(o.msg, "Payload should not have a msg");
1253
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
1257
}, test.onload ? 0 : 400);
1270
'test: async multiple css, success': function() {
1278
var trans = Y.Get.css(path(["a.css?delay=100", "b.css?delay=75", "c.css?delay=50"]), {
1280
data: {a:1, b:2, c:3},
1281
context: {bar:"foo"},
1283
onFailure: function(o) {
1284
Y.Assert.fail("onFailure shouldn't have been called");
1286
onSuccess: function(o) {
1290
setTimeout(function() {
1291
test.resume(function() {
1293
Y.Assert.areEqual("1111", this.na.getComputedStyle("zIndex"), "a.css does not seem to be loaded");
1294
Y.Assert.areEqual("1234", this.nb.getComputedStyle("zIndex"), "b.css does not seem to be loaded");
1295
Y.Assert.areEqual("4321", this.nc.getComputedStyle("zIndex"), "c.css does not seem to be loaded");
1296
Y.Assert.isTrue(counts.success === 1, "onSuccess called more than once");
1298
areObjectsReallyEqual({a:1, b:2, c:3}, o.data, "Payload has unexpected data value");
1300
//Y.Assert.areEqual(trans.tId, o.tId, "Payload has unexpected tId");
1302
Y.Assert.areEqual(3, o.nodes.length, "Payload nodes property has unexpected length");
1303
Y.Assert.isUndefined(o.statusText, "Payload should not have a statusText");
1304
Y.Assert.isUndefined(o.msg, "Payload should not have a msg");
1306
Y.Assert.areEqual("foo", context.bar, "Callback context not set");
1310
}, test.onload ? 0 : 400);
1324
'test: insertBefore, single' : function() {
1328
test.createInsertBeforeNode();
1330
var trans = Y.Get.css(path("a.css?delay=30"), {
1332
insertBefore: "insertBeforeMe",
1334
onSuccess: function(o) {
1336
setTimeout(function() {
1337
test.resume(function() {
1339
var n = Y.Node.one(o.nodes[0]);
1341
var insertBefore = Y.Node.one("#insertBeforeMe");
1343
Y.Assert.isTrue(n.compareTo(insertBefore.previous()), "Not inserted before insertBeforeMe");
1345
/* TODO: These don't work as expected on IE (even though insertBefore worked). Better cross-browser assertion? */
1347
Y.Assert.areEqual("9991", this.na.getComputedStyle("zIndex"), "a.css does not seem to be inserted before ib.css");
1353
}, test.onload ? 0 : 100);
1366
'test: insertBefore, multiple' : function() {
1370
test.createInsertBeforeNode();
1372
var trans = Y.Get.css(path(["a.css?delay=20", "b.css?delay=75", "c.css?delay=10"]), {
1374
insertBefore: "insertBeforeMe",
1376
onSuccess: function(o) {
1377
setTimeout(function() {
1378
test.resume(function() {
1379
var insertBefore = Y.Node.one("#insertBeforeMe");
1381
for (var i = o.nodes.length-1; i >= 0; i--) {
1382
var n = Y.Node.one(o.nodes[i]);
1383
Y.Assert.isTrue(n.compareTo(insertBefore.previous()), "Not inserted before insertBeforeMe");
1387
/* TODO: These don't work as expected on IE (even though insertBefore worked). Better cross-browser assertion? */
1389
Y.Assert.areEqual("9991", this.na.getComputedStyle("zIndex"), "a.css does not seem to be inserted before ib.css");
1390
Y.Assert.areEqual("9992", this.nb.getComputedStyle("zIndex"), "b.css does not seem to be inserted before ib.css");
1391
Y.Assert.areEqual("9993", this.nc.getComputedStyle("zIndex"), "c.css does not seem to be inserted before ib.css");
1396
}, test.onload ? 0 : 200);
1409
'test: async, insertBefore, multiple' : function() {
1413
test.createInsertBeforeNode();
1415
var trans = Y.Get.css(path(["a.css?delay=30", "b.css?delay=10", "c.css?delay=50"]), {
1417
insertBefore: "insertBeforeMe",
1419
onSuccess: function(o) {
1421
setTimeout(function() {
1422
test.resume(function() {
1423
var insertBefore = Y.Node.one("#insertBeforeMe");
1425
for (var i = o.nodes.length-1; i >= 0; i--) {
1426
var n = Y.Node.one(o.nodes[i]);
1427
Y.Assert.isTrue(n.compareTo(insertBefore.previous()), "Not inserted before insertBeforeMe");
1431
/* TODO: These don't work as expected on IE (even though insertBefore worked). Better cross-browser assertion? */
1433
Y.Assert.areEqual("9991", this.na.getComputedStyle("zIndex"), "a.css does not seem to be inserted before ib.css");
1434
Y.Assert.areEqual("9992", this.nb.getComputedStyle("zIndex"), "b.css does not seem to be inserted before ib.css");
1435
Y.Assert.areEqual("9993", this.nc.getComputedStyle("zIndex"), "c.css does not seem to be inserted before ib.css");
1442
}, test.onload ? 0 : 200);
1457
'test: charset, single' : function() {
1461
var trans = Y.Get.css(path("a.css?delay=20"), {
1463
charset: "ISO-8859-1",
1465
onSuccess: function(o) {
1466
setTimeout(function() {
1467
test.resume(function() {
1469
var node = document.getElementById(o.nodes[0].id);
1471
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1472
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1477
}, test.onload ? 0 : 100);
1490
'test: charset, multiple' : function() {
1494
var trans = Y.Get.css(path(["a.css?delay=10", "b.css?delay=50", "c.css?delay=20"]), {
1496
charset: "ISO-8859-1",
1498
onSuccess: function(o) {
1500
setTimeout(function() {
1501
test.resume(function() {
1503
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
1505
for (var i = 0; i < o.nodes.length; i++) {
1507
var node = document.getElementById(o.nodes[i].id);
1509
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1510
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1515
}, test.onload ? 0 : 200);
1528
'test: async, charset, multiple' : function() {
1532
var trans = Y.Get.css(path(["a.css?delay=30", "b.css?delay=10", "c.css?delay=20"]), {
1534
charset: "ISO-8859-1",
1536
onSuccess: function(o) {
1538
setTimeout(function() {
1539
test.resume(function() {
1541
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
1543
for (var i = 0; i < o.nodes.length; i++) {
1545
var node = document.getElementById(o.nodes[i].id);
1547
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1548
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1554
}, test.onload ? 0 : 200);
1568
'test: attributes, single' : function() {
1572
var trans = Y.Get.css(path("a.css?delay=10"), {
1575
"charset": "ISO-8859-1",
1576
"title": "myscripts"
1579
onSuccess: function(o) {
1581
setTimeout(function() {
1582
test.resume(function() {
1584
var node = document.getElementById(o.nodes[0].id);
1586
Y.Assert.areEqual("myscripts", node.title, "title property not set");
1587
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1588
Y.Assert.areEqual("myscripts", node.getAttribute("title"), "title attribute not set");
1589
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1594
}, test.onload ? 0 : 100);
1608
'test: attributes, multiple' : function() {
1612
var trans = Y.Get.css(path(["a.css?delay=10", "b.css?delay=50", "c.css?delay=20"]), {
1615
"charset": "ISO-8859-1",
1616
"title": "myscripts"
1619
onSuccess: function(o) {
1621
setTimeout(function() {
1622
test.resume(function() {
1624
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
1626
for (var i = 0; i < o.nodes.length; i++) {
1628
var node = document.getElementById(o.nodes[i].id);
1630
Y.Assert.areEqual("myscripts", node.title, "title property not set");
1631
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1632
Y.Assert.areEqual("myscripts", node.getAttribute("title"), "title attribute not set");
1633
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1638
}, test.onload ? 0 : 200);
1653
'test: async, attributes, multiple' : function() {
1657
var trans = Y.Get.css(path(["a.css?delay=10", "b.css?delay=50", "c.css?delay=20"]), {
1660
"charset": "ISO-8859-1",
1661
"title": "myscripts"
1664
onSuccess: function(o) {
1666
setTimeout(function() {
1667
test.resume(function() {
1669
Y.Assert.areEqual(3, o.nodes.length, "Unexpected node count");
1671
for (var i = 0; i < o.nodes.length; i++) {
1673
var node = document.getElementById(o.nodes[i].id);
1675
Y.Assert.areEqual("myscripts", node.title, "title property not set");
1676
Y.Assert.areEqual("ISO-8859-1", node.charset, "charset property not set");
1677
Y.Assert.areEqual("myscripts", node.getAttribute("title"), "title attribute not set");
1678
Y.Assert.areEqual("ISO-8859-1", node.getAttribute("charset"), "charset attribute not set");
1683
}, test.onload ? 0 : 200);
1699
// TODO: CSS failure not widely supported. Enable when success/failure handling is in place
1701
'ignore: single css, failure': function() {
1709
Y.Get.abort(Y.Get.css(path("a.css"), {
1711
data: {a:1, b:2, c:3},
1712
context: {bar:"foo"},
1714
onSuccess: function(o) {
1715
Y.Assert.fail("onSuccess shouldn't have been called");
1718
onFailure: function(o) {
1720
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
1723
onEnd: function(o) {
1729
// TODO: CSS failure not widely supported. Enable when success/failure handling is in place
1731
'ignore: multiple css, failure': function() {
1738
Y.Get.abort(Y.Get.css(path(["a.css", "b.css", "c.css"]), {
1740
data: {a:1, b:2, c:3},
1741
context: {bar:"foo"},
1743
onSuccess: function(o) {
1744
test.resume(function() {
1745
Y.Assert.fail("onSuccess shouldn't have been called");
1749
onFailure: function(o) {
1750
test.resume(function() {
1752
Y.Assert.isTrue(counts.failure === 1, "onFailure called more than once");
1757
onEnd: function(o) {
1765
// TODO: CSS failure not widely supported. Enable when success/failure handling is in place
1767
'ignore: async multiple css, failure': function() {
1772
Y.GetTests.Functional = new Y.Test.Case({
1774
name: "Functional Tests",
1776
'test: Loader, ScrollView' : function() {
1779
YUI().use("scrollview", function(Y2) {
1780
test.resume(function() {
1781
Y.Assert.isFunction(Y2.ScrollView, "ScrollView not loaded");
1788
'test: Loader, Autocomplete' : function() {
1791
YUI().use("autocomplete-list", function(Y2) {
1792
test.resume(function() {
1793
Y.Assert.isFunction(Y2.AutoCompleteList, "Autocomplete not loaded");