2 * mobile support unit tests
7 excludeFileProtocol: function(callback){
8 var message = "Tests require script reload and cannot be run via file: protocol";
10 if (location.protocol == "file:") {
11 test(message, function(){
19 // TODO prevent test suite loads when the browser doesn't support push state
20 // and push-state false is defined.
21 setPushStateFor: function( libs ) {
22 if( $.support.pushState && location.search.indexOf( "push-state" ) >= 0 ) {
23 $.support.pushState = false;
26 $.each(libs, function(i, l) {
27 $( "<script>", { src: l }).appendTo("head");
33 reloadLib: function(libName){
34 if(this.reloads[libName] === undefined) {
35 this.reloads[libName] = {
36 lib: $("script[src$='" + libName + "']"),
41 var lib = this.reloads[libName].lib.clone(),
42 src = lib.attr('src');
44 //NOTE append "cache breaker" to force reload
45 lib.attr('src', src + "?" + this.reloads[libName].count++);
46 $("body").append(lib);
49 rerunQunit: function(){
52 $("script:not([src*='.\/'])").each(function(i, elem){
53 var src = elem.src.split("/");
54 self.reloadLib(src[src.length - 1]);
59 alterExtend: function(extraExtension){
60 var extendFn = $.extend;
62 $.extend = function(object, extension){
63 // NOTE extend the object as normal
64 var result = extendFn.apply(this, arguments);
66 // NOTE add custom extensions
67 result = extendFn(result, extraExtension);
72 hideActivePageWhenComplete: function() {
73 if( $('#qunit-testresult').length > 0 ) {
74 $('.ui-page-active').css('display', 'none');
76 setTimeout($.testHelper.hideActivePageWhenComplete, 500);
80 openPage: function(hash){
81 location.href = location.href.split('#')[0] + hash;
84 sequence: function(fns, interval){
85 $.each(fns, function(i, fn){
86 setTimeout(fn, i * interval);
90 pageSequence: function(fns){
91 this.eventSequence("pagechange", fns);
94 eventSequence: function(event, fns, timedOut){
98 if( fn === undefined ) return;
100 // if a pagechange or defined event is never triggered
101 // continue in the sequence to alert possible failures
102 var warnTimer = setTimeout(function(){
103 self.eventSequence(event, fns, true);
106 // bind the recursive call to the event
107 $.mobile.pageContainer.one(event, function(){
108 clearTimeout(warnTimer);
110 // Let the current stack unwind before we fire off the next item in the sequence.
111 // TODO setTimeout(self.pageSequence, 0, [fns, event]);
112 setTimeout(function(){ self.eventSequence(event, fns); }, 0);
115 // invoke the function which should, in some fashion,
116 // trigger the defined event
120 decorate: function(opts){
121 var thisVal = opts.self || window;
125 opts.before && opts.before.apply(thisVal, arguments);
126 returnVal = opts.fn.apply(thisVal, arguments);
127 opts.after && opts.after.apply(thisVal, arguments);
133 assertUrlLocation: function( args ) {
134 var parts = $.mobile.path.parseUrl( location.href ),
135 pathnameOnward = location.href.replace( parts.domain, "" );
137 if( $.support.pushState ) {
138 same( pathnameOnward, args.hashOrPush || args.push, args.report );
140 same( parts.hash, "#" + (args.hashOrPush || args.hash), args.report );