2 * mobile support unit tests
5 $.testHelper.excludeFileProtocol(function(){
6 var prependToFn = $.fn.prependTo,
7 libName = "jquery.mobile.support.js";
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 test( "detects functionality from basic affirmative properties and attributes", function(){
19 // TODO expose properties for less brittle tests
21 WebKitTransitionEvent: true,
23 onorientationchange: true
26 document.ontouchend = true;
28 window.history.pushState = function(){};
29 window.history.replaceState = function(){};
31 $.mobile.media = function(){ return true; };
33 $.testHelper.reloadLib(libName);
35 ok($.support.orientation);
37 ok($.support.cssTransitions);
38 ok($.support.pushState);
39 ok($.support.mediaquery);
42 test( "detects functionality from basic negative properties and attributes (where possible)", function(){
43 delete window["orientation"];
44 delete document["ontouchend"];
46 $.testHelper.reloadLib(libName);
48 ok(!$.support.orientation);
52 // NOTE mocks prependTo to simulate base href updates or lack thereof
53 var mockBaseCheck = function( url ){
54 var prependToFn = $.fn.prependTo;
56 $.fn.prependTo = function( selector ){
57 var result = prependToFn.call(this, selector);
58 if(this[0].href && this[0].href.indexOf("testurl") != -1)
59 result = [{href: url}];
64 test( "detects dynamic base tag when new base element added and base href updates", function(){
65 mockBaseCheck(location.protocol + '//' + location.host + location.pathname + "ui-dir/");
66 $.testHelper.reloadLib(libName);
67 ok($.support.dynamicBaseTag);
70 test( "detects no dynamic base tag when new base element added and base href unchanged", function(){
71 mockBaseCheck('testurl');
72 $.testHelper.reloadLib(libName);
73 ok(!$.support.dynamicBaseTag);
76 test( "jQM's IE browser check properly detects IE versions", function(){
77 $.testHelper.reloadLib(libName);
79 //here we're just comparing our version to what the conditional compilation finds
80 var ie = !!$.browser.msie, //get a boolean
81 version = parseInt( $.browser.version, 10),
82 jqmdetectedver = $.mobile.browser.ie;
85 same(version, jqmdetectedver, "It's IE and the version is correct");
88 same(ie, jqmdetectedver, "It's not IE");
93 //TODO propExists testing, refactor propExists into mockable method
94 //TODO scrollTop testing, refactor scrollTop logic into mockable method