Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / tests / unit / button-markup / buttonMarkup_core.js
1 /*
2  * mobile buttonMarkup tests
3  */
4 (function($){
5         module("jquery.mobile.buttonMarkup.js");
6
7         test( "header buttons should have the header class", function() {
8                 var headerButton1 = $("#header-button-1"),
9                     headerButton2 = $("#header-button-2");
10
11                 ok((headerButton1.hasClass("ui-btn-left") &&
12                     headerButton2.hasClass("ui-btn-right")), "first header button should have class 'ui-btn-left' and the second one should have 'ui-btn-right'");
13         });
14
15         test( "control group buttons should be enhanced inside a footer", function(){
16                 var group, linkCount;
17
18                 group = $("#control-group-footer");
19                 linkCount = group.find( "a" ).length;
20
21                 deepEqual( group.find("a.ui-btn").length, linkCount, "all 4 links should be buttons");
22                 deepEqual( group.find("a > span.ui-corner-left").length, 1, "only 1 left cornered button");
23                 deepEqual( group.find("a > span.ui-corner-right").length, 1, "only 1 right cornered button");
24                 deepEqual( group.find("a > span:not(.ui-corner-left):not(.ui-corner-right)").length, linkCount - 2, "only 2 buttons are cornered");
25         });
26
27         test( "control group buttons should respect theme-related data attributes", function(){
28                 var group = $("#control-group-content");
29
30                 ok(!group.find('[data-shadow=false]').hasClass("ui-shadow"),
31                          "buttons with data-shadow=false should not have the ui-shadow class");
32                 ok(!group.find('[data-corners=false]').hasClass("ui-btn-corner-all"),
33                          "buttons with data-corners=false should not have the ui-btn-corner-all class");
34                 ok(!group.find('[data-iconshadow=false] .ui-icon').hasClass("ui-icon-shadow"),
35                          "buttons with data-iconshadow=false should not have the ui-icon-shadow class on their icons");
36         });
37
38         // Test for issue #3046 and #3054:
39         test( "mousedown on SVG elements should not throw an exception", function(){
40                 var svg = $("#embedded-svg"),
41                         success = true,
42                         rect;
43                 ok(svg.length > 0, "found embedded svg document" );
44                 if ( svg.length > 0 ) {
45                         rect = $( "rect", svg );
46                         ok(rect.length > 0, "found rect" );
47                         try {
48                                 rect.trigger("mousedown");
49                         } catch ( ex ) {
50                                 success = false;
51                         }
52                         ok( success, "mousedown executed without exception");
53                 }
54         });
55
56         test( "Elements with “data-mini='true'” should have “ui-mini” class attached to enhanced element.", function(){
57                 var $mini = $("#mini"),
58                         $full = $("#full"),
59                         $minicontrol = $('#mini-control');
60
61                 ok( $full.not('.ui-mini'), "Original element does not have data attribute, enhanced version does not recieve .ui-mini.");
62                 ok( $mini.is('.ui-mini'), "Original element has data attribute, enhanced version recieves .ui-mini." );
63                 ok( $minicontrol.is('.ui-mini'), "Controlgroup has data attribute and recieves .ui-mini.");
64         });
65
66         test( "Ensure icon positioning defaults to left, and can be overridden with “data-iconpos”", function() {
67                 var posdefault = $("#iconpos1"),
68                     posleft = $("#iconpos2"),
69                         posright = $("#iconpos3");
70
71                 ok( posdefault.hasClass("ui-btn-icon-left"), "Button with unspecified icon position gets .ui-btn-icon-left" );
72                 ok( posleft.hasClass("ui-btn-icon-left"), "Button with left icon positioning specified .ui-btn-icon-left" );
73                 ok( posright.hasClass("ui-btn-icon-right"), "Button with right icon positioning specified .ui-btn-icon-right" );
74
75         });
76
77         asyncTest( "ui-btn-* should be applied based on a setting", function() {
78                 // force touch support so the timeout is set
79                 $.Event.prototype.originalEvent = {
80                         type: "touch"
81                 };
82
83                 var $btn = $( "#hover-delay" );
84
85
86                 $btn.trigger( "vmousedown" );
87
88                 setTimeout(function() {
89                                 ok( $btn.attr("class").indexOf( "ui-btn-down" ) == -1, "button doesn't have the down class yet" );
90                 }, $.mobile.buttonMarkup.hoverDelay / 2);
91
92                 setTimeout(function() {
93                                 ok( $btn.attr("class").indexOf( "ui-btn-down" ) >= 0, "button has the down class yet" );
94                                 start();
95                 }, $.mobile.buttonMarkup.hoverDelay + 100 );
96         });
97 })(jQuery);