2 * mobile support unit tests
5 $.testHelper.excludeFileProtocol(function(){
6 var prependToFn = $.fn.prependTo,
7 moduleName = "jquery.mobile.support";
11 //NOTE undo any mocking
12 $.fn.prependTo = prependToFn;
16 // NOTE following two tests have debatable value as they only
17 // prevent property name changes and improper attribute checks
18 asyncTest( "detects functionality from basic affirmative properties and attributes", function(){
19 // TODO expose properties for less brittle tests
21 WebKitTransitionEvent: true,
24 window.history.pushState = function(){};
25 window.history.replaceState = function(){};
27 $.mobile.media = function(){ return true; };
29 $.testHelper.reloadModule( moduleName ).done( function() {
30 ok($.support.cssTransitions, "css transitions are supported" );
31 ok($.support.pushState, "push state is supported" );
32 ok($.support.mediaquery, "media queries are supported" );
37 asyncTest( "detects orientation change", function() {
40 onorientationchange: true
43 $.testHelper.reloadModule( "jquery.mobile.support.orientation" ).done( function() {
44 ok($.support.orientation, "orientation is supported" );
49 asyncTest( "detects touch", function() {
50 document.ontouchend = true;
52 $.testHelper.reloadModule( "jquery.mobile.support.touch" ).done( function() {
53 ok( $.mobile.support.touch, "touch is supported" );
54 ok( $.support.touch, "touch is supported" );
59 asyncTest( "detects functionality from basic negative properties and attributes (where possible)", function(){
60 delete window["orientation"];
62 $.testHelper.reloadModule( "jquery.mobile.support.orientation" ).done( function() {
63 ok(!$.support.orientation, "orientation is not supported" );
68 // NOTE mocks prependTo to simulate base href updates or lack thereof
69 var mockBaseCheck = function( url ){
70 var prependToFn = $.fn.prependTo;
72 $.fn.prependTo = function( selector ){
73 var result = prependToFn.call(this, selector);
74 if(this[0].href && this[0].href.indexOf("testurl") != -1)
75 result = [{href: url}];
80 asyncTest( "detects dynamic base tag when new base element added and base href updates", function(){
81 mockBaseCheck(location.protocol + '//' + location.host + location.pathname + "ui-dir/");
82 $.testHelper.reloadModule( moduleName ).done( function() {
83 ok($.support.dynamicBaseTag);
88 asyncTest( "detects no dynamic base tag when new base element added and base href unchanged", function(){
89 mockBaseCheck('testurl');
90 $.testHelper.reloadModule( moduleName ).done( function() {
91 ok(!$.support.dynamicBaseTag);
96 asyncTest( "jQM's IE browser check properly detects IE versions", function(){
97 $.testHelper.reloadModule( moduleName ).done( function() {
98 //here we're just comparing our version to what the conditional compilation finds
99 var ie = !!$.browser.msie, //get a boolean
100 version = parseInt( $.browser.version, 10),
101 jqmdetectedver = $.mobile.browser.ie;
104 deepEqual(version, jqmdetectedver, "It's IE and the version is correct");
107 deepEqual(ie, jqmdetectedver, "It's not IE");
114 //TODO propExists testing, refactor propExists into mockable method
115 //TODO scrollTop testing, refactor scrollTop logic into mockable method