| 1 |
define( [ |
| 2 |
"jquery" |
| 3 |
], function( $ ) { |
| 4 |
|
| 5 |
var exports = {}, |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
oldActive = 0, |
| 10 |
splice = [].splice; |
| 11 |
|
| 12 |
exports.forceScrollableWindow = function( appendTo ) { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
return $( "<div>" ) |
| 17 |
.css( { |
| 18 |
height: "11000px", |
| 19 |
width: "11000px" |
| 20 |
} ) |
| 21 |
.appendTo( appendTo || "#qunit-fixture" ); |
| 22 |
}; |
| 23 |
|
| 24 |
exports.onFocus = function( element, onFocus ) { |
| 25 |
var fn = function( event ) { |
| 26 |
if ( !event.originalEvent ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
element.off( "focus", fn ); |
| 30 |
onFocus(); |
| 31 |
}; |
| 32 |
|
| 33 |
element.on( "focus", fn )[ 0 ].focus(); |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
exports.moduleAfterEach = function( assert ) { |
| 41 |
|
| 42 |
|
| 43 |
if ( jQuery.timers && jQuery.timers.length !== 0 ) { |
| 44 |
assert.equal( jQuery.timers.length, 0, "No timers are still running" ); |
| 45 |
splice.call( jQuery.timers, 0, jQuery.timers.length ); |
| 46 |
jQuery.fx.stop(); |
| 47 |
} |
| 48 |
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) { |
| 49 |
assert.equal( jQuery.active, oldActive, "No AJAX requests are still active" ); |
| 50 |
oldActive = jQuery.active; |
| 51 |
} |
| 52 |
}; |
| 53 |
|
| 54 |
exports.testIframe = function( title, fileName, func, wrapper, iframeStyles ) { |
| 55 |
if ( !wrapper ) { |
| 56 |
wrapper = QUnit.test; |
| 57 |
} |
| 58 |
wrapper.call( QUnit, title, function( assert ) { |
| 59 |
var done = assert.async(), |
| 60 |
$iframe = jQuery( "<iframe></iframe>" ) |
| 61 |
.css( { |
| 62 |
position: "absolute", |
| 63 |
top: "0", |
| 64 |
left: "-600px", |
| 65 |
width: "500px", |
| 66 |
zIndex: 1, |
| 67 |
background: "white" |
| 68 |
} ) |
| 69 |
.attr( { id: "qunit-fixture-iframe", src: fileName } ); |
| 70 |
|
| 71 |
|
| 72 |
if ( iframeStyles ) { |
| 73 |
$iframe.css( iframeStyles ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
window.iframeCallback = function() { |
| 79 |
var args = Array.prototype.slice.call( arguments ); |
| 80 |
|
| 81 |
args.unshift( assert ); |
| 82 |
|
| 83 |
setTimeout( function() { |
| 84 |
var result; |
| 85 |
|
| 86 |
this.iframeCallback = undefined; |
| 87 |
|
| 88 |
result = func.apply( this, args ); |
| 89 |
|
| 90 |
function finish() { |
| 91 |
func = function() {}; |
| 92 |
$iframe.remove(); |
| 93 |
done(); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
if ( result && result.then ) { |
| 98 |
result.then( finish ); |
| 99 |
} else { |
| 100 |
finish(); |
| 101 |
} |
| 102 |
} ); |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
$iframe.prependTo( document.body ); |
| 109 |
} ); |
| 110 |
}; |
| 111 |
window.iframeCallback = undefined; |
| 112 |
|
| 113 |
return exports; |
| 114 |
|
| 115 |
} ); |