561b37e82fc6e6f222062be46cb5b21e02ae4e8d
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / tests / unit / core / core_scroll.js
1 /*
2  * mobile core unit tests
3  */
4
5 (function($){
6         var libName = "jquery.mobile.core.js",
7                         scrollTimeout = 20, // TODO expose timing as an attribute
8                         scrollStartEnabledTimeout = 150;
9
10         module(libName, {
11                 setup: function(){
12                         $("<div id='scroll-testing' style='height: 1000px'></div>").appendTo("body");
13                 },
14
15                 teardown: function(){
16                         $("#scroll-testing").remove();
17                 }
18         });
19
20         var scrollUp = function( pos ){
21                 $(window).scrollTop(1000);
22                 ok($(window).scrollTop() > 0, $(window).scrollTop());
23                 $.mobile.silentScroll(pos);
24         };
25
26         asyncTest( "silent scroll scrolls the page to the top by default", function(){
27                 scrollUp();
28
29                 setTimeout(function(){
30                         same($(window).scrollTop(), 0);
31                         start();
32                 }, scrollTimeout);
33         });
34
35         asyncTest( "silent scroll scrolls the page to the passed y position", function(){
36                 var pos = 10;
37                 scrollUp(pos);
38
39                 setTimeout(function(){
40                         same($(window).scrollTop(), pos);
41                         start();
42                 }, scrollTimeout);
43         });
44
45         test( "silent scroll is async", function(){
46                 scrollUp();
47                 ok($(window).scrollTop() != 0, "scrolltop position should not be zero");
48                 start();
49         });
50
51         asyncTest( "scrolling marks scrollstart as disabled for 150 ms", function(){
52                 $.event.special.scrollstart.enabled = true;
53                 scrollUp();
54                 ok(!$.event.special.scrollstart.enabled);
55
56                 setTimeout(function(){
57                         ok($.event.special.scrollstart.enabled);
58                         start();
59                 }, scrollStartEnabledTimeout);
60         });
61
62         //TODO test that silentScroll is called on window load
63 })(jQuery);