unittests/tests/widgets/sliderWidget.js
branchpopcorn-port
changeset 318 463382f92211
parent 259 7d748154f0b5
child 427 440ffc18f827
equal deleted inserted replaced
317:a3492448fa9a 318:463382f92211
     1 function test_slider_widget() {
     1 function test_slider_widget() {
     2  module("slider widget testing", 
     2  module("slider widget testing",
     3   {setup : function() {    
     3   {setup : function() {
     4     this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
     4     this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
     5     
     5 
     6     this.dt = new IriSP.DataLoader();
     6     this.dt = new IriSP.DataLoader();
     7     this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */
     7     this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */
     8             
     8 
     9     this.config = {
     9     this.config = {
    10 						metadata:{
    10 						metadata:{
    11 							format:'cinelab',
    11 							format:'cinelab',
    12 							src:'test.json',
    12 							src:'test.json',
    13 							load:'json'},
    13 							load:'json'},
    15 							height:1,
    15 							height:1,
    16 							mode:'radio',
    16 							mode:'radio',
    17 							container:'widget-div',
    17 							container:'widget-div',
    18 							debug:true,
    18 							debug:true,
    19 							css:'../src/css/LdtPlayer.css'}
    19 							css:'../src/css/LdtPlayer.css'}
    20     },  
    20     },
    21   teardown: function() {
    21   teardown: function() {
    22     /* free the popcorn object because it has signal handlers attached to it */
    22     /* free the popcorn object because it has signal handlers attached to it */
    23     this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
    23     this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
    24   }});
    24   }});
    25   
    25 
    26   test("test widget initialization", function() {  
    26   test("test widget initialization", function() {
    27     var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);    
    27     var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);
    28     widget.draw();
    28     widget.draw();
    29     
    29 
    30     ok(IriSP.jQuery("#widget-div").children().hasClass("sliderBackground"), "test if the div has been set-up");
    30     ok(IriSP.jQuery("#widget-div").children().hasClass("Ldt-sliderBackground"), "test if the div has been set-up");
    31     ok(IriSP.jQuery("#widget-div").children().hasClass("sliderForeground"), "test if the div has been set-up");
    31     ok(IriSP.jQuery("#widget-div").children().hasClass("Ldt-sliderForeground"), "test if the div has been set-up");
    32   
    32 
    33   });
    33   });
    34   
    34 
    35   test("test slider seeking", function() {    
    35   test("test slider seeking", function() {
    36     var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);    
    36     var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);
    37     widget.draw();
    37     widget.draw();
    38     
    38 
    39     var spy_callback = this.spy();
    39     var spy_callback = this.spy();
    40     widget._Popcorn.listen("timeupdate", spy_callback);       
    40     widget._Popcorn.listen("timeupdate", spy_callback);
    41     IriSP.jQuery("#widget-div").children().click();
    41     IriSP.jQuery("#widget-div").children().click();
    42     ok(spy_callback.called, "handling function has been called");
    42     ok(spy_callback.called, "handling function has been called");
    43   });
    43   });
    44   
    44 
    45     test("test slider dragging", function() {
    45   test("test slider dragging", function() {
    46     
    46 
    47     /* comes from the jquery unit tests */
    47     /* comes from the jquery unit tests */
    48     var drag = function(handle, dx, dy) {
    48     var drag = function(handle, dx, dy) {
    49       var element = el.data("draggable").element;
    49       var element = el.data("draggable").element;
    50       $(handle).simulate("drag", {
    50       $(handle).simulate("drag", {
    51         dx: dx || 0,
    51         dx: dx || 0,
    52         dy: dy || 0
    52         dy: dy || 0
    53       });
    53       });
    54       dragged = { dx: dx, dy: dy };
    54       dragged = { dx: dx, dy: dy };
    55     }    
    55     }
    56     
    56 
    57     var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);    
    57     var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);
    58     widget.draw();
    58     widget.draw();
    59     
    59 
    60     var spy_callback = this.spy();
    60     var spy_callback = this.spy();
    61     widget._Popcorn.listen("timeupdate", spy_callback);
    61     widget._Popcorn.listen("timeupdate", spy_callback);
    62     
    62 
    63     IriSP.jQuery("#widget-div").children(".positionMarker").simulate("drag", 70, 50);
    63     IriSP.jQuery("#widget-div").children(".Ldt-sliderPositionMarker").simulate("drag", 70, 50);
    64     ok(spy_callback.called, "handling function has been called");
    64     ok(spy_callback.called, "handling function has been called");
    65   });
    65   });
    66 }
    66 }