Tokentextarea: Fix issues
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / tests / unit / page / page_core.js
1 /*
2  * mobile page unit tests
3  */
4 (function($){
5         var libName = 'jquery.mobile.page',
6                 themedefault = $.mobile.page.prototype.options.theme,
7                 keepNative = $.mobile.page.prototype.options.keepNative;
8
9         module(libName, {
10                 setup: function() {
11                         $.mobile.page.prototype.options.keepNative = keepNative;
12                 }
13         });
14
15         var eventStack = [],
16                 etargets = [],
17                 cEvents=[],
18                 cTargets=[];
19
20         $( document ).bind( "pagebeforecreate pagecreate", function( e ){
21                 eventStack.push( e.type );
22                 etargets.push( e.target );
23         });
24
25         $( "#c" ).live( "pagebeforecreate", function( e ){
26                 cEvents.push( e.type );
27                 cTargets.push( e.target );
28                 return false;
29         });
30
31         test( "pagecreate event fires when page is created", function(){
32                 ok( eventStack[0] === "pagecreate" || eventStack[1] === "pagecreate" );
33         });
34
35         test( "pagebeforecreate event fires when page is created", function(){
36                 ok( eventStack[0] === "pagebeforecreate" || eventStack[1] === "pagebeforecreate" );
37         });
38
39         test( "pagebeforecreate fires before pagecreate", function(){
40                 ok( eventStack[0] === "pagebeforecreate" );
41         });
42
43         test( "target of pagebeforecreate event was div #a", function(){
44                 ok( $( etargets[0] ).is("#a") );
45         });
46
47         test( "target of pagecreate event was div #a" , function(){
48                 ok( $( etargets[0] ).is("#a") );
49         });
50
51         test( "page element has ui-page class" , function(){
52                 ok( $( "#a" ).hasClass( "ui-page" ) );
53         });
54
55         test( "page element has default body theme when not overidden" , function(){
56                 ok( $( "#a" ).hasClass( "ui-body-" + themedefault ) );
57         });
58
59         test( "B page has non-default theme matching its data-theme attr" , function(){
60                 $( "#b" ).page();
61                 var btheme = $( "#b" ).jqmData( "theme" );
62                 ok( $( "#b" ).hasClass( "ui-body-" + btheme ) );
63         });
64
65         test( "Binding to pagebeforecreate and returning false prevents pagecreate event from firing" , function(){
66                 $( "#c" ).page();
67
68                 ok( cEvents[0] === "pagebeforecreate" );
69                 ok( !cTargets[1] );
70         });
71
72         test( "Binding to pagebeforecreate and returning false prevents classes from being applied to page" , function(){
73                 $( "#c" ).page();
74
75                 ok( !$( "#c" ).hasClass( "ui-body-" + themedefault ) );
76                 ok( !$( "#c" ).hasClass( "ui-page" ) );
77         });
78
79         test( "keepNativeSelector returns the default where keepNative is not different", function() {
80                 var pageProto = $.mobile.page.prototype;
81                 pageProto.options.keepNative = pageProto.options.keepNativeDefault;
82
83                 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
84         });
85
86         test( "keepNativeSelector returns the default where keepNative is empty, undefined, whitespace", function() {
87                 var pageProto = $.mobile.page.prototype;
88
89                 pageProto.options.keepNative = "";
90                 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
91
92                 pageProto.options.keepNative = undefined;
93                 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
94
95                 pageProto.options.keepNative = "  ";
96                 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
97         });
98
99         test( "keepNativeSelector returns a selector joined with the default", function() {
100                 var pageProto = $.mobile.page.prototype;
101
102                 pageProto.options.keepNative = "foo, bar";
103                 same(pageProto.keepNativeSelector(), "foo, bar, " + pageProto.options.keepNativeDefault);
104         });
105
106         test( "links inside an ignored container do not enhance", function() {
107                 var $ignored = $( "#ignored-link" ), $enhanced = $( "#enhanced-link" );
108
109                 $.mobile.ignoreContentEnabled = true;
110
111                 $ignored.parent().trigger( "create" );
112                 same( $ignored.attr( "class" ), undefined, "ignored link doesn't have link class" );
113
114                 $enhanced.parent().trigger( "create" );
115                 same( $enhanced.attr( "class" ).indexOf("ui-link"), 0, "enhanced link has link class" );
116
117                 $.mobile.ignoreContentEnabled = false;
118         });
119         
120         
121         asyncTest( "page container is updated to page theme at pagebeforeshow", function(){
122                 
123                 expect( 1 );
124                 
125                 var pageTheme = "ui-overlay-" + $.mobile.activePage.page( "option", "theme" );
126
127                 $.mobile.pageContainer.removeClass( pageTheme );
128                 
129                 $.mobile.activePage
130                         .bind( "pagebeforeshow", function(){
131                                 ok( $.mobile.pageContainer.hasClass( pageTheme ), "Page container has the same theme as the page on pagebeforeshow" );
132                                 start();
133                         })
134                         .trigger( "pagebeforeshow" );
135
136         } );
137         
138         asyncTest( "page container is updated to page theme at pagebeforeshow", function(){
139                 
140                 expect( 1 );
141                 
142                 var pageTheme = "ui-overlay-" + $.mobile.activePage.page( "option", "theme" );
143
144                 $.mobile.pageContainer.addClass( pageTheme );
145                 
146                 $.mobile.activePage
147                         .bind( "pagebeforehide", function(){
148                                 ok( !$.mobile.pageContainer.hasClass( pageTheme ), "Page container does not have the same theme as the page on pagebeforeshow" );
149                                 start();
150                         })
151                         .trigger( "pagebeforehide" );
152
153         } );
154         
155         
156         
157 })(jQuery);