added reload lib helper, moved support core over

This commit is contained in:
John Bender 2010-11-23 00:27:31 +08:00 committed by Scott Jehl
parent 4bec9b1ae2
commit 521777dcb7
2 changed files with 22 additions and 14 deletions

View file

@ -6,7 +6,7 @@
$.testHelper = {
excludeFileProtocol: function(callback){
var message = "Tests require script reload and cannot be run via file: protocol";
//NOTE alert tester that running the file locally will not work for these tests
if ( location.protocol == "file:" ) {
test(message, function(){
ok(false, message);
@ -14,6 +14,21 @@
} else {
callback();
}
},
reloadCounts: {},
reloadLib: function(libName){
var lib = $("script[src$=" + libName + "]").clone(),
src = lib.attr('src');
if(this.reloadCounts[libName] === undefined) {
this.reloadCounts[libName] = 0;
}
//NOTE append "cache breaker" to force reload
lib.attr('src', src + "?" + this.reloadCounts[libName]++);
$("body").append(lib);
}
};
})(jQuery);

View file

@ -4,15 +4,8 @@
(function( $ ) {
$.testHelper.excludeFileProtocol(function(){
var reloadCount = 0,
lib = $("script[src$=support.js]"),
src = lib.attr('src'),
reloadLib = function(){
//NOTE append "cache breaker" to force reload
lib.attr('src', src + "?" + reloadCount++);
$("body").append(lib);
},
prependToFn = $.fn.prependTo;
var prependToFn = $.fn.prependTo,
libName = "jquery.mobile.support.js";
module("mobile.support", {
teardown: function(){
@ -35,7 +28,7 @@
history.pushState = function(){};
$.mobile.media = function(){ return true; };
reloadLib();
$.testHelper.reloadLib(libName);
ok($.support.orientation);
ok($.support.touch);
@ -48,7 +41,7 @@
delete window["orientation"];
delete document["ontouchend"];
reloadLib();
$.testHelper.reloadLib(libName);
ok(!$.support.orientation);
ok(!$.support.touch);
@ -68,13 +61,13 @@
test( "detects dynamic base tag when new base element added and base href updates", function(){
mockBaseCheck(location.protocol + '//' + location.host + location.pathname + "ui-dir/");
reloadLib();
$.testHelper.reloadLib(libName);
ok($.support.dynamicBaseTag);
});
test( "detects no dynamic base tag when new base element added and base href unchanged", function(){
mockBaseCheck('testurl');
reloadLib();
$.testHelper.reloadLib(libName);
ok(!$.support.dynamicBaseTag);
});