Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/js/tests.js
blob: 15e1f814bbdfaf4b7c793274952dff99dd9d8536 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
 $(document).ready(
     function(){
	 // k is a shortcut for the Karma object
	 var k = Karma.karma;

	 var hasProperties = function (properties) {
	     for (var prop in properties) {
		 if (!this[prop]){
		     return false;
		 }
		 else {
		     return true;
		 }
	     }
	 };

	 var shouldError = function ( cb ){
	     try {
		 cb();
	     } 
	     catch (e) {
		 return true;
	     }
	     return false;	 
	 };
	 
	 var shouldNotError = function ( cb ) {
	     return !shouldError( cb );
	 };

	 var checkErrorMsg = function(){
	     var errorMsg = $('#errorList>li').text();
	     var regex = new RegExp('error', 'i');
	     return regex.test(errorMsg);
	 };

	 //unit test suite uses this function
	 Karma.karma.reset = function () {
	     while($('#starterMsg').length === 1){
		 $('#starterMsg').remove();
	     };

	     while($('#karma-status').length === 1){
		 $('#karma-status').remove();
	     };
	     /* if (this._statusDiv){
		 if (this._statusDiv.parentNode){
		     this._statusDiv.parentNode.removeChild(this._statusDiv);
		 }
	     }

	     var starterMsg = document.getElementById('starterMsg');
	     if(starterMsg){
		 if(starterMsg.parentNode){
		     starterMsg.parentNode.removeChild(starterMsg);
		 }
	     }*/
	     
	     this._assetPath = "assets/";
	     this.locale = undefined;
	     this._localized = false;
	     this._localePath = "";
	     this.image = {};
	     this.canvas = {};
	     this.audio = {};
	     this.svg = {};
	     this.video = {};
	     this._initialized = false;
	     this._statusDiv = undefined;
	     this._counters.total = 0; 
	     this._counters.errors = 0; 
	     this._counters.loaded = 0; 
	     this._loaderDiv = undefined;
	     return Karma.karma;
	 };

	 //clean up any error message crap left behind
	 //by initializing and resetting Karma.karma
	 //call it in the last asynchronous test
	 var removeMsgs = function () {
	     while($('#karma-status').length === 1){
		 $('#karma-status').remove();
	     };
	 };


	 module("Module Helpers");


	 test("Basic Requirements", function() {
		  expect(5);

		  //Need to test if doctype is html5
		  // and if browser supports html5

		  ok( Karma, "Karma library loaded");
		  ok( Array.prototype.push, "Array.push()" );
		  ok( Function.prototype.apply, "Function.apply()" );
		  ok( document.getElementById, "getElementById" );
		  ok( document.getElementsByTagName, "getElementsByTagName" );
	      });

	 test("Karma.create", function(){
		  expect(2);
		  var mock = {};
		  //test against empty object
		  same(Karma.create({}), mock, "doesn't match empty object");
		  mock.age = 30;
		  var mock1 = Karma.create(mock);
		  equals(mock.age, mock1.age, "child object inherits property");
		  
	      });

	 test("Karma.clone", function(){
		  expect(2);

		  var mock = { name: "foo", age: 30, children : ["adrian", "sheila",
								 "stephanie"], spouse: { wife: "Marie"}};
		  same(Karma.clone(mock), mock, 
		       "cloned object matches original");
		  mock.spouse.wife = "Marjorie";
		  same(Karma.clone(mock), mock, 
		       "cloned object matches original after original changed after cloning");
		  
	      });

	 test("Karma.objectPlus", function(){
		  expect(2);

		  var warrior = { name : "conan", age : 30, dance : true};
		  var oldProto = warrior.__proto__;
		  var ninja = { dance : false, tattoo : true};
		  var newProto = warrior.__proto__;

		  Karma.objectPlus(warrior, ninja);
		  ok( warrior.dance === ninja.dance && warrior.tattoo ===
		       ninja.tattoo, "target object wasn't updated with source");
		  ok( oldProto === newProto, "the object prototype changed.");
	      });
	 
	 test("Karma.copyObjectPlus", function(){
		  expect(2);
		  var warrior = { name : "conan", age : 30, dance : true};
		  var copyWarrior = Karma.clone(warrior);
		  var ninja = { dance : false, name : "Yoshi"};

		  var ninja1 =  Karma.copyObjectPlus(warrior, ninja);

		  ok( ninja1.dance === ninja.dance && ninja1.age === warrior.age &&
		       ninja1.name === ninja.name, 
		       "target object wasn't updated with source");
		  ok( warrior.__proto__.isPrototypeOf(ninja1), 
		       "the protoypeObject changed");	 

	      });


	 module("Module Karma core library");
	 

	 test("Karma()", function () { 
		  expect(2);
		  var karma1 = Karma();
		  ok(k._initialized === true, 
		     "Karma() sets initialized property on k");
		  var karma2 = Karma();
		  ok(karma1 === karma2, "Karma() only allows one instance of Karma.karma");
		  
	      });
	 
	 test("Karma._isHtml5()", 
	     function(){		 
		 expect(2);
		 // throw error if doctype not set to html5
		 
		 ok(shouldError(
			function(){
			    Karma.karma._init();
			    var doctype = "xhtml";
			    Karma._isHtml5(doctype);     
			}), "The doctype has to be set to <!DOCTYPE html>" +
				" in order to use karma");		       
		 var errorElem = document.getElementById('errorDoctype');
		 var regex = new RegExp('ERROR', 'i');
		 ok(regex.test(errorElem.innerText), "The Error placeholder" +
		    "contains error message");
		 
		 //cleanup
		 var doctype = "xhtml";
		 errorElem.parentNode.removeChild(errorElem);
		 });

	 test("Karma.karma._init()", function() {
		  expect(5);
		  k.reset();
		  ok(
		      shouldNotError(
			  function(){
			      k._init();
			  }), "Karma.karma._init() does not throw errors when " +
			  "initialized with no options");
		  
		  k.reset();

		  ok(shouldError(function () {
				     k._init({locale : "foo"});}), 
		      "emits error on invalid locale");

		  k.reset();

		      var goodOptions = {locale : "en", 
			  image : [{ name: "chimp", 
			      file : 'happyMonkey.jpg' }
				  ],  
			      audio : [{ name: "correct", 
					 file : 'correct.ogg'}
				      ], 
			       canvas : [{ name: "test", domId : 'testCanvas'}]};

		  ok(shouldNotError(function () { k._init(goodOptions);}), 
		     "accepts good options");
		  
		  k.reset();
		  
		  var badOptions = {locale : "blabla", image : [{ name: "chimp", 
							       file : 'chimp.png' }], 
				    audio : [{ name: "correct", file : 'notthere.ogg'}], 
				    canvas : [{ name: "", domId : 'noCanvas'}]};
		  
		  ok(shouldError(function () { k._init(badOptions); }), 
		     "Rejects bad options");
		  
		  k.reset();

		  //test that init won't overwrite private properties
		  k._init({_counters : { errors : 500}});
		  ok(k._counters.errors !== 500, "Private property not overwritten");     
		  
		  k.reset();
	      });



	 test("Karma.karma.ready()", function () {
		  expect(3);
		  ok(shouldError(function () {k.ready();}), "Uninitialized karma instance " + 
		       "generates error on .ready()");
		  
		  k.reset();

		  k._init().ready();
		  var starterMsg = document.getElementById('starterMsg');
		  ok(starterMsg, 
		     "Karma.karma.ready() with no callback displays starter msg");
		  //clean up
		  document.body.removeChild(starterMsg);
		  k.reset();
		  
		  var ninjaName = "Bruce Lee";
		  var testCb = function () { ninjaName = "Chuck Norris";};
		  
		  k._init().ready(testCb);
		  ok(ninjaName === "Chuck Norris", "ready() calls callback");

		  k.reset();
		  
	      });


	 test("karma._isValidLocale(locale)",
	      function () {
		  /* reject locale if has more than 2 letters
		   * before dash or underscore
		   * 
		   */
		  expect(4);
		  // test valid locale
		  ok(k._isValidLocale("en"), "Valid locale option accepted");

		  // test valid locale
		  ok(k._isValidLocale("en-us"), "Valid locale option accepted");
		  
		  //test invalid locale
		  ok(!k._isValidLocale("foo"), "Invalid locale rejected");		  

		  //test invalid locale
		  ok(!k._isValidLocale("en_Foobar"), "Invalid locale rejected");		  

	      });


	 test("karma._normalizeLocale(locale)", function () { 
		  /*
		   * change any "-" dash to underscore
		   * make sure first part lowercase
		   * make sure part after underscore is uppercase
		   *
		   * don't do anything if already ok
		   * 
		   * don't choke on locale w/ only two letters 
		   */
		  expect(3);
		  ok(k._normalizeLocale("EN-us") === "en_US",
		      "lowercase, uppercase, and dash properly changed");
		  ok(k._normalizeLocale("en_US") === "en_US", 
		      "Doesn't screw up locale that is already ok");
		  ok(k._normalizeLocale("en") === "en",
		      "handles 2 letter locale.");
		  
	      });

	 
	 test("karma._computeLocalePath(locale)",
	      function() {
		  /* 
		   * for locale es_SP 
		   *    make sure returns path  "../assets/locale_name/" 
		   * 
		   */
		  expect(2);
		  ok(Karma._computeLocalePath("en_US") === 
		     "assets/en_US/", "computes correct path");

		  ok(Karma._computeLocalePath("es") === 
		     "assets/es/", "computes correct path");
	      });



	 //have to do this asynchronously let the error event propagate
	 asyncTest("Karma.kImage._init(/* bad options */)", 
	      function(){
		  expect(4);
		  var kImage1 = Karma.create(Karma.kImage);		  
		  k.reset()._init();
		  var oldErrors = k._counters.errors;
		  var oldTotal = k._counters.total;
		  try {
		      kImage1._init({name: "notthere", file: "notthere.png"});
		  } catch (e){}
	     
	    	 setTimeout(
		     function (){
			 ok(kImage1.status === "error", "bad file name produces error");
			 ok(k._counters.errors >= oldErrors + 1 , 
			    "Error counter was incremented on load error");
			 ok(k._counters.total === oldTotal + 1 , 
			    "Total Assets counter was incremented");
			 ok(checkErrorMsg(),
			    "error message appended");
			 //k.reset();
			 start();
		     }, 1000);
	     });
			  


	 asyncTest("Karma.kImage._init(/* good options */)", 
	     function(){
		 expect(3);
		 k.reset()._init();
		 var oldErrors = k._counters.errors;
		 var oldTotal = k._counters.total;
		 var kMock = { name: "chimp", file: "happyMonkey.jpg"};
		 var kImage2 = Karma.create(Karma.kImage)._init(kMock);
		 
		 setTimeout(
		     function () {
		      ok(kImage2.status === "loaded", "Good file is loaded");		
		      ok(k._counters.errors === oldErrors, 
		      "Error counter not incremented");
		      ok(k._counters.total === oldTotal + 1 , 
			 "Total Assets counter was incremented");
			 k.reset();
		      start();
		  }, 1000);
	     });


	 test("Karma.kImage._init( /* localize an asset when locale not set */)",
	      function(){
		  expect(1);
		  var kMock = Karma.create(Karma.kImage);
		  k.locale = undefined;
		  
		  ok(shouldError(
			 function () {
			     kMock._init({ name: 'esMonkey', file: 'happyMonkey.jpg',
			      _localized: true });
			 }), 
			 "You can't localize an asset if the locale isn't defined for your lesson");
	      });

	
	 asyncTest("Karma.kImage._init() w/ _localized file", 
		   function(){
		       expect(2);
		       k.reset()._init();
		       var kMock = Karma.create(Karma.kImage);	
		       var oldErrors = k._counters.errors;
		       var oldTotal = k._counters.total;
		       shouldError(
			   function(){
			       kMock._init({ name : 'monkey', file : 'happyMonkey.jpg', 
				     _localized : true});
			   });
		       
		       setTimeout(
			   function(){
			       ok(k._counters.errors === oldErrors,
				  "Properly loads localized file");
			       ok(k._counters.total === oldTotal + 1 , 
				  "Total Assets counter was incremented");
			       k.reset();
			       start();
			   }, 1000);
		   });

	
	 //k.kAudio._init()

	 //k.kVideo._init()
         test("Karma.kVideo._init()", 
	      function(){
		  k.reset()._init();
		  var config = {'name':'myVideo', 'file':'myVideo.ogv'};
		  var myVideo = Karma.create(Karma.kVideo);
		  ok(shouldError(
			 function(){
			     myVideo._init(config);
			 }), "Video is not yet supported");
		  ok(Karma.karma._counters.errors > 0, "Error counter incremented");
	      });

	 test("Karma._isLocalized(boolLocalized)",
		 function(){
		  /*
		   * reject non-boolean values
		   * 
		   * produce error if item is localized but not
		   * locale isn't set for karma object
		   */
	 	     expect(4);
		     
		     k.locale = "en";
		     ok(Karma._isLocalized(true),
			"handles true value");
		     ok(Karma._isLocalized(false) === false,
			"handles false value");
		     ok(shouldError(function(){
					Karma._isLocalized("true");}),
			"rejects non-boolean value");

		     k.locale = undefined;
		     ok(shouldError(function(){
					Karma._isLocalized(true);
				    }), 
			"Emits error if item is localized but Karma instance isn't");
		     
	      });
	 
	 
 	 asyncTest("Karma._makeCollection(collection, 'image') w/ good images", 3, 
	     function(){
		 k.reset()._init();
		 var configs = [ 
		     {name : "chimp", file:"happyMonkey.jpg"},
		     {name:"chili", file:"chili.png"},
		     {name:"plussign", file:"plussign.png"}
			     ];    

		 Karma._makeCollection(configs, 'image');
		 setTimeout(
		     function(){
			 ok(k.image.chili.name === configs[1].name, 
			 "can access image by name");
			 ok(k._counters.loaded === 3, 
			 "Counter of loaded assets was properly incremented");
			 ok(k._counters.errors === 0, 
			 "Counter of errors hasn't changed");
			 ok(k._counters.total === 3, 
			 "Counter of total assets properly incremented");
			 k.reset();
			 start();
		     }, 2000);
	     });

	 asyncTest("Karma._makeCollection(collection, 'image') w/ 2 good images and " +
		   "1 bad one.", 4, 
	     function(){
		 k.reset()._init();
		 var configs = [ 
		     {name : "chimp", file:"happyMonkey.jpg"},
		     {name:"notthere", file:"notthere.png"},
		     {name:"chili", file:"chili.png"}
			     ];    
		 Karma._makeCollection(configs, 'image');
		 setTimeout(
		     function(){
			 ok(k._counters.loaded === 2, 
			 "Counter of loaded assets was properly incremented");
			 ok(k._counters.errors === 1, 
			 "Counter of errors was properly incremented");
			 ok(k._counters.total === 3, 
			 "Counter of total assets properly incremented");
			 ok(checkErrorMsg(), "Error Message generated");

			 k.reset();
			 start();
		     }, 2000);
	     });

	 asyncTest("Karma._makeCollection(collection, 'image') w/ 3 good imgs, 1 localized", 
		 function(){
		     expect(4);
		     k.reset()._init({locale: "es"});
		     var configs = [ 
			 {name : "chimp", file:"happyMonkey.jpg", 
			 _localized : true},
		     {name:"chili", file:"chili.png"},
		     {name:"plussign", file:"plussign.png"}
			     ];    

		     Karma._makeCollection(configs, 'image');
		     setTimeout(
			 function(){
			     ok(k.image.chimp._path === 
				"assets/es/image/", 
			     "can access image by name");
			     ok(k._counters.loaded === 3, 
			 "Counter of loaded assets was properly incremented");
			     ok(k._counters.errors === 0, 
			     "Counter of errors hasn't changed");
			     ok(k._counters.total === 3, 
			     "Counter of total assets properly incremented");
			     k.reset();
			     start();
		     }, 2000);
	     });
	       
	 	 
	 asyncTest("Karma._makeCollection(configs, 'audio') w/ good audio",  
	     function(){
		 expect(5);
		 k.reset()._init();
		 var configs = [ 
		     {name : "correct", file:"correct.ogg"},
		     {name:"incorrect", file:"incorrect.ogg"},
		     {name:"trigger", file:"trigger.ogg"}
			     ];    

		 Karma._makeCollection(configs, 'audio');
		 setTimeout(
		     function(){
			 ok(k.audio.correct.name === configs[0].name, 
			 "can access sound by name");
			 ok(k.audio.correct.play, 
			    "play() method is attached");
			 ok(k._counters.loaded === 3, 
			 "Counter of loaded assets was properly incremented");
			 ok(k._counters.errors === 0, 
			 "Counter of errors hasn't changed");
			 ok(k._counters.total === 3, 
			 "Counter of total assets properly incremented");
			 k.reset();
			 start();
		     }, 2000);
	     });

	 asyncTest("Karma._makeCollection(configs, 'audio') w/ 2 good sounds and " +
		   "1 bad one.",  
	     function(){
		 expect(4);
		 k.reset()._init();
		 var configs = [ 
		     {name : "correct", file: "correct.ogg"},
		     {name:"notthere", file: "notthere.ogg"},
		     {name:"trigger", file: "trigger.ogg"}
			     ];    

		 Karma._makeCollection(configs, 'audio');
		 setTimeout(
		     function(){
			 ok(k._counters.loaded === 2, 
			 "Counter of loaded assets was properly incremented");
			 ok(k._counters.errors === 1, 
			 "Counter of errors was properly incremented");
			 ok(k._counters.total === 3, 
			 "Counter of total assets properly incremented");
			 ok(checkErrorMsg(), "Error Message generated");

			 k.reset();
			 start();
		     }, 2000);
	     });

	 asyncTest("Karma._makeCollection(audio, 'audio') w/ 3 good sounds, 1 localized", 
		 function(){
		     expect(4);
		     k.reset()._init({locale: "es"});
		     var configs = [ 
			 {name : "correct", file:"correct.ogg", 
			  _localized: true},
			 {name:"incorrect", file:"incorrect.ogg"},
			 {name:"trigger", file:"trigger.ogg"}
			     ];    

		     Karma._makeCollection(configs, 'audio');
		     setTimeout(
			 function(){
			     ok(k.audio.correct._path === 
				"assets/es/audio/", 
			     "can access sound by name");
			     ok(k._counters.loaded === 3, 
			 "Counter of loaded assets was properly incremented");
			     ok(k._counters.errors === 0, 
				"Counter of errors hasn't changed");
			     ok(k._counters.total === 3, 
				"Counter of total assets properly incremented");
			     start();
		     }, 2000);
	     });

	 test("Karma._makeCollection for Canvases",
	      function(){
		  expect(7);
		  var configs = [{name: "myCanvas"}];
		  ok(shouldError(
			 function(){
			     Karma._makeCollection(configs, 'canvas');
			 }
		     ), "throws error if domId not specified");		     
		  
		  configs = [{name: "myCanvas", domId:"notThere"}];
		  ok(shouldError(
			 function(){
			     Karma._makeCollection(configs, "canvas");
			 }
		     ), "throws error if domId not present in html");
		  
		  configs = [{name: "myCanvas", domId:"testCanvas"}];
		  ok(shouldNotError(
			 function(){
			     Karma._makeCollection(configs, 'canvas');
			 }
		     ), "accepts valid canvas options");

		  ok(k.canvas.myCanvas.ctx instanceof 
		     CanvasRenderingContext2D, "The canvas has valid 2D Context");
		  ok(k.canvas.myCanvas.width === 200,
		     "width set the dom value");
		  ok(k.canvas.myCanvas.height === 200,
		     "height set the dom value");

		  configs = [{name: "badCanvas", domId:"badCanvas", 
		      width: 100}];
		  ok(shouldError(
			 function(){
			     Karma._makeCollection(configs, 'canvas');
			 }
		     ),	 
		     "Throws error if only width or height but not both" +
		     " specified in the html");
		  
	      });

	 test("Karma._makeCollection for SVGs",
	      function(){
		  expect(5);
		  var configs = [{name: "mySvg"}];
		  ok(shouldError(
			 function(){
			     Karma._makeCollection(configs, 'svg');
			 }
		     ), "throws error if domId not specified");		     
		  
		  configs = [{name: "mySvg", domId:"notThere"}];
		  ok(shouldError(
			 function(){
			     Karma._makeCollection(configs, 'svg');
			 }
		     ), "throws error if domId not present in html");
		  
		  configs = [{name: "mySvg", domId:"testSvg"}];
		  ok(shouldNotError(
			 function(){
			     Karma._makeCollection(configs, 'svg');
			 }
		     ), "accepts valid svg options");

		  ok(k.svg.mySvg, "Valid svg accessible by name");

		  configs = [{name: "badSvg", domId:"badSvg", 
		      width: 100}];
		  ok(shouldError(
			 function(){
			     Karma._makeCollection(configs, 'svg');
			 }
		     ),	 
		     "Throws error if only width or height but not both" +
		     " specified in the html");
		  
	      });
     
	 
	 asyncTest("Karma._makeCollection good svg loads",  
	       function(){
	           expect(4);
		   k.reset()._init();
		   $('#nothiddendiv').css('display', 'block');
		   var configs = [{name: "testSvg", domId:"testSvg"}];
		   Karma._makeCollection(configs, 'svg');
		   
		 setTimeout(
	             function(){
			 ok(k.svg.testSvg, "svg exists");
			 ok(k._counters.loaded >= 1, "loaded counter incremented");
			 ok(k._counters.total === 1, "total counter incremented ");
			 ok(k._counters.errors === 0, "error counter not incremented");
			 $('#nothiddendiv').css('display', 'none');
		         start();	 
		     }, 1000);
	     });

	  asyncTest("Karma._makeCollection good localized svg loads",  
	       function(){
	           expect(3);
		   k.reset()._init();
		   $('#nothiddendiv').css('display', 'block');
		   var configs = [{name: "testSvg", domId:"testSvg", 
			      _localized : true}];
		   Karma._makeCollection(configs, 'svg');
		 setTimeout(
	             function(){
			 ok(k._counters.loaded >= 1, "loaded counter incremented " +
			    "with good localized svg");
			 ok(k._counters.total === 1, "total counter incremented " +
			    "with good localized svg");
			 ok(k._counters.errors === 0, "error counter not incremented " +
			    "with good localized svg");
			 $('#nothiddendiv').css('display', 'none');

		        start();	 
		     }, 500);
	     });	 

	 //Karma._makeVideos tests
	 

	 //Karma.karma.radians
	 test('Karma.radians',
	       function(){
		   expect(1);
		   ok(Karma.radians(50) >= 0.87 &&
		      Karma.radians(50) <= 0.88,
		      "correct result computed");
	       });

	 //Karma.distance2
	 test('Karma.distance2',
	      function(){
		  ok(Karma.distance2({x: 1, y:2}, {x: 9, y: 15}) === 64,
		    "returns correct value");
	      });

	 //Karma.distance
	 test('Karma.distance',
	      function(){
		  ok(Karma.distance({x: 1, y:2}, {x: 9, y: 15}) === 8,
		    "returns correct value");
	      });

	 //Karma.rand
	 test('Karma.rand',
	      function(){
		  var rand = Karma.rand(5, 8);
		  ok(rand >= 5 && rand <= 8, 
		     "Generates valid range of numbers");
	      }
	     );



	 test("k.canvas['testCanvas'].strokeStyle('#ffffff') " +
	      "sets strokeStyle correctly", 
	      function(){
		  expect(3);
		  var configs = [{name: "myCanvas", domId:"testCanvas"}];
		  Karma._makeCollection(configs, 'canvas');
		  k.canvas.myCanvas.strokeStyle('#ffffff'); 
		  ok( k.canvas.myCanvas.ctx.strokeStyle ===
		      '#ffffff', 'Stroke style properly set');
		  ok(shouldError(
		      function(){
			  k.canvas.myCanvas.ctx.strokeStyle('#ffffff'); 

		      }),"ctx.strokeStyle is a property and not a function");
		  
		  ok(shouldNotError(
		      function(){
			  k.canvas.myCanvas.strokeStyle('#ffffff')
			      .clear().save().restore().clearRect(0, 0, 20, 20);
		      }),"Chaining works!");

	      });


	 /*
	  //this is boilerplate text for an asyncTest
	  //don't delete it unless u love typing ;)
	  asyncTest(" ",  
	       function(){
	         expect(0);
		 setTimeout(
	             function(){
		        start();	 
	  }, 500);
	     });

	  */
	 
	 test("Karma.karma.ready() removes 'Karma is loading ... ' message",  
		   function(){
		       expect(1);
		       k.reset()._init();
		       k.ready();
		       //firefox puts a space between the colon and none
		       var regex = new RegExp('display: *none');
		       ok(regex.test(k._statusDiv.getAttribute('style')), 
			       "ready() hides Karma is loading message");
			    
		      /* setTimeout(function() {
			       var style = k._statusDiv.getAttribute('style');
			       ok(style === "display:none;", 
			       "ready() hides Karma is loading message");
			       start();
				   },
 			       10);*/
		   });

	 //for whatever reason, this test only works if run last
	 asyncTest("Karma.karma.ready() check callback execution",  
		   function(){
		       expect(2);
		       //test that callback isn't called while asset isn't ready yet
		       var foo = "bar";
		       var testCb = function () { 
			   foo = "baz";
		       };

		       k.reset()._init();
		       k._counters.total = 5000;  
		       k.ready(testCb);
		       ok( foo === "bar", "callback not called before all assets loaded");
		       k._counters.total = k._counters.loaded = 0;
		  
		       //wait for callback to be called by ready 
		       setTimeout(function() {
				      ok(foo === "baz", 
					  "ready() calls callback after assets loaded");
				      //called in last asyncTest to remove 
				      //error messages
				      k.reset();
				      start();
				  },
				  10);
		   }); 	 

	 test("Karma.kCanvas 2DRendering Context Helpers",
	      function(){
		 k.reset()._init();
		 /* var config = {name: "myCanvas", domId:"testCanvas"};
		  var myCanvas = Karma.kCanvas._init(config);
		  myCanvas.globalAlpha(0.1);
		  ok(myCanvas.ctx.globalAlpha === 0.1,
		     "globalAlpha property set");
		  */
		  ok( 1=== 1, 'foo');
		  k.reset();
		  
	      });
	


     });