mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
added tests for mobile.support, still working on mocking for property check on body styles
This commit is contained in:
parent
d94b2c536b
commit
370d745bf3
3 changed files with 77 additions and 39 deletions
|
|
@ -23,13 +23,6 @@
|
|||
</ol>
|
||||
|
||||
<div id="main" style="position: absolute; top: -10000px; left: -10000px;">
|
||||
|
||||
<div id="widget-wrapper">
|
||||
<div id="widget">
|
||||
<div>...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -24,13 +24,6 @@
|
|||
</ol>
|
||||
|
||||
<div id="main" style="position: absolute; top: -10000px; left: -10000px;">
|
||||
|
||||
<div id="widget-wrapper">
|
||||
<div id="widget">
|
||||
<div>...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -1,36 +1,88 @@
|
|||
/*
|
||||
* mobile support unit tests
|
||||
*/
|
||||
|
||||
(function( $ ) {
|
||||
var reloadLib = function(){
|
||||
$("script[src$=support.js]").appendTo("body");
|
||||
};
|
||||
//NOTE alert tester that running the file locally will not work for these tests
|
||||
if ( location.protocol == "file:" ) {
|
||||
var message = "Tests require script reload and cannot be run via file: protocol";
|
||||
|
||||
module("mobile.support", {
|
||||
teardown: function(){
|
||||
$("body script[src$=support.js]").remove();
|
||||
}
|
||||
});
|
||||
test(message, function(){
|
||||
ok(false, message);
|
||||
});
|
||||
} else {
|
||||
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;
|
||||
|
||||
// NOTE test has debatable value, only prevents property name changes
|
||||
// and improper sources for attribute checks
|
||||
test( "detects functionality from basic properties and attributes", function(){
|
||||
// TODO expose properties for less brittle tests
|
||||
$.extend(window, {
|
||||
orientation: true,
|
||||
WebKitTransitionEvent: true
|
||||
module("mobile.support", {
|
||||
teardown: function(){
|
||||
//NOTE undo any mocking
|
||||
$.fn.prependTo = prependToFn;
|
||||
}
|
||||
});
|
||||
|
||||
document["ontouchend"] = true;
|
||||
history.pushState = function(){};
|
||||
$.mobile.media = function(){ return true; };
|
||||
// NOTE following two tests have debatable value as they only
|
||||
// prevent property name changes and improper attribute checks
|
||||
test( "detects functionality from basic affirmative properties and attributes", function(){
|
||||
// TODO expose properties for less brittle tests
|
||||
$.extend(window, {
|
||||
WebKitTransitionEvent: true,
|
||||
orientation: true
|
||||
});
|
||||
|
||||
reloadLib();
|
||||
document.ontouchend = true;
|
||||
|
||||
ok($.support.orientation);
|
||||
ok($.support.cssTransitions);
|
||||
ok($.support.touch);
|
||||
ok($.support.pushState);
|
||||
ok($.support.mediaquery);
|
||||
});
|
||||
history.pushState = function(){};
|
||||
$.mobile.media = function(){ return true; };
|
||||
|
||||
reloadLib();
|
||||
|
||||
ok($.support.orientation);
|
||||
ok($.support.touch);
|
||||
ok($.support.cssTransitions);
|
||||
ok($.support.pushState);
|
||||
ok($.support.mediaquery);
|
||||
});
|
||||
|
||||
test( "detects functionality from basic negative properties and attributes (where possible)", function(){
|
||||
delete window["orientation"];
|
||||
delete document["ontouchend"];
|
||||
|
||||
reloadLib();
|
||||
|
||||
ok(!$.support.orientation);
|
||||
ok(!$.support.touch);
|
||||
});
|
||||
|
||||
// NOTE mocks prependTo to simulate base href updates or lack thereof
|
||||
var mockBaseCheck = function( url ){
|
||||
var prependToFn = $.fn.prependTo;
|
||||
|
||||
$.fn.prependTo = function( selector ){
|
||||
var result = prependToFn.call($(this), selector);
|
||||
if(this[0].href && this[0].href.indexOf("testurl") != -1)
|
||||
result = [{href: url}];
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
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();
|
||||
ok($.support.dynamicBaseTag);
|
||||
});
|
||||
|
||||
test( "detects no dynamic base tag when new base element added and base href unchanged", function(){
|
||||
mockBaseCheck('testurl');
|
||||
reloadLib();
|
||||
ok(!$.support.dynamicBaseTag);
|
||||
});
|
||||
}
|
||||
})(jQuery);
|
||||
Loading…
Reference in a new issue