2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 // find *Spec.js files in the src directory next to the corresponding source file
18 var test = window.test = {};
20 test.cb = (function( jasmine ) {
27 createSpy: function( name, arg, data, context ) {
28 return jasmine.createSpy( name ).and.callFake( function() {
29 callbacks.push( { cb: arguments[ arg || 0 ], data: data, context: context } );
33 var exec = callbacks.shift();
34 exec.cb.apply( exec.context, exec.data );
37 while( callbacks.length ) {
45 test.clock = ( function() {
46 var id = 0, timers, saved;
47 var names = [ "setTimeout", "setInterval", "clearTimeout", "clearInterval" ];
48 var byNext = function( a, b ) { return a.next - b.next; };
50 setTimeout: function( fn, t ) {
51 timers.push( { id: id, fn: fn, next: t, t: t, type: "t" } );
54 clearTimeout: function( id ) {
55 timers = timers.filter( function( timer ) { return timer.id !== id; } );
57 setInterval: function( fn, t ) {
58 timers.push( { id: id, fn: fn, next: t, t: t, type: "i" } );
61 clearInterval: function( id ) {
62 timers = timers.filter( function( timer ) { return timer.id !== id; } );
70 names.forEach( function( n ) {
76 names.forEach( function( n ) {
84 timers.sort( byNext );
86 if( t0.type === "t" ) {