f7a390e107ffefb7ea6821f48d214791f5cb22c3
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / tests / unit / support / support_core.js
1 /*
2  * mobile support unit tests
3  */
4
5 $.testHelper.excludeFileProtocol(function(){
6         var     prependToFn = $.fn.prependTo,
7                         libName = "jquery.mobile.support.js";
8
9         module(libName, {
10                 teardown: function(){
11                         //NOTE undo any mocking
12                         $.fn.prependTo = prependToFn;
13                 }
14         });
15
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
20                 $.extend(window, {
21                         WebKitTransitionEvent: true,
22                         orientation: true,
23                         onorientationchange: true
24                 });
25
26                 document.ontouchend = true;
27
28                 window.history.pushState = function(){};
29                 window.history.replaceState = function(){};
30
31                 $.mobile.media = function(){ return true; };
32
33                 $.testHelper.reloadLib(libName);
34
35                 ok($.support.orientation);
36                 ok($.support.touch);
37                 ok($.support.cssTransitions);
38                 ok($.support.pushState);
39                 ok($.support.mediaquery);
40         });
41
42         test( "detects functionality from basic negative properties and attributes (where possible)", function(){
43                 delete window["orientation"];
44                 delete document["ontouchend"];
45
46                 $.testHelper.reloadLib(libName);
47
48                 ok(!$.support.orientation);
49                 ok(!$.support.touch);
50         });
51
52         // NOTE mocks prependTo to simulate base href updates or lack thereof
53         var mockBaseCheck = function( url ){
54                 var prependToFn = $.fn.prependTo;
55
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}];
60                         return result;
61                 };
62         };
63
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);
68         });
69
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);
74         });
75
76         test( "jQM's IE browser check properly detects IE versions", function(){
77                 $.testHelper.reloadLib(libName);
78
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;
83
84                         if( ie ){
85                                 same(version, jqmdetectedver, "It's IE and the version is correct");
86                         }
87                         else{
88                                 same(ie, jqmdetectedver, "It's not IE");
89                         }
90         });
91
92
93         //TODO propExists testing, refactor propExists into mockable method
94         //TODO scrollTop testing, refactor scrollTop logic into mockable method
95 });