2 * mobile support unit tests
7 // This function takes sets of files to load asynchronously. Each set will be loaded after
8 // the previous set has completed loading. That is, each require and it's dependencies in a
9 // set will be loaded asynchronously, but each set will be run in serial.
10 asyncLoad: function( seq ) {
12 baseUrl: "../../../js"
15 function loadSeq( seq, i ){
17 $( document ).ready( function() {
18 var $fixture = $( '#qunit-fixture' );
19 if ( $fixture.length ) {
20 QUnit.config.fixture = $fixture.html();
27 require( seq[i], function() {
32 // stop qunit from running the tests until everything is in the page
33 QUnit.config.autostart = false;
38 excludeFileProtocol: function(callback){
39 var message = "Tests require script reload and cannot be run via file: protocol";
41 if (location.protocol == "file:") {
42 test(message, function(){
50 // TODO prevent test suite loads when the browser doesn't support push state
51 // and push-state false is defined.
52 setPushState: function() {
53 if( $.support.pushState && location.search.indexOf( "push-state" ) >= 0 ) {
54 $.support.pushState = false;
60 reloadModule: function(libName){
61 var deferred = $.Deferred(),
64 // where a module loader isn't defined use the old way
65 if( !window.require ) {
66 this.reloadLib( libName );
71 if(this.reloads[libName] === undefined) {
72 this.reloads[libName] = {
77 //Clear internal cache of module inside of require
78 context = require.s.contexts._;
79 delete context.defined[libName];
80 delete context.specified[libName];
81 delete context.loaded[libName];
82 delete context.urlFetched[require.toUrl(libName + '.js')];
86 baseUrl: "../../../js"
96 reloadLib: function(libName){
97 if(this.reloads[libName] === undefined) {
98 this.reloads[libName] = {
99 lib: $("script[src$='" + libName + "']"),
104 var lib = this.reloads[libName].lib.clone(),
105 src = lib.attr('src');
107 //NOTE append "cache breaker" to force reload
108 lib.attr('src', src + "?" + this.reloads[libName].count++);
109 $("body").append(lib);
112 rerunQunit: function(){
115 $("script:not([src*='.\/'])").each(function(i, elem){
116 var src = elem.src.split("/");
117 self.reloadLib(src[src.length - 1]);
122 alterExtend: function(extraExtension){
123 var extendFn = $.extend;
125 $.extend = function(object, extension){
126 // NOTE extend the object as normal
127 var result = extendFn.apply(this, arguments);
129 // NOTE add custom extensions
130 result = extendFn(result, extraExtension);
135 hideActivePageWhenComplete: function() {
136 if( $('#qunit-testresult').length > 0 ) {
137 $('.ui-page-active').css('display', 'none');
139 setTimeout($.testHelper.hideActivePageWhenComplete, 500);
143 openPage: function(hash){
144 location.href = location.href.split('#')[0] + hash;
147 sequence: function(fns, interval){
148 $.each(fns, function(i, fn){
149 setTimeout(fn, i * interval);
153 pageSequence: function( fns ){
154 this.eventSequence( "pagechange", fns );
157 eventSequence: function( event, fns, timedOut ){
159 $.each(fns, function( i, fn ) {
161 if( i !== fns.length - 1) seq.push( event );
164 this.eventCascade( seq );
167 eventCascade: function( sequence, timedOut ) {
168 var fn = sequence.shift(),
169 event = sequence.shift(),
172 if( fn === undefined ) {
177 // if a pagechange or defined event is never triggered
178 // continue in the sequence to alert possible failures
179 var warnTimer = setTimeout(function() {
180 self.eventCascade( sequence, true );
183 // bind the recursive call to the event
184 $.mobile.pageContainer.one(event, function() {
185 clearTimeout( warnTimer );
187 // Let the current stack unwind before we fire off the next item in the sequence.
188 // TODO setTimeout(self.pageSequence, 0, sequence);
189 setTimeout(function(){ self.eventCascade(sequence); }, 0);
193 // invoke the function which should, in some fashion,
194 // trigger the next event
198 deferredSequence: function(fns) {
199 var fn = fns.shift(),
200 deferred = $.Deferred(),
205 if ( res && $.type( res.done ) === "function" ) {
206 res.done(function() {
207 self.deferredSequence( fns ).done(function() {
212 self.deferredSequence( fns ).done(function() {
222 decorate: function(opts){
223 var thisVal = opts.self || window;
227 opts.before && opts.before.apply(thisVal, arguments);
228 returnVal = opts.fn.apply(thisVal, arguments);
229 opts.after && opts.after.apply(thisVal, arguments);
235 assertUrlLocation: function( args ) {
236 var parts = $.mobile.path.parseUrl( location.href ),
237 pathnameOnward = location.href.replace( parts.domain, "" );
239 if( $.support.pushState ) {
240 same( pathnameOnward, args.hashOrPush || args.push, args.report );
242 same( parts.hash, "#" + (args.hashOrPush || args.hash), args.report );