Revert "Export"
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / tests / unit / support / support_core.js
1 /*
2  * mobile support unit tests
3  */
4
5 $.testHelper.excludeFileProtocol(function(){
6         var     prependToFn = $.fn.prependTo,
7                 moduleName = "jquery.mobile.support";
8
9         module(moduleName, {
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         asyncTest( "detects functionality from basic affirmative properties and attributes", function(){
19                 // TODO expose properties for less brittle tests
20                 $.extend(window, {
21                         WebKitTransitionEvent: true,
22                 });
23
24                 window.history.pushState = function(){};
25                 window.history.replaceState = function(){};
26
27                 $.mobile.media = function(){ return true; };
28
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" );
33                         start();
34                 });
35         });
36
37         asyncTest( "detects orientation change", function() {
38                 $.extend(window, {
39                         orientation: true,
40                         onorientationchange: true
41                 });
42
43                 $.testHelper.reloadModule( "jquery.mobile.support.orientation" ).done( function() {
44                         ok($.support.orientation, "orientation is supported" );
45                         start();
46                 });
47         });
48
49         asyncTest( "detects touch", function() {
50                 document.ontouchend = true;
51
52                 $.testHelper.reloadModule( "jquery.mobile.support.touch" ).done( function() {
53                         ok( $.mobile.support.touch, "touch is supported" );
54                         ok( $.support.touch, "touch is supported" );
55                         start();
56                 });
57         });
58
59         asyncTest( "detects functionality from basic negative properties and attributes (where possible)", function(){
60                 delete window["orientation"];
61
62                 $.testHelper.reloadModule( "jquery.mobile.support.orientation" ).done( function() {
63                         ok(!$.support.orientation, "orientation is not supported" );
64                         start();
65                 });
66         });
67
68         // NOTE mocks prependTo to simulate base href updates or lack thereof
69         var mockBaseCheck = function( url ){
70                 var prependToFn = $.fn.prependTo;
71
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}];
76                         return result;
77                 };
78         };
79
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);
84                         start();
85                 });
86         });
87
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);
92                         start();
93                 });
94         });
95
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;
102
103                         if( ie ){
104                                 deepEqual(version, jqmdetectedver, "It's IE and the version is correct");
105                         }
106                         else{
107                                 deepEqual(ie, jqmdetectedver, "It's not IE");
108                         }
109                         start();
110                 });
111         });
112
113
114         //TODO propExists testing, refactor propExists into mockable method
115         //TODO scrollTop testing, refactor scrollTop logic into mockable method
116 });